Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
2e1bf66d
authored
Nov 11, 2024
by
Archer
Committed by
GitHub
Nov 11, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: auto add empty response (#3113)
parent
952771e3
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
151 additions
and
0 deletions
+151
-0
docSite/content/zh-cn/docs/development/openapi/chat.md
+143
-0
packages/service/core/workflow/dispatch/index.ts
+8
-0
No files found.
docSite/content/zh-cn/docs/development/openapi/chat.md
View file @
2e1bf66d
...
@@ -312,6 +312,149 @@ event取值:
...
@@ -312,6 +312,149 @@ event取值:
{{
<
/
tabs
>
}}
{{
<
/
tabs
>
}}
### 交互节点响应
如果工作流中包含交互节点,依然是调用该 API 接口,需要设置
`detail=true`
,并可以从
`event=interactive`
的数据中获取交互节点的配置信息。如果是
`stream=false`
,则可以从 choice 中获取
`type=interactive`
的元素,获取交互节点的选择信息。
当你调用一个带交互节点的工作流时,如果工作流遇到了交互节点,那么会直接返回,你可以得到下面的信息:
{{
<
tabs
tabTotal=
"2"
>
}}
{{
<
tab
tabName=
"用户选择"
>
}}
{{
<
markdownify
>
}}
```
json
{
"interactive"
:
{
"type"
:
"userSelect"
,
"params"
:
{
"description"
:
"测试"
,
"userSelectOptions"
:
[
{
"value"
:
"Confirm"
,
"key"
:
"option1"
},
{
"value"
:
"Cancel"
,
"key"
:
"option2"
}
]
}
}
}
```
{{
<
/
markdownify
>
}}
{{
<
/
tab
>
}}
{{
<
tab
tabName=
"表单输入"
>
}}
{{
<
markdownify
>
}}
```
json
{
"interactive"
:
{
"type"
:
"userInput"
,
"params"
:
{
"description"
:
"测试"
,
"inputForm"
:
[
{
"type"
:
"input"
,
"key"
:
"测试 1"
,
"label"
:
"测试 1"
,
"description"
:
""
,
"value"
:
""
,
"defaultValue"
:
""
,
"valueType"
:
"string"
,
"required"
:
false
,
"list"
:
[
{
"label"
:
""
,
"value"
:
""
}
]
},
{
"type"
:
"numberInput"
,
"key"
:
"测试 2"
,
"label"
:
"测试 2"
,
"description"
:
""
,
"value"
:
""
,
"defaultValue"
:
""
,
"valueType"
:
"number"
,
"required"
:
false
,
"list"
:
[
{
"label"
:
""
,
"value"
:
""
}
]
}
]
}
}
}
```
{{
<
/
markdownify
>
}}
{{
<
/
tab
>
}}
{{
<
/
tabs
>
}}
### 交互节点继续运行
紧接着上一节,当你接收到交互节点信息后,可以根据这些数据进行 UI 渲染,引导用户输入或选择相关信息。然后需要再次发起对话,来继续工作流。调用的接口与仍是该接口,你需要按以下格式来发起请求:
{{
<
tabs
tabTotal=
"2"
>
}}
{{
<
tab
tabName=
"用户选择"
>
}}
{{
<
markdownify
>
}}
对于用户选择,你只需要直接传递一个选择的结果给 messages 即可。
```
bash
curl
--location
--request
POST
'https://api.fastgpt.in/api/v1/chat/completions'
\
--header
'Authorization: Bearer fastgpt-xxx'
\
--header
'Content-Type: application/json'
\
--data-raw
'{
"stream": true,
"detail": true,
"chatId":"22222231",
"messages": [
{
"role": "user",
"content": "Confirm"
}
]
}'
```
{{
<
/
markdownify
>
}}
{{
<
/
tab
>
}}
{{
<
tab
tabName=
"表单输入"
>
}}
{{
<
markdownify
>
}}
表单输入稍微麻烦一点,需要将输入的内容,以对象形式并序列化成字符串,作为
`messages`
的值。对象的 key 对应表单的 key,value 为用户输入的值。务必确保
`chatId`
是一致的。
```
bash
curl
--location
--request
POST
'https://api.fastgpt.in/api/v1/chat/completions'
\
--header
'Authorization: Bearer fastgpt-xxxx'
\
--header
'Content-Type: application/json'
\
--data-raw
'{
"stream": true,
"detail": true,
"chatId":"22231",
"messages": [
{
"role": "user",
"content": "{\"测试 1\":\"这是输入框的内容\",\"测试 2\":666}"
}
]
}'
```
{{
<
/
markdownify
>
}}
{{
<
/
tab
>
}}
{{
<
/
tabs
>
}}
## 请求插件
## 请求插件
插件的接口与对话接口一致,仅请求参数略有区别,有以下规定:
插件的接口与对话接口一致,仅请求参数略有区别,有以下规定:
...
...
packages/service/core/workflow/dispatch/index.ts
View file @
2e1bf66d
...
@@ -699,5 +699,13 @@ export const mergeAssistantResponseAnswerText = (response: AIChatItemValueItemTy
...
@@ -699,5 +699,13 @@ export const mergeAssistantResponseAnswerText = (response: AIChatItemValueItemTy
result
.
push
(
item
);
result
.
push
(
item
);
}
}
// If result is empty, auto add a text message
if
(
result
.
length
===
0
)
{
result
.
push
({
type
:
ChatItemValueTypeEnum
.
text
,
text
:
{
content
:
''
}
});
}
return
result
;
return
result
;
};
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment