From 488e2f476e7039d46969576c0987f1cb67f2fb0f Mon Sep 17 00:00:00 2001 From: archer <545436317@qq.com> Date: Tue, 11 Apr 2023 17:28:43 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=87=8D=E5=90=8D=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E9=AB=98=E4=BA=AE;perf:=20=E6=9C=AA=E5=8C=B9=E9=85=8D=E5=88=B0?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E6=97=B6=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/api/chat/vectorGpt.ts | 20 ++++++++++---------- src/pages/chat/components/SlideBar.tsx | 6 ++---- src/pages/chat/index.tsx | 2 -- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/pages/api/chat/vectorGpt.ts b/src/pages/api/chat/vectorGpt.ts index 92c594f23..daf99fa14 100644 --- a/src/pages/api/chat/vectorGpt.ts +++ b/src/pages/api/chat/vectorGpt.ts @@ -96,18 +96,18 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) } } - if (formatRedisPrompt.length === 0) { - throw new Error('对不起,我没有找到你的问题'); + if (formatRedisPrompt.length > 0) { + // textArr 筛选,最多 2800 tokens + const systemPrompt = systemPromptFilter(formatRedisPrompt, 2800); + + prompts.unshift({ + obj: 'SYSTEM', + value: `${model.systemPrompt} 知识库内容是最新的,知识库内容为: "${systemPrompt}"` + }); + } else { + return res.send('对不起,你的问题不在知识库中。'); } - // textArr 筛选,最多 2800 tokens - const systemPrompt = systemPromptFilter(formatRedisPrompt, 2800); - - prompts.unshift({ - obj: 'SYSTEM', - value: `${model.systemPrompt} 知识库内容是最新的,知识库内容为: "${systemPrompt}"` - }); - // 控制在 tokens 数量,防止超出 const filterPrompts = openaiChatFilter(prompts, modelConstantsData.contextMaxToken); diff --git a/src/pages/chat/components/SlideBar.tsx b/src/pages/chat/components/SlideBar.tsx index e05ddce4f..42bd53764 100644 --- a/src/pages/chat/components/SlideBar.tsx +++ b/src/pages/chat/components/SlideBar.tsx @@ -35,13 +35,11 @@ import WxConcat from '@/components/WxConcat'; import { useMarkdown } from '@/hooks/useMarkdown'; const SlideBar = ({ - name, chatId, modelId, resetChat, onClose }: { - name?: string; chatId: string; modelId: string; resetChat: () => void; @@ -188,14 +186,14 @@ const SlideBar = ({ }} fontSize={'xs'} border={'1px solid transparent'} - {...(item.name === name + {...(item._id === modelId ? { borderColor: 'rgba(255,255,255,0.5)', backgroundColor: 'rgba(255,255,255,0.1)' } : {})} onClick={async () => { - if (item.name === name) return; + if (item._id === modelId) return; router.replace(`/chat?chatId=${await getChatSiteId(item._id)}`); onClose(); }} diff --git a/src/pages/chat/index.tsx b/src/pages/chat/index.tsx index 8ae7a6286..4205c156e 100644 --- a/src/pages/chat/index.tsx +++ b/src/pages/chat/index.tsx @@ -362,7 +362,6 @@ const Chat = ({ chatId }: { chatId: string }) => { {