Skip to content

Commit ab57bfc

Browse files
authored
perf: completions api.fix: new chat question guide (FlowiseAI#361)
1 parent 11848b8 commit ab57bfc

File tree

16 files changed

+555
-538
lines changed

16 files changed

+555
-538
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ https://github.com/labring/FastGPT/assets/15308462/7d3a38df-eb0e-4388-9250-2409b
3939
- [x] 文本内容提取成结构化数据
4040
- [x] HTTP 扩展
4141
- [ ] 嵌入 Laf,实现在线编写 HTTP 模块
42-
- [ ] 连续对话引导
42+
- [x] 对话下一步指引
4343
- [ ] 对话多路线选择
4444
- [x] 源文件引用追踪
4545
- [ ] 自定义文件阅读器
@@ -55,7 +55,7 @@ https://github.com/labring/FastGPT/assets/15308462/7d3a38df-eb0e-4388-9250-2409b
5555
- [x] 知识库单点搜索测试
5656
- [x] 对话时反馈引用并可修改与删除
5757
- [x] 完整上下文呈现
58-
- [ ] 完整模块中间值呈现
58+
- [x] 完整模块中间值呈现
5959
4. OpenAPI
6060
- [x] completions 接口(对齐 GPT 接口)
6161
- [ ] 知识库 CRUD

docSite/content/docs/development/openApi.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ FastGPT 的 API Key 有 2 类,一类是全局通用的 key;一类是携带
4646
**请求示例:**
4747

4848
```bash
49-
curl --location --request POST 'https://fastgpt.run/api/openapi/v1/chat/completions' \
49+
curl --location --request POST 'https://fastgpt.run/api/v1/chat/completions' \
5050
--header 'Authorization: Bearer apikey' \
5151
--header 'Content-Type: application/json' \
5252
--data-raw '{

docSite/content/docs/use-cases/onwechat.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ weight: 312
2626

2727
## 3. 创建 docker-compose.yml 文件
2828

29-
只需要修改 `OPEN_AI_API_KEY``OPEN_AI_API_BASE` 两个环境变量即可。其中 `OPEN_AI_API_KEY` 为第一步获取的秘钥,`OPEN_AI_API_BASE` 为 FastGPT 的 OpenAPI 地址,例如:`https://fastgpt.run/api/openapi/v1`
29+
只需要修改 `OPEN_AI_API_KEY``OPEN_AI_API_BASE` 两个环境变量即可。其中 `OPEN_AI_API_KEY` 为第一步获取的秘钥,`OPEN_AI_API_BASE` 为 FastGPT 的 OpenAPI 地址,例如:`https://fastgpt.run/api/v1`
3030

3131
随便找一个目录,创建一个 docker-compose.yml 文件,将下面的代码复制进去。
3232

@@ -40,7 +40,7 @@ services:
4040
- seccomp:unconfined
4141
environment:
4242
OPEN_AI_API_KEY: 'fastgpt-z51pkjqm9nrk03a1rx2funoy'
43-
OPEN_AI_API_BASE: 'https://fastgpt.run/api/openapi/v1'
43+
OPEN_AI_API_BASE: 'https://fastgpt.run/api/v1'
4444
MODEL: 'gpt-3.5-turbo'
4545
CHANNEL_TYPE: 'wx'
4646
PROXY: ''

docSite/content/docs/use-cases/openapi.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Tips: 安全起见,你可以设置一个额度或者过期时间,放置 key
2525
## 替换三方应用的变量
2626

2727
```bash
28-
OPENAI_API_BASE_URL: https://fastgpt.run/api/openapi (改成自己部署的域名)
28+
OPENAI_API_BASE_URL: https://fastgpt.run/api (改成自己部署的域名)
2929
OPENAI_API_KEY = 上一步获取到的秘钥
3030
```
3131

projects/app/src/api/fetch.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ interface StreamFetchProps {
1212
abortSignal: AbortController;
1313
}
1414
export const streamFetch = ({
15-
url = '/api/openapi/v1/chat/completions',
15+
url = '/api/v1/chat/completions',
1616
data,
1717
onMessage,
1818
abortSignal

projects/app/src/components/ChatBox/index.tsx

+14-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { useMarkdown } from '@/hooks/useMarkdown';
2727
import { AppModuleItemType, VariableItemType } from '@/types/app';
2828
import { VariableInputEnum } from '@/constants/app';
2929
import { useForm } from 'react-hook-form';
30-
import { MessageItemType } from '@/pages/api/openapi/v1/chat/completions';
30+
import type { MessageItemType } from '@/types/core/chat/type';
3131
import { fileDownload } from '@/utils/web/file';
3232
import { htmlTemplate } from '@/constants/common';
3333
import { useRouter } from 'next/router';
@@ -158,6 +158,7 @@ const ChatBox = (
158158
onStartChat?: (e: StartChatFnProps) => Promise<{
159159
responseText: string;
160160
[TaskResponseKeyEnum.responseData]: ChatHistoryItemResType[];
161+
isNewChat?: boolean;
161162
}>;
162163
onDelMessage?: (e: { contentId?: string; index: number }) => void;
163164
},
@@ -173,6 +174,7 @@ const ChatBox = (
173174
const TextareaDom = useRef<HTMLTextAreaElement>(null);
174175
const chatController = useRef(new AbortController());
175176
const questionGuideController = useRef(new AbortController());
177+
const isNewChatReplace = useRef(false);
176178

177179
const [refresh, setRefresh] = useState(false);
178180
const [variables, setVariables] = useState<Record<string, any>>({}); // settings variable
@@ -381,14 +383,20 @@ const ChatBox = (
381383

382384
const messages = adaptChat2GptMessages({ messages: newChatList, reserveId: true });
383385

384-
const { responseData, responseText } = await onStartChat({
386+
const {
387+
responseData,
388+
responseText,
389+
isNewChat = false
390+
} = await onStartChat({
385391
chatList: newChatList,
386392
messages,
387393
controller: abortSignal,
388394
generatingMessage,
389395
variables
390396
});
391397

398+
isNewChatReplace.current = isNewChat;
399+
392400
// set finish status
393401
setChatHistory((state) =>
394402
state.map((item, index) => {
@@ -542,9 +550,12 @@ const ChatBox = (
542550

543551
// page change and abort request
544552
useEffect(() => {
553+
isNewChatReplace.current = false;
545554
return () => {
546555
chatController.current?.abort('leave');
547-
questionGuideController.current?.abort('leave');
556+
if (!isNewChatReplace.current) {
557+
questionGuideController.current?.abort('leave');
558+
}
548559
// close voice
549560
cancelBroadcast();
550561
};

projects/app/src/components/Markdown/index.module.scss

+3-4
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,10 @@
171171
.markdown ol li > *:first-child {
172172
margin-top: 0;
173173
}
174-
.markdown ul ul,
175-
.markdown ul ol,
176-
.markdown ol ol,
177-
.markdown ol ul {
174+
.markdown ul,
175+
.markdown ol {
178176
margin-bottom: 0;
177+
padding-left: 14px;
179178
}
180179
.markdown dl {
181180
padding: 0;

projects/app/src/pages/api/chat/chatTest.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { sseErrRes } from '@/service/response';
55
import { sseResponseEventEnum } from '@/constants/chat';
66
import { sseResponse } from '@/service/utils/tools';
77
import { AppModuleItemType } from '@/types/app';
8-
import { dispatchModules } from '../openapi/v1/chat/completions';
8+
import { dispatchModules } from '@/pages/api/v1/chat/completions';
99
import { pushChatBill } from '@/service/common/bill/push';
1010
import { BillSourceEnum } from '@/constants/user';
1111
import { ChatItemType } from '@/types/chat';

0 commit comments

Comments
 (0)