'use client' import type { FC } from 'react' import React, { useRef, useState } from 'react' import { useTranslation } from 'react-i18next' import { RiCloseLine } from '@remixicon/react' import Toast from '../../base/toast' import { ModelTypeEnum } from '../../header/account-setting/model-provider-page/declarations' import type { RetrievalConfig } from '@/types/app' import RetrievalMethodConfig from '@/app/components/datasets/common/retrieval-method-config' import EconomicalRetrievalMethodConfig from '@/app/components/datasets/common/economical-retrieval-method-config' import Button from '@/app/components/base/button' import { ensureRerankModelSelected, isReRankModelSelected } from '@/app/components/datasets/common/check-rerank-model' import { useModelListAndDefaultModelAndCurrentProviderAndModel } from '@/app/components/header/account-setting/model-provider-page/hooks' type Props = { indexMethod: string value: RetrievalConfig isShow: boolean onHide: () => void onSave: (value: RetrievalConfig) => void } const ModifyRetrievalModal: FC = ({ indexMethod, value, isShow, onHide, onSave, }) => { const ref = useRef(null) const { t } = useTranslation() const [retrievalConfig, setRetrievalConfig] = useState(value) // useClickAway(() => { // if (ref) // onHide() // }, ref) const { modelList: rerankModelList, defaultModel: rerankDefaultModel, currentModel: isRerankDefaultModelValid, } = useModelListAndDefaultModelAndCurrentProviderAndModel(ModelTypeEnum.rerank) const handleSave = () => { if ( !isReRankModelSelected({ rerankDefaultModel, isRerankDefaultModelValid: !!isRerankDefaultModelValid, rerankModelList, retrievalConfig, indexMethod, }) ) { Toast.notify({ type: 'error', message: t('appDebug.datasetConfig.rerankModelRequired') }) return } onSave(ensureRerankModelSelected({ rerankDefaultModel: rerankDefaultModel!, retrievalConfig, indexMethod, })) } if (!isShow) return null return (
{t('datasetSettings.form.retrievalSetting.title')}
{t('datasetSettings.form.retrievalSetting.learnMore')} {t('datasetSettings.form.retrievalSetting.description')}
{indexMethod === 'high_quality' ? ( ) : ( )}
) } export default React.memo(ModifyRetrievalModal)