From 09879004be3ff42efd7b87fc8f2462d0e4c425d0 Mon Sep 17 00:00:00 2001 From: archer <545436317@qq.com> Date: Sat, 5 Aug 2023 14:14:51 +0800 Subject: [PATCH] fix: abort chat response --- client/data/config.json | 4 ++-- client/src/components/ChatBox/index.tsx | 28 ++++++------------------- client/src/pages/chat/index.tsx | 20 ++++++++++-------- client/src/pages/chat/share.tsx | 2 +- client/src/pages/login/index.tsx | 22 ++++++++++++++++++- 5 files changed, 41 insertions(+), 35 deletions(-) diff --git a/client/data/config.json b/client/data/config.json index 6a5617237..bffa8d34b 100644 --- a/client/data/config.json +++ b/client/data/config.json @@ -14,6 +14,7 @@ "qaMaxProcess": 15, "pgIvfflatProbe": 20 }, + "plugins": {}, "ChatModels": [ { "model": "gpt-3.5-turbo", @@ -62,6 +63,5 @@ "name": "Embedding-2", "price": 0.2 } - ], - "plugins": {} + ] } diff --git a/client/src/components/ChatBox/index.tsx b/client/src/components/ChatBox/index.tsx index 4133ed66f..ccd9421b3 100644 --- a/client/src/components/ChatBox/index.tsx +++ b/client/src/components/ChatBox/index.tsx @@ -89,19 +89,12 @@ const Empty = () => { const { data: versionIntro } = useMarkdown({ url: '/versionIntro.md' }); return ( - + {/* version intro */} - + - + @@ -451,7 +444,7 @@ const ChatBox = ( useEffect(() => { return () => { - controller.current?.abort(); + controller.current?.abort('leave'); // close voice cancelBroadcast(); }; @@ -470,16 +463,7 @@ const ChatBox = ( return ( - + {showEmpty && } @@ -775,7 +759,7 @@ const ChatBox = ( cursor={'pointer'} name={'stop'} color={'gray.500'} - onClick={() => controller.current?.abort()} + onClick={() => controller.current?.abort('stop')} /> ) : ( { const newTitle = prompts[0].content?.slice(0, 20) || '新对话'; // update history - if (completionChatId !== chatId && !controller.signal.aborted) { - forbidRefresh.current = true; + if (completionChatId !== chatId) { const newHistory: ChatHistoryItemType = { chatId: completionChatId, updateTime: new Date(), @@ -89,12 +88,15 @@ const Chat = ({ appId, chatId }: { appId: string; chatId: string }) => { top: false }; updateHistory(newHistory); - router.replace({ - query: { - chatId: completionChatId, - appId - } - }); + if (controller.signal.reason !== 'leave') { + forbidRefresh.current = true; + router.replace({ + query: { + chatId: completionChatId, + appId + } + }); + } } else { const currentChat = history.find((item) => item.chatId === chatId); currentChat && @@ -116,7 +118,7 @@ const Chat = ({ appId, chatId }: { appId: string; chatId: string }) => { [appId, chatId, history, router, setChatData, updateHistory] ); - // 删除一句话 + // del one chat content const delOneHistoryItem = useCallback( async ({ contentId, index }: { contentId?: string; index: number }) => { if (!chatId || !contentId) return; diff --git a/client/src/pages/chat/share.tsx b/client/src/pages/chat/share.tsx index eb3606673..1cc7401ec 100644 --- a/client/src/pages/chat/share.tsx +++ b/client/src/pages/chat/share.tsx @@ -73,7 +73,7 @@ const OutLink = ({ shareId, chatId }: { shareId: string; chatId: string }) => { shareId }); - if (completionChatId !== chatId && !controller.signal.aborted) { + if (completionChatId !== chatId && controller.signal.reason !== 'leave') { router.replace({ query: { shareId, diff --git a/client/src/pages/login/index.tsx b/client/src/pages/login/index.tsx index 7e93bfecc..05d6f9fac 100644 --- a/client/src/pages/login/index.tsx +++ b/client/src/pages/login/index.tsx @@ -1,6 +1,6 @@ import React, { useState, useCallback } from 'react'; import styles from './index.module.scss'; -import { Box, Flex, Image } from '@chakra-ui/react'; +import { Box, Flex, Image, useDisclosure } from '@chakra-ui/react'; import { PageTypeEnum } from '@/constants/user'; import { useGlobalStore } from '@/store/global'; import type { ResLogin } from '@/api/response/user'; @@ -11,6 +11,8 @@ import LoginForm from './components/LoginForm'; import dynamic from 'next/dynamic'; import { serviceSideProps } from '@/utils/i18n'; import { setToken } from '@/utils/user'; +import { feConfigs } from '@/store/static'; +import WxConcat from '@/components/WxConcat'; const RegisterForm = dynamic(() => import('./components/RegisterForm')); const ForgetPasswordForm = dynamic(() => import('./components/ForgetPasswordForm')); @@ -21,6 +23,7 @@ const Login = () => { const [pageType, setPageType] = useState<`${PageTypeEnum}`>(PageTypeEnum.login); const { setUserInfo } = useUserStore(); const { setLastChatId, setLastChatAppId } = useChatStore(); + const { isOpen, onOpen, onClose } = useDisclosure(); const loginSuccess = useCallback( (res: ResLogin) => { @@ -84,6 +87,7 @@ const Login = () => { )} { borderRadius={isPc ? 'md' : 'none'} > + + {feConfigs?.show_register && ( + + 无法登录,点击联系 + + )} + + {isOpen && } ); };