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,
"pgIvfflatProbe": 20
},
"plugins": {},
"ChatModels": [
{
"model": "gpt-3.5-turbo",
@@ -62,6 +63,5 @@
"name": "Embedding-2",
"price": 0.2
}
],
"plugins": {}
]
}

View File

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

View File

@@ -79,8 +79,7 @@ const Chat = ({ appId, chatId }: { appId: string; chatId: string }) => {
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;

View File

@@ -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,

View File

@@ -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 = () => {
)}
<Box
position={'relative'}
order={1}
flex={`0 0 ${isPc ? '400px' : '100%'}`}
height={'100%'}
@@ -94,8 +98,24 @@ const Login = () => {
borderRadius={isPc ? 'md' : 'none'}
>
<DynamicComponent type={pageType} />
{feConfigs?.show_register && (
<Box
fontSize={'sm'}
color={'myGray.600'}
cursor={'pointer'}
position={'absolute'}
right={5}
bottom={3}
onClick={onOpen}
>
</Box>
)}
</Box>
</Flex>
{isOpen && <WxConcat onClose={onClose} />}
</Flex>
);
};