Skip to content

Commit c02864f

Browse files
fix: package plus request (#4492)
* fix plus request (#4476) * perf: package plus request * perf: plus request fix * fix: doc --------- Co-authored-by: heheer <[email protected]>
1 parent e4629a5 commit c02864f

File tree

21 files changed

+158
-290
lines changed

21 files changed

+158
-290
lines changed

docSite/content/zh-cn/docs/development/openapi/chat.md

Lines changed: 15 additions & 177 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,13 @@ weight: 852
3434

3535
### 请求
3636

37-
<!-- #### v2
38-
39-
v1,v2 接口请求参数一致,仅请求地址不一样。
40-
4137
{{< tabs tabTotal="3" >}}
4238
{{< tab tabName="基础请求示例" >}}
4339
{{< markdownify >}}
4440

4541
```bash
46-
curl --location --request POST 'http://localhost:3000/api/v2/chat/completions' \
47-
--header 'Authorization: fastgpt-xxxxxx' \
42+
curl --location --request POST 'http://localhost:3000/api/v1/chat/completions' \
43+
--header 'Authorization: Bearer fastgpt-xxxxxx' \
4844
--header 'Content-Type: application/json' \
4945
--data-raw '{
5046
"chatId": "my_chatId",
@@ -58,7 +54,7 @@ curl --location --request POST 'http://localhost:3000/api/v2/chat/completions' \
5854
"messages": [
5955
{
6056
"role": "user",
61-
"content": "你是谁"
57+
"content": "导演是谁"
6258
}
6359
]
6460
}'
@@ -74,7 +70,7 @@ curl --location --request POST 'http://localhost:3000/api/v2/chat/completions' \
7470
* 目前不支持上传文件,需上传到自己的对象存储中,获取对应的文件链接。
7571

7672
```bash
77-
curl --location --request POST 'http://localhost:3000/api/v2/chat/completions' \
73+
curl --location --request POST 'http://localhost:3000/api/v1/chat/completions' \
7874
--header 'Authorization: Bearer fastgpt-xxxxxx' \
7975
--header 'Content-Type: application/json' \
8076
--data-raw '{
@@ -126,15 +122,17 @@ curl --location --request POST 'http://localhost:3000/api/v2/chat/completions' \
126122
{{< /tab >}}
127123
{{< /tabs >}}
128124

129-
#### v1
125+
<!-- #### v2
126+
127+
v1,v2 接口请求参数一致,仅请求地址不一样。
130128
131129
{{< tabs tabTotal="3" >}}
132130
{{< tab tabName="基础请求示例" >}}
133131
{{< markdownify >}}
134132
135133
```bash
136-
curl --location --request POST 'http://localhost:3000/api/v1/chat/completions' \
137-
--header 'Authorization: Bearer fastgpt-xxxxxx' \
134+
curl --location --request POST 'http://localhost:3000/api/v2/chat/completions' \
135+
--header 'Authorization: fastgpt-xxxxxx' \
138136
--header 'Content-Type: application/json' \
139137
--data-raw '{
140138
"chatId": "my_chatId",
@@ -148,7 +146,7 @@ curl --location --request POST 'http://localhost:3000/api/v1/chat/completions' \
148146
"messages": [
149147
{
150148
"role": "user",
151-
"content": "导演是谁"
149+
"content": "你是谁"
152150
}
153151
]
154152
}'
@@ -164,7 +162,7 @@ curl --location --request POST 'http://localhost:3000/api/v1/chat/completions' \
164162
* 目前不支持上传文件,需上传到自己的对象存储中,获取对应的文件链接。
165163
166164
```bash
167-
curl --location --request POST 'http://localhost:3000/api/v1/chat/completions' \
165+
curl --location --request POST 'http://localhost:3000/api/v2/chat/completions' \
168166
--header 'Authorization: Bearer fastgpt-xxxxxx' \
169167
--header 'Content-Type: application/json' \
170168
--data-raw '{
@@ -216,6 +214,10 @@ curl --location --request POST 'http://localhost:3000/api/v1/chat/completions' \
216214
{{< /tab >}}
217215
{{< /tabs >}}
218216
217+
#### v1
218+
219+
220+
219221
### 响应
220222
221223
#### v2
@@ -745,8 +747,6 @@ curl --location --request POST 'https://api.fastgpt.in/api/v1/chat/completions'
745747

746748
### 请求示例
747749

748-
#### v1
749-
750750
```bash
751751
curl --location --request POST 'http://localhost:3000/api/v1/chat/completions' \
752752
--header 'Authorization: Bearer test-xxxxx' \
@@ -760,25 +760,8 @@ curl --location --request POST 'http://localhost:3000/api/v1/chat/completions' \
760760
}'
761761
```
762762

763-
#### v2
764-
765-
```bash
766-
curl --location --request POST 'http://localhost:3000/api/v2/chat/completions' \
767-
--header 'Authorization: Bearer test-xxxxx' \
768-
--header 'Content-Type: application/json' \
769-
--data-raw '{
770-
"stream": false,
771-
"chatId": "test",
772-
"variables": {
773-
"query":"你好"
774-
}
775-
}'
776-
```
777-
778763
### 响应示例
779764

780-
#### v1
781-
782765
{{< tabs tabTotal="3" >}}
783766

784767
{{< tab tabName="detail=true,stream=false 响应" >}}
@@ -937,151 +920,6 @@ event取值:
937920
{{< /tab >}}
938921
{{< /tabs >}}
939922

940-
941-
#### v2
942-
943-
{{< tabs tabTotal="3" >}}
944-
945-
{{< tab tabName="detail=true,stream=false 响应" >}}
946-
{{< markdownify >}}
947-
948-
* 插件的输出可以通过查找`responseData`中, `moduleType=pluginOutput`的元素,其`pluginOutput`是插件的输出。
949-
* 流输出,仍可以通过`choices`进行获取。
950-
951-
```json
952-
{
953-
"responseData": [
954-
{
955-
"id": "bsH1ZdbYkz9iJwYa",
956-
"nodeId": "pluginInput",
957-
"moduleName": "workflow:template.plugin_start",
958-
"moduleType": "pluginInput",
959-
"runningTime": 0
960-
},
961-
{
962-
"id": "zDgfqSPhbYZFHVIn",
963-
"nodeId": "h4Gr4lJtFVQ6qI4c",
964-
"moduleName": "AI 对话",
965-
"moduleType": "chatNode",
966-
"runningTime": 1.44,
967-
"totalPoints": 0,
968-
"model": "GPT-4o-mini",
969-
"tokens": 34,
970-
"inputTokens": 8,
971-
"outputTokens": 26,
972-
"query": "你好",
973-
"reasoningText": "",
974-
"historyPreview": [
975-
{
976-
"obj": "Human",
977-
"value": "你好"
978-
},
979-
{
980-
"obj": "AI",
981-
"value": "你好!有什么我可以帮助你的吗?"
982-
}
983-
],
984-
"contextTotalLen": 2
985-
},
986-
{
987-
"id": "uLLwKKRZvufXzgF4",
988-
"nodeId": "pluginOutput",
989-
"moduleName": "common:core.module.template.self_output",
990-
"moduleType": "pluginOutput",
991-
"runningTime": 0,
992-
"totalPoints": 0,
993-
"pluginOutput": {
994-
"result": "你好!有什么我可以帮助你的吗?"
995-
}
996-
}
997-
],
998-
"newVariables": {
999-
1000-
},
1001-
"id": "test",
1002-
"model": "",
1003-
"usage": {
1004-
"prompt_tokens": 1,
1005-
"completion_tokens": 1,
1006-
"total_tokens": 1
1007-
},
1008-
"choices": [
1009-
{
1010-
"message": {
1011-
"role": "assistant",
1012-
"content": "你好!有什么我可以帮助你的吗?"
1013-
},
1014-
"finish_reason": "stop",
1015-
"index": 0
1016-
}
1017-
]
1018-
}
1019-
```
1020-
1021-
{{< /markdownify >}}
1022-
{{< /tab >}}
1023-
1024-
1025-
{{< tab tabName="detail=true,stream=true 响应" >}}
1026-
{{< markdownify >}}
1027-
1028-
* 插件的输出可以通过获取`event=flowResponses`中的字符串,并将其反序列化后得到一个数组。同样的,查找 `moduleType=pluginOutput`的元素,其`pluginOutput`是插件的输出。
1029-
* 流输出,仍和对话接口一样获取。
1030-
1031-
```bash
1032-
data: {"event":"flowNodeResponse","data":"{\"id\":\"q8ablUOqHGgqLIRM\",\"nodeId\":\"pluginInput\",\"moduleName\":\"workflow:template.plugin_start\",\"moduleType\":\"pluginInput\",\"runningTime\":0}"}
1033-
1034-
data: {"event":"flowNodeStatus","data":"{\"status\":\"running\",\"name\":\"AI 对话\"}"}
1035-
1036-
data: {"event":"answer","data":"{\"id\":\"\",\"object\":\"\",\"created\":0,\"model\":\"\",\"choices\":[{\"delta\":{\"role\":\"assistant\",\"content\":\"你好\"},\"index\":0,\"finish_reason\":null}]}"}
1037-
1038-
data: {"event":"answer","data":"{\"id\":\"\",\"object\":\"\",\"created\":0,\"model\":\"\",\"choices\":[{\"delta\":{\"role\":\"assistant\",\"content\":\"\"},\"index\":0,\"finish_reason\":null}]}"}
1039-
1040-
data: {"event":"answer","data":"{\"id\":\"\",\"object\":\"\",\"created\":0,\"model\":\"\",\"choices\":[{\"delta\":{\"role\":\"assistant\",\"content\":\"有什么\"},\"index\":0,\"finish_reason\":null}]}"}
1041-
1042-
data: {"event":"answer","data":"{\"id\":\"\",\"object\":\"\",\"created\":0,\"model\":\"\",\"choices\":[{\"delta\":{\"role\":\"assistant\",\"content\":\"\"},\"index\":0,\"finish_reason\":null}]}"}
1043-
1044-
data: {"event":"answer","data":"{\"id\":\"\",\"object\":\"\",\"created\":0,\"model\":\"\",\"choices\":[{\"delta\":{\"role\":\"assistant\",\"content\":\"可以\"},\"index\":0,\"finish_reason\":null}]}"}
1045-
1046-
data: {"event":"answer","data":"{\"id\":\"\",\"object\":\"\",\"created\":0,\"model\":\"\",\"choices\":[{\"delta\":{\"role\":\"assistant\",\"content\":\"帮助\"},\"index\":0,\"finish_reason\":null}]}"}
1047-
1048-
data: {"event":"answer","data":"{\"id\":\"\",\"object\":\"\",\"created\":0,\"model\":\"\",\"choices\":[{\"delta\":{\"role\":\"assistant\",\"content\":\"\"},\"index\":0,\"finish_reason\":null}]}"}
1049-
1050-
data: {"event":"answer","data":"{\"id\":\"\",\"object\":\"\",\"created\":0,\"model\":\"\",\"choices\":[{\"delta\":{\"role\":\"assistant\",\"content\":\"的吗\"},\"index\":0,\"finish_reason\":null}]}"}
1051-
1052-
data: {"event":"answer","data":"{\"id\":\"\",\"object\":\"\",\"created\":0,\"model\":\"\",\"choices\":[{\"delta\":{\"role\":\"assistant\",\"content\":\"\"},\"index\":0,\"finish_reason\":null}]}"}
1053-
1054-
data: {"event":"flowNodeResponse","data":"{\"id\":\"rqlXLUap8QeiN7Kf\",\"nodeId\":\"h4Gr4lJtFVQ6qI4c\",\"moduleName\":\"AI 对话\",\"moduleType\":\"chatNode\",\"runningTime\":1.79,\"totalPoints\":0,\"model\":\"GPT-4o-mini\",\"tokens\":137,\"inputTokens\":111,\"outputTokens\":26,\"query\":\"你好\",\"reasoningText\":\"\",\"historyPreview\":[{\"obj\":\"Human\",\"value\":\"[{\\\"renderTypeList\\\":[\\\"reference\\\"],\\\"selectedTypeInde\\n\\n...[hide 174 chars]...\\n\\ncanSelectImg\\\":true,\\\"required\\\":false,\\\"value\\\":\\\"你好\\\"}]\"},{\"obj\":\"AI\",\"value\":\"你好!有什么我可以帮助你的吗?\"},{\"obj\":\"Human\",\"value\":\"你好\"},{\"obj\":\"AI\",\"value\":\"你好!有什么我可以帮助你的吗?\"}],\"contextTotalLen\":4}"}
1055-
1056-
data: {"event":"flowNodeResponse","data":"{\"id\":\"lHCpHI0MrM00HQlX\",\"nodeId\":\"pluginOutput\",\"moduleName\":\"common:core.module.template.self_output\",\"moduleType\":\"pluginOutput\",\"runningTime\":0,\"totalPoints\":0,\"pluginOutput\":{\"result\":\"你好!有什么我可以帮助你的吗?\"}}"}
1057-
1058-
data: {"event":"answer","data":"{\"id\":\"\",\"object\":\"\",\"created\":0,\"model\":\"\",\"choices\":[{\"delta\":{\"role\":\"assistant\",\"content\":null},\"index\":0,\"finish_reason\":\"stop\"}]}"}
1059-
1060-
data: {"event":"answer","data":"[DONE]"}
1061-
```
1062-
1063-
{{< /markdownify >}}
1064-
{{< /tab >}}
1065-
1066-
{{< tab tabName="输出获取" >}}
1067-
{{< markdownify >}}
1068-
1069-
event取值:
1070-
1071-
- answer: 返回给客户端的文本(最终会算作回答)
1072-
- fastAnswer: 指定回复返回给客户端的文本(最终会算作回答)
1073-
- toolCall: 执行工具
1074-
- toolParams: 工具参数
1075-
- toolResponse: 工具返回
1076-
- flowNodeStatus: 运行到的节点状态
1077-
- flowNodeResponse: 单个节点详细响应
1078-
- updateVariables: 更新变量
1079-
- error: 报错
1080-
1081-
{{< /markdownify >}}
1082-
{{< /tab >}}
1083-
{{< /tabs >}}
1084-
1085923
# 对话 CRUD
1086924

1087925
{{% alert icon="🤖 " context="success" %}}

docSite/content/zh-cn/docs/development/upgrading/494.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,5 @@ curl --location --request POST 'https://{{host}}/api/admin/initv494' \
6262
## 🐛 修复
6363

6464
1. 搜索应用/知识库时,无法点击目录进入下一层。
65-
2. 重新训练时,参数未成功初始化。
65+
2. 重新训练时,参数未成功初始化。
66+
3. package/service 部分请求在多 app 中不一致。
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { FeishuServer, YuqueServer } from '@fastgpt/global/core/dataset/apiDataset';
2+
import {
3+
DeepRagSearchProps,
4+
SearchDatasetDataResponse
5+
} from '../../core/dataset/search/controller';
6+
import { AuthOpenApiLimitProps } from '../../support/openapi/auth';
7+
import { CreateUsageProps, ConcatUsageProps } from '@fastgpt/global/support/wallet/usage/api';
8+
import {
9+
GetProApiDatasetFileContentParams,
10+
GetProApiDatasetFileListParams,
11+
GetProApiDatasetFilePreviewUrlParams
12+
} from '../../core/dataset/apiDataset/proApi';
13+
14+
declare global {
15+
var textCensorHandler: (params: { text: string }) => Promise<{ code: number; message?: string }>;
16+
var deepRagHandler: (data: DeepRagSearchProps) => Promise<SearchDatasetDataResponse>;
17+
var authOpenApiHandler: (data: AuthOpenApiLimitProps) => Promise<any>;
18+
var createUsageHandler: (data: CreateUsageProps) => Promise<void>;
19+
var concatUsageHandler: (data: ConcatUsageProps) => Promise<void>;
20+
21+
// API dataset
22+
var getProApiDatasetFileList: (data: GetProApiDatasetFileListParams) => Promise<APIFileItem[]>;
23+
var getProApiDatasetFileContent: (
24+
data: GetProApiDatasetFileContentParams
25+
) => Promise<ApiFileReadContentResponse>;
26+
var getProApiDatasetFilePreviewUrl: (
27+
data: GetProApiDatasetFilePreviewUrlParams
28+
) => Promise<string>;
29+
}
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
export const FastGPTProUrl = process.env.PRO_URL ? `${process.env.PRO_URL}/api` : '';
2-
export const isFastGPTMainService = !!process.env.PRO_URL;
32
// @ts-ignore
43
export const isFastGPTProService = () => !!global.systemConfig;

packages/service/common/api/requestPlusApi.ts renamed to packages/service/core/chat/postTextCensor.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { POST } from './plusRequest';
2-
31
export const postTextCensor = (data: { text: string }) =>
4-
POST<{ code?: number; message: string }>('/common/censor/check', data)
2+
global
3+
.textCensorHandler(data)
54
.then((res) => {
65
if (res?.code === 5000) {
76
return Promise.reject(res);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { ParentIdType } from '@fastgpt/global/common/parentFolder/type';
2+
import { FeishuServer, YuqueServer } from '@fastgpt/global/core/dataset/apiDataset';
3+
4+
export enum ProApiDatasetOperationTypeEnum {
5+
LIST = 'list',
6+
READ = 'read',
7+
CONTENT = 'content'
8+
}
9+
10+
export type ProApiDatasetCommonParams = {
11+
feishuServer?: FeishuServer;
12+
yuqueServer?: YuqueServer;
13+
};
14+
15+
export type GetProApiDatasetFileListParams = ProApiDatasetCommonParams & {
16+
parentId?: ParentIdType;
17+
};
18+
19+
export type GetProApiDatasetFileContentParams = ProApiDatasetCommonParams & {
20+
apiFileId: string;
21+
};
22+
23+
export type GetProApiDatasetFilePreviewUrlParams = ProApiDatasetCommonParams & {
24+
apiFileId: string;
25+
};

packages/service/core/dataset/read.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { readRawContentByFileBuffer } from '../../common/file/read/utils';
99
import { parseFileExtensionFromUrl } from '@fastgpt/global/common/string/tools';
1010
import { APIFileServer, FeishuServer, YuqueServer } from '@fastgpt/global/core/dataset/apiDataset';
1111
import { useApiDatasetRequest } from './apiDataset/api';
12-
import { POST } from '../../common/api/plusRequest';
1312

1413
export const readFileRawTextByUrl = async ({
1514
teamId,
@@ -168,11 +167,7 @@ export const readApiServerFileContent = async ({
168167
}
169168

170169
if (feishuServer || yuqueServer) {
171-
return POST<{
172-
title?: string;
173-
rawText: string;
174-
}>(`/core/dataset/systemApiDataset`, {
175-
type: 'content',
170+
return global.getProApiDatasetFileContent({
176171
feishuServer,
177172
yuqueServer,
178173
apiFileId

packages/service/core/dataset/search/controller.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import { MongoDatasetCollectionTags } from '../tag/schema';
2424
import { readFromSecondary } from '../../../common/mongo/utils';
2525
import { MongoDatasetDataText } from '../data/dataTextSchema';
2626
import { ChatItemType } from '@fastgpt/global/core/chat/type';
27-
import { POST } from '../../../common/api/plusRequest';
2827
import { NodeInputKeyEnum } from '@fastgpt/global/core/workflow/constants';
2928
import { datasetSearchQueryExtension } from './utils';
3029
import type { RerankModelItemType } from '@fastgpt/global/core/ai/model.d';
@@ -850,5 +849,4 @@ export type DeepRagSearchProps = SearchDatasetDataProps & {
850849
[NodeInputKeyEnum.datasetDeepSearchMaxTimes]?: number;
851850
[NodeInputKeyEnum.datasetDeepSearchBg]?: string;
852851
};
853-
export const deepRagSearch = (data: DeepRagSearchProps) =>
854-
POST<SearchDatasetDataResponse>('/core/dataset/deepRag', data);
852+
export const deepRagSearch = (data: DeepRagSearchProps) => global.deepRagHandler(data);

0 commit comments

Comments
 (0)