mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 13:03:50 +00:00
add answer quote number (#4658)
This commit is contained in:
@@ -5,10 +5,10 @@ import {
|
||||
Popover,
|
||||
PopoverTrigger,
|
||||
PopoverContent,
|
||||
PopoverHeader,
|
||||
PopoverBody,
|
||||
PopoverArrow,
|
||||
PopoverCloseButton
|
||||
Box,
|
||||
Flex
|
||||
} from '@chakra-ui/react';
|
||||
import MyIcon from '@fastgpt/web/components/common/Icon';
|
||||
import MyTooltip from '@fastgpt/web/components/common/MyTooltip';
|
||||
@@ -17,9 +17,9 @@ import { useTranslation } from 'next-i18next';
|
||||
import React, { useMemo } from 'react';
|
||||
import { getQuoteData } from '@/web/core/dataset/api';
|
||||
import MyBox from '@fastgpt/web/components/common/MyBox';
|
||||
import RawSourceBox from '../core/dataset/RawSourceBox';
|
||||
import { getCollectionSourceData } from '@fastgpt/global/core/dataset/collection/utils';
|
||||
import Markdown from '.';
|
||||
import { getSourceNameIcon } from '@fastgpt/global/core/dataset/utils';
|
||||
|
||||
const A = ({ children, ...props }: any) => {
|
||||
const { t } = useTranslation();
|
||||
@@ -52,46 +52,99 @@ const A = ({ children, ...props }: any) => {
|
||||
}
|
||||
|
||||
// Quote
|
||||
if (props.href === 'QUOTE' && typeof children?.[0] === 'string') {
|
||||
if (props.href?.startsWith('QUOTE') && typeof children?.[0] === 'string') {
|
||||
const indexMatch = props.href.match(/QUOTE(\d+)/);
|
||||
const index = indexMatch ? indexMatch[1] : '1';
|
||||
|
||||
const sourceData = useMemo(
|
||||
() => getCollectionSourceData(quoteData?.collection),
|
||||
[quoteData?.collection]
|
||||
);
|
||||
const icon = useMemo(
|
||||
() => getSourceNameIcon({ sourceId: sourceData.sourceId, sourceName: sourceData.sourceName }),
|
||||
[sourceData]
|
||||
);
|
||||
|
||||
return (
|
||||
<Popover
|
||||
direction="rtl"
|
||||
isLazy
|
||||
placement="auto"
|
||||
direction="rtl"
|
||||
placement="bottom"
|
||||
strategy={'fixed'}
|
||||
onOpen={() => runAsync(String(children))}
|
||||
>
|
||||
<PopoverTrigger>
|
||||
<Button variant={'unstyled'} minH={0} minW={0} h={'auto'}>
|
||||
<MyTooltip label={t('common:read_quote')}>
|
||||
<MyIcon
|
||||
name={'core/chat/quoteSign'}
|
||||
w={'1rem'}
|
||||
color={'primary.700'}
|
||||
cursor={'pointer'}
|
||||
transform={'translateY(-3px)'}
|
||||
/>
|
||||
<Box
|
||||
w={5}
|
||||
h={5}
|
||||
border={'1px solid'}
|
||||
borderRadius={'full'}
|
||||
borderColor={'myGray.200'}
|
||||
color={'myGray.500'}
|
||||
fontSize={'10px'}
|
||||
display={'flex'}
|
||||
alignItems={'center'}
|
||||
justifyContent={'center'}
|
||||
ml={0.5}
|
||||
transform={'translateY(-2px)'}
|
||||
>
|
||||
{index}
|
||||
</Box>
|
||||
</MyTooltip>
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent boxShadow={'lg'} w={'400px'}>
|
||||
<MyBox isLoading={loading} minH={'300px'}>
|
||||
<PopoverContent boxShadow={'lg'} w={'400px'} py={4}>
|
||||
<MyBox isLoading={loading} minH={'224px'}>
|
||||
<PopoverArrow />
|
||||
<PopoverHeader h={'40px'} display={'flex'} alignItems={'center'}>
|
||||
{quoteData?.collection && (
|
||||
<RawSourceBox
|
||||
collectionId={quoteData?.collection._id}
|
||||
{...getCollectionSourceData(quoteData?.collection)}
|
||||
fontSize={'sm'}
|
||||
color={'black'}
|
||||
textDecoration={'none'}
|
||||
/>
|
||||
)}
|
||||
<PopoverCloseButton />
|
||||
</PopoverHeader>
|
||||
<PopoverBody fontSize={'sm'} maxH={'400px'} overflow={'auto'}>
|
||||
<Markdown source={quoteData?.q} />
|
||||
<Markdown source={quoteData?.a} />
|
||||
<PopoverBody
|
||||
px={4}
|
||||
py={0}
|
||||
fontSize={'sm'}
|
||||
maxW={'400px'}
|
||||
maxH={'224px'}
|
||||
overflow={'auto'}
|
||||
>
|
||||
<Box
|
||||
alignItems={'center'}
|
||||
fontSize={'xs'}
|
||||
border={'sm'}
|
||||
borderRadius={'sm'}
|
||||
overflow={'hidden'}
|
||||
display={'inline-flex'}
|
||||
height={6}
|
||||
>
|
||||
<Flex
|
||||
color={'myGray.500'}
|
||||
bg={'myGray.150'}
|
||||
w={4}
|
||||
justifyContent={'center'}
|
||||
fontSize={'10px'}
|
||||
h={'full'}
|
||||
alignItems={'center'}
|
||||
mr={1}
|
||||
flexShrink={0}
|
||||
>
|
||||
{index}
|
||||
</Flex>
|
||||
<Flex px={1.5}>
|
||||
<MyIcon name={icon as any} mr={1} flexShrink={0} w={'12px'} />
|
||||
<Box
|
||||
className={'textEllipsis'}
|
||||
wordBreak={'break-all'}
|
||||
flex={'1 0 0'}
|
||||
fontSize={'mini'}
|
||||
color={'myGray.900'}
|
||||
>
|
||||
{sourceData.sourceName}
|
||||
</Box>
|
||||
</Flex>
|
||||
</Box>
|
||||
<Box>
|
||||
<Markdown source={quoteData?.q} />
|
||||
{quoteData?.a && <Markdown source={quoteData?.a} />}
|
||||
</Box>
|
||||
</PopoverBody>
|
||||
</MyBox>
|
||||
</PopoverContent>
|
||||
|
@@ -59,7 +59,7 @@ const QuoteList = React.memo(function QuoteList({
|
||||
};
|
||||
}
|
||||
|
||||
return item;
|
||||
return { ...item, q: item.q || '', a: item.a || '' };
|
||||
});
|
||||
|
||||
return processedData.sort((a, b) => {
|
||||
|
@@ -93,6 +93,11 @@ const EditModal = ({ onClose, ...props }: RenderInputProps & { onClose: () => vo
|
||||
label: t('common:core.dataset.search.Source name'),
|
||||
icon: 'core/app/simpleMode/variable'
|
||||
},
|
||||
{
|
||||
key: 'sourceIndex',
|
||||
label: t('common:core.dataset.search.Source index'),
|
||||
icon: 'core/app/simpleMode/variable'
|
||||
},
|
||||
{
|
||||
key: 'q',
|
||||
label: 'q',
|
||||
@@ -218,14 +223,14 @@ const EditModal = ({ onClose, ...props }: RenderInputProps & { onClose: () => vo
|
||||
</Box>
|
||||
</Flex>
|
||||
<Box mt={4}>
|
||||
<Flex {...LabelStyles} mb={1}>
|
||||
<Flex {...LabelStyles} mb={1} alignItems={'center'}>
|
||||
<FormLabel>{t('common:core.app.Quote templates')}</FormLabel>
|
||||
<QuestionTip
|
||||
ml={1}
|
||||
label={t('workflow:quote_content_tip', {
|
||||
default: getQuoteTemplate(nodeVersion)
|
||||
})}
|
||||
></QuestionTip>
|
||||
/>
|
||||
<Box flex={1} />
|
||||
<Box
|
||||
{...selectTemplateBtn}
|
||||
@@ -253,14 +258,14 @@ const EditModal = ({ onClose, ...props }: RenderInputProps & { onClose: () => vo
|
||||
/>
|
||||
</Box>
|
||||
<Box mt={4}>
|
||||
<Flex {...LabelStyles} mb={1}>
|
||||
<Flex {...LabelStyles} mb={1} alignItems={'center'}>
|
||||
<FormLabel>{t('common:core.app.Quote prompt')}</FormLabel>
|
||||
<QuestionTip
|
||||
ml={1}
|
||||
label={t('workflow:quote_prompt_tip', {
|
||||
default: getQuotePrompt(nodeVersion, aiChatQuoteRole)
|
||||
})}
|
||||
></QuestionTip>
|
||||
/>
|
||||
</Flex>
|
||||
<PromptEditor
|
||||
variables={quotePromptVariables}
|
||||
|
Reference in New Issue
Block a user