diff --git a/client/src/pages/api/openapi/v1/chat/completions.ts b/client/src/pages/api/openapi/v1/chat/completions.ts index 1b9f78bff..93b26e56f 100644 --- a/client/src/pages/api/openapi/v1/chat/completions.ts +++ b/client/src/pages/api/openapi/v1/chat/completions.ts @@ -13,7 +13,7 @@ import { dispatchClassifyQuestion } from '@/service/moduleDispatch'; import type { CreateChatCompletionRequest } from 'openai'; -import { gptMessage2ChatType } from '@/utils/adapt'; +import { gptMessage2ChatType, textAdaptGptResponse } from '@/utils/adapt'; import { getChatHistory } from './getHistory'; import { saveChat } from '@/service/utils/chat/saveChat'; import { sseResponse } from '@/service/utils/tools'; @@ -154,6 +154,14 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex console.log(`finish time: ${(Date.now() - startTime) / 1000}s`); if (stream) { + sseResponse({ + res, + event: sseResponseEventEnum.answer, + data: textAdaptGptResponse({ + text: null, + finish_reason: 'stop' + }) + }); sseResponse({ res, event: sseResponseEventEnum.answer, diff --git a/client/src/pages/chat/share.tsx b/client/src/pages/chat/share.tsx index 0404fc0c7..208dfefee 100644 --- a/client/src/pages/chat/share.tsx +++ b/client/src/pages/chat/share.tsx @@ -169,7 +169,7 @@ const ShareChat = ({ shareId, chatId }: { shareId: string; chatId: string }) => onChangeChat={(chatId) => { console.log(chatId); - router.push({ + router.replace({ query: { chatId: chatId || '', shareId diff --git a/client/src/service/moduleDispatch/chat/oneapi.ts b/client/src/service/moduleDispatch/chat/oneapi.ts index 6bb9b9ebd..d13a3a731 100644 --- a/client/src/service/moduleDispatch/chat/oneapi.ts +++ b/client/src/service/moduleDispatch/chat/oneapi.ts @@ -209,21 +209,7 @@ async function streamResponse({ res, response }: { res: NextApiResponse; respons if (res.closed || error) return; - if (data === '[DONE]') { - sseResponse({ - res, - event: sseResponseEventEnum.answer, - data: textAdaptGptResponse({ - text: null, - finish_reason: 'stop' - }) - }); - sseResponse({ - res, - event: sseResponseEventEnum.answer, - data: '[DONE]' - }); - } else { + if (data !== '[DONE]') { sseResponse({ res, event: sseResponseEventEnum.answer,