fix: abort chat response

This commit is contained in:
archer
2023-08-05 14:14:51 +08:00
parent 236e7d3c3f
commit 09879004be
5 changed files with 41 additions and 35 deletions

View File

@@ -14,6 +14,7 @@
"qaMaxProcess": 15, "qaMaxProcess": 15,
"pgIvfflatProbe": 20 "pgIvfflatProbe": 20
}, },
"plugins": {},
"ChatModels": [ "ChatModels": [
{ {
"model": "gpt-3.5-turbo", "model": "gpt-3.5-turbo",
@@ -62,6 +63,5 @@
"name": "Embedding-2", "name": "Embedding-2",
"price": 0.2 "price": 0.2
} }
], ]
"plugins": {}
} }

View File

@@ -89,19 +89,12 @@ const Empty = () => {
const { data: versionIntro } = useMarkdown({ url: '/versionIntro.md' }); const { data: versionIntro } = useMarkdown({ url: '/versionIntro.md' });
return ( return (
<Box <Box pt={6} w={'85%'} maxW={'600px'} m={'auto'} alignItems={'center'} justifyContent={'center'}>
pt={[6, 0]}
w={'85%'}
maxW={'600px'}
m={'auto'}
alignItems={'center'}
justifyContent={'center'}
>
{/* version intro */} {/* version intro */}
<Card p={4} mb={10}> <Card p={4} mb={10} minH={'200px'}>
<Markdown source={versionIntro} /> <Markdown source={versionIntro} />
</Card> </Card>
<Card p={4}> <Card p={4} minH={'600px'}>
<Markdown source={chatProblem} /> <Markdown source={chatProblem} />
</Card> </Card>
</Box> </Box>
@@ -451,7 +444,7 @@ const ChatBox = (
useEffect(() => { useEffect(() => {
return () => { return () => {
controller.current?.abort(); controller.current?.abort('leave');
// close voice // close voice
cancelBroadcast(); cancelBroadcast();
}; };
@@ -470,16 +463,7 @@ const ChatBox = (
return ( return (
<Flex flexDirection={'column'} h={'100%'}> <Flex flexDirection={'column'} h={'100%'}>
<Box <Box ref={ChatBoxRef} flex={'1 0 0'} h={0} w={'100%'} overflow={'overlay'} px={[4, 0]} pb={3}>
ref={ChatBoxRef}
flex={'1 0 0'}
h={0}
w={'100%'}
overflow={'overlay'}
px={[4, 0]}
mt={[0, 5]}
pb={3}
>
<Box maxW={['100%', '92%']} h={'100%'} mx={'auto'}> <Box maxW={['100%', '92%']} h={'100%'} mx={'auto'}>
{showEmpty && <Empty />} {showEmpty && <Empty />}
@@ -775,7 +759,7 @@ const ChatBox = (
cursor={'pointer'} cursor={'pointer'}
name={'stop'} name={'stop'}
color={'gray.500'} color={'gray.500'}
onClick={() => controller.current?.abort()} onClick={() => controller.current?.abort('stop')}
/> />
) : ( ) : (
<MyIcon <MyIcon

View File

@@ -79,8 +79,7 @@ const Chat = ({ appId, chatId }: { appId: string; chatId: string }) => {
const newTitle = prompts[0].content?.slice(0, 20) || '新对话'; const newTitle = prompts[0].content?.slice(0, 20) || '新对话';
// update history // update history
if (completionChatId !== chatId && !controller.signal.aborted) { if (completionChatId !== chatId) {
forbidRefresh.current = true;
const newHistory: ChatHistoryItemType = { const newHistory: ChatHistoryItemType = {
chatId: completionChatId, chatId: completionChatId,
updateTime: new Date(), updateTime: new Date(),
@@ -89,12 +88,15 @@ const Chat = ({ appId, chatId }: { appId: string; chatId: string }) => {
top: false top: false
}; };
updateHistory(newHistory); updateHistory(newHistory);
router.replace({ if (controller.signal.reason !== 'leave') {
query: { forbidRefresh.current = true;
chatId: completionChatId, router.replace({
appId query: {
} chatId: completionChatId,
}); appId
}
});
}
} else { } else {
const currentChat = history.find((item) => item.chatId === chatId); const currentChat = history.find((item) => item.chatId === chatId);
currentChat && currentChat &&
@@ -116,7 +118,7 @@ const Chat = ({ appId, chatId }: { appId: string; chatId: string }) => {
[appId, chatId, history, router, setChatData, updateHistory] [appId, chatId, history, router, setChatData, updateHistory]
); );
// 删除一句话 // del one chat content
const delOneHistoryItem = useCallback( const delOneHistoryItem = useCallback(
async ({ contentId, index }: { contentId?: string; index: number }) => { async ({ contentId, index }: { contentId?: string; index: number }) => {
if (!chatId || !contentId) return; if (!chatId || !contentId) return;

View File

@@ -73,7 +73,7 @@ const OutLink = ({ shareId, chatId }: { shareId: string; chatId: string }) => {
shareId shareId
}); });
if (completionChatId !== chatId && !controller.signal.aborted) { if (completionChatId !== chatId && controller.signal.reason !== 'leave') {
router.replace({ router.replace({
query: { query: {
shareId, shareId,

View File

@@ -1,6 +1,6 @@
import React, { useState, useCallback } from 'react'; import React, { useState, useCallback } from 'react';
import styles from './index.module.scss'; 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 { PageTypeEnum } from '@/constants/user';
import { useGlobalStore } from '@/store/global'; import { useGlobalStore } from '@/store/global';
import type { ResLogin } from '@/api/response/user'; import type { ResLogin } from '@/api/response/user';
@@ -11,6 +11,8 @@ import LoginForm from './components/LoginForm';
import dynamic from 'next/dynamic'; import dynamic from 'next/dynamic';
import { serviceSideProps } from '@/utils/i18n'; import { serviceSideProps } from '@/utils/i18n';
import { setToken } from '@/utils/user'; import { setToken } from '@/utils/user';
import { feConfigs } from '@/store/static';
import WxConcat from '@/components/WxConcat';
const RegisterForm = dynamic(() => import('./components/RegisterForm')); const RegisterForm = dynamic(() => import('./components/RegisterForm'));
const ForgetPasswordForm = dynamic(() => import('./components/ForgetPasswordForm')); const ForgetPasswordForm = dynamic(() => import('./components/ForgetPasswordForm'));
@@ -21,6 +23,7 @@ const Login = () => {
const [pageType, setPageType] = useState<`${PageTypeEnum}`>(PageTypeEnum.login); const [pageType, setPageType] = useState<`${PageTypeEnum}`>(PageTypeEnum.login);
const { setUserInfo } = useUserStore(); const { setUserInfo } = useUserStore();
const { setLastChatId, setLastChatAppId } = useChatStore(); const { setLastChatId, setLastChatAppId } = useChatStore();
const { isOpen, onOpen, onClose } = useDisclosure();
const loginSuccess = useCallback( const loginSuccess = useCallback(
(res: ResLogin) => { (res: ResLogin) => {
@@ -84,6 +87,7 @@ const Login = () => {
)} )}
<Box <Box
position={'relative'}
order={1} order={1}
flex={`0 0 ${isPc ? '400px' : '100%'}`} flex={`0 0 ${isPc ? '400px' : '100%'}`}
height={'100%'} height={'100%'}
@@ -94,8 +98,24 @@ const Login = () => {
borderRadius={isPc ? 'md' : 'none'} borderRadius={isPc ? 'md' : 'none'}
> >
<DynamicComponent type={pageType} /> <DynamicComponent type={pageType} />
{feConfigs?.show_register && (
<Box
fontSize={'sm'}
color={'myGray.600'}
cursor={'pointer'}
position={'absolute'}
right={5}
bottom={3}
onClick={onOpen}
>
</Box>
)}
</Box> </Box>
</Flex> </Flex>
{isOpen && <WxConcat onClose={onClose} />}
</Flex> </Flex>
); );
}; };