From 5be57da407bee2693fd418ee52a8fc8090276580 Mon Sep 17 00:00:00 2001 From: archer <545436317@qq.com> Date: Sat, 24 Jun 2023 21:39:34 +0800 Subject: [PATCH] fix: v1 api --- client/src/pages/api/openapi/chat/chat.ts | 48 ++++++++++++++++------- client/src/service/utils/chat/index.ts | 1 + 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/client/src/pages/api/openapi/chat/chat.ts b/client/src/pages/api/openapi/chat/chat.ts index 10a6ef809..967a7cca7 100644 --- a/client/src/pages/api/openapi/chat/chat.ts +++ b/client/src/pages/api/openapi/chat/chat.ts @@ -65,10 +65,14 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex const modelConstantsData = ChatModelMap[model.chat.chatModel]; const prompt = prompts[prompts.length - 1]; - const { userSystemPrompt = [], quotePrompt = [] } = await (async () => { + const { + userSystemPrompt = [], + userLimitPrompt = [], + quotePrompt = [] + } = await (async () => { // 使用了知识库搜索 if (model.chat.relatedKbs?.length > 0) { - const { userSystemPrompt, quotePrompt } = await appKbSearch({ + const { quotePrompt, userSystemPrompt, userLimitPrompt } = await appKbSearch({ model, userId, fixedQuote: [], @@ -78,21 +82,29 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex }); return { - userSystemPrompt: userSystemPrompt ? [userSystemPrompt] : [], + userSystemPrompt, + userLimitPrompt, quotePrompt: [quotePrompt] }; } - if (model.chat.systemPrompt) { - return { - userSystemPrompt: [ - { - obj: ChatRoleEnum.System, - value: model.chat.systemPrompt - } - ] - }; - } - return {}; + return { + userSystemPrompt: model.chat.systemPrompt + ? [ + { + obj: ChatRoleEnum.System, + value: model.chat.systemPrompt + } + ] + : [], + userLimitPrompt: model.chat.limitPrompt + ? [ + { + obj: ChatRoleEnum.Human, + value: model.chat.limitPrompt + } + ] + : [] + }; })(); // search result is empty @@ -102,7 +114,13 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex } // 读取对话内容 - const completePrompts = [...quotePrompt, ...prompts.slice(0, -1), ...userSystemPrompt, prompt]; + const completePrompts = [ + ...quotePrompt, + ...userSystemPrompt, + ...prompts.slice(0, -1), + ...userLimitPrompt, + prompt + ]; // 计算温度 const temperature = (modelConstantsData.maxTemperature * (model.chat.temperature / 10)).toFixed( diff --git a/client/src/service/utils/chat/index.ts b/client/src/service/utils/chat/index.ts index 3bf6eb3ec..385cfba10 100644 --- a/client/src/service/utils/chat/index.ts +++ b/client/src/service/utils/chat/index.ts @@ -238,6 +238,7 @@ export const V2_StreamResponse = async ({ } if (error) { + console.log(error); return Promise.reject(error); }