'use client' import { useCallback, useState } from 'react' import { useRouter } from 'next/navigation' import { RiArrowLeftLine, RiArrowRightLine } from '@remixicon/react' import { useTranslation } from 'react-i18next' import KnowledgeBaseInfo from './KnowledgeBaseInfo' import ExternalApiSelection from './ExternalApiSelection' import RetrievalSettings from './RetrievalSettings' import InfoPanel from './InfoPanel' import type { CreateKnowledgeBaseReq } from './declarations' import Divider from '@/app/components/base/divider' import Button from '@/app/components/base/button' type ExternalKnowledgeBaseCreateProps = { onConnect: (formValue: CreateKnowledgeBaseReq) => void loading: boolean } const ExternalKnowledgeBaseCreate: React.FC = ({ onConnect, loading }) => { const { t } = useTranslation() const router = useRouter() const [formData, setFormData] = useState({ name: '', description: '', external_knowledge_api_id: '', external_knowledge_id: '', external_retrieval_model: { top_k: 2, score_threshold: 0.5, score_threshold_enabled: false, }, provider: 'external', }) const navBackHandle = useCallback(() => { router.replace('/datasets') }, [router]) const handleFormChange = (newData: CreateKnowledgeBaseReq) => { setFormData(newData) } const isFormValid = formData.name.trim() !== '' && formData.external_knowledge_api_id !== '' && formData.external_knowledge_id !== '' && formData.external_retrieval_model.top_k !== undefined && formData.external_retrieval_model.score_threshold !== undefined return (
{t('dataset.connectDataset')}

{t('dataset.connectHelper.helper1')} {t('dataset.connectHelper.helper2')} {t('dataset.connectHelper.helper3')} {t('dataset.connectHelper.helper4')} {t('dataset.connectHelper.helper5')}

handleFormChange({ ...formData, ...data, })} /> handleFormChange({ ...formData, ...data, })} /> handleFormChange({ ...formData, external_retrieval_model: { ...formData.external_retrieval_model, ...data, }, })} />
) } export default ExternalKnowledgeBaseCreate