mirror of
https://github.com/labring/FastGPT.git
synced 2025-10-20 18:54:09 +00:00
docs: update the framework of doc site (#207)
Signed-off-by: Carson Yang <yangchuansheng33@gmail.com>
This commit is contained in:
8
docSite/content/docs/workflow/modules/_index.md
Normal file
8
docSite/content/docs/workflow/modules/_index.md
Normal file
@@ -0,0 +1,8 @@
|
||||
---
|
||||
weight: 420
|
||||
title: "模块介绍"
|
||||
description: "介绍 FastGPT 的常用模块"
|
||||
icon: "apps"
|
||||
draft: false
|
||||
images: []
|
||||
---
|
71
docSite/content/docs/workflow/modules/ai_chat.md
Normal file
71
docSite/content/docs/workflow/modules/ai_chat.md
Normal file
@@ -0,0 +1,71 @@
|
||||
---
|
||||
title: "AI 对话"
|
||||
description: "FastGPT AI 对话模块介绍"
|
||||
icon: "chat"
|
||||
draft: false
|
||||
toc: true
|
||||
weight: 423
|
||||
---
|
||||
|
||||
## 特点
|
||||
|
||||
- 可重复添加(复杂编排时防止线太乱,可以更美观)
|
||||
- 有外部输入
|
||||
- 有静态配置
|
||||
- 触发执行
|
||||
- 核心模块
|
||||
|
||||

|
||||
|
||||
## 参数说明
|
||||
|
||||
### 对话模型
|
||||
|
||||
可以通过 [config.json](/docs/installation/reference/models/) 配置可选的对话模型,通过 [one-api](/docs/installation/one-api/) 来实现多模型接入。
|
||||
|
||||
### 温度 & 回复上限
|
||||
|
||||
+ **温度**:越低回答越严谨,少废话(实测下来,感觉差别不大)
|
||||
+ **回复上限**:最大回复 token 数量(只有 OpenAI 模型有效)。注意,是回复!不是总 tokens。
|
||||
|
||||
### 系统提示词(可被外部输入覆盖)
|
||||
|
||||
被放置在上下文数组的最前面,role 为 system,用于引导模型。具体用法参考各搜索引擎的教程~
|
||||
|
||||
### 限定词(可被外部输入覆盖)
|
||||
|
||||
与系统提示词类似,role 也是 system 类型,只不过位置会被放置在问题前,拥有更强的引导作用。
|
||||
|
||||
### 引用内容
|
||||
|
||||
接收一个外部输入的数组,主要是由【知识库搜索】模块生成,也可以由 HTTP 模块从外部引入。数据结构示例如下:
|
||||
|
||||
```ts
|
||||
type DataType = {
|
||||
kb_id?: string;
|
||||
id?: string;
|
||||
q: string;
|
||||
a: string;
|
||||
source?: string;
|
||||
};
|
||||
// 如果是外部引入的内容,尽量不要携带 kb_id 和 id
|
||||
const quoteList: DataType[] = [
|
||||
{ kb_id: '11', id: '222', q: '你还', a: '哈哈', source: '' },
|
||||
{ kb_id: '11', id: '333', q: '你还', a: '哈哈', source: '' },
|
||||
{ kb_id: '11', id: '444', q: '你还', a: '哈哈', source: '' }
|
||||
];
|
||||
```
|
||||
|
||||
## 完整上下文组成
|
||||
|
||||
最终发送给 LLM 大模型的数据是一个数组,内容和顺序如下:
|
||||
|
||||
```bash
|
||||
[
|
||||
系统提示词
|
||||
引用内容
|
||||
聊天记录
|
||||
限定词
|
||||
问题
|
||||
]
|
||||
```
|
60
docSite/content/docs/workflow/modules/content_extract.md
Normal file
60
docSite/content/docs/workflow/modules/content_extract.md
Normal file
@@ -0,0 +1,60 @@
|
||||
---
|
||||
title: "内容提取"
|
||||
description: "FastGPT 内容提取模块介绍"
|
||||
icon: "content_paste_go"
|
||||
draft: false
|
||||
toc: true
|
||||
weight: 424
|
||||
---
|
||||
|
||||
## 特点
|
||||
|
||||
- 可重复添加
|
||||
- 有外部输入
|
||||
- 需要手动配置
|
||||
- 触发执行
|
||||
- function_call 模块
|
||||
- 核心模块
|
||||
|
||||

|
||||
|
||||
## 功能
|
||||
|
||||
从文本中提取结构化数据,通常是配合 HTTP 模块实现扩展。也可以做一些直接提取操作,例如:翻译。
|
||||
|
||||
## 参数说明
|
||||
|
||||
### 提取要求描述
|
||||
|
||||
顾名思义,给模型设置一个目标,需要提取哪些内容。
|
||||
|
||||
**示例 1**
|
||||
|
||||
> 你是实验室预约助手,从对话中提取出姓名,预约时间,实验室号。当前时间 {{cTime}}
|
||||
|
||||
**示例 2**
|
||||
|
||||
> 你是谷歌搜索助手,从对话中提取出搜索关键词
|
||||
|
||||
**示例 3**
|
||||
|
||||
> 将我的问题直接翻译成英文,不要回答问题
|
||||
|
||||
### 历史记录
|
||||
|
||||
通常需要一些历史记录,才能更完整的提取用户问题。例如上图中需要提供姓名、时间和实验室名,用户可能一开始只给了时间和实验室名,没有提供自己的姓名。再经过一轮缺失提示后,用户输入了姓名,此时需要结合上一次的记录才能完整的提取出 3 个内容。
|
||||
|
||||
### 目标字段
|
||||
|
||||
目标字段与提取的结果相对应,从上图可以看到,每增加一个字段,输出会增加一个对应的出口。
|
||||
|
||||
+ **key**: 字段的唯一标识,不可重复!
|
||||
+ **字段描述**:描述该字段是关于什么的,例如:姓名、时间、搜索词等等。
|
||||
+ **必须**:是否强制模型提取该字段,可能提取出来是空字符串。
|
||||
|
||||
## 输出介绍
|
||||
|
||||
- **字段完全提取**:说明用户的问题中包含需要提取的所有内容。
|
||||
- **提取字段缺失**:与 “字段完全提取” 对立,有缺失提取的字段时触发。
|
||||
- **完整提取结果**: 一个 JSON 字符串,包含所有字段的提取结果。
|
||||
- **目标字段提取结果**:类型均为字符串。
|
18
docSite/content/docs/workflow/modules/guide.md
Normal file
18
docSite/content/docs/workflow/modules/guide.md
Normal file
@@ -0,0 +1,18 @@
|
||||
---
|
||||
title: "用户引导"
|
||||
description: "FastGPT 用户引导模块介绍"
|
||||
icon: "psychology"
|
||||
draft: false
|
||||
toc: true
|
||||
weight: 426
|
||||
---
|
||||
|
||||
## 特点
|
||||
|
||||
- 仅可添加 1 个
|
||||
- 无外部输入
|
||||
- 不参与实际调度
|
||||
|
||||
如图,可以在用户提问前给予一定引导。并可以设置引导问题。
|
||||
|
||||

|
19
docSite/content/docs/workflow/modules/history.md
Normal file
19
docSite/content/docs/workflow/modules/history.md
Normal file
@@ -0,0 +1,19 @@
|
||||
---
|
||||
title: "历史记录"
|
||||
description: "FastGPT 历史记录模块介绍"
|
||||
icon: "history"
|
||||
draft: false
|
||||
toc: true
|
||||
weight: 427
|
||||
---
|
||||
|
||||
# 特点
|
||||
|
||||
- 可重复添加(防止复杂编排时线太乱,重复添加可以更美观)
|
||||
- 无外部输入
|
||||
- 流程入口
|
||||
- 自动执行
|
||||
|
||||
每次对话时,会从数据库取最多 n 条聊天记录作为上下文。注意,不是指本轮对话最多 n 条上下文,本轮对话还包括:提示词、限定词、引用内容和问题。
|
||||
|
||||

|
104
docSite/content/docs/workflow/modules/http.md
Normal file
104
docSite/content/docs/workflow/modules/http.md
Normal file
@@ -0,0 +1,104 @@
|
||||
---
|
||||
title: "HTTP 模块"
|
||||
description: "FastGPT HTTP 模块介绍"
|
||||
icon: "http"
|
||||
draft: false
|
||||
toc: true
|
||||
weight: 428
|
||||
---
|
||||
|
||||
## 特点
|
||||
|
||||
- 可重复添加
|
||||
- 有外部输入
|
||||
- 手动配置
|
||||
- 触发执行
|
||||
- 核中核模块
|
||||
|
||||

|
||||
|
||||
## 介绍
|
||||
|
||||
HTTP 模块会向对应的地址发送一个 POST 请求(Body 中携带 JSON 类型的参数,具体的参数可自定义),并接收一个 JSON 响应值,字段也是自定义。如上图中,我们定义了一个入参:「提取的字段」(定义的 key 为 appointment,类型为 string)和一个出参:「提取结果」(定义的 key 为 response,类型为 string)。
|
||||
|
||||
那么,这个请求的命令为:
|
||||
|
||||
```bash
|
||||
curl --location --request POST 'https://xxxx.laf.dev/appointment-lab' \
|
||||
--header 'Content-Type: application/json' \
|
||||
--data-raw '{
|
||||
"appointment":"{\"name\":\"小明\",\"time\":\"2023/08/16 15:00\",\"labname\":\"子良A323\"}"
|
||||
}'
|
||||
```
|
||||
|
||||
响应为:
|
||||
|
||||
```json
|
||||
{
|
||||
"response": "您已经有一个预约记录了,每人仅能同时预约一个实验室:\n 姓名:小明\n 时间: 2023/08/15 15:00\n 实验室: 子良A323\n "
|
||||
}
|
||||
```
|
||||
|
||||
{{% alert context="warning" %}}
|
||||
如果你不想额外部署服务,可以使用 [Laf](https://laf.dev/) 来快速开发上线接口,即写即发,无需部署。
|
||||
|
||||
下面是在 Laf 上编写的一个请求示例:
|
||||
{{% /alert %}}
|
||||
|
||||
```ts
|
||||
import cloud from '@lafjs/cloud';
|
||||
const db = cloud.database();
|
||||
|
||||
export default async function (ctx: FunctionContext) {
|
||||
const { appointment } = ctx.body;
|
||||
const { name, time, labname } = JSON.parse(appointment);
|
||||
|
||||
const missData = [];
|
||||
if (!name) missData.push('你的姓名');
|
||||
if (!time) missData.push('需要预约的时间');
|
||||
if (!labname) missData.push('实验室名称');
|
||||
|
||||
if (missData.length > 0) {
|
||||
return {
|
||||
response: `请提供: ${missData.join('、')}`
|
||||
};
|
||||
}
|
||||
|
||||
const { data: record } = await db
|
||||
.collection('LabAppointment')
|
||||
.where({
|
||||
name,
|
||||
status: 'unStart'
|
||||
})
|
||||
.getOne();
|
||||
|
||||
if (record) {
|
||||
return {
|
||||
response: `您已经有一个预约记录了,每人仅能同时预约一个实验室:
|
||||
姓名:${record.name}
|
||||
时间: ${record.time}
|
||||
实验室: ${record.labname}
|
||||
`
|
||||
};
|
||||
}
|
||||
|
||||
await db.collection('LabAppointment').add({
|
||||
name,
|
||||
time,
|
||||
labname,
|
||||
status: 'unStart'
|
||||
});
|
||||
|
||||
return {
|
||||
response: `预约成功。
|
||||
姓名:${name}
|
||||
时间: ${time}
|
||||
实验室: ${labname}
|
||||
`
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
## 作用
|
||||
|
||||
基于 HTTP 模块可以无限扩展,比如操作数据库、执行联网搜索、发送邮箱等等。如果你有有趣的案例,欢迎提交 PR 到 [编排案例](/docs/category/examples)
|
17
docSite/content/docs/workflow/modules/input.md
Normal file
17
docSite/content/docs/workflow/modules/input.md
Normal file
@@ -0,0 +1,17 @@
|
||||
---
|
||||
title: "用户问题"
|
||||
description: "FastGPT 用户问题模块介绍"
|
||||
icon: "input"
|
||||
draft: false
|
||||
toc: true
|
||||
weight: 430
|
||||
---
|
||||
|
||||
## 特点
|
||||
|
||||
- 可重复添加(防止复杂编排时线太乱,重复添加可以更美观)
|
||||
- 无外部输入
|
||||
- 流程入口
|
||||
- 自动执行
|
||||
|
||||

|
78
docSite/content/docs/workflow/modules/question.md
Normal file
78
docSite/content/docs/workflow/modules/question.md
Normal file
@@ -0,0 +1,78 @@
|
||||
---
|
||||
title: "问题分类"
|
||||
description: "FastGPT 问题分类模块介绍"
|
||||
icon: "quiz"
|
||||
draft: false
|
||||
toc: true
|
||||
weight: 425
|
||||
---
|
||||
|
||||
## 特点
|
||||
|
||||
- 可重复添加
|
||||
- 有外部输入
|
||||
- 需要手动配置
|
||||
- 触发执行
|
||||
- function_call 模块
|
||||
|
||||

|
||||
|
||||
## 功能
|
||||
|
||||
可以将用户的问题进行分类,分类后执行不同操作。在一些较模糊的场景中,分类效果不是很明显。
|
||||
|
||||
## 参数说明
|
||||
|
||||
### 系统提示词
|
||||
|
||||
被放置在对话最前面,可用于补充说明分类内容的定义。例如问题会被分为:
|
||||
|
||||
1. 打招呼
|
||||
2. Laf 常见问题
|
||||
3. 其他问题
|
||||
|
||||
由于 Laf 不是一个明确的东西,需要给它一个定义,此时提示词里可以填入 Laf 的定义:
|
||||
|
||||
```
|
||||
Laf 是云开发平台,可以快速的开发应用
|
||||
Laf 是一个开源的 BaaS 开发平台(Backend as a Service)
|
||||
Laf 是一个开箱即用的 serverless 开发平台
|
||||
Laf 是一个集「函数计算」、「数据库」、「对象存储」等于一身的一站式开发平台
|
||||
Laf 可以是开源版的腾讯云开发、开源版的 Google Firebase、开源版的 UniCloud
|
||||
```
|
||||
|
||||
### 聊天记录
|
||||
|
||||
适当增加一些聊天记录,可以联系上下文进行分类。
|
||||
|
||||
### 用户问题
|
||||
|
||||
用户输入的内容。
|
||||
|
||||
### 分类内容
|
||||
|
||||
依然以这 3 个分类为例,可以看到最终组成的 Function。其中返回值由系统随机生成,不需要关心。
|
||||
|
||||
1. 打招呼
|
||||
2. Laf 常见问题
|
||||
3. 其他问题
|
||||
|
||||
```js
|
||||
const agentFunction = {
|
||||
name: agentFunName,
|
||||
description: '判断用户问题的类型属于哪方面,返回对应的枚举字段',
|
||||
parameters: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
type: {
|
||||
type: 'string',
|
||||
description: `打招呼,返回: abc;Laf 常见问题,返回:vvv;其他问题,返回:aaa`
|
||||
enum: ["abc","vvv","aaa"]
|
||||
}
|
||||
},
|
||||
required: ['type']
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
上面的 Function 必然会返回 `type = abc,vvv,aaa` 其中一个值,从而实现分类判断。
|
32
docSite/content/docs/workflow/modules/reply.md
Normal file
32
docSite/content/docs/workflow/modules/reply.md
Normal file
@@ -0,0 +1,32 @@
|
||||
---
|
||||
title: "指定回复"
|
||||
description: "FastGPT 指定回复模块介绍"
|
||||
icon: "reply"
|
||||
draft: false
|
||||
toc: true
|
||||
weight: 429
|
||||
---
|
||||
|
||||
## 特点
|
||||
|
||||
- 可重复添加(防止复杂编排时线太乱,重复添加可以更美观)
|
||||
- 可手动输入
|
||||
- 可外部输入
|
||||
- 会输出结果给客户端
|
||||
|
||||
制定回复模块通常用户特殊状态回复,当然你也可以像图 2 一样,实现一些比较骚的操作~ 触发逻辑非常简单:
|
||||
|
||||
1. 一种是写好回复内容,通过触发器触发。
|
||||
2. 一种是不写回复内容,直接由外部输入触发,并回复输入的内容。
|
||||
|
||||
{{< figure
|
||||
src="/imgs/specialreply.png"
|
||||
alt=""
|
||||
caption="图 1"
|
||||
>}}
|
||||
|
||||
{{< figure
|
||||
src="/imgs/specialreply2.png"
|
||||
alt=""
|
||||
caption="图 2"
|
||||
>}}
|
24
docSite/content/docs/workflow/modules/trigger.md
Normal file
24
docSite/content/docs/workflow/modules/trigger.md
Normal file
@@ -0,0 +1,24 @@
|
||||
---
|
||||
title: "触发器"
|
||||
description: "FastGPT 触发器模块介绍"
|
||||
icon: "work_history"
|
||||
draft: false
|
||||
toc: true
|
||||
weight: 421
|
||||
---
|
||||
|
||||
细心的同学可以发现,在每个功能模块里都会有一个叫【触发器】的外部输入,并且是 any 类型。
|
||||
|
||||
它的**核心作用**就是控制模块的执行时机,以下图两个知识库搜索中的【AI 对话】模块为例子:
|
||||
|
||||
| 图 1 | 图 2 |
|
||||
| ---------------------------- | ---------------------------- |
|
||||
|  |  |
|
||||
|
||||
【知识库搜索】模块中,由于**引用内容**始终会有输出,会导致【AI 对话】模块的**引用内容**输入无论有没有搜到内容都会被赋值。如果此时不连接触发器(图 2),在搜索结束后必定会执行【AI 对话】模块。
|
||||
|
||||
有时候,你可能希望空搜索时候进行额外处理,例如:回复固定内容、调用其他提示词的 GPT、发送一个 HTTP 请求…… 此时就需要用到触发器,需要将 **搜索结果不为空** 和 **触发器** 连接起来。
|
||||
|
||||
当搜索结果为空时,【知识库搜索】模块不会输出 **搜索结果不为空** 的结果,因此 【AI 对话】 模块的触发器始终为空,便不会执行。
|
||||
|
||||
总之,记住模块执行的逻辑就可以灵活的使用触发器:**外部输入字段(有连接的才有效)全部被赋值时才会被执行**。
|
35
docSite/content/docs/workflow/modules/variable.md
Normal file
35
docSite/content/docs/workflow/modules/variable.md
Normal file
@@ -0,0 +1,35 @@
|
||||
---
|
||||
title: "全局变量"
|
||||
description: "FastGPT 全局变量模块介绍"
|
||||
icon: "variables"
|
||||
draft: false
|
||||
toc: true
|
||||
weight: 422
|
||||
---
|
||||
|
||||
## 特点
|
||||
|
||||
- 仅可添加 1 个
|
||||
- 需要手动配置
|
||||
- 对其他模块有影响
|
||||
- 可作为用户引导
|
||||
|
||||
## 说明
|
||||
|
||||
可以在对话前设置一些问题,让用户输入或选择,并将用户输入/选择的结果注入到其他模块中。目前仅会注入到 string 类型的数据里(对应蓝色圆圈的输入)。
|
||||
|
||||
如下图,定义了两个变量:目标语言和下拉框测试(忽略)
|
||||
|
||||
用户在对话前会被要求先填写目标语言,配合用户引导,我们就构建了一个简单的翻译机器人。**目标语言**的 `key:language` 被写入到【AI 对话】模块的限定词里。
|
||||
|
||||

|
||||
|
||||
通过完整对话记录我们可以看到,实际的限定词从:“将我的问题直接翻译成{{language}}” 变成了 “将我的问题直接翻译成英语”,因为 {{language}} 被变量替换了。
|
||||
|
||||

|
||||
|
||||
## 系统级变量
|
||||
|
||||
除了用户自定义设置的变量外,还会有一些系统变量:
|
||||
|
||||
+ **cTime**: 当前时间。例如:2023/3/3 20:22
|
Reference in New Issue
Block a user