fix: code
parent
201d16be46
commit
731689398c
|
|
@ -31,7 +31,10 @@ In workflows, it's often necessary to deal with unstructured data processing, su
|
||||||
def main(http_response: str) -> str:
|
def main(http_response: str) -> str:
|
||||||
import json
|
import json
|
||||||
data = json.loads(http_response)
|
data = json.loads(http_response)
|
||||||
return data['data']['name']
|
return {
|
||||||
|
# do not forget to declare 'result' in the output variables
|
||||||
|
'result': data['data']['name']
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Mathematical Calculations
|
### Mathematical Calculations
|
||||||
|
|
@ -40,19 +43,27 @@ When complex mathematical calculations are needed in workflows, the code node ca
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def main(x: list) -> float:
|
def main(x: list) -> float:
|
||||||
return sum([(i - sum(x) / len(x)) ** 2 for i in x]) / len(x)
|
return {
|
||||||
|
# do not forget to declare 'result' in the output variables
|
||||||
|
'result': sum([(i - sum(x) / len(x)) ** 2 for i in x]) / len(x)
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Data Concatenation
|
### Data Concatenation
|
||||||
|
|
||||||
|
Sometimes, you may need to concatenate multiple data sources, such as multiple knowledge retrievals, data searches, API calls, etc. The code node can help you integrate these data sources. Here's a simple example that merges data from two knowledge bases:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def main(knowledge1: list, knowledge2: list) -> list:
|
def main(knowledge1: list, knowledge2: list) -> list:
|
||||||
return knowledge1 + knowledge2
|
return {
|
||||||
|
# do not forget to declare 'result' in the output variables
|
||||||
|
'result': knowledge1 + knowledge2
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## 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
|
If 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
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,10 @@
|
||||||
def main(http_response: str) -> str:
|
def main(http_response: str) -> str:
|
||||||
import json
|
import json
|
||||||
data = json.loads(http_response)
|
data = json.loads(http_response)
|
||||||
return data['data']['name']
|
return {
|
||||||
|
# 注意在输出变量中声明result
|
||||||
|
'result': data['data']['name']
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### 数学计算
|
### 数学计算
|
||||||
|
|
@ -35,7 +38,10 @@ def main(http_response: str) -> str:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def main(x: list) -> float:
|
def main(x: list) -> float:
|
||||||
return sum([(i - sum(x) / len(x)) ** 2 for i in x]) / len(x)
|
return {
|
||||||
|
# 注意在输出变量中声明result
|
||||||
|
'result' : sum([(i - sum(x) / len(x)) ** 2 for i in x]) / len(x)
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### 拼接数据
|
### 拼接数据
|
||||||
|
|
@ -43,7 +49,10 @@ def main(x: list) -> float:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def main(knowledge1: list, knowledge2: list) -> list:
|
def main(knowledge1: list, knowledge2: list) -> list:
|
||||||
return knowledge1 + knowledge2
|
return {
|
||||||
|
# 注意在输出变量中声明result
|
||||||
|
'result': knowledge1 + knowledge2
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## 本地部署
|
## 本地部署
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue