import React, { useState } from 'react'; import { Box, Textarea, Button, Flex } from '@chakra-ui/react'; import { useForm } from 'react-hook-form'; import { useToast } from '@/hooks/useToast'; import { useRequest } from '@/hooks/useRequest'; import { getErrText } from '@/utils/tools'; import { postKbDataFromList } from '@/api/plugins/kb'; import { TrainingModeEnum } from '@/constants/plugin'; import MyTooltip from '@/components/MyTooltip'; import { QuestionOutlineIcon } from '@chakra-ui/icons'; import { useDatasetStore } from '@/store/dataset'; type ManualFormType = { q: string; a: string }; const ManualImport = ({ kbId }: { kbId: string }) => { const { kbDetail } = useDatasetStore(); const maxToken = kbDetail.vectorModel?.maxToken || 2000; const { register, handleSubmit, reset } = useForm({ defaultValues: { q: '', a: '' } }); const { toast } = useToast(); const [qLen, setQLen] = useState(0); const { mutate: onImportData, isLoading } = useRequest({ mutationFn: async (e: ManualFormType) => { if (e.a.length + e.q.length >= 3000) { toast({ title: '总长度超长了', status: 'warning' }); return; } try { const data = { a: e.a, q: e.q, source: '手动录入' }; const { insertLen } = await postKbDataFromList({ kbId, mode: TrainingModeEnum.index, data: [data] }); if (insertLen === 0) { toast({ title: '已存在完全一致的数据', status: 'warning' }); } else { toast({ title: '导入数据成功,需要一段时间训练', status: 'success' }); reset({ a: '', q: '' }); } } catch (err: any) { toast({ title: getErrText(err, '出现了点意外~'), status: 'error' }); } } }); return ( {'匹配的知识点'}