fix: model test channel id;fix: quote reader (#4123)
* fix: model test channel id * fix: quote reader
This commit is contained in:
@@ -34,7 +34,15 @@ type ModelTestItem = {
|
||||
duration?: number;
|
||||
};
|
||||
|
||||
const ModelTest = ({ models, onClose }: { models: string[]; onClose: () => void }) => {
|
||||
const ModelTest = ({
|
||||
channelId,
|
||||
models,
|
||||
onClose
|
||||
}: {
|
||||
channelId: number;
|
||||
models: string[];
|
||||
onClose: () => void;
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const { toast } = useToast();
|
||||
const [testModelList, setTestModelList] = useState<ModelTestItem[]>([]);
|
||||
@@ -57,6 +65,7 @@ const ModelTest = ({ models, onClose }: { models: string[]; onClose: () => void
|
||||
colorSchema: 'red'
|
||||
}
|
||||
});
|
||||
|
||||
const { loading: loadingModels } = useRequest2(getSystemModelList, {
|
||||
manual: false,
|
||||
refreshDeps: [models],
|
||||
@@ -95,7 +104,7 @@ const ModelTest = ({ models, onClose }: { models: string[]; onClose: () => void
|
||||
);
|
||||
const start = Date.now();
|
||||
try {
|
||||
await getTestModel(model);
|
||||
await getTestModel({ model, channelId });
|
||||
const duration = Date.now() - start;
|
||||
setTestModelList((prev) =>
|
||||
prev.map((item) =>
|
||||
|
||||
@@ -74,7 +74,7 @@ const ChannelTable = ({ Tab }: { Tab: React.ReactNode }) => {
|
||||
}
|
||||
});
|
||||
|
||||
const [testModels, setTestModels] = useState<string[]>();
|
||||
const [modelTestData, setTestModelData] = useState<{ channelId: number; models: string[] }>();
|
||||
|
||||
const isLoading =
|
||||
loadingChannelList ||
|
||||
@@ -165,7 +165,11 @@ const ChannelTable = ({ Tab }: { Tab: React.ReactNode }) => {
|
||||
{
|
||||
icon: 'core/chat/sendLight',
|
||||
label: t('account_model:model_test'),
|
||||
onClick: () => setTestModels(item.models)
|
||||
onClick: () =>
|
||||
setTestModelData({
|
||||
channelId: item.id,
|
||||
models: item.models
|
||||
})
|
||||
},
|
||||
...(item.status === ChannelStatusEnum.ChannelStatusEnabled
|
||||
? [
|
||||
@@ -222,7 +226,9 @@ const ChannelTable = ({ Tab }: { Tab: React.ReactNode }) => {
|
||||
onSuccess={refreshChannelList}
|
||||
/>
|
||||
)}
|
||||
{!!testModels && <ModelTest models={testModels} onClose={() => setTestModels(undefined)} />}
|
||||
{!!modelTestData && (
|
||||
<ModelTest {...modelTestData} onClose={() => setTestModelData(undefined)} />
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -35,9 +35,11 @@ const CollectionReader = ({
|
||||
const { t } = useTranslation();
|
||||
const router = useRouter();
|
||||
const { userInfo } = useUserStore();
|
||||
|
||||
const { collectionId, datasetId, chatItemDataId, sourceId, sourceName } = metadata;
|
||||
const [quoteIndex, setQuoteIndex] = useState(0);
|
||||
|
||||
// Get dataset permission
|
||||
const { data: permissionData, loading: isPermissionLoading } = useRequest2(
|
||||
async () => await getDatasetDataPermission(datasetId),
|
||||
{
|
||||
@@ -56,6 +58,7 @@ const CollectionReader = ({
|
||||
|
||||
const currentQuoteItem = filterResults[quoteIndex];
|
||||
|
||||
// Get quote list
|
||||
const {
|
||||
dataList: datasetDataList,
|
||||
setDataList: setDatasetDataList,
|
||||
|
||||
@@ -22,10 +22,14 @@ const QuoteReader = ({
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const filterRawSearch = useMemo(() => {
|
||||
return rawSearch.filter((item) => metadata.collectionIdList.includes(item.collectionId));
|
||||
}, [rawSearch, metadata.collectionIdList]);
|
||||
|
||||
const { data: quoteList, loading } = useRequest2(
|
||||
async () =>
|
||||
await getQuoteDataList({
|
||||
datasetDataIdList: rawSearch.map((item) => item.id),
|
||||
datasetDataIdList: filterRawSearch.map((item) => item.id),
|
||||
collectionIdList: metadata.collectionIdList,
|
||||
chatItemDataId: metadata.chatItemDataId,
|
||||
appId: metadata.appId,
|
||||
@@ -33,12 +37,13 @@ const QuoteReader = ({
|
||||
...metadata.outLinkAuthData
|
||||
}),
|
||||
{
|
||||
refreshDeps: [metadata, filterRawSearch],
|
||||
manual: false
|
||||
}
|
||||
);
|
||||
|
||||
const formatedDataList = useMemo(() => {
|
||||
return rawSearch
|
||||
return filterRawSearch
|
||||
.map((searchItem) => {
|
||||
const dataItem = quoteList?.find((item) => item._id === searchItem.id);
|
||||
|
||||
@@ -57,7 +62,7 @@ const QuoteReader = ({
|
||||
.sort((a, b) => {
|
||||
return (b.score.primaryScore?.value || 0) - (a.score.primaryScore?.value || 0);
|
||||
});
|
||||
}, [quoteList, rawSearch]);
|
||||
}, [quoteList, filterRawSearch]);
|
||||
|
||||
return (
|
||||
<Flex flexDirection={'column'} h={'full'}>
|
||||
@@ -71,16 +76,48 @@ const QuoteReader = ({
|
||||
>
|
||||
<Box flex={1} py={4}>
|
||||
<Flex gap={2} mr={2} mb={1}>
|
||||
<MyIcon name={'core/chat/quoteFill'} w={['1rem', '1.25rem']} color={'primary.600'} />
|
||||
<Box
|
||||
maxW={['200px', '300px']}
|
||||
className={'textEllipsis'}
|
||||
wordBreak={'break-all'}
|
||||
color={'myGray.900'}
|
||||
fontWeight={'medium'}
|
||||
>
|
||||
{t('common:core.chat.Quote Amount', { amount: rawSearch.length })}
|
||||
</Box>
|
||||
{metadata.sourceId ? (
|
||||
<>
|
||||
<MyIcon
|
||||
name={
|
||||
getSourceNameIcon({
|
||||
sourceId: metadata.sourceId,
|
||||
sourceName: metadata.sourceName || ''
|
||||
}) as any
|
||||
}
|
||||
w={['1rem', '1.25rem']}
|
||||
color={'primary.600'}
|
||||
/>
|
||||
<Box
|
||||
ml={1}
|
||||
maxW={['200px', '220px']}
|
||||
className={'textEllipsis'}
|
||||
wordBreak={'break-all'}
|
||||
fontSize={'sm'}
|
||||
color={'myGray.900'}
|
||||
fontWeight={'medium'}
|
||||
>
|
||||
{metadata.sourceName || t('common:common.UnKnow Source')}
|
||||
</Box>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<MyIcon
|
||||
name={'core/chat/quoteFill'}
|
||||
w={['1rem', '1.25rem']}
|
||||
color={'primary.600'}
|
||||
/>
|
||||
<Box
|
||||
maxW={['200px', '300px']}
|
||||
className={'textEllipsis'}
|
||||
wordBreak={'break-all'}
|
||||
color={'myGray.900'}
|
||||
fontWeight={'medium'}
|
||||
>
|
||||
{t('common:core.chat.Quote Amount', { amount: filterRawSearch.length })}
|
||||
</Box>
|
||||
</>
|
||||
)}
|
||||
</Flex>
|
||||
<Box fontSize={'mini'} color={'myGray.500'}>
|
||||
{t('common:core.chat.quote.Quote Tip')}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import React from 'react';
|
||||
import { SearchDataResponseItemType } from '@fastgpt/global/core/dataset/type';
|
||||
import { useContextSelector } from 'use-context-selector';
|
||||
import { ChatItemContext, GetQuoteProps } from '@/web/core/chat/context/chatItemContext';
|
||||
import CollectionQuoteReader from './CollectionQuoteReader';
|
||||
import QuoteReader from './QuoteReader';
|
||||
import { useContextSelector } from 'use-context-selector';
|
||||
|
||||
const ChatQuoteList = ({
|
||||
rawSearch = [],
|
||||
@@ -18,7 +18,7 @@ const ChatQuoteList = ({
|
||||
|
||||
return (
|
||||
<>
|
||||
{'collectionId' in metadata && isShowReadRawSource && (
|
||||
{'collectionId' in metadata && (
|
||||
<CollectionQuoteReader rawSearch={rawSearch} metadata={metadata} onClose={onClose} />
|
||||
)}
|
||||
{'collectionIdList' in metadata && (
|
||||
|
||||
Reference in New Issue
Block a user