diff --git a/en/.gitbook/assets/06f7c6ba-fbe0-4aeb-b7d4-fa1df0b07a5e.png b/en/.gitbook/assets/06f7c6ba-fbe0-4aeb-b7d4-fa1df0b07a5e.png new file mode 100644 index 0000000..39bfdab Binary files /dev/null and b/en/.gitbook/assets/06f7c6ba-fbe0-4aeb-b7d4-fa1df0b07a5e.png differ diff --git a/en/.gitbook/assets/output (1).png b/en/.gitbook/assets/output (1).png new file mode 100644 index 0000000..4e51f25 Binary files /dev/null and b/en/.gitbook/assets/output (1).png differ diff --git a/en/.gitbook/assets/output (2).png b/en/.gitbook/assets/output (2).png new file mode 100644 index 0000000..3d22d6a Binary files /dev/null and b/en/.gitbook/assets/output (2).png differ diff --git a/en/.gitbook/assets/output (3).png b/en/.gitbook/assets/output (3).png new file mode 100644 index 0000000..06575b9 Binary files /dev/null and b/en/.gitbook/assets/output (3).png differ diff --git a/en/.gitbook/assets/output (4).png b/en/.gitbook/assets/output (4).png new file mode 100644 index 0000000..16fec39 Binary files /dev/null and b/en/.gitbook/assets/output (4).png differ diff --git a/en/.gitbook/assets/output.png b/en/.gitbook/assets/output.png new file mode 100644 index 0000000..4644119 Binary files /dev/null and b/en/.gitbook/assets/output.png differ diff --git a/en/features/workflow/node/code.md b/en/features/workflow/node/code.md index 4c79e66..993b4cf 100644 --- a/en/features/workflow/node/code.md +++ b/en/features/workflow/node/code.md @@ -1,10 +1,11 @@ # Code ## Navigation -- [Introduction](#introduction) -- [Use Cases](#use-cases) -- [Local Deployment](#local-deployment) -- [Security Policy](#security-policy) + +* [Introduction](code.md#introduction) +* [Use Cases](code.md#use-cases) +* [Local Deployment](code.md#local-deployment) +* [Security Policy](code.md#security-policy) ## 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: -
+
## 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 + With the code node, you can perform the following common operations: ### 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: ```python @@ -31,6 +35,7 @@ def main(http_response: str) -> str: ``` ### 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: ```python @@ -46,10 +51,13 @@ def main(knowledge1: list, knowledge2: list) -> list: ``` ## 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 + ```bash docker-compose -f docker-compose.middleware.yaml up -d ``` ## 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. diff --git a/en/features/workflow/node/http-request.md b/en/features/workflow/node/http-request.md index 2ed514d..8a779be 100644 --- a/en/features/workflow/node/http-request.md +++ b/en/features/workflow/node/http-request.md @@ -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. -
+
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. diff --git a/en/features/workflow/node/template.md b/en/features/workflow/node/template.md index 334629b..f40f3b0 100644 --- a/en/features/workflow/node/template.md +++ b/en/features/workflow/node/template.md @@ -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: -
+
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 %} ``` -
+
This template node can then be used within a Chatflow to return intermediate outputs to the end user, before a LLM response is initiated. diff --git a/en/features/workflow/node/variable-assigner.md b/en/features/workflow/node/variable-assigner.md index 4c324c6..c87f994 100644 --- a/en/features/workflow/node/variable-assigner.md +++ b/en/features/workflow/node/variable-assigner.md @@ -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. -
+
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 gives a single `output` variable of the specified type for downstream use.