'use client' import type { FC } from 'react' import React, { useEffect, useMemo, useState } from 'react' import { useTranslation } from 'react-i18next' import useSWR from 'swr' import { omit } from 'lodash-es' import cn from 'classnames' import { useBoolean } from 'ahooks' import { useContext } from 'use-context-selector' import SegmentCard from '../documents/detail/completed/SegmentCard' import docStyle from '../documents/detail/completed/style.module.css' import Textarea from './textarea' import s from './style.module.css' import HitDetail from './hit-detail' import ModifyRetrievalModal from './modify-retrieval-modal' import type { HitTestingResponse, HitTesting as HitTestingType } from '@/models/datasets' import Loading from '@/app/components/base/loading' import Modal from '@/app/components/base/modal' import Drawer from '@/app/components/base/drawer' import Pagination from '@/app/components/base/pagination' import FloatRightContainer from '@/app/components/base/float-right-container' import { fetchTestingRecords } from '@/service/datasets' import DatasetDetailContext from '@/context/dataset-detail' import type { RetrievalConfig } from '@/types/app' import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints' import useTimestamp from '@/hooks/use-timestamp' const limit = 10 type Props = { datasetId: string } const RecordsEmpty: FC = () => { const { t } = useTranslation() return
{t('datasetHitTesting.noRecentTip')}
} const HitTesting: FC = ({ datasetId }: Props) => { const { t } = useTranslation() const { formatTime } = useTimestamp() const media = useBreakpoints() const isMobile = media === MediaType.mobile const [hitResult, setHitResult] = useState() // 初始化记录为空数组 const [submitLoading, setSubmitLoading] = useState(false) const [currParagraph, setCurrParagraph] = useState<{ paraInfo?: HitTestingType; showModal: boolean }>({ showModal: false }) const [text, setText] = useState('') const [currPage, setCurrPage] = React.useState(0) const { data: recordsRes, error, mutate: recordsMutate } = useSWR({ action: 'fetchTestingRecords', datasetId, params: { limit, page: currPage + 1 }, }, apiParams => fetchTestingRecords(omit(apiParams, 'action'))) const total = recordsRes?.total || 0 const points = useMemo(() => (hitResult?.records.map(v => [v.tsne_position.x, v.tsne_position.y]) || []), [hitResult?.records]) const onClickCard = (detail: HitTestingType) => { setCurrParagraph({ paraInfo: detail, showModal: true }) } const { dataset: currentDataset } = useContext(DatasetDetailContext) const [retrievalConfig, setRetrievalConfig] = useState(currentDataset?.retrieval_model_dict as RetrievalConfig) const [isShowModifyRetrievalModal, setIsShowModifyRetrievalModal] = useState(false) const [isShowRightPanel, { setTrue: showRightPanel, setFalse: hideRightPanel, set: setShowRightPanel }] = useBoolean(!isMobile) useEffect(() => { setShowRightPanel(!isMobile) }, [isMobile, setShowRightPanel]) return (

{t('datasetHitTesting.title')}

{t('datasetHitTesting.desc')}