model perf (#3657)

* fix: model

* dataset quote

* perf: model config

* model tag

* doubao model config

* perf: config model

* feat: model test
This commit is contained in:
Archer
2025-01-24 14:10:14 +08:00
committed by archer
parent f2be9ae32d
commit e48df175d7
171 changed files with 1902 additions and 3126 deletions

View File

@@ -0,0 +1,105 @@
import { eventBus, EventNameEnum } from '@/web/common/utils/eventbus';
import {
Button,
Link,
Popover,
PopoverTrigger,
PopoverContent,
PopoverHeader,
PopoverBody,
PopoverArrow,
PopoverCloseButton
} from '@chakra-ui/react';
import MyIcon from '@fastgpt/web/components/common/Icon';
import MyTooltip from '@fastgpt/web/components/common/MyTooltip';
import { useRequest2 } from '@fastgpt/web/hooks/useRequest';
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 '.';
const A = ({ children, ...props }: any) => {
const { t } = useTranslation();
const {
data: quoteData,
loading,
runAsync
} = useRequest2(getQuoteData, {
manual: true
});
// 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
variant={'whitePrimary'}
size={'xs'}
borderRadius={'md'}
my={1}
onClick={() => eventBus.emit(EventNameEnum.sendQuestion, { text })}
>
{text}
</Button>
</MyTooltip>
);
}
// Quote
if (props.href === 'QUOTE' && typeof children?.[0] === 'string') {
return (
<Popover
direction="rtl"
isLazy
placement="auto"
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)'}
/>
</MyTooltip>
</Button>
</PopoverTrigger>
<PopoverContent boxShadow={'lg'} w={'400px'}>
<MyBox isLoading={loading} minH={'300px'}>
<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>
</MyBox>
</PopoverContent>
</Popover>
);
}
return <Link {...props}>{children}</Link>;
};
export default A;

View File

@@ -10,12 +10,7 @@ import RehypeExternalLinks from 'rehype-external-links';
import styles from './index.module.scss';
import dynamic from 'next/dynamic';
import { Link, Button, Box } from '@chakra-ui/react';
import MyTooltip from '@fastgpt/web/components/common/MyTooltip';
import { useTranslation } from 'next-i18next';
import { EventNameEnum, eventBus } from '@/web/common/utils/eventbus';
import MyIcon from '@fastgpt/web/components/common/Icon';
import { MARKDOWN_QUOTE_SIGN } from '@fastgpt/global/core/chat/constants';
import { Box } from '@chakra-ui/react';
import { CodeClassNameEnum } from './utils';
const CodeLight = dynamic(() => import('./CodeLight'), { ssr: false });
@@ -27,6 +22,7 @@ const IframeHtmlCodeBlock = dynamic(() => import('./codeBlock/iframe-html'), { s
const ChatGuide = dynamic(() => import('./chat/Guide'), { ssr: false });
const QuestionGuide = dynamic(() => import('./chat/QuestionGuide'), { ssr: false });
const A = dynamic(() => import('./A'), { ssr: false });
type Props = {
source?: string;
@@ -74,7 +70,10 @@ const MarkdownRender = ({ source = '', showAnimation, isDisabled, forbidZhFormat
'$1$3 $2$4'
)
// 处理引用标记
.replace(/\n*(\[QUOTE SIGN\]\(.*\))/g, '$1');
.replace(/\n*(\[QUOTE SIGN\]\(.*\))/g, '$1')
// 处理 [quote:id] 格式引用,将 [quote:675934a198f46329dfc6d05a] 转换为 [675934a198f46329dfc6d05a]()
.replace(/\[quote:?\s*([a-f0-9]{24})\](?!\()/gi, '[$1](QUOTE)')
.replace(/\[([a-f0-9]{24})\](?!\()/g, '[$1](QUOTE)');
// 还原 URL
const finalText = textWithSpaces.replace(
@@ -155,53 +154,6 @@ function Image({ src }: { src?: string }) {
return <MdImage src={src} />;
}
function A({ children, ...props }: any) {
const { t } = useTranslation();
// 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
variant={'whitePrimary'}
size={'xs'}
borderRadius={'md'}
my={1}
onClick={() => eventBus.emit(EventNameEnum.sendQuestion, { text })}
>
{text}
</Button>
</MyTooltip>
);
}
// quote link(未使用)
if (children?.length === 1 && typeof children?.[0] === 'string') {
const text = String(children);
if (text === MARKDOWN_QUOTE_SIGN && props.href) {
return (
<MyTooltip label={props.href}>
<MyIcon
name={'core/chat/quoteSign'}
transform={'translateY(-2px)'}
w={'18px'}
color={'primary.500'}
cursor={'pointer'}
_hover={{
color: 'primary.700'
}}
// onClick={() => getCollectionSourceAndOpen(props.href)}
/>
</MyTooltip>
);
}
}
return <Link {...props}>{children}</Link>;
}
function RewritePre({ children }: any) {
const modifiedChildren = React.Children.map(children, (child) => {
if (React.isValidElement(child)) {

View File

@@ -307,12 +307,11 @@ const AIChatSettingsModal = ({
)}
{showVisionSwitch && (
<Flex {...FlexItemStyles} h={'25px'}>
<Box {...LabelStyles}>
<Box {...LabelStyles} w={llmSupportVision ? '9rem' : 'auto'}>
<Flex alignItems={'center'}>
{t('app:llm_use_vision')}
<QuestionTip ml={1} label={t('app:llm_use_vision_tip')}></QuestionTip>
</Flex>
{llmSupportVision ? (
<Switch
isChecked={useVision}
@@ -323,7 +322,7 @@ const AIChatSettingsModal = ({
}}
/>
) : (
<Box fontSize={'sm'} color={'myGray.500'}>
<Box ml={3} fontSize={'sm'} color={'myGray.500'}>
{t('app:llm_not_support_vision')}
</Box>
)}

View File

@@ -82,7 +82,7 @@ const ModelTable = () => {
) : (
<Flex color={'myGray.700'}>
<Box fontWeight={'bold'} color={'myGray.900'} mr={0.5}>
{item.charsPointsPrice}
{item.charsPointsPrice || 0}
</Box>
{`${t('common:support.wallet.subscription.point')} / 1K Tokens`}
</Flex>
@@ -95,7 +95,7 @@ const ModelTable = () => {
priceLabel: (
<Flex color={'myGray.700'}>
<Box fontWeight={'bold'} color={'myGray.900'} mr={0.5}>
{item.charsPointsPrice}
{item.charsPointsPrice || 0}
</Box>
{` ${t('common:support.wallet.subscription.point')} / 1K Tokens`}
</Flex>
@@ -108,7 +108,7 @@ const ModelTable = () => {
priceLabel: (
<Flex color={'myGray.700'}>
<Box fontWeight={'bold'} color={'myGray.900'} mr={0.5}>
{item.charsPointsPrice}
{item.charsPointsPrice || 0}
</Box>
{` ${t('common:support.wallet.subscription.point')} / 1K ${t('common:unit.character')}`}
</Flex>