import { useContext } from 'use-context-selector' import { useTranslation } from 'react-i18next' import cn from 'classnames' import Button from '../../base/button' import Tag from '../../base/tag' import Tooltip from '../../base/tooltip' import { getIcon } from '../common/retrieval-method-info' import s from './style.module.css' import DatasetDetailContext from '@/context/dataset-detail' import type { HitTestingResponse } from '@/models/datasets' import { hitTesting } from '@/service/datasets' import { asyncRunSafe } from '@/utils' import { RETRIEVE_METHOD, type RetrievalConfig } from '@/types/app' type TextAreaWithButtonIProps = { datasetId: string onUpdateList: () => void setHitResult: (res: HitTestingResponse) => void loading: boolean setLoading: (v: boolean) => void text: string setText: (v: string) => void onClickRetrievalMethod: () => void retrievalConfig: RetrievalConfig isEconomy: boolean onSubmit?: () => void } const TextAreaWithButton = ({ datasetId, onUpdateList, setHitResult, setLoading, loading, text, setText, onClickRetrievalMethod, retrievalConfig, isEconomy, onSubmit: _onSubmit, }: TextAreaWithButtonIProps) => { const { t } = useTranslation() const { indexingTechnique } = useContext(DatasetDetailContext) function handleTextChange(event: any) { setText(event.target.value) } const onSubmit = async () => { setLoading(true) const [e, res] = await asyncRunSafe( hitTesting({ datasetId, queryText: text, retrieval_model: { ...retrievalConfig, search_method: isEconomy ? RETRIEVE_METHOD.keywordSearch : retrievalConfig.search_method, }, }) as Promise, ) if (!e) { setHitResult(res) onUpdateList?.() } setLoading(false) _onSubmit && _onSubmit() } const retrievalMethod = isEconomy ? RETRIEVE_METHOD.invertedIndex : retrievalConfig.search_method const Icon = getIcon(retrievalMethod) return ( <>
{t('datasetHitTesting.input.title')}
{t(`dataset.retrieval.${retrievalMethod}.title`)}