fix: 重名模型高亮;perf: 未匹配到问题时输出

This commit is contained in:
archer 2023-04-11 17:28:43 +08:00
parent 915b104b8a
commit 488e2f476e
No known key found for this signature in database
GPG Key ID: 166CA6BF2383B2BB
3 changed files with 12 additions and 16 deletions

View File

@ -96,18 +96,18 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
} }
} }
if (formatRedisPrompt.length === 0) { if (formatRedisPrompt.length > 0) {
throw new Error('对不起,我没有找到你的问题'); // 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 数量,防止超出 // 控制在 tokens 数量,防止超出
const filterPrompts = openaiChatFilter(prompts, modelConstantsData.contextMaxToken); const filterPrompts = openaiChatFilter(prompts, modelConstantsData.contextMaxToken);

View File

@ -35,13 +35,11 @@ import WxConcat from '@/components/WxConcat';
import { useMarkdown } from '@/hooks/useMarkdown'; import { useMarkdown } from '@/hooks/useMarkdown';
const SlideBar = ({ const SlideBar = ({
name,
chatId, chatId,
modelId, modelId,
resetChat, resetChat,
onClose onClose
}: { }: {
name?: string;
chatId: string; chatId: string;
modelId: string; modelId: string;
resetChat: () => void; resetChat: () => void;
@ -188,14 +186,14 @@ const SlideBar = ({
}} }}
fontSize={'xs'} fontSize={'xs'}
border={'1px solid transparent'} border={'1px solid transparent'}
{...(item.name === name {...(item._id === modelId
? { ? {
borderColor: 'rgba(255,255,255,0.5)', borderColor: 'rgba(255,255,255,0.5)',
backgroundColor: 'rgba(255,255,255,0.1)' backgroundColor: 'rgba(255,255,255,0.1)'
} }
: {})} : {})}
onClick={async () => { onClick={async () => {
if (item.name === name) return; if (item._id === modelId) return;
router.replace(`/chat?chatId=${await getChatSiteId(item._id)}`); router.replace(`/chat?chatId=${await getChatSiteId(item._id)}`);
onClose(); onClose();
}} }}

View File

@ -362,7 +362,6 @@ const Chat = ({ chatId }: { chatId: string }) => {
<Box flex={'0 0 250px'} w={0} h={'100%'}> <Box flex={'0 0 250px'} w={0} h={'100%'}>
<SlideBar <SlideBar
resetChat={resetChat} resetChat={resetChat}
name={chatData?.name}
chatId={chatId} chatId={chatId}
modelId={chatData.modelId} modelId={chatData.modelId}
onClose={onCloseSlider} onClose={onCloseSlider}
@ -394,7 +393,6 @@ const Chat = ({ chatId }: { chatId: string }) => {
<DrawerContent maxWidth={'250px'}> <DrawerContent maxWidth={'250px'}>
<SlideBar <SlideBar
resetChat={resetChat} resetChat={resetChat}
name={chatData?.name}
chatId={chatId} chatId={chatId}
modelId={chatData.modelId} modelId={chatData.modelId}
onClose={onCloseSlider} onClose={onCloseSlider}