mirror of
https://github.com/langgenius/dify-docs-archived.git
synced 2026-07-01 20:35:52 -04:00
update: structured outputs case (#738)
This commit is contained in:
@@ -212,7 +212,7 @@ Click **Add Field** and set parameters below:
|
||||
|
||||
1. Click the AI Generate icon, select a model (like GPT-4o), and describe what you need:
|
||||
|
||||
> “I need a JSON Schema for user profiles with username (string), age (number), and interests (array).”
|
||||
> "I need a JSON Schema for user profiles with username (string), age (number), and interests (array)."
|
||||
|
||||
2. Click **Generate** to create a schema:
|
||||
|
||||
@@ -285,7 +285,7 @@ Click **Add Field** and set parameters below:
|
||||
|
||||
1. Click the AI Generate icon, select a model (like GPT-4o), and describe what you need:
|
||||
|
||||
> “I need a JSON Schema for user profiles with username (string), age (number), and interests (array).”
|
||||
> "I need a JSON Schema for user profiles with username (string), age (number), and interests (array)."
|
||||
|
||||
2. Click **Generate** to create a schema:
|
||||
|
||||
@@ -357,40 +357,8 @@ For more information about exception handling methods, please refer to the [Erro
|
||||
|
||||
* **Structured Outputs**
|
||||
|
||||
**Scenario**: You are building a user feedback analysis workflow on Dify. The LLM node needs to read user reviews and return standardized ratings and comments in a consistent format for downstream nodes to process.
|
||||
**Case: Customer Information Intake Form**
|
||||
|
||||
**Solution**: In your workflow’s LLM node, you can use the JSON Schema Editor to define a structured format. This ensures the LLM generates results in a strict predefined format instead of unstructured text.
|
||||
Watch the following video to learn how to use JSON Schema Editor to collect customer information:
|
||||
|
||||
1. Define your output structure in the JSON Schema Editor:
|
||||
|
||||
```
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"rating": {
|
||||
"type": "integer",
|
||||
"description": "user's rating"
|
||||
},
|
||||
"comment": {
|
||||
"type": "string",
|
||||
"description": "user's comments"
|
||||
}
|
||||
},
|
||||
"required": ["rating", "comment"]
|
||||
}
|
||||
```
|
||||
|
||||
2. Test it with a review in your Start node:
|
||||
|
||||
> “This product is excellent!”
|
||||
|
||||
3. The LLM node will return a clean, structured response:
|
||||
|
||||
```
|
||||
{
|
||||
"structured_output": {
|
||||
"comment": "This product is excellent!",
|
||||
"rating": 5
|
||||
}
|
||||
}
|
||||
```
|
||||
{% embed url="https://youtu.be/u8NQFxrsaW0" %}
|
||||
@@ -366,45 +366,6 @@ LLMノードの出力変数をクリックし、構造化スイッチの設定
|
||||
|
||||
* **構造化出力**
|
||||
|
||||
**シナリオ**: Difyワークフローを使用してユーザーフィードバック分析ワークフローを構築する際に、LLMノードはユーザー評価を読み取り、標準化された評価とコメントを返します。これにより、後続ノードがデータを正しく処理できるよう、データ形式の一貫性を保ちます。
|
||||
以下の動画を通じて、構造化出力機能を使用して顧客情報を収集する方法を理解することができます:
|
||||
|
||||
**解決策**: ワークフローのLLMノードで、**JSONスキーマエディタ**を使用してLLM出力の構造化フォーマットを定義できます。これにより、LLM は自由形式のテキストではなく、定義済みのフォーマットに従って結果を出力します。
|
||||
|
||||
**操作手順**:
|
||||
|
||||
1. **LLM**ノードの**JSONスキーマエディタ**で、以下のフィールドを追加します。これによりLLMは指定の構造でデータを出力します。
|
||||
|
||||
```
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"rating": {
|
||||
"type": "integer",
|
||||
"description": "ユーザー評価"
|
||||
},
|
||||
"comment": {
|
||||
"type": "string",
|
||||
"description": "ユーザーコメント"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"rating",
|
||||
"comment"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
2. ワークフローの**開始**ノードで、ユーザー評価を入力します。例:
|
||||
|
||||
> "この製品はとても素晴らしいです。使用体験も良好です!"
|
||||
|
||||
3. **JSONスキーマエディタ**による処理後、LLMから出力される**構造化データ**は以下のようになります。
|
||||
|
||||
```
|
||||
{
|
||||
"structured_output": { // LLMからの出力データ
|
||||
"comment": "この製品はとても素晴らしいです。使用体験も良好です!",
|
||||
"rating": 5
|
||||
}
|
||||
}
|
||||
```
|
||||
{% embed url="https://youtu.be/u8NQFxrsaW0" %}
|
||||
@@ -383,45 +383,8 @@ LLM 节点处理信息时有可能会遇到输入文本超过 Token 限制,未
|
||||
|
||||
* **结构化输出**
|
||||
|
||||
**场景**:你正在使用 Dify 构建一个用户反馈分析工作流。LLM 节点需要读取用户评价,并返回标准化的评分和评论内容,确保数据格式一致,便于后续节点处理。
|
||||
**案例:客户信息采集表单**
|
||||
|
||||
**解决方案**:在工作流的 LLM 节点中,使用 **JSON Schema 编辑器** 定义结构化格式。这样能确保 LLM 生成的结果被限制在预设格式中,而非输出杂乱文本。
|
||||
你可以通过以下视频,了解如何使用结构化输出功能采集客户信息:
|
||||
|
||||
**操作步骤**:
|
||||
|
||||
1. 在 **LLM** 节点的 **JSON Schema 编辑器** 中,添加以下字段,确保 LLM 按照规定的结构输出数据:
|
||||
|
||||
```
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"rating": {
|
||||
"type": "integer",
|
||||
"description": "user's rating"
|
||||
},
|
||||
"comment": {
|
||||
"type": "string",
|
||||
"description": "user's comments"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"rating",
|
||||
"comment"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
2. 在工作流的 **开始** 节点,输入一个用户评价,如:
|
||||
|
||||
> "这个产品非常棒,使用体验很好!"
|
||||
|
||||
3. 经过 **JSON Schema 编辑器** 的处理,AI 生成的 **结构化数据** 如下:
|
||||
|
||||
```
|
||||
{
|
||||
"structured_output": {
|
||||
"comment": "这个产品非常棒,使用体验很好!",
|
||||
"rating": 5
|
||||
}
|
||||
}
|
||||
```
|
||||
{% embed url="https://youtu.be/u8NQFxrsaW0" %}
|
||||
Reference in New Issue
Block a user