Fix type errors in example code

This commit is contained in:
Fisher
2025-06-14 23:33:43 +08:00
parent a9965491d3
commit eb236df692
3 changed files with 9 additions and 9 deletions

View File

@@ -31,7 +31,7 @@ Using the code node, you can perform the following common operations:
In workflows, you often have to deal with unstructured data processing, such as parsing, extracting, and transforming JSON strings. A typical example is data processing from an HTTP node. In common API return structures, data may be nested within multiple layers of JSON objects, and you need to extract certain fields. The code node can help you perform these operations. Here is a simple example that extracts the `data.name` field from a JSON string returned by an HTTP node:
```python
def main(http_response: str) -> str:
def main(http_response: str) -> dict:
import json
data = json.loads(http_response)
return {
@@ -45,7 +45,7 @@ def main(http_response: str) -> str:
When you need to perform complex mathematical calculations in a workflow, you can also use the code node. For example, calculating a complex mathematical formula or performing some statistical analysis on data. Here is a simple example that calculates the variance of an array:
```python
def main(x: list) -> float:
def main(x: list) -> dict:
return {
# Note to declare 'result' in the output variables
'result': sum([(i - sum(x) / len(x)) ** 2 for i in x]) / len(x)
@@ -57,7 +57,7 @@ def main(x: list) -> float:
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 together. Here is a simple example that merges data from two knowledge bases:
```python
def main(knowledge1: list, knowledge2: list) -> list:
def main(knowledge1: list, knowledge2: list) -> dict:
return {
# Note to declare 'result' in the output variables
'result': knowledge1 + knowledge2

View File

@@ -24,7 +24,7 @@ version: '日本語'
ワークフローでは、しばしば非構造化データの処理が必要です。例えば、JSON文字列の解析、抽出、変換などです。典型的な例として、HTTPードのデータ処理があります。一般的なAPI応答構造では、データが多層のJSONオブジェクトにネストされていることがあり、特定のフィールドを抽出する必要があります。コードードはこれらの操作を支援します。以下は、HTTPードから返されたJSON文字列から`data.name`フィールドを抽出する簡単な例です:
```python
def main(http_response: str) -> str:
def main(http_response: str) -> dict:
import json
data = json.loads(http_response)
return {
@@ -38,7 +38,7 @@ def main(http_response: str) -> str:
ワークフロー内で複雑な数学計算を行う必要がある場合、コードノードを使用できます。例えば、複雑な数学公式の計算やデータの統計分析です。以下は、配列の平方差を計算する簡単な例です:
```python
def main(x: list) -> float:
def main(x: list) -> dict:
return {
# 出力変数にresultを宣言することに注意
'result' : sum([(i - sum(x) / len(x)) ** 2 for i in x]) / len(x)
@@ -50,7 +50,7 @@ def main(x: list) -> float:
時には、複数のデータソースを結合する必要がある場合があります。例えば、複数の知識検索、データサーチ、API呼び出しなどです。コードードはこれらのデータソースを統合するのに役立ちます。以下は、2つのナレッジベースのデータを結合する簡単な例です
```python
def main(knowledge1: list, knowledge2: list) -> list:
def main(knowledge1: list, knowledge2: list) -> dict:
return {
# 出力変数にresultを宣言することに注意
'result': knowledge1 + knowledge2

View File

@@ -30,7 +30,7 @@ title: 代码执行
在工作流中经常要面对非结构化的数据处理如JSON字符串的解析、提取、转换等。最典型的例子就是HTTP节点的数据处理在常见的API返回结构中数据可能会被嵌套在多层JSON对象中而我们需要提取其中的某些字段。代码节点可以帮助你完成这些操作下面是一个简单的例子它从HTTP节点返回的JSON字符串中提取了`data.name`字段:
```python
def main(http_response: str) -> str:
def main(http_response: str) -> dict:
import json
data = json.loads(http_response)
return {
@@ -44,7 +44,7 @@ def main(http_response: str) -> str:
当工作流中需要进行一些复杂的数学计算时,也可以使用代码节点。例如,计算一个复杂的数学公式,或者对数据进行一些统计分析。下面是一个简单的例子,它计算了一个数组的平方差:
```python
def main(x: list) -> float:
def main(x: list) -> dict:
return {
# 注意在输出变量中声明result
'result' : sum([(i - sum(x) / len(x)) ** 2 for i in x]) / len(x)
@@ -56,7 +56,7 @@ def main(x: list) -> float:
有时也许你需要拼接多个数据源如多个知识检索、数据搜索、API调用等代码节点可以帮助你将这些数据源整合在一起。下面是一个简单的例子它将两个知识库的数据合并在一起
```python
def main(knowledge1: list, knowledge2: list) -> list:
def main(knowledge1: list, knowledge2: list) -> dict:
return {
# 注意在输出变量中声明result
'result': knowledge1 + knowledge2