perf: abort

This commit is contained in:
archer
2023-07-18 15:20:58 +08:00
parent 8a25aeabc4
commit 2330186a09
8 changed files with 50 additions and 28 deletions

View File

@@ -1,6 +1,6 @@
{
"vectorMaxProcess": 10,
"qaMaxProcess": 10,
"pgIvfflatProbe": 10,
"vectorMaxProcess": 15,
"qaMaxProcess": 15,
"pgIvfflatProbe": 20,
"sensitiveCheck": false
}

View File

@@ -5,7 +5,8 @@ import React, {
useMemo,
forwardRef,
useImperativeHandle,
ForwardedRef
ForwardedRef,
useEffect
} from 'react';
import { throttle } from 'lodash';
import { ChatItemType, ChatSiteItemType, ExportChatType } from '@/types/chat';
@@ -31,6 +32,7 @@ import { MessageItemType } from '@/pages/api/openapi/v1/chat/completions';
import MyTooltip from '../MyTooltip';
import { fileDownload } from '@/utils/file';
import { htmlTemplate } from '@/constants/common';
import { useRouter } from 'next/router';
import dynamic from 'next/dynamic';
const QuoteModal = dynamic(() => import('./QuoteModal'));
@@ -133,6 +135,7 @@ const ChatBox = (
) => {
const ChatBoxRef = useRef<HTMLDivElement>(null);
const theme = useTheme();
const router = useRouter();
const { copyData } = useCopyData();
const { toast } = useToast();
const { userInfo } = useUserStore();
@@ -392,6 +395,12 @@ const ChatBox = (
[chatHistory.length, showEmptyIntro, variableModules, welcomeText]
);
useEffect(() => {
return () => {
controller.current?.abort();
};
}, [router.query]);
return (
<Flex flexDirection={'column'} h={'100%'}>
<Box ref={ChatBoxRef} flex={'1 0 0'} h={0} overflow={'overlay'} px={[2, 5, 7]} pt={[0, 5]}>

View File

@@ -1,4 +1,4 @@
import React, { useRef } from 'react';
import React, { useMemo, useRef } from 'react';
import ReactMarkdown from 'react-markdown';
import RemarkGfm from 'remark-gfm';
import RemarkMath from 'remark-math';
@@ -48,13 +48,16 @@ const Markdown = ({
isChatting?: boolean;
onClick?: (e: any) => void;
}) => {
const components = useRef({
a: Link,
img: Image,
pre: 'div',
p: 'div',
code: (props: any) => <Code {...props} onClick={onClick} />
});
const components = useMemo(
() => ({
a: Link,
img: Image,
pre: 'div',
p: 'div',
code: (props: any) => <Code {...props} onClick={onClick} />
}),
[onClick]
);
return (
<ReactMarkdown
@@ -64,7 +67,7 @@ const Markdown = ({
remarkPlugins={[RemarkGfm, RemarkMath, RemarkBreaks]}
rehypePlugins={[RehypeKatex]}
// @ts-ignore
components={components.current}
components={components}
>
{source}
</ReactMarkdown>

View File

@@ -89,6 +89,14 @@ export async function chatCompletion({
// FastGpt temperature range: 1~10
temperature = +(modelConstantsData.maxTemperature * (temperature / 10)).toFixed(2);
const limitText = (() => {
if (limitPrompt) return limitPrompt;
if (quotePrompt && !limitPrompt) {
return '根据知识库内容回答问题,仅回复知识库提供的内容。';
}
return '';
})();
const messages: ChatItemType[] = [
...(quotePrompt
? [
@@ -107,11 +115,11 @@ export async function chatCompletion({
]
: []),
...history,
...(limitPrompt
...(limitText
? [
{
obj: ChatRoleEnum.System,
value: limitPrompt
value: limitText
}
]
: []),

View File

@@ -145,7 +145,7 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
});
}
console.log(`finish time: ${(Date.now() - startTime) / 100}s`);
console.log(`finish time: ${(Date.now() - startTime) / 1000}s`);
if (stream) {
sseResponse({

View File

@@ -23,6 +23,7 @@ import { postCreateApp } from '@/api/app';
import { useRouter } from 'next/router';
import { appTemplates } from '@/constants/flow/ModuleTemplate';
import Avatar from '@/components/Avatar';
import MyTooltip from '@/components/MyTooltip';
type FormType = {
avatar: string;
@@ -102,21 +103,22 @@ const CreateModal = ({ onClose, onSuccess }: { onClose: () => void; onSuccess: (
<Modal isOpen onClose={onClose}>
<ModalOverlay />
<ModalContent w={'700px'} maxW={'90vw'}>
<ModalHeader fontSize={'2xl'}> AI </ModalHeader>
<ModalHeader fontSize={'2xl'}> AI </ModalHeader>
<ModalBody>
<Box color={'myGray.800'} fontWeight={'bold'}>
</Box>
<Flex mt={3} alignItems={'center'}>
<Avatar
src={getValues('avatar')}
w={['32px', '36px']}
h={['32px', '36px']}
cursor={'pointer'}
title={'点击选择头像'}
borderRadius={'md'}
onClick={onOpenSelectFile}
/>
<MyTooltip label={'点击设置头像'}>
<Avatar
src={getValues('avatar')}
w={['32px', '36px']}
h={['32px', '36px']}
cursor={'pointer'}
borderRadius={'md'}
onClick={onOpenSelectFile}
/>
</MyTooltip>
<Input
ml={4}
bg={'myWhite.600'}

View File

@@ -66,7 +66,7 @@ const Chat = () => {
const newTitle = prompts[0].content?.slice(0, 20) || '新对话';
// update history
if (newChatId) {
if (newChatId && !controller.signal.aborted) {
forbidRefresh.current = true;
const newHistory: ChatHistoryItemType = {
_id: newChatId,

View File

@@ -69,7 +69,7 @@ const ShareChat = ({ shareId, chatId }: { shareId: string; chatId: string }) =>
shareId
});
if (newChatId) {
if (newChatId && !controller.signal.aborted) {
router.replace({
query: {
shareId,