import * as React from 'react'; import { useLocation } from 'react-router-dom'; import { observer } from 'mobx-react'; import './style.less'; import { Button, Input, Form, Divider, Splitter, Select, InputNumber, InputNumberProps, Radio, Switch, Row, Col, Slider, Space, RadioChangeEvent, Spin, message } from 'antd'; import { PlusCircleOutlined, MinusCircleOutlined } from '@ant-design/icons'; import { apis } from '@/apis'; import router from '@/router'; const { TextArea } = Input; const FormItem = Form.Item; const { Option } = Select; const MAX_COUNT = 10; const Index = 1; const QuestionAnswerInfo: React.FC = () => { const [form] = Form.useForm(); // top_p const [topPValue, setTopPValue] = React.useState(0.1); const TopPDecimalStep: React.FC = () => { const onChange: InputNumberProps['onChange'] = (value) => { if (Number.isNaN(value)) { return; } setTopPValue(value as number); }; return ( ); }; const [tempValue, setTempValue] = React.useState(0.01); // temperature const TempDecimalStep: React.FC = () => { const onChange: InputNumberProps['onChange'] = (value) => { if (Number.isNaN(value)) { return; } setTempValue(value as number); }; return ( ); }; type ModelList = { label: string, value: string, }[]; type KnowledgeList = { label: string, value: string, }[]; const [step, setStep] = React.useState(1); const [pageLoading, setPageLoading] = React.useState(false); const [modelList, setModelList] = React.useState([]); const [knowledgeList, setKnowledgeList] = React.useState([]); const [isVisible, setIsVisible] = React.useState(false); const [isVisibleCus, setIsVisibleCus] = React.useState(false); const [isVisibleSlice, setIsVisibleSlice] = React.useState(false); const [isVisibleRerank, setIsVisibleRerank] = React.useState(false); const [name, setName] = React.useState(''); const style: React.CSSProperties = { display: 'flex', flexDirection: 'column', gap: 8, width: 300, }; const location = useLocation(); const init = async (id: string) => { await Promise.all([ api.fetchKnowlegde(), api.fetchModelList(), ]) if (id) { await api.fetchDetail(id); } } React.useEffect(() => { const id = location?.state?.id; init(id) }, []); // 定义一个状态来存储输入框数组 const [inputs, setInputs] = React.useState([{ id: 1, value: '' }]); // 添加新输入框的函数 const addInput = () => { const newId = inputs.length + 1; // 生成新的唯一ID setInputs([...inputs, { id: newId, value: '' }]); }; const delInput = () => { const newId = inputs.length - 1; // 生成新的唯一ID setInputs(inputs.slice(0, inputs.length - 1)); }; // 处理输入变更的函数 const handleChange = (id: number, value: string) => { setInputs(inputs.map(input => (input.id === id ? { ...input, value } : input))); }; // const onChange: InputNumberProps['onChange'] = (value) => { // console.log('changed', value); // }; // const onChangeShow = (checked: boolean) => { // console.log(`switch to ${checked}`); // }; // const onChangeModel = (checked: boolean) => { // setIsVisibleRerank(!isVisibleRerank); // }; // const onChangeCount = (value: string) => { // if (value === 'fixed') { // setIsVisibleSlice(!isVisibleSlice); // } else { // setIsVisibleSlice(false); // } // }; // 召回方式 const onChangeRecallMethod = (e: RadioChangeEvent) => { }; // 获取应用详情 const api = { fetchDetail: async (app_id: string) => { setPageLoading(true); try { const res = await apis.fetchApplicationDetail(app_id) const sd = res.data.questionlist.map((item: any, index: number) => { return { "id": index + 1, "value": item.question, } }); const info = res.data.detail; if (info.paramDesc === 'custom') { setIsVisibleCus(!isVisibleCus); //自定义回答风格 } // if (jsonObj.rerank_status === 1) { // setIsVisibleRerank(!isVisibleRerank) //模型 // } // //召回切片数量 // if (jsonObj.slice_config_type === 'fixed') { // setIsVisibleSlice(!isVisibleSlice); // }else { // setIsVisibleSlice(false); // } setTopPValue(info.topP as number); setTempValue(info.temperature as number); setName(info.name); form.setFieldsValue({ id: info.id, name: info.name, //应用名称 desc: info.desc, //应用描述 prompt: info.prompt, //应用提示语 top_p: info.top_p, //topP temperature: info.temperature, //温度 knowledge_ids: info.knowledge_ids, slice_count: info.slice_count, model: info.model, icon_color: info.icon_color, icon_type: info.icon_type, questionList: sd, //问题列表 // max_token: info.max_token, //应用最大token // updateDate: info.updateDate, // 更新时间 // param_desc: info.paramDesc, //回答风格 // questionList: sd, //问题列表 // knowledge_ids: jsonObj.knowledge_ids, //知识库id // model: jsonObj.model, //模型名称 // slice_config_type: jsonObj.slice_config_type, //切片类型 // recall_method: jsonObj.recall_method, //召回方式 // slice_count: jsonObj.slice_count, //切片数量 // rerank_model_name: jsonObj.rerank_model_name, //模型名称 // recall_slice_splicing_method: jsonObj.recall_slice_splicing_method, // rerank_status: jsonObj.rerank_status, //开启rerank // show_recall_result: jsonObj.show_recall_result, //是否展示召回结果 // recall_index_type_list: jsonObj.recall_index_type_list, //知识库id // rerank_index_type_list: jsonObj.rerank_index_type_list, //知识库id }) console.log(sd, 'sd'); setInputs(sd); } catch (error) { console.error(error); } finally { setPageLoading(false); } }, //获取知识库列表 fetchKnowlegde: async () => { try { const res = await apis.fetchKnowledgeList(); const list = res.data.map((item: any) => { return { label: item.name, value: item.knowledgeId, } }); setKnowledgeList(list); } catch (error: any) { console.error(error); } }, // 获取模型列表 fetchModelList: async () => { try { const res = await apis.fetchModelList(); const list = res.data.data.map((item: any) => { return { label: item.modelName, value: item.modelCode, } }); setModelList(list); } catch (error: any) { console.error(error); } }, } const handleRedioClick = (value: string) => { setIsVisibleCus(false); } return (