flow moduoles (#161)
* flow intro * docs:flow modules * docs:flow modules
1
docSite/docs/flow-modules/examples/index.md
Normal file
@@ -0,0 +1 @@
|
||||
# Wait for completion
|
Before Width: | Height: | Size: 413 KiB After Width: | Height: | Size: 437 KiB |
BIN
docSite/docs/flow-modules/imgs/intro2.png
Normal file
After Width: | Height: | Size: 273 KiB |
BIN
docSite/docs/flow-modules/imgs/intro3.png
Normal file
After Width: | Height: | Size: 92 KiB |
BIN
docSite/docs/flow-modules/imgs/intro4.png
Normal file
After Width: | Height: | Size: 329 KiB |
@@ -2,22 +2,68 @@
|
||||
sidebar_position: 1
|
||||
---
|
||||
|
||||
# 模块编排介绍
|
||||
# Quick Start
|
||||
|
||||
FastGpt V4 后将采用新的交互方式来构建 AI 应用。使用了“节点”编排的方式去掉原先的表单方式。提高可玩性和扩展性的同时也提高了上手的门槛,这篇文章就来简单介绍一下 “预览版” 的模块编排基本使用方法。
|
||||
Starting from FastGpt V4, a new interactive way is introduced to build AI applications. It uses Flow node orchestration to implement complex workflows, improving playability and scalability. However, this also increases the learning curve, and users with some development background may find it easier to use.
|
||||
This article provides a brief introduction to the basics of module orchestration. Each module will be explained in detail in separate chapters.
|
||||

|
||||
|
||||

|
||||
## What is a Module?
|
||||
|
||||
预览版仅包含了 8 个模块,你可以利用它们来完全实现 V3 的知识库功能。此外,预览版还加入了问题分类模块,可以实现多路线任务。
|
||||
In programming, a module can be understood as a function or interface. It can be seen as a **step**. By connecting multiple modules together, you can gradually achieve the final AI output.
|
||||
In the following diagram, we have a simple AI conversation. It consists of a user input question, chat records, and an AI conversation module.
|
||||

|
||||
The workflow is as follows:
|
||||
|
||||
## 基础知识
|
||||
1. After the user inputs a question, a request is sent to the server with the question, resulting in an output from the "User Question" module.
|
||||
2. The "Chat Records" module retrieves the number of records from the database based on the set "Max Record Count", resulting in an output.
|
||||
After the above two steps, we obtain the results of the two blue dots on the left. The results are injected into the "AI" conversation module on the right.
|
||||
3. The AI conversation module uses the chat records and user question as inputs to call the conversation API and generate a response. (The conversation result output is hidden by default and will be sent to the client whenever the conversation module is triggered)
|
||||
|
||||
### 什么是模块
|
||||
### Module Categories
|
||||
|
||||
在程序中,模块可以理解为一个个 function 或者接口。对于非技术背景同学,可以理解为它就是一个**步骤**。将多个模块一个个拼接起来,即可一步步的去实现最终的 AI 输出。
|
||||
In terms of functionality, modules can be divided into 3 categories:
|
||||
|
||||
### 如何阅读和理解
|
||||
1. Read-only modules: global variables, user prompts
|
||||
2. System modules: chat records (no input, directly retrieved from the database), user question (workflow entry)
|
||||
3. Function modules: knowledge base search, AI conversation, and other remaining modules (these modules have both input and output and can be freely combined)
|
||||
|
||||
1. 建议从左往右阅读。
|
||||
2. 从 **用户问题** 模块开始。用户问题模块,代表的是用户发送了一段文本,触发任务开始。
|
||||
3.
|
||||
### Module Components
|
||||
|
||||
Each module consists of 3 core parts: fixed parameters, external inputs (represented by a circle on the left), and outputs (represented by a circle on the right).
|
||||
For read-only modules, you only need to fill in the prompts and they do not participate in the workflow execution.
|
||||
For system modules, usually only fixed parameters and outputs are present, and the focus is on where the output is directed.
|
||||
For function modules, all 3 parts are important. Taking the AI conversation module in the following diagram as an example:
|
||||

|
||||
The dialogue model, temperature, reply limit, system prompts, and restricted words are fixed parameters. The system prompts and restricted words can also be used as external inputs, which means that if you have an input flow to the system prompts, the originally filled content will be **overwritten**.
|
||||
The triggers, referenced content, chat records, and user question are external inputs that need to flow in from the outputs of other modules.
|
||||
The reply end is the output of this module.
|
||||
|
||||
### When are Modules Executed?
|
||||
|
||||
Remember the principles:
|
||||
|
||||
1. Only **connected** external inputs matter, i.e., the circles on the left are connected.
|
||||
2. Execution is triggered when all connected inputs have values.
|
||||
|
||||
#### Example 1:
|
||||
|
||||
The chat records module is automatically executed, so the input for chat records is automatically assigned a value. When the user sends a question, the "User Question" module outputs a value, and at this point, the user question input of the "AI Conversation" module is also assigned a value. After both connected inputs have values, the "AI Conversation" module is executed.
|
||||

|
||||
|
||||
#### Example 2:
|
||||
|
||||
The following diagram shows an example of a knowledge base search.
|
||||
|
||||
1. The chat history flows into the "AI" conversation module.
|
||||
2. The user's question flows into both the "Knowledge Base Search" and "AI Conversation" modules. Since the triggers and referenced content of the "AI Conversation" module are still empty, it will not be executed at this point.
|
||||
3. The "Knowledge Base Search" module has only one external input, and it is assigned a value, so it starts executing.
|
||||
4. When the "Knowledge Base Search" result is empty, the value of "Search Result Not Empty" is empty and will not be output. Therefore, the "AI Conversation" module cannot be executed due to the triggers not being assigned a value. However, "Search Result Empty" has an output and flows to the triggers of the specified reply module, so the "Specified Reply" module outputs a response.
|
||||
5. When the "Knowledge Base Search" result is not empty, both "Search Result Not Empty" and "Referenced Content" have outputs, which flow into the "AI Conversation" module. At this point, all 4 external inputs of the "AI Conversation" module are assigned values, and it starts executing.
|
||||

|
||||
|
||||
## How to Read?
|
||||
|
||||
1. It is recommended to read from left to right.
|
||||
2. Start with the "User Question" module. The user question module represents a user sending a piece of text, triggering the task.
|
||||
3. Pay attention to the "AI Conversation" and "Specified Reply" modules, as these are the places where the answers are output.
|
||||
|
62
docSite/docs/flow-modules/modules/ai_chat.md
Normal file
@@ -0,0 +1,62 @@
|
||||
# AI Chat
|
||||
|
||||
- Repeatable addition (to prevent messy lines in complex arrangements and make it more visually appealing)
|
||||
- External input available
|
||||
- Static configuration available
|
||||
- Trigger execution
|
||||
- Core module
|
||||
|
||||

|
||||
|
||||
## Parameter Description
|
||||
|
||||
### Chat Model
|
||||
|
||||
You can configure the optional chat models through [data/config.json](/docs/develop/data_config/chat_models) and implement multi-model access through [OneAPI](http://localhost:3000/docs/develop/oneapi).
|
||||
|
||||
### Temperature & Reply Limit
|
||||
|
||||
Temperature: The lower the temperature, the more precise the answer and the less unnecessary words (tested, but the difference doesn't seem significant).
|
||||
Reply Limit: Maximum number of reply tokens (only applicable to OpenAI models). Note that this is the reply, not the total tokens.
|
||||
|
||||
### System Prompt (can be overridden by external input)
|
||||
|
||||
Placed at the beginning of the context array with the role as system, used to guide the model. Refer to the tutorials of various search engines for specific usage~
|
||||
|
||||
### Constraint Words (can be overridden by external input)
|
||||
|
||||
Similar to system prompts, the role is also system type, but the position is placed before the question, with a stronger guiding effect.
|
||||
|
||||
### Quoted Content
|
||||
|
||||
Receives an array of external input, mainly generated by the "Knowledge Base Search" module, and can also be imported from external sources through the Http module. The data structure example is as follows:
|
||||
|
||||
```ts
|
||||
type DataType = {
|
||||
kb_id?: string;
|
||||
id?: string;
|
||||
q: string;
|
||||
a: string;
|
||||
source?: string;
|
||||
};
|
||||
// If it is externally imported content, try not to carry kb_id and 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: '' }
|
||||
];
|
||||
```
|
||||
|
||||
## Complete Context Composition
|
||||
|
||||
The data sent to the LLM model in the end is an array, with the content and order as follows:
|
||||
|
||||
```
|
||||
[
|
||||
System Prompt
|
||||
Quoted Content
|
||||
Chat History
|
||||
Constraint Words
|
||||
Question
|
||||
]
|
||||
```
|
9
docSite/docs/flow-modules/modules/guide.md
Normal file
@@ -0,0 +1,9 @@
|
||||
# User Guide
|
||||
|
||||
- Only one can be added
|
||||
- No external input
|
||||
- Not involved in actual scheduling
|
||||
|
||||
As shown in the image, you can provide some guidance to the user before asking questions. You can also set a guiding question.
|
||||
|
||||

|
10
docSite/docs/flow-modules/modules/history.md
Normal file
@@ -0,0 +1,10 @@
|
||||
# History
|
||||
|
||||
- Can be repeated (to prevent messy lines when complex arrangements are made, for a more aesthetic appearance)
|
||||
- No external input
|
||||
- Entry point of the process
|
||||
- Automatic execution
|
||||
|
||||
During each conversation, up to n chat records will be retrieved from the database as context. Note that this does not refer to a maximum of n context records for the current round of conversation, as the current round of conversation also includes: prompts, qualifiers, referenced content, and questions.
|
||||
|
||||

|
BIN
docSite/docs/flow-modules/modules/imgs/aichat.png
Normal file
After Width: | Height: | Size: 84 KiB |
BIN
docSite/docs/flow-modules/modules/imgs/chatinput.png
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
docSite/docs/flow-modules/modules/imgs/guide.png
Normal file
After Width: | Height: | Size: 77 KiB |
BIN
docSite/docs/flow-modules/modules/imgs/history.png
Normal file
After Width: | Height: | Size: 23 KiB |
BIN
docSite/docs/flow-modules/modules/imgs/specialreply.png
Normal file
After Width: | Height: | Size: 182 KiB |
BIN
docSite/docs/flow-modules/modules/imgs/specialreply2.png
Normal file
After Width: | Height: | Size: 228 KiB |
BIN
docSite/docs/flow-modules/modules/imgs/trigger1.png
Normal file
After Width: | Height: | Size: 115 KiB |
BIN
docSite/docs/flow-modules/modules/imgs/trigger2.png
Normal file
After Width: | Height: | Size: 121 KiB |
BIN
docSite/docs/flow-modules/modules/imgs/variable.png
Normal file
After Width: | Height: | Size: 285 KiB |
BIN
docSite/docs/flow-modules/modules/imgs/variable2.png
Normal file
After Width: | Height: | Size: 108 KiB |
11
docSite/docs/flow-modules/modules/special_reply.md
Normal file
@@ -0,0 +1,11 @@
|
||||
# Special Reply
|
||||
|
||||
- Can be added repeatedly (to prevent messy lines in complex arrangements and make it more visually appealing)
|
||||
- Can be manually inputted
|
||||
- Can be externally inputted
|
||||
- Will output results to the client
|
||||
|
||||
The special reply module is usually used for replying to specific states. Of course, you can also implement some fancy operations like in Figure 2. The triggering logic is very simple. One way is to write the reply content and trigger it through a trigger. Another way is to not write the reply content and directly trigger it through external input, and reply with the inputted content.
|
||||
|
||||

|
||||

|
20
docSite/docs/flow-modules/modules/trigger.md
Normal file
@@ -0,0 +1,20 @@
|
||||
---
|
||||
sidebar_position: 1
|
||||
---
|
||||
|
||||
# Introduction to Triggers
|
||||
|
||||
Observant students may notice that there is an external input called "Trigger" in each functional module, and it is of type "any".
|
||||
Its **core function** is to control the timing of module execution. Let's take the "AI Dialogue" module in the two knowledge base search examples below as an example:
|
||||
|
||||
| Figure 1 | Figure 2 |
|
||||
| ---------------------------- | ---------------------------- |
|
||||
|  |  |
|
||||
|
||||
In the "Knowledge Base Search" module, since the referenced content always has an output, the "Referenced Content" input of the "AI Dialogue" module will always be assigned a value, regardless of whether the content is found or not. If the trigger is not connected (Figure 2), the "AI Dialogue" module will always be executed after the search is completed.
|
||||
|
||||
Sometimes, you may want to perform additional processing when there is an empty search, such as replying with fixed content, calling another GPT with different prompts, or sending an HTTP request... In this case, you need to use a trigger and connect the **search result is not empty** with the **trigger**.
|
||||
When the search result is empty, the "Knowledge Base Search" module will not output the result of **search result is not empty**, so the trigger of the "AI Dialogue" module will always be empty and it will not be executed.
|
||||
|
||||
In summary, by understanding the logic of module execution, you can use triggers flexibly:
|
||||
**Execute when all external input fields (those with connections) are assigned values**.
|
8
docSite/docs/flow-modules/modules/user_input.md
Normal file
@@ -0,0 +1,8 @@
|
||||
# User Questions
|
||||
|
||||
- Repeated Addition (to prevent messy lines and improve visual aesthetics in complex workflows)
|
||||
- No external input
|
||||
- Flow entry point
|
||||
- Automatic execution
|
||||
|
||||

|
19
docSite/docs/flow-modules/modules/variable.md
Normal file
@@ -0,0 +1,19 @@
|
||||
---
|
||||
sidebar_position: 2
|
||||
---
|
||||
|
||||
# Global Variables
|
||||
|
||||
- Only one can be added
|
||||
- Manually configured
|
||||
- Affects other modules
|
||||
- Can be used for user guidance
|
||||
|
||||
You can set some questions before the conversation starts, allowing users to input or select their answers, and inject the results into other modules. Currently, it can only be injected into string type data (represented by a blue circle).
|
||||
In the example below, two variables are defined: "Target Language" and "Dropdown Test (Ignore)". Users will be asked to fill in the target language before the conversation starts. With user guidance, we can build a simple translation bot. The key of "Target Language" (language) is written into the qualifiers of the "AI Dialogue" module.
|
||||
|
||||

|
||||
|
||||
By examining the complete conversation log, we can see that the actual qualifier changes from "Translate my question directly into {{language}}" to "Translate my question directly into English" because {{language}} is replaced by the variable.
|
||||
|
||||

|