Docs: fix zh-cn sitemap (#1631)

Signed-off-by: Carson Yang <yangchuansheng33@gmail.com>
This commit is contained in:
Carson Yang
2024-05-29 15:46:43 +08:00
committed by GitHub
parent f1e16b209a
commit 5c8f2f95f7
107 changed files with 4 additions and 4 deletions

View File

@@ -0,0 +1,8 @@
---
weight: 400
title: "编排示例"
description: "介绍 FastGPT 的高级编排实践案例"
icon: "list"
draft: false
images: []
---

View File

@@ -0,0 +1,471 @@
---
title: 'Dalle3 绘图'
description: '使用 HTTP 模块绘制图片'
icon: 'image'
draft: false
toc: true
weight: 404
---
| | |
| --------------------- | --------------------- |
| ![](/imgs/demo-dalle1.webp) | ![](/imgs/demo-dalle2.webp) |
## OpenAI Dalle3 接口
先来看下官方接口的参数和响应值:
Body
```json
{
"model": "dall-e-3",
"prompt": "A cute baby sea otter",
"n": 1,
"size": "1024x1024"
}
```
Response
```json
{
"created": 1589478378,
"data": [
{
"url": "https://..."
},
{
"url": "https://..."
}
]
}
```
## 编排思路
1. 通过 AI 来优化图片绘制的提示词(这步省略了,自己找提示词即可)
2. 通过 `【HTTP 请求】模块` 调用 Dalle3 接口,获取图片的 URL。
3. 通过 `【文本加工】模块` 来构建 `Markdown` 的图片格式。
4. 通过 `【指定回复】模块` 来直接输出图片链接。
### 1. 构建 HTTP 模块
请求参数直接复制 Dalle3 接口的即可,并求改 prompt 为变量。需要增加一个 `Headers.Authorization`
Body:
```json
{
"model": "dall-e-3",
"prompt": "{{prompt}}",
"n": 1,
"size": "1024x1024"
}
```
Headers:
`Authorization: Bearer sk-xxx`
Response:
响应值需要根据 Dalle3 接口的返回值进行获取我们只绘制了1张图片所以只需要取第一张图片的 URL 即可。给 HTTP 模块增加一个自定义输出 `data[0].url`
### 2. 文本加工 - 构建图片链接
`Markdown` 语法中 `![图片描述](图片链接)` 表示插入图片图片链接由【HTTP 请求】模块输出。
因此可以增加一个输入来接收 `【HTTP 请求】模块` 的图片链接输出,并在 `【文本加工】模块 - 文本` 中通过变量来引用图片链接,从而得到一个完整的 `Markdown` 图片格式。
### 3. 指定回复
指定回复可以直接输出传入的内容到客户端,因此可以直接输出加工好的 `Markdown` 图片格式即可。
## 编排代码
{{% details title="编排配置" closed="true" %}}
```json
{
"nodes": [
{
"nodeId": "userGuide",
"name": "系统配置",
"intro": "可以配置应用的系统参数",
"avatar": "/imgs/workflow/userGuide.png",
"flowNodeType": "userGuide",
"position": {
"x": 531.2422736065552,
"y": -486.7611729549753
},
"inputs": [
{
"key": "welcomeText",
"renderTypeList": [
"hidden"
],
"valueType": "string",
"label": "core.app.Welcome Text",
"value": ""
},
{
"key": "variables",
"renderTypeList": [
"hidden"
],
"valueType": "any",
"label": "core.app.Chat Variable",
"value": []
},
{
"key": "questionGuide",
"valueType": "boolean",
"renderTypeList": [
"hidden"
],
"label": "core.app.Question Guide",
"value": false
},
{
"key": "tts",
"renderTypeList": [
"hidden"
],
"valueType": "any",
"label": "",
"value": {
"type": "web"
}
},
{
"key": "whisper",
"renderTypeList": [
"hidden"
],
"valueType": "any",
"label": "",
"value": {
"open": false,
"autoSend": false,
"autoTTSResponse": false
}
},
{
"key": "scheduleTrigger",
"renderTypeList": [
"hidden"
],
"valueType": "any",
"label": "",
"value": null
}
],
"outputs": []
},
{
"nodeId": "448745",
"name": "流程开始",
"intro": "",
"avatar": "/imgs/workflow/userChatInput.svg",
"flowNodeType": "workflowStart",
"position": {
"x": 532.1275542407774,
"y": 46.03775600322817
},
"inputs": [
{
"key": "userChatInput",
"renderTypeList": [
"reference",
"textarea"
],
"valueType": "string",
"label": "用户问题",
"required": true,
"toolDescription": "用户问题"
}
],
"outputs": [
{
"id": "userChatInput",
"key": "userChatInput",
"label": "core.module.input.label.user question",
"valueType": "string",
"type": "static"
}
]
},
{
"nodeId": "tMyUnRL5jIrC",
"name": "HTTP 请求",
"intro": "可以发出一个 HTTP 请求,实现更为复杂的操作(联网搜索、数据库查询等)",
"avatar": "/imgs/workflow/http.png",
"flowNodeType": "httpRequest468",
"showStatus": true,
"position": {
"x": 921.2377506442713,
"y": -483.94114977914256
},
"inputs": [
{
"key": "system_addInputParam",
"renderTypeList": [
"addInputParam"
],
"valueType": "dynamic",
"label": "",
"required": false,
"description": "core.module.input.description.HTTP Dynamic Input",
"editField": {
"key": true,
"valueType": true
}
},
{
"key": "prompt",
"valueType": "string",
"label": "prompt",
"renderTypeList": [
"reference"
],
"description": "",
"canEdit": true,
"editField": {
"key": true,
"valueType": true
},
"value": [
"448745",
"userChatInput"
]
},
{
"key": "system_httpMethod",
"renderTypeList": [
"custom"
],
"valueType": "string",
"label": "",
"value": "POST",
"required": true
},
{
"key": "system_httpReqUrl",
"renderTypeList": [
"hidden"
],
"valueType": "string",
"label": "",
"description": "core.module.input.description.Http Request Url",
"placeholder": "https://api.ai.com/getInventory",
"required": false,
"value": "https://api.openai.com/v1/images/generations"
},
{
"key": "system_httpHeader",
"renderTypeList": [
"custom"
],
"valueType": "any",
"value": [
{
"key": "Authorization",
"type": "string",
"value": "Bearer sk-zsfBsxEU3ApSFGYxF4CdB97e9556412588421823371b9f7b"
}
],
"label": "",
"description": "core.module.input.description.Http Request Header",
"placeholder": "core.module.input.description.Http Request Header",
"required": false
},
{
"key": "system_httpParams",
"renderTypeList": [
"hidden"
],
"valueType": "any",
"value": [],
"label": "",
"required": false
},
{
"key": "system_httpJsonBody",
"renderTypeList": [
"hidden"
],
"valueType": "any",
"value": "{\n \"model\": \"dall-e-3\",\n \"prompt\": \"{{prompt}}\",\n \"n\": 1,\n \"size\": \"1024x1024\"\n}",
"label": "",
"required": false
}
],
"outputs": [
{
"id": "system_addOutputParam",
"key": "system_addOutputParam",
"type": "dynamic",
"valueType": "dynamic",
"label": "",
"editField": {
"key": true,
"valueType": true
}
},
{
"id": "httpRawResponse",
"key": "httpRawResponse",
"label": "原始响应",
"description": "HTTP请求的原始响应。只能接受字符串或JSON类型响应数据。",
"valueType": "any",
"type": "static"
},
{
"id": "DeKGGioBwaMf",
"type": "dynamic",
"key": "data[0].url",
"valueType": "string",
"label": "data[0].url"
}
]
},
{
"nodeId": "CO3POL8svbbi",
"name": "文本加工",
"intro": "可对固定或传入的文本进行加工后输出,非字符串类型数据最终会转成字符串类型。",
"avatar": "/imgs/workflow/textEditor.svg",
"flowNodeType": "pluginModule",
"showStatus": false,
"position": {
"x": 1417.5940290051137,
"y": -478.81889618104356
},
"inputs": [
{
"key": "system_addInputParam",
"valueType": "dynamic",
"label": "动态外部数据",
"renderTypeList": [
"addInputParam"
],
"required": false,
"description": "",
"canEdit": false,
"value": "",
"editField": {
"key": true
},
"dynamicParamDefaultValue": {
"inputType": "reference",
"valueType": "string",
"required": true
}
},
{
"key": "url",
"valueType": "string",
"label": "url",
"renderTypeList": [
"reference"
],
"required": true,
"description": "",
"canEdit": true,
"editField": {
"key": true
},
"value": [
"tMyUnRL5jIrC",
"DeKGGioBwaMf"
]
},
{
"key": "文本",
"valueType": "string",
"label": "文本",
"renderTypeList": [
"textarea"
],
"required": true,
"description": "",
"canEdit": false,
"value": "![]({{url}})",
"editField": {
"key": true
},
"maxLength": "",
"dynamicParamDefaultValue": {
"inputType": "reference",
"valueType": "string",
"required": true
}
}
],
"outputs": [
{
"id": "text",
"type": "static",
"key": "text",
"valueType": "string",
"label": "text",
"description": ""
}
],
"pluginId": "community-textEditor"
},
{
"nodeId": "7mapnCgHfKW6",
"name": "指定回复",
"intro": "该模块可以直接回复一段指定的内容。常用于引导、提示。非字符串内容传入时,会转成字符串进行输出。",
"avatar": "/imgs/workflow/reply.png",
"flowNodeType": "answerNode",
"position": {
"x": 1922.5628399315042,
"y": -471.67391598231796
},
"inputs": [
{
"key": "text",
"renderTypeList": [
"textarea",
"reference"
],
"valueType": "string",
"label": "core.module.input.label.Response content",
"description": "core.module.input.description.Response content",
"placeholder": "core.module.input.description.Response content",
"selectedTypeIndex": 1,
"value": [
"CO3POL8svbbi",
"text"
]
}
],
"outputs": []
}
],
"edges": [
{
"source": "448745",
"target": "tMyUnRL5jIrC",
"sourceHandle": "448745-source-right",
"targetHandle": "tMyUnRL5jIrC-target-left"
},
{
"source": "tMyUnRL5jIrC",
"target": "CO3POL8svbbi",
"sourceHandle": "tMyUnRL5jIrC-source-right",
"targetHandle": "CO3POL8svbbi-target-left"
},
{
"source": "CO3POL8svbbi",
"target": "7mapnCgHfKW6",
"sourceHandle": "CO3POL8svbbi-source-right",
"targetHandle": "7mapnCgHfKW6-target-left"
}
]
}
```
{{% /details %}}

View File

@@ -0,0 +1,489 @@
---
title: '发送飞书webhook通知'
description: '利用工具调用模块发送一个飞书webhook通知'
icon: 'image'
draft: false
toc: true
weight: 404
---
该文章展示如何发送一个简单的飞书webhook通知以此类推发送其他类型的通知也可以这么操作。
| | |
| --------------------- | --------------------- |
| ![](/imgs/feishuwebhook1.webp) | ![](/imgs/feishuwebhook2.webp) |
## 1. 准备飞书机器人
| | | |
| --------------------- | --------------------- |--------------------- |
| ![](/imgs/feishuwebhook3.png) | ![](/imgs/feishuwebhook4.webp) |![](/imgs/feishuwebhook5.png) |
## 2. 导入编排代码
复制下面配置点击「高级编排」右上角的导入按键导入该配置导入后将飞书提供的接口地址复制到「HTTP 模块」。
{{% details title="编排配置" closed="true" %}}
```json
[
{
"nodeId": "userGuide",
"name": "core.module.template.App system setting",
"intro": "core.app.tip.userGuideTip",
"avatar": "/imgs/workflow/userGuide.png",
"flowNodeType": "userGuide",
"position": {
"x": -92.26884681344463,
"y": 710.9354029649536
},
"inputs": [
{
"key": "welcomeText",
"type": "hidden",
"valueType": "string",
"label": "core.app.Welcome Text",
"showTargetInApp": false,
"showTargetInPlugin": false,
"value": "",
"connected": false
},
{
"key": "variables",
"type": "hidden",
"valueType": "any",
"label": "core.module.Variable",
"value": [],
"showTargetInApp": false,
"showTargetInPlugin": false,
"connected": false
},
{
"key": "questionGuide",
"valueType": "boolean",
"type": "switch",
"label": "",
"showTargetInApp": false,
"showTargetInPlugin": false,
"value": false,
"connected": false
},
{
"key": "tts",
"type": "hidden",
"valueType": "any",
"label": "",
"showTargetInApp": false,
"showTargetInPlugin": false,
"value": {
"type": "web"
},
"connected": false
}
],
"outputs": []
},
{
"nodeId": "userChatInput",
"name": "core.module.template.Chat entrance",
"intro": "当用户发送一个内容后,流程将会从这个模块开始执行。",
"avatar": "/imgs/workflow/userChatInput.svg",
"flowNodeType": "questionInput",
"position": {
"x": 241.60980819261408,
"y": 1330.9528898009685
},
"inputs": [
{
"key": "userChatInput",
"type": "systemInput",
"valueType": "string",
"label": "core.module.input.label.user question",
"showTargetInApp": false,
"showTargetInPlugin": false,
"connected": false
}
],
"outputs": [
{
"key": "userChatInput",
"label": "core.module.input.label.user question",
"type": "source",
"valueType": "string",
"targets": [
{
"nodeId": "n84rvg",
"key": "userChatInput"
}
]
}
]
},
{
"nodeId": "n84rvg",
"name": "工具调用(实验)",
"intro": "通过AI模型自动选择一个或多个功能块进行调用也可以对插件进行调用。",
"avatar": "/imgs/workflow/tool.svg",
"flowNodeType": "tools",
"showStatus": true,
"position": {
"x": 809.4264785615641,
"y": 873.3971746859133
},
"inputs": [
{
"key": "model",
"type": "settingLLMModel",
"label": "core.module.input.label.aiModel",
"required": true,
"valueType": "string",
"showTargetInApp": false,
"showTargetInPlugin": false,
"llmModelType": "all",
"value": "gpt-3.5-turbo",
"connected": false
},
{
"key": "temperature",
"type": "hidden",
"label": "",
"value": 0,
"valueType": "number",
"min": 0,
"max": 10,
"step": 1,
"showTargetInApp": false,
"showTargetInPlugin": false,
"connected": false
},
{
"key": "maxToken",
"type": "hidden",
"label": "",
"value": 2000,
"valueType": "number",
"min": 100,
"max": 4000,
"step": 50,
"showTargetInApp": false,
"showTargetInPlugin": false,
"connected": false
},
{
"key": "systemPrompt",
"type": "textarea",
"max": 3000,
"valueType": "string",
"label": "core.ai.Prompt",
"description": "core.app.tip.chatNodeSystemPromptTip",
"placeholder": "core.app.tip.chatNodeSystemPromptTip",
"showTargetInApp": true,
"showTargetInPlugin": true,
"connected": false
},
{
"key": "history",
"type": "numberInput",
"label": "core.module.input.label.chat history",
"required": true,
"min": 0,
"max": 30,
"valueType": "chatHistory",
"value": 6,
"showTargetInApp": true,
"showTargetInPlugin": true,
"connected": false
},
{
"key": "userChatInput",
"type": "custom",
"label": "",
"required": true,
"valueType": "string",
"showTargetInApp": true,
"showTargetInPlugin": true,
"connected": true
}
],
"outputs": [
{
"key": "userChatInput",
"label": "core.module.input.label.user question",
"type": "hidden",
"valueType": "string",
"targets": []
},
{
"key": "selectedTools",
"valueType": "tools",
"type": "hidden",
"targets": [
{
"nodeId": "3mbu91",
"key": "selectedTools"
}
]
},
{
"key": "finish",
"label": "",
"description": "",
"valueType": "boolean",
"type": "hidden",
"targets": []
}
]
},
{
"nodeId": "3mbu91",
"name": "HTTP 请求",
"intro": "调用飞书webhook发送一个通知",
"avatar": "/imgs/workflow/http.png",
"flowNodeType": "httpRequest468",
"showStatus": true,
"position": {
"x": 1483.6437630977423,
"y": 798.9716928475544
},
"inputs": [
{
"key": "system_httpMethod",
"type": "custom",
"valueType": "string",
"label": "",
"value": "POST",
"required": true,
"showTargetInApp": false,
"showTargetInPlugin": false,
"connected": false
},
{
"key": "system_httpReqUrl",
"type": "hidden",
"valueType": "string",
"label": "",
"description": "core.module.input.description.Http Request Url",
"placeholder": "https://api.ai.com/getInventory",
"required": false,
"showTargetInApp": false,
"showTargetInPlugin": false,
"value": "这里填写你的飞书机器人地址",
"connected": false
},
{
"key": "system_httpHeader",
"type": "custom",
"valueType": "any",
"value": [],
"label": "",
"description": "core.module.input.description.Http Request Header",
"placeholder": "core.module.input.description.Http Request Header",
"required": false,
"showTargetInApp": false,
"showTargetInPlugin": false,
"connected": false
},
{
"key": "system_httpParams",
"type": "hidden",
"valueType": "any",
"value": [],
"label": "",
"required": false,
"showTargetInApp": false,
"showTargetInPlugin": false,
"connected": false
},
{
"key": "system_httpJsonBody",
"type": "hidden",
"valueType": "any",
"value": "{\r\n \"msg_type\": \"text\",\r\n \"content\": {\r\n \"text\": \"{{text}}\"\r\n }\r\n}",
"label": "",
"required": false,
"showTargetInApp": false,
"showTargetInPlugin": false,
"connected": false
},
{
"key": "DYNAMIC_INPUT_KEY",
"type": "target",
"valueType": "any",
"label": "core.workflow.inputType.dynamicTargetInput",
"description": "core.module.input.description.dynamic input",
"required": false,
"showTargetInApp": false,
"showTargetInPlugin": true,
"hideInApp": true,
"connected": false
},
{
"key": "system_addInputParam",
"type": "addInputParam",
"valueType": "any",
"label": "",
"required": false,
"showTargetInApp": false,
"showTargetInPlugin": false,
"editField": {
"key": true,
"description": true,
"dataType": true
},
"defaultEditField": {
"label": "",
"key": "",
"description": "",
"inputType": "target",
"valueType": "string"
},
"connected": false
},
{
"valueType": "string",
"type": "hidden",
"key": "text",
"label": "text",
"toolDescription": "需要发送的通知内容",
"required": true,
"connected": false
}
],
"outputs": [
{
"key": "httpRawResponse",
"label": "原始响应",
"description": "HTTP请求的原始响应。只能接受字符串或JSON类型响应数据。",
"valueType": "any",
"type": "source",
"targets": [
{
"nodeId": "rzx4mj",
"key": "switch"
},
{
"nodeId": "psdhs1",
"key": "switch"
}
]
},
{
"key": "system_addOutputParam",
"type": "addOutputParam",
"valueType": "any",
"label": "",
"targets": [],
"editField": {
"key": true,
"description": true,
"dataType": true,
"defaultValue": true
},
"defaultEditField": {
"label": "",
"key": "",
"description": "",
"outputType": "source",
"valueType": "string"
}
},
{
"type": "source",
"valueType": "string",
"key": "prompt",
"label": "prompt",
"description": "",
"required": false,
"edit": true,
"editField": {
"key": true,
"description": true,
"dataType": true,
"defaultValue": true
},
"targets": []
}
]
},
{
"nodeId": "rzx4mj",
"name": "工具调用终止",
"intro": "该模块需配置工具调用使用。当该模块被执行时本次工具调用将会强制结束并且不再调用AI针对工具调用结果回答问题。",
"avatar": "/imgs/workflow/toolStop.svg",
"flowNodeType": "stopTool",
"position": {
"x": 2145.5070710160267,
"y": 1306.3581817783079
},
"inputs": [
{
"key": "switch",
"type": "triggerAndFinish",
"label": "",
"description": "core.module.input.description.Trigger",
"valueType": "any",
"showTargetInApp": true,
"showTargetInPlugin": true,
"connected": true
}
],
"outputs": []
},
{
"nodeId": "psdhs1",
"name": "指定回复",
"intro": "该模块可以直接回复一段指定的内容。常用于引导、提示。非字符串内容传入时,会转成字符串进行输出。",
"avatar": "/imgs/workflow/reply.png",
"flowNodeType": "answerNode",
"position": {
"x": 2117.0429459850598,
"y": 1658.4125434513746
},
"inputs": [
{
"key": "switch",
"type": "triggerAndFinish",
"label": "",
"description": "core.module.input.description.Trigger",
"valueType": "any",
"showTargetInApp": true,
"showTargetInPlugin": true,
"connected": true
},
{
"key": "text",
"type": "textarea",
"valueType": "any",
"label": "core.module.input.label.Response content",
"description": "core.module.input.description.Response content",
"placeholder": "core.module.input.description.Response content",
"showTargetInApp": true,
"showTargetInPlugin": true,
"value": "笑死发送成功啦",
"connected": false
}
],
"outputs": [
{
"key": "finish",
"label": "",
"description": "",
"valueType": "boolean",
"type": "hidden",
"targets": []
}
]
}
]
```
{{% /details %}}
## 3. 流程说明
1. 为工具调用挂载一个HTTP模块功能描述写上调用飞书webhook发送一个通知。
2. HTTP模块的输入参数中填写飞书机器人的地址填写发送的通知内容。
3. HTTP模块输出连接上一个工具终止模块用于强制结束工具调用。不终止的话会把调用结果返回给模型模型会继续回答一次问题浪费 Tokens
4. HTTP模块输出再连上一个指定回复直接回复一个发送成功用于替代AI的回答。

View File

@@ -0,0 +1,432 @@
---
title: '固定开头和结尾内容'
description: '利用指定回复,创建固定的开头和结尾'
icon: 'healing'
draft: false
toc: true
weight: 401
---
![](/imgs/demo-fix-evidence1.jpg)
![](/imgs/demo-fix-evidence2.jpg)
如上图,可以通过指定回复编排一个固定的开头和结尾内容。
## 模块编排
复制下面配置,点击「高级编排」右上角的导入按键,导入该配置。
{{% details title="编排配置" closed="true" %}}
```json
{
"nodes": [
{
"nodeId": "7z5g5h",
"name": "流程开始",
"intro": "",
"avatar": "/imgs/workflow/userChatInput.svg",
"flowNodeType": "workflowStart",
"position": {
"x": -269.50851681351924,
"y": 1657.6123698022448
},
"inputs": [
{
"key": "userChatInput",
"renderTypeList": [
"reference",
"textarea"
],
"valueType": "string",
"label": "问题输入",
"required": true,
"toolDescription": "用户问题",
"type": "systemInput",
"showTargetInApp": false,
"showTargetInPlugin": false,
"connected": false,
"selectedTypeIndex": 0,
"value": [
"7z5g5h",
"userChatInput"
]
}
],
"outputs": [
{
"id": "userChatInput",
"type": "static",
"key": "userChatInput",
"valueType": "string",
"label": "core.module.input.label.user question"
}
]
},
{
"nodeId": "nlfwkc",
"name": "AI 对话",
"intro": "AI 大模型对话",
"avatar": "/imgs/workflow/AI.png",
"flowNodeType": "chatNode",
"showStatus": true,
"position": {
"x": 907.2058332478431,
"y": 1348.9992737142143
},
"inputs": [
{
"key": "model",
"renderTypeList": [
"settingLLMModel",
"reference"
],
"label": "core.module.input.label.aiModel",
"valueType": "string",
"type": "selectLLMModel",
"required": true,
"showTargetInApp": false,
"showTargetInPlugin": false,
"value": "gpt-3.5-turbo",
"connected": false,
"selectedTypeIndex": 0
},
{
"key": "temperature",
"renderTypeList": [
"hidden"
],
"label": "",
"value": 0,
"valueType": "number",
"min": 0,
"max": 10,
"step": 1,
"type": "hidden",
"showTargetInApp": false,
"showTargetInPlugin": false,
"connected": false,
"selectedTypeIndex": 0
},
{
"key": "maxToken",
"renderTypeList": [
"hidden"
],
"label": "",
"value": 2000,
"valueType": "number",
"min": 100,
"max": 4000,
"step": 50,
"type": "hidden",
"showTargetInApp": false,
"showTargetInPlugin": false,
"connected": false,
"selectedTypeIndex": 0
},
{
"key": "isResponseAnswerText",
"renderTypeList": [
"hidden"
],
"label": "",
"value": true,
"valueType": "boolean",
"type": "hidden",
"showTargetInApp": false,
"showTargetInPlugin": false,
"connected": false,
"selectedTypeIndex": 0
},
{
"key": "quoteTemplate",
"renderTypeList": [
"hidden"
],
"label": "",
"valueType": "string",
"type": "hidden",
"showTargetInApp": false,
"showTargetInPlugin": false,
"connected": false,
"selectedTypeIndex": 0
},
{
"key": "quotePrompt",
"renderTypeList": [
"hidden"
],
"label": "",
"valueType": "string",
"type": "hidden",
"showTargetInApp": false,
"showTargetInPlugin": false,
"connected": false,
"selectedTypeIndex": 0
},
{
"key": "systemPrompt",
"renderTypeList": [
"textarea",
"reference"
],
"max": 300,
"valueType": "string",
"label": "core.ai.Prompt",
"description": "core.app.tip.chatNodeSystemPromptTip",
"placeholder": "core.app.tip.chatNodeSystemPromptTip",
"type": "textarea",
"showTargetInApp": true,
"showTargetInPlugin": true,
"value": "",
"connected": false,
"selectedTypeIndex": 0
},
{
"key": "history",
"renderTypeList": [
"numberInput",
"reference"
],
"valueType": "chatHistory",
"label": "core.module.input.label.chat history",
"required": true,
"min": 0,
"max": 30,
"value": 6,
"type": "numberInput",
"showTargetInApp": true,
"showTargetInPlugin": true,
"connected": false,
"selectedTypeIndex": 0
},
{
"key": "userChatInput",
"renderTypeList": [
"reference",
"textarea"
],
"valueType": "string",
"label": "问题输入",
"required": true,
"toolDescription": "用户问题",
"type": "custom",
"showTargetInApp": true,
"showTargetInPlugin": true,
"connected": true,
"selectedTypeIndex": 0,
"value": [
"7z5g5h",
"userChatInput"
]
},
{
"key": "quoteQA",
"renderTypeList": [
"settingDatasetQuotePrompt"
],
"label": "",
"debugLabel": "知识库引用",
"description": "core.module.Dataset quote.Input description",
"valueType": "datasetQuote",
"type": "target",
"showTargetInApp": true,
"showTargetInPlugin": true,
"connected": true,
"selectedTypeIndex": 0,
"value": [
"fljhzy",
"quoteQA"
]
}
],
"outputs": [
{
"id": "answerText",
"type": "static",
"key": "answerText",
"valueType": "string",
"label": "core.module.output.label.Ai response content",
"description": "core.module.output.description.Ai response content"
},
{
"id": "history",
"type": "static",
"key": "history",
"valueType": "chatHistory",
"label": "core.module.output.label.New context",
"description": "core.module.output.description.New context"
}
]
},
{
"nodeId": "q9equb",
"name": "core.module.template.App system setting",
"intro": "可以配置应用的系统参数。",
"avatar": "/imgs/workflow/userGuide.png",
"flowNodeType": "userGuide",
"position": {
"x": -275.92529567956024,
"y": 1094.1001488133452
},
"inputs": [
{
"key": "welcomeText",
"renderTypeList": [
"hidden"
],
"valueType": "string",
"label": "core.app.Welcome Text",
"type": "hidden",
"showTargetInApp": false,
"showTargetInPlugin": false,
"value": "你好,我是电影《星际穿越》 AI 助手,有什么可以帮助你的?\n[导演是谁]\n[剧情介绍]\n[票房分析]",
"connected": false,
"selectedTypeIndex": 0
},
{
"key": "variables",
"renderTypeList": [
"hidden"
],
"valueType": "any",
"label": "core.module.Variable",
"value": [],
"type": "hidden",
"showTargetInApp": false,
"showTargetInPlugin": false,
"connected": false,
"selectedTypeIndex": 0
},
{
"key": "questionGuide",
"valueType": "boolean",
"renderTypeList": [
"hidden"
],
"label": "",
"type": "switch",
"showTargetInApp": false,
"showTargetInPlugin": false,
"connected": false,
"selectedTypeIndex": 0
},
{
"key": "tts",
"renderTypeList": [
"hidden"
],
"valueType": "any",
"label": "",
"type": "hidden",
"showTargetInApp": false,
"showTargetInPlugin": false,
"connected": false,
"selectedTypeIndex": 0
},
{
"key": "whisper",
"renderTypeList": [
"hidden"
],
"valueType": "any",
"label": ""
},
{
"key": "scheduleTrigger",
"renderTypeList": [
"hidden"
],
"valueType": "any",
"label": "",
"value": null
}
],
"outputs": []
},
{
"nodeId": "tc90wz",
"name": "指定回复",
"intro": "该模块可以直接回复一段指定的内容。常用于引导、提示。非字符串内容传入时,会转成字符串进行输出。",
"avatar": "/imgs/workflow/reply.png",
"flowNodeType": "answerNode",
"position": {
"x": 159.49274056478237,
"y": 1621.4635230667668
},
"inputs": [
{
"key": "text",
"renderTypeList": [
"textarea",
"reference"
],
"valueType": "any",
"label": "core.module.input.label.Response content",
"description": "core.module.input.description.Response content",
"placeholder": "core.module.input.description.Response content",
"type": "textarea",
"showTargetInApp": true,
"showTargetInPlugin": true,
"value": "这是开头\\n",
"connected": false,
"selectedTypeIndex": 0
}
],
"outputs": []
},
{
"nodeId": "U5T3dMVY4wj7",
"name": "指定回复",
"intro": "该模块可以直接回复一段指定的内容。常用于引导、提示。非字符串内容传入时,会转成字符串进行输出。",
"avatar": "/imgs/workflow/reply.png",
"flowNodeType": "answerNode",
"position": {
"x": 1467.0625486167608,
"y": 1597.346243737531
},
"inputs": [
{
"key": "text",
"renderTypeList": [
"textarea",
"reference"
],
"valueType": "string",
"label": "core.module.input.label.Response content",
"description": "core.module.input.description.Response content",
"placeholder": "core.module.input.description.Response content",
"value": "这是结尾"
}
],
"outputs": []
}
],
"edges": [
{
"source": "7z5g5h",
"target": "tc90wz",
"sourceHandle": "7z5g5h-source-right",
"targetHandle": "tc90wz-target-left"
},
{
"source": "tc90wz",
"target": "nlfwkc",
"sourceHandle": "tc90wz-source-right",
"targetHandle": "nlfwkc-target-left"
},
{
"source": "nlfwkc",
"target": "U5T3dMVY4wj7",
"sourceHandle": "nlfwkc-source-right",
"targetHandle": "U5T3dMVY4wj7-target-left"
}
]
}
```
{{% /details %}}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,853 @@
---
title: '实验室预约'
description: '展示高级编排操作数据库的能力'
icon: 'database'
draft: false
toc: true
weight: 403
---
| | |
| --------------------- | --------------------- |
| ![](/imgs/demo-appointment1.webp) | ![](/imgs/demo-appointment2.webp) |
| ![](/imgs/demo-appointment3.webp) | ![](/imgs/demo-appointment4.webp) |
本示例演示了利用工具调用,自动选择调用知识库搜索实验室相关内容,或调用 HTTP 模块实现数据库的 CRUD 操作。
以一个实验室预约为例,用户可以通过对话系统预约、取消、修改预约和查询预约记录。
## 1. 全局变量使用
通过设计一个全局变量,让用户输入姓名,模拟用户身份信息。实际使用过程中,通常是直接通过嵌入 Token 来标记用户身份。
## 2. 工具调用
![](/imgs/demo-appointment5.png)
背景知识中,引导模型调用工具去执行不通的操作。
{{% alert icon="🤗" context="warning" %}}
**Tips:** 这里需要增加适当的上下文,方便模型结合历史纪录进行判断和决策~
{{% /alert %}}
## 3. HTTP 模块
![](/imgs/demo-appointment6.jpg)
HTTP模块中需要设置 3 个工具参数:
- 预约行为:可取 get, put, post, delete 四个值分别对应查询、修改、新增、删除操作。当然你也可以写4个HTTP模块来分别处理。
- labname: 实验室名。非必填,因为查询和删除时候,不需要。
- time: 预约时间。
# 总结
1. 工具调用模块是非常强大的功能,可以在一定程度上替代问题分类和内容提取。
2. 通过工具模块,动态的调用不同的工具,可以将复杂业务解耦。
# 附件
## 编排配置
可直接复制,导入到 FastGPT 中。
{{% details title="编排配置" closed="true" %}}
```json
{
"nodes": [
{
"nodeId": "userChatInput",
"name": "流程开始",
"intro": "当用户发送一个内容后,流程将会从这个模块开始执行。",
"avatar": "/imgs/workflow/userChatInput.svg",
"flowNodeType": "workflowStart",
"position": {
"x": 309.7143912167367,
"y": 1501.2761754220846
},
"inputs": [
{
"key": "userChatInput",
"renderTypeList": [
"reference",
"textarea"
],
"valueType": "string",
"label": "问题输入",
"required": true,
"toolDescription": "用户问题",
"type": "systemInput",
"showTargetInApp": false,
"showTargetInPlugin": false,
"connected": false,
"selectedTypeIndex": 0,
"value": [
"userChatInput",
"userChatInput"
]
}
],
"outputs": [
{
"id": "userChatInput",
"type": "static",
"key": "userChatInput",
"valueType": "string",
"label": "core.module.input.label.user question"
}
]
},
{
"nodeId": "eg5upi",
"name": "指定回复",
"intro": "该模块可以直接回复一段指定的内容。常用于引导、提示。非字符串内容传入时,会转成字符串进行输出。",
"avatar": "/imgs/workflow/reply.png",
"flowNodeType": "answerNode",
"position": {
"x": 1962.729630445213,
"y": 2295.9791334948304
},
"inputs": [
{
"key": "text",
"renderTypeList": [
"textarea",
"reference"
],
"valueType": "any",
"label": "core.module.input.label.Response content",
"description": "core.module.input.description.Response content",
"placeholder": "core.module.input.description.Response content",
"type": "textarea",
"showTargetInApp": true,
"showTargetInPlugin": true,
"connected": true,
"selectedTypeIndex": 1,
"value": [
"40clf3",
"result"
]
}
],
"outputs": []
},
{
"nodeId": "kge59i",
"name": "用户引导",
"intro": "可以配置应用的系统参数。",
"avatar": "/imgs/workflow/userGuide.png",
"flowNodeType": "userGuide",
"position": {
"x": -327.218389965887,
"y": 1504.8056414948464
},
"inputs": [
{
"key": "welcomeText",
"renderTypeList": [
"hidden"
],
"valueType": "string",
"label": "core.app.Welcome Text",
"type": "hidden",
"showTargetInApp": false,
"showTargetInPlugin": false,
"value": "你好,我是实验室助手,请问有什么可以帮助你的么?如需预约或修改预约实验室,请提供姓名、时间和实验室名称。\n[实验室介绍]\n[开放时间]\n[预约]",
"connected": false,
"selectedTypeIndex": 0
},
{
"key": "variables",
"renderTypeList": [
"hidden"
],
"valueType": "any",
"label": "core.module.Variable",
"value": [
{
"id": "gt9b23",
"key": "name",
"label": "name",
"type": "input",
"required": true,
"maxLen": 50,
"enums": [
{
"value": ""
}
]
}
],
"type": "hidden",
"showTargetInApp": false,
"showTargetInPlugin": false,
"connected": false,
"selectedTypeIndex": 0
},
{
"key": "questionGuide",
"valueType": "boolean",
"renderTypeList": [
"hidden"
],
"label": "",
"type": "switch",
"showTargetInApp": false,
"showTargetInPlugin": false,
"value": false,
"connected": false,
"selectedTypeIndex": 0
},
{
"key": "tts",
"renderTypeList": [
"hidden"
],
"valueType": "any",
"label": "",
"type": "hidden",
"showTargetInApp": false,
"showTargetInPlugin": false,
"value": {
"type": "model",
"model": "tts-1",
"voice": "alloy"
},
"connected": false,
"selectedTypeIndex": 0
},
{
"key": "whisper",
"renderTypeList": [
"hidden"
],
"valueType": "any",
"label": "",
"type": "hidden",
"showTargetInApp": false,
"showTargetInPlugin": false,
"connected": false,
"selectedTypeIndex": 0
},
{
"key": "scheduleTrigger",
"renderTypeList": [
"hidden"
],
"valueType": "any",
"label": "",
"value": null
}
],
"outputs": []
},
{
"nodeId": "40clf3",
"name": "HTTP请求",
"intro": "可以发出一个 HTTP 请求,实现更为复杂的操作(联网搜索、数据库查询等)",
"avatar": "/imgs/workflow/http.png",
"flowNodeType": "httpRequest468",
"showStatus": true,
"position": {
"x": 1118.6532653446993,
"y": 1955.886106913907
},
"inputs": [
{
"key": "system_httpMethod",
"renderTypeList": [
"custom"
],
"valueType": "string",
"label": "",
"value": "POST",
"required": true,
"type": "custom",
"showTargetInApp": false,
"showTargetInPlugin": false,
"connected": false,
"selectedTypeIndex": 0
},
{
"valueType": "string",
"renderTypeList": [
"reference"
],
"key": "action",
"label": "action",
"toolDescription": "预约行为,一共四种:\nget - 查询预约情况\nput - 更新预约\npost - 新增预约\ndelete - 删除预约",
"required": true,
"canEdit": true,
"editField": {
"key": true,
"description": true
}
},
{
"valueType": "string",
"renderTypeList": [
"reference"
],
"key": "labname",
"label": "labname",
"toolDescription": "实验室名称",
"required": false,
"canEdit": true,
"editField": {
"key": true,
"description": true
}
},
{
"valueType": "string",
"renderTypeList": [
"reference"
],
"key": "time",
"label": "time",
"toolDescription": "预约时间,按 YYYY/MM/DD HH:mm 格式返回",
"required": false,
"canEdit": true,
"editField": {
"key": true,
"description": true
}
},
{
"key": "system_httpReqUrl",
"renderTypeList": [
"hidden"
],
"valueType": "string",
"label": "",
"description": "core.module.input.description.Http Request Url",
"placeholder": "https://api.ai.com/getInventory",
"required": false,
"type": "hidden",
"showTargetInApp": false,
"showTargetInPlugin": false,
"value": "https://d8dns0.laf.dev/appointment-lab",
"connected": false,
"selectedTypeIndex": 0
},
{
"key": "system_httpHeader",
"renderTypeList": [
"custom"
],
"valueType": "any",
"value": [],
"label": "",
"description": "core.module.input.description.Http Request Header",
"placeholder": "core.module.input.description.Http Request Header",
"required": false,
"type": "custom",
"showTargetInApp": false,
"showTargetInPlugin": false,
"connected": false,
"selectedTypeIndex": 0
},
{
"key": "system_httpParams",
"renderTypeList": [
"hidden"
],
"valueType": "any",
"value": [],
"label": "",
"required": false,
"type": "hidden",
"showTargetInApp": false,
"showTargetInPlugin": false,
"connected": false,
"selectedTypeIndex": 0
},
{
"key": "system_httpJsonBody",
"renderTypeList": [
"hidden"
],
"valueType": "any",
"value": "{\r\n \"name\": \"{{name}}\",\r\n \"time\": \"{{time}}\",\r\n \"labname\": \"{{labname}}\",\r\n \"action\": \"{{action}}\"\r\n}",
"label": "",
"required": false,
"type": "hidden",
"showTargetInApp": false,
"showTargetInPlugin": false,
"connected": false,
"selectedTypeIndex": 0
},
{
"key": "system_addInputParam",
"renderTypeList": [
"addInputParam"
],
"valueType": "dynamic",
"label": "",
"required": false,
"description": "core.module.input.description.HTTP Dynamic Input",
"editField": {
"key": true,
"valueType": true
}
}
],
"outputs": [
{
"id": "system_addOutputParam",
"type": "dynamic",
"key": "system_addOutputParam",
"valueType": "dynamic",
"label": "",
"editField": {
"key": true,
"valueType": true
}
},
{
"id": "result",
"type": "static",
"key": "result",
"valueType": "string",
"label": "result",
"description": "result",
"canEdit": true,
"editField": {
"key": true,
"name": true,
"description": true,
"dataType": true
}
},
{
"id": "httpRawResponse",
"type": "static",
"key": "httpRawResponse",
"valueType": "any",
"label": "原始响应",
"description": "HTTP请求的原始响应。只能接受字符串或JSON类型响应数据。"
}
]
},
{
"nodeId": "fYxwWym8flYL",
"name": "工具调用(实验)",
"intro": "通过AI模型自动选择一个或多个功能块进行调用也可以对插件进行调用。",
"avatar": "/imgs/workflow/tool.svg",
"flowNodeType": "tools",
"showStatus": true,
"position": {
"x": 933.9342354248961,
"y": 1229.3563445150553
},
"inputs": [
{
"key": "model",
"renderTypeList": [
"settingLLMModel",
"reference"
],
"label": "core.module.input.label.aiModel",
"valueType": "string",
"llmModelType": "all",
"value": "gpt-3.5-turbo"
},
{
"key": "temperature",
"renderTypeList": [
"hidden"
],
"label": "",
"value": 0,
"valueType": "number",
"min": 0,
"max": 10,
"step": 1
},
{
"key": "maxToken",
"renderTypeList": [
"hidden"
],
"label": "",
"value": 2000,
"valueType": "number",
"min": 100,
"max": 4000,
"step": 50
},
{
"key": "systemPrompt",
"renderTypeList": [
"textarea",
"reference"
],
"max": 3000,
"valueType": "string",
"label": "core.ai.Prompt",
"description": "core.app.tip.chatNodeSystemPromptTip",
"placeholder": "core.app.tip.chatNodeSystemPromptTip",
"value": "当前时间为: {{cTime}}\n你是实验室助手用户可能会询问实验室相关介绍或预约实验室。\n请选择合适的工具去帮助他们。"
},
{
"key": "history",
"renderTypeList": [
"numberInput",
"reference"
],
"valueType": "chatHistory",
"label": "core.module.input.label.chat history",
"required": true,
"min": 0,
"max": 30,
"value": 6
},
{
"key": "userChatInput",
"renderTypeList": [
"reference",
"textarea"
],
"valueType": "string",
"label": "用户问题",
"required": true,
"value": [
"userChatInput",
"userChatInput"
]
}
],
"outputs": []
},
{
"nodeId": "JSSQtDgwmmbE",
"name": "知识库搜索",
"intro": "调用“语义检索”和“全文检索”能力,从“知识库”中查找实验室介绍和使用规则等信息。",
"avatar": "/imgs/workflow/db.png",
"flowNodeType": "datasetSearchNode",
"showStatus": true,
"position": {
"x": 447.0795498711184,
"y": 1971.5311041711186
},
"inputs": [
{
"key": "datasets",
"renderTypeList": [
"selectDataset",
"reference"
],
"label": "core.module.input.label.Select dataset",
"value": [],
"valueType": "selectDataset",
"list": [],
"required": true
},
{
"key": "similarity",
"renderTypeList": [
"selectDatasetParamsModal"
],
"label": "",
"value": 0.4,
"valueType": "number"
},
{
"key": "limit",
"renderTypeList": [
"hidden"
],
"label": "",
"value": 1500,
"valueType": "number"
},
{
"key": "searchMode",
"renderTypeList": [
"hidden"
],
"label": "",
"valueType": "string",
"value": "embedding"
},
{
"key": "usingReRank",
"renderTypeList": [
"hidden"
],
"label": "",
"valueType": "boolean",
"value": false
},
{
"key": "datasetSearchUsingExtensionQuery",
"renderTypeList": [
"hidden"
],
"label": "",
"valueType": "boolean",
"value": false
},
{
"key": "datasetSearchExtensionModel",
"renderTypeList": [
"hidden"
],
"label": "",
"valueType": "string",
"value": "gpt-3.5-turbo"
},
{
"key": "datasetSearchExtensionBg",
"renderTypeList": [
"hidden"
],
"label": "",
"valueType": "string",
"value": ""
},
{
"key": "userChatInput",
"renderTypeList": [
"reference",
"textarea"
],
"valueType": "string",
"label": "用户问题",
"required": true,
"toolDescription": "需要检索的内容"
}
],
"outputs": [
{
"id": "quoteQA",
"key": "quoteQA",
"label": "core.module.Dataset quote.label",
"description": "特殊数组格式,搜索结果为空时,返回空数组。",
"type": "static",
"valueType": "datasetQuote"
}
]
},
{
"nodeId": "IdntVQiTopHT",
"name": "工具调用终止",
"intro": "该模块需配置工具调用使用。当该模块被执行时本次工具调用将会强制结束并且不再调用AI针对工具调用结果回答问题。",
"avatar": "/imgs/workflow/toolStop.svg",
"flowNodeType": "stopTool",
"position": {
"x": 1969.73331750207,
"y": 2650.0258908119413
},
"inputs": [],
"outputs": []
}
],
"edges": [
{
"source": "40clf3",
"target": "eg5upi",
"sourceHandle": "40clf3-source-right",
"targetHandle": "eg5upi-target-left"
},
{
"source": "userChatInput",
"target": "fYxwWym8flYL",
"sourceHandle": "userChatInput-source-right",
"targetHandle": "fYxwWym8flYL-target-left"
},
{
"source": "fYxwWym8flYL",
"target": "40clf3",
"sourceHandle": "selectedTools",
"targetHandle": "selectedTools"
},
{
"source": "fYxwWym8flYL",
"target": "JSSQtDgwmmbE",
"sourceHandle": "selectedTools",
"targetHandle": "selectedTools"
},
{
"source": "40clf3",
"target": "IdntVQiTopHT",
"sourceHandle": "40clf3-source-right",
"targetHandle": "IdntVQiTopHT-target-left"
}
]
}
```
{{% /details %}}
## Laf 云函数代码
可以在 [Laf](https://laf.dev/) 中快速构建 HTTP 接口。
{{% details title="函数代码" closed="true" %}}
```ts
import cloud from '@lafjs/cloud'
const db = cloud.database()
type RequestType = {
name: string;
time?: string;
labname?: string;
action: 'post' | 'delete' | 'put' | 'get'
}
export default async function (ctx: FunctionContext) {
try {
const { action,...body } = ctx.body as RequestType
if (action === 'get') {
return await getRecord(ctx.body)
}
if (action === 'post') {
return await createRecord(ctx.body)
}
if (action === 'put') {
return await putRecord(ctx.body)
}
if (action === 'delete') {
return await removeRecord(ctx.body)
}
return {
result: "异常"
}
} catch (err) {
return {
result: "异常"
}
}
}
async function putRecord({ name, time, labname }: RequestType) {
const missData = []
if (!name) missData.push("你的姓名")
if (missData.length > 0) {
return {
result: `请提供: ${missData.join("、")}`
}
}
const { data: record } = await db.collection("LabAppointment").where({
name, status: "unStart"
}).getOne()
if (!record) {
return {
result: `${name} 还没有预约记录`
}
}
const updateWhere = {
name,
time: time || record.time,
labname: labname || record.labname
}
await db.collection("LabAppointment").where({
name, status: "unStart"
}).update(updateWhere)
return {
result: `修改预约成功。
姓名:${name}·
时间: ${updateWhere.time}
实验室名: ${updateWhere.labname}
` }
}
async function getRecord({ name }: RequestType) {
if (!name) {
return {
result: "请提供你的姓名"
}
}
const { data } = await db.collection('LabAppointment').where({ name, status: "unStart" }).getOne()
if (!data) {
return {
result: `${name} 没有预约中的记录`
}
}
return {
result: `${name} 有一条预约记录:
姓名:${data.name}
时间: ${data.time}
实验室名: ${data.labname}
`
}
}
async function removeRecord({ name }: RequestType) {
if (!name) {
return {
result: "请提供你的姓名"
}
}
const { deleted } = await db.collection('LabAppointment').where({ name, status: "unStart" }).remove()
if (deleted > 0) {
return {
result: `取消预约记录成功: ${name}`
}
}
return {
result: ` ${name} 没有预约中的记录`
}
}
async function createRecord({ name, time, labname }: RequestType) {
const missData = []
if (!name) missData.push("你的姓名")
if (!time) missData.push("需要预约的时间")
if (!labname) missData.push("实验室名名称")
if (missData.length > 0) {
return {
result: `请提供: ${missData.join("、")}`
}
}
const { data: record } = await db.collection("LabAppointment").where({
name, status: "unStart"
}).getOne()
if (record) {
return {
result: `您已经有一个预约记录了:
姓名:${record.name}
时间: ${record.time}
实验室名: ${record.labname}
每人仅能同时预约一个实验室名。
`
}
}
await db.collection("LabAppointment").add({
name, time, labname, status: "unStart"
})
return {
result: `预约成功。
姓名:${name}
时间: ${time}
实验室名: ${labname}
` }
}
```
{{% /details %}}