GITBOOK-79: No subject
parent
4773ad3720
commit
85a379a00b
Binary file not shown.
|
After Width: | Height: | Size: 155 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 104 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 542 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 248 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 74 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 85 KiB |
|
|
@ -1,10 +1,11 @@
|
||||||
# Code
|
# Code
|
||||||
|
|
||||||
## Navigation
|
## Navigation
|
||||||
- [Introduction](#introduction)
|
|
||||||
- [Use Cases](#use-cases)
|
* [Introduction](code.md#introduction)
|
||||||
- [Local Deployment](#local-deployment)
|
* [Use Cases](code.md#use-cases)
|
||||||
- [Security Policy](#security-policy)
|
* [Local Deployment](code.md#local-deployment)
|
||||||
|
* [Security Policy](code.md#security-policy)
|
||||||
|
|
||||||
## Introduction
|
## Introduction
|
||||||
|
|
||||||
|
|
@ -12,15 +13,18 @@ The code node supports the execution of Python / NodeJS code to perform data tra
|
||||||
|
|
||||||
This node significantly enhances developers' flexibility, allowing them to embed custom Python or Javascript scripts in their workflows and manipulate variables in ways that preset nodes cannot achieve. Through configuration options, you can specify the required input and output variables and write the corresponding execution code:
|
This node significantly enhances developers' flexibility, allowing them to embed custom Python or Javascript scripts in their workflows and manipulate variables in ways that preset nodes cannot achieve. Through configuration options, you can specify the required input and output variables and write the corresponding execution code:
|
||||||
|
|
||||||
<figure><img src="../../../.gitbook/assets/image (157).png" alt="" width="375"><figcaption></figcaption></figure>
|
<figure><img src="../../../.gitbook/assets/output.png" alt="" width="375"><figcaption></figcaption></figure>
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
If you need to use variables from other nodes within the code node, you need to define the variable names in `input variables` and reference these variables, see [Variable Reference](../key_concept.md#variable) for details.
|
|
||||||
|
If you need to use variables from other nodes within the code node, you need to define the variable names in `input variables` and reference these variables, see [Variable Reference](../key\_concept.md#variable) for details.
|
||||||
|
|
||||||
## Use Cases
|
## Use Cases
|
||||||
|
|
||||||
With the code node, you can perform the following common operations:
|
With the code node, you can perform the following common operations:
|
||||||
|
|
||||||
### Structured Data Processing
|
### Structured Data Processing
|
||||||
|
|
||||||
In workflows, it's often necessary to deal with unstructured data processing, such as parsing, extracting, and transforming JSON strings. A typical example is data processing in the HTTP node, where data might be nested within multiple layers of JSON objects, and we need to extract certain fields. The code node can help you accomplish these tasks. Here's a simple example that extracts the `data.name` field from a JSON string returned by an HTTP node:
|
In workflows, it's often necessary to deal with unstructured data processing, such as parsing, extracting, and transforming JSON strings. A typical example is data processing in the HTTP node, where data might be nested within multiple layers of JSON objects, and we need to extract certain fields. The code node can help you accomplish these tasks. Here's a simple example that extracts the `data.name` field from a JSON string returned by an HTTP node:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
|
@ -31,6 +35,7 @@ def main(http_response: str) -> str:
|
||||||
```
|
```
|
||||||
|
|
||||||
### Mathematical Calculations
|
### Mathematical Calculations
|
||||||
|
|
||||||
When complex mathematical calculations are needed in workflows, the code node can also be used. For example, to calculate a complex mathematical formula or perform some statistical analysis on the data. Here is a simple example that calculates the variance of a list:
|
When complex mathematical calculations are needed in workflows, the code node can also be used. For example, to calculate a complex mathematical formula or perform some statistical analysis on the data. Here is a simple example that calculates the variance of a list:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
|
@ -46,10 +51,13 @@ def main(knowledge1: list, knowledge2: list) -> list:
|
||||||
```
|
```
|
||||||
|
|
||||||
## Local Deployment
|
## Local Deployment
|
||||||
|
|
||||||
f you are a user deploying locally, you need to start a sandbox service, which ensures that malicious code is not executed. Also, launching this service requires Docker, and you can find specific information about the Sandbox service [here](https://github.com/langgenius/dify/tree/main/docker/docker-compose.middleware.yaml). You can also directly start the service using docker-compose
|
f you are a user deploying locally, you need to start a sandbox service, which ensures that malicious code is not executed. Also, launching this service requires Docker, and you can find specific information about the Sandbox service [here](https://github.com/langgenius/dify/tree/main/docker/docker-compose.middleware.yaml). You can also directly start the service using docker-compose
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker-compose -f docker-compose.middleware.yaml up -d
|
docker-compose -f docker-compose.middleware.yaml up -d
|
||||||
```
|
```
|
||||||
|
|
||||||
## Security Policy
|
## Security Policy
|
||||||
|
|
||||||
The execution environment is sandboxed for both Python and Javascript, meaning that certain functionalities that require extensive system resources or pose security risks are not available. This includes, but is not limited to, direct file system access, network calls, and operating system-level commands.
|
The execution environment is sandboxed for both Python and Javascript, meaning that certain functionalities that require extensive system resources or pose security risks are not available. This includes, but is not limited to, direct file system access, network calls, and operating system-level commands.
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,6 @@
|
||||||
|
|
||||||
HTTP Request node lets you craft and dispatch HTTP requests to specified endpoints, enabling a wide range of integrations and data exchanges with external services. The node supports all common HTTP request methods, and lets you fully customize over the URL, headers, query parameters, body content, and authorization details of the request.
|
HTTP Request node lets you craft and dispatch HTTP requests to specified endpoints, enabling a wide range of integrations and data exchanges with external services. The node supports all common HTTP request methods, and lets you fully customize over the URL, headers, query parameters, body content, and authorization details of the request.
|
||||||
|
|
||||||
<figure><img src="https://langgenius.feishu.cn/space/api/box/stream/download/asynccode/?code=YjQ4Y2EyNjhlNWQ3NDA0ZGJiMWUzYTYyMWFkNWRlOThfek1Dd2c1Z3VwdU1jVGpqMkNrM2hzUUZmMXFEUldaOGpfVG9rZW46WGJwOGJuQ0pJb245TFN4aUtXUmNuUktFblVjXzE3MTI1OTc2ODg6MTcxMjYwMTI4OF9WNA" alt="" width="375"><figcaption></figcaption></figure>
|
<figure><img src="../../../.gitbook/assets/06f7c6ba-fbe0-4aeb-b7d4-fa1df0b07a5e.png" alt="" width="375"><figcaption></figcaption></figure>
|
||||||
|
|
||||||
A really handy feature with HTTP request is the ability to dynamically construct the request by inserting variables in different fields. For instance, in a customer support scenario, variables such as username or customer ID can be used to personalize automated responses sent via a POST request, or retrieve individual-specific information related to the customer.The HTTP request returns `body`, `status_code`, `headers`, and `files` as outputs. If the response includes files of [MIME](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics\_of\_HTTP/MIME\_types/Common\_types) types (currently limited to images), the node automatically saves these as `files` for downstream use.
|
A really handy feature with HTTP request is the ability to dynamically construct the request by inserting variables in different fields. For instance, in a customer support scenario, variables such as username or customer ID can be used to personalize automated responses sent via a POST request, or retrieve individual-specific information related to the customer.The HTTP request returns `body`, `status_code`, `headers`, and `files` as outputs. If the response includes files of [MIME](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics\_of\_HTTP/MIME\_types/Common\_types) types (currently limited to images), the node automatically saves these as `files` for downstream use.
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
Template lets you dynamically format and combine variables from previous nodes into a single text-based output using Jinja2, a powerful templating syntax for Python. It's useful for combining data from multiple sources into a specific structure required by subsequent nodes. The simple example below shows how to assemble an article by piecing together various previous outputs:
|
Template lets you dynamically format and combine variables from previous nodes into a single text-based output using Jinja2, a powerful templating syntax for Python. It's useful for combining data from multiple sources into a specific structure required by subsequent nodes. The simple example below shows how to assemble an article by piecing together various previous outputs:
|
||||||
|
|
||||||
<figure><img src="https://langgenius.feishu.cn/space/api/box/stream/download/asynccode/?code=MzE1NTFmODViNTFmMDQzNTg5YTZhMjFiODdlYjI4ZTFfRHRJVEJpNlNWVWVxYWs0c1I3c09OTzFCUUJoWURndkpfVG9rZW46R210aGJUa3R0b3ByTVV4QVlwc2NXNTFRbnZjXzE3MTI1OTczOTM6MTcxMjYwMDk5M19WNA" alt="" width="375"><figcaption></figcaption></figure>
|
<figure><img src="../../../.gitbook/assets/output (1).png" alt="" width="375"><figcaption></figcaption></figure>
|
||||||
|
|
||||||
Beyond naive use cases, you can create more complex templates as per Jinja's [documentation](https://jinja.palletsprojects.com/en/3.1.x/templates/) for a variety of tasks. Here's one template that structures retrieved chunks and their relevant metadata from a knowledge retrieval node into a formatted markdown:
|
Beyond naive use cases, you can create more complex templates as per Jinja's [documentation](https://jinja.palletsprojects.com/en/3.1.x/templates/) for a variety of tasks. Here's one template that structures retrieved chunks and their relevant metadata from a knowledge retrieval node into a formatted markdown:
|
||||||
|
|
||||||
|
|
@ -22,7 +22,7 @@ Beyond naive use cases, you can create more complex templates as per Jinja's [do
|
||||||
{% endraw %}
|
{% endraw %}
|
||||||
```
|
```
|
||||||
|
|
||||||
<figure><img src="https://langgenius.feishu.cn/space/api/box/stream/download/asynccode/?code=ZjFhMzg4MzVkNTU2MmY1ZDg0NTVjY2RiMWM5MDU4YmVfRUwybmxWQlZHc0pxNE5CVGx0b0JaYmVDdzlFeEJUMDBfVG9rZW46SktUN2JKaFhLb3hEemV4NVZQMmN1TGhsbmlmXzE3MTI1OTczOTM6MTcxMjYwMDk5M19WNA" alt=""><figcaption></figcaption></figure>
|
<figure><img src="../../../.gitbook/assets/output (2).png" alt=""><figcaption></figcaption></figure>
|
||||||
|
|
||||||
This template node can then be used within a Chatflow to return intermediate outputs to the end user, before a LLM response is initiated.
|
This template node can then be used within a Chatflow to return intermediate outputs to the end user, before a LLM response is initiated.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,10 @@
|
||||||
|
|
||||||
The Variable Assigner node serves as a hub for collecting branch outputs within the workflow, ensuring that regardless of which branch is taken, the output can be referenced by a single variable. The output can subsequently be manipulated by nodes downstream.
|
The Variable Assigner node serves as a hub for collecting branch outputs within the workflow, ensuring that regardless of which branch is taken, the output can be referenced by a single variable. The output can subsequently be manipulated by nodes downstream.
|
||||||
|
|
||||||
<figure><img src="https://langgenius.feishu.cn/space/api/box/stream/download/asynccode/?code=YWFlNDlhZWRmN2U5NmI1MzIyNzcwNDIxOGRjNmFmMjVfV29TVmt0SHdMdjlXRGR2TFdGdFdraGV2SFIxWmt3OFpfVG9rZW46WVJKZ2I5a1Ztb0RMRnp4ZnpQZGN5Z1Y5bnliXzE3MTI1OTc2NDg6MTcxMjYwMTI0OF9WNA" alt=""><figcaption></figcaption></figure>
|
<figure><img src="../../../.gitbook/assets/output (3).png" alt=""><figcaption></figcaption></figure>
|
||||||
|
|
||||||
Variable Assigner supports multiple types of output variables including `String`,`Number`, `Object`, and `Array`. Given the specified output type, you may add input variables from the dropdown list of variables to the node. The list of variables is derived from previous branch outputs and autofiltered based on the specified type.
|
Variable Assigner supports multiple types of output variables including `String`,`Number`, `Object`, and `Array`. Given the specified output type, you may add input variables from the dropdown list of variables to the node. The list of variables is derived from previous branch outputs and autofiltered based on the specified type.
|
||||||
|
|
||||||
<figure><img src="https://langgenius.feishu.cn/space/api/box/stream/download/asynccode/?code=MmQ5OGY3OTBiZjdkYjUzM2M4ODBmMWFmYTc0YzUwMzJfY0JJWkJBcWd1WlVXQTJ4RW56Uk11WE1pOEtZeXN6dzJfVG9rZW46TjA5TGJqWmF4b3VIb3R4eUI4ZWNkUWVkbnNmXzE3MTI1OTc0Mjg6MTcxMjYwMTAyOF9WNA" alt="" width="375"><figcaption></figcaption></figure>
|
<figure><img src="../../../.gitbook/assets/output (4).png" alt="" width="375"><figcaption></figcaption></figure>
|
||||||
|
|
||||||
Variable Assigner gives a single `output` variable of the specified type for downstream use.
|
Variable Assigner gives a single `output` variable of the specified type for downstream use.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue