import { apiInterceptors, recallMethodOptions, recallTest, recallTestRecommendQuestion } from '@/client/api'; import MarkDownContext from '@/new-components/common/MarkdownContext'; import { ISpace, RecallTestProps } from '@/types/knowledge'; import { SettingOutlined } from '@ant-design/icons'; import { useRequest } from 'ahooks'; import { Button, Card, Empty, Form, Input, InputNumber, Modal, Popover, Select, Spin, Tag } from 'antd'; import React, { useEffect } from 'react'; type RecallTestModalProps = { open: boolean; setOpen: React.Dispatch>; space: ISpace; }; // const tagColors = ['magenta', 'orange', 'geekblue', 'purple', 'cyan', 'green']; const RecallTestModal: React.FC = ({ open, setOpen, space }) => { const [form] = Form.useForm(); const [extraForm] = Form.useForm(); // 获取推荐问题 const { run: questionsRun } = useRequest( // const { data: questions = [], run: questionsRun } = useRequest( async () => { const [, res] = await apiInterceptors(recallTestRecommendQuestion(space.name + '')); return res ?? []; }, { manual: true, }, ); // 召回方法选项 const { data: options = [], run: optionsRun } = useRequest( async () => { const [, res] = await apiInterceptors(recallMethodOptions(space.name + '')); return res ?? []; }, { manual: true, onSuccess: data => { extraForm.setFieldValue('recall_retrievers', data); }, }, ); useEffect(() => { if (open) { // questionsRun(); optionsRun(); } }, [open, optionsRun, questionsRun]); // 召回测试 const { run: recallTestRun, data: resultList = [], loading, } = useRequest( async (props: RecallTestProps) => { const [, res] = await apiInterceptors(recallTest({ ...props }, space.name + '')); return res ?? []; }, { manual: true, }, ); const onTest = async () => { form.validateFields().then(async values => { const extraVal = extraForm.getFieldsValue(); await recallTestRun({ recall_top_k: 1, recall_retrievers: options, ...values, ...extraVal }); }); }; return ( setOpen(false)} centered destroyOnClose={true} > {/* {questions?.length > 0 && (
{questions.map((item, index) => ( { form.setFieldValue('question', item); }} > {item} ))}
)} */}
{resultList.length > 0 ? (
{resultList.map(item => ( # {item.chunk_id} {item.metadata.source}
} extra={
score: {item.score}
} key={item.chunk_id} size='small' className='mb-4 border-gray-500 shadow-md' > {item.content}
))} ) : ( )}
); }; export default RecallTestModal;