Test parse cite and add tool call parallel (#4737)

* add quote response filter (#4727)

* chatting

* add quote response filter

* add test

* remove comment

* perf: cite hidden

* perf: format llm response

* feat: comment

* update default chunk size

* update default chunk size

---------

Co-authored-by: heheer <heheer@sealos.io>
This commit is contained in:
Archer
2025-04-30 17:43:50 +08:00
committed by GitHub
parent 683ab6c17d
commit fdd4e9edbd
53 changed files with 1131 additions and 716 deletions

View File

@@ -21,16 +21,16 @@ import MyBox from '@fastgpt/web/components/common/MyBox';
import { getCollectionSourceData } from '@fastgpt/global/core/dataset/collection/utils';
import Markdown from '.';
import { getSourceNameIcon } from '@fastgpt/global/core/dataset/utils';
import { Types } from 'mongoose';
const A = ({ children, chatAuthData, ...props }: any) => {
const A = ({ children, chatAuthData, showAnimation, ...props }: any) => {
const { t } = useTranslation();
const { isOpen, onOpen, onClose } = useDisclosure();
const content = useMemo(() => String(children), [children]);
// empty href link
if (!props.href && typeof children?.[0] === 'string') {
const text = useMemo(() => String(children), [children]);
return (
<MyTooltip label={t('common:core.chat.markdown.Quick Question')}>
<Button
@@ -38,16 +38,23 @@ const A = ({ children, chatAuthData, ...props }: any) => {
size={'xs'}
borderRadius={'md'}
my={1}
onClick={() => eventBus.emit(EventNameEnum.sendQuestion, { text })}
onClick={() => eventBus.emit(EventNameEnum.sendQuestion, { text: content })}
>
{text}
{content}
</Button>
</MyTooltip>
);
}
// Quote
if (props.href?.startsWith('QUOTE') && typeof children?.[0] === 'string') {
// Cite
if (
(props.href?.startsWith('CITE') || props.href?.startsWith('QUOTE')) &&
typeof children?.[0] === 'string'
) {
if (!Types.ObjectId.isValid(content)) {
return <></>;
}
const {
data: quoteData,
loading,
@@ -74,6 +81,7 @@ const A = ({ children, chatAuthData, ...props }: any) => {
onClose={onClose}
onOpen={() => {
onOpen();
if (showAnimation) return;
getQuoteDataById(String(children));
}}
trigger={'hover'}
@@ -90,7 +98,7 @@ const A = ({ children, chatAuthData, ...props }: any) => {
</Button>
</PopoverTrigger>
<PopoverContent boxShadow={'lg'} w={'500px'} maxW={'90vw'} py={4}>
<MyBox isLoading={loading}>
<MyBox isLoading={loading || showAnimation}>
<PopoverArrow />
<PopoverBody py={0} px={0} fontSize={'sm'}>
<Flex px={4} pb={1} justifyContent={'space-between'}>

View File

@@ -60,9 +60,9 @@ const MarkdownRender = ({
img: Image,
pre: RewritePre,
code: Code,
a: (props: any) => <A {...props} chatAuthData={chatAuthData} />
a: (props: any) => <A {...props} showAnimation={showAnimation} chatAuthData={chatAuthData} />
};
}, [chatAuthData]);
}, [chatAuthData, showAnimation]);
const formatSource = useMemo(() => {
if (showAnimation || forbidZhFormat) return source;

View File

@@ -27,14 +27,14 @@ export const mdTextFormat = (text: string) => {
return match;
});
// 处理 [quote:id] 格式引用,将 [quote:675934a198f46329dfc6d05a] 转换为 [675934a198f46329dfc6d05a](QUOTE)
// 处理 [quote:id] 格式引用,将 [quote:675934a198f46329dfc6d05a] 转换为 [675934a198f46329dfc6d05a](CITE)
text = text
// .replace(
// /([\u4e00-\u9fa5\u3000-\u303f])([a-zA-Z0-9])|([a-zA-Z0-9])([\u4e00-\u9fa5\u3000-\u303f])/g,
// '$1$3 $2$4'
// )
// 处理 格式引用,将 [675934a198f46329dfc6d05a] 转换为 [675934a198f46329dfc6d05a](QUOTE)
.replace(/\[([a-f0-9]{24})\](?!\()/g, '[$1](QUOTE)');
// 处理 格式引用,将 [675934a198f46329dfc6d05a] 转换为 [675934a198f46329dfc6d05a](CITE)
.replace(/\[([a-f0-9]{24})\](?!\()/g, '[$1](CITE)');
// 处理链接后的中文标点符号,增加空格
text = text.replace(/(https?:\/\/[^\s、]+)([,。!?;:、])/g, '$1 $2');

View File

@@ -240,11 +240,6 @@ const ChatItem = (props: Props) => {
quoteId?: string;
}) => {
if (!setQuoteData) return;
if (isChatting)
return toast({
title: t('chat:chat.waiting_for_response'),
status: 'info'
});
const collectionIdList = collectionId
? [collectionId]
@@ -277,18 +272,7 @@ const ChatItem = (props: Props) => {
}
});
},
[
setQuoteData,
isChatting,
toast,
t,
quoteList,
isShowReadRawSource,
appId,
chatId,
chat.dataId,
outLinkAuthData
]
[setQuoteData, quoteList, isShowReadRawSource, appId, chatId, chat.dataId, outLinkAuthData]
);
useEffect(() => {

View File

@@ -96,8 +96,6 @@ const RenderText = React.memo(function RenderText({
text: string;
chatItemDataId: string;
}) {
const isResponseDetail = useContextSelector(ChatItemContext, (v) => v.isResponseDetail);
const appId = useContextSelector(ChatBoxContext, (v) => v.appId);
const chatId = useContextSelector(ChatBoxContext, (v) => v.chatId);
const outLinkAuthData = useContextSelector(ChatBoxContext, (v) => v.outLinkAuthData);
@@ -106,10 +104,8 @@ const RenderText = React.memo(function RenderText({
if (!text) return '';
// Remove quote references if not showing response detail
return isResponseDetail
? text
: text.replace(/\[([a-f0-9]{24})\]\(QUOTE\)/g, '').replace(/\[([a-f0-9]{24})\](?!\()/g, '');
}, [text, isResponseDetail]);
return text;
}, [text]);
const chatAuthData = useCreation(() => {
return { appId, chatId, chatItemDataId, ...outLinkAuthData };

View File

@@ -12,7 +12,7 @@ import { getWebLLMModel } from '@/web/common/system/utils';
const SearchParamsTip = ({
searchMode,
similarity = 0,
limit = 1500,
limit = 5000,
responseEmptyText,
usingReRank = false,
datasetSearchUsingExtensionQuery,