import React, { useEffect, useMemo, useState } from 'react'; import { Box, Textarea, Button, Flex, useTheme, Grid, Progress, Switch } from '@chakra-ui/react'; import { useDatasetStore } from '@/web/core/dataset/store/dataset'; import { useSearchTestStore, SearchTestStoreItemType } from '@/web/core/dataset/store/searchTest'; import { getDatasetDataItemById, postSearchText } from '@/web/core/dataset/api'; import MyIcon from '@/components/Icon'; import { useRequest } from '@/web/common/hooks/useRequest'; import { formatTimeToChatTime } from '@/utils/tools'; import InputDataModal, { type InputDataType } from './InputDataModal'; import { useSystemStore } from '@/web/common/system/useSystemStore'; import { getErrText } from '@fastgpt/global/common/error/utils'; import { useToast } from '@/web/common/hooks/useToast'; import { customAlphabet } from 'nanoid'; import MyTooltip from '@/components/MyTooltip'; import { QuestionOutlineIcon } from '@chakra-ui/icons'; import { SearchDataResponseItemType } from '@fastgpt/global/core/dataset/type'; import { useTranslation } from 'next-i18next'; import { feConfigs } from '@/web/common/system/staticData'; const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz1234567890', 12); const Test = ({ datasetId }: { datasetId: string }) => { const { t } = useTranslation(); const theme = useTheme(); const { toast } = useToast(); const { setLoading } = useSystemStore(); const { datasetDetail } = useDatasetStore(); const { datasetTestList, pushDatasetTestItem, delDatasetTestItemById, updateDatasetItemById } = useSearchTestStore(); const [inputText, setInputText] = useState(''); const [datasetTestItem, setDatasetTestItem] = useState(); const [editInputData, setEditInputData] = useState(); const [rerank, setRerank] = useState(false); const kbTestHistory = useMemo( () => datasetTestList.filter((item) => item.datasetId === datasetId), [datasetId, datasetTestList] ); const { mutate, isLoading } = useRequest({ mutationFn: () => postSearchText({ datasetId, text: inputText.trim(), rerank, limit: 20 }), onSuccess(res: SearchDataResponseItemType[]) { if (!res || res.length === 0) { return toast({ status: 'warning', title: t('dataset.test.noResult') }); } const testItem = { id: nanoid(), datasetId, text: inputText.trim(), time: new Date(), results: res }; pushDatasetTestItem(testItem); setDatasetTestItem(testItem); }, onError(err) { toast({ title: getErrText(err), status: 'error' }); } }); useEffect(() => { setDatasetTestItem(undefined); }, [datasetId]); return ( 测试文本