Commit ba965320 by archer

perf: openapi

parent 67e10d6f
...@@ -13,7 +13,7 @@ import { ...@@ -13,7 +13,7 @@ import {
dispatchClassifyQuestion dispatchClassifyQuestion
} from '@/service/moduleDispatch'; } from '@/service/moduleDispatch';
import type { CreateChatCompletionRequest } from 'openai'; import type { CreateChatCompletionRequest } from 'openai';
import { gptMessage2ChatType } from '@/utils/adapt'; import { gptMessage2ChatType, textAdaptGptResponse } from '@/utils/adapt';
import { getChatHistory } from './getHistory'; import { getChatHistory } from './getHistory';
import { saveChat } from '@/service/utils/chat/saveChat'; import { saveChat } from '@/service/utils/chat/saveChat';
import { sseResponse } from '@/service/utils/tools'; import { sseResponse } from '@/service/utils/tools';
...@@ -157,6 +157,14 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex ...@@ -157,6 +157,14 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
sseResponse({ sseResponse({
res, res,
event: sseResponseEventEnum.answer, event: sseResponseEventEnum.answer,
data: textAdaptGptResponse({
text: null,
finish_reason: 'stop'
})
});
sseResponse({
res,
event: sseResponseEventEnum.answer,
data: '[DONE]' data: '[DONE]'
}); });
......
...@@ -169,7 +169,7 @@ const ShareChat = ({ shareId, chatId }: { shareId: string; chatId: string }) => ...@@ -169,7 +169,7 @@ const ShareChat = ({ shareId, chatId }: { shareId: string; chatId: string }) =>
onChangeChat={(chatId) => { onChangeChat={(chatId) => {
console.log(chatId); console.log(chatId);
router.push({ router.replace({
query: { query: {
chatId: chatId || '', chatId: chatId || '',
shareId shareId
......
...@@ -209,21 +209,7 @@ async function streamResponse({ res, response }: { res: NextApiResponse; respons ...@@ -209,21 +209,7 @@ async function streamResponse({ res, response }: { res: NextApiResponse; respons
if (res.closed || error) return; if (res.closed || error) return;
if (data === '[DONE]') { if (data !== '[DONE]') {
sseResponse({
res,
event: sseResponseEventEnum.answer,
data: textAdaptGptResponse({
text: null,
finish_reason: 'stop'
})
});
sseResponse({
res,
event: sseResponseEventEnum.answer,
data: '[DONE]'
});
} else {
sseResponse({ sseResponse({
res, res,
event: sseResponseEventEnum.answer, event: sseResponseEventEnum.answer,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment