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 ( 添加预设问题 { inputs.map(input => ( 问题 {input.id} handleChange(input.id, e.target.value)} /> ))} { form.validateFields(['name', 'desc']).then(async (values) => { setStep(2); setInputs(inputs); console.log(inputs, 'inputs'); }).catch((error) => { console.error(error); }); }} > 下一步 { setStep(1); }} > 上一步 { form.validateFields().then(async (values) => { const data = values; const question: string[] = []; if (inputs) { inputs.map((item, index) => { question.push(item.value); }); } console.log(question, 'question'); const info = { id: values.id, name: values.name, //应用名称 desc: values.desc, //应用描述 prompt: values.prompt, //应用提示语 top_p: values.top_p, //topP temperature: values.temperature, //温度 knowledge_ids: values.knowledge_ids, slice_count: values.slice_count, model: values.model, icon_color: values.icon_color, icon_type: values.icon_type, questionList: question, // knowledge_info: { // model: values.model, // 默认模型名称 // knowledge_ids: values.knowledge_ids, // 知识库id列表 // slice_config_type: values.slice_config_type, // 切片类型,默认为 fixed // recall_method: values.recall_method, // 召回方式,默认为 embedding // recall_index_type_list: values.recall_index_type_list, // 索引配置类型列表,默认为空数组 // slice_count: values.slice_count, // 切片数量,默认为空字符串 // rerank_status: values.rerank_status ? 1 : 0, // 是否开启rerank,默认关闭 // rerank_model_name: values.rerank_model_name, // 模型名称,默认为空字符串 // show_recall_result: values.show_recall_result, // 是否展示召回结果,默认为空字符串 // recall_slice_splicing_method: values.recall_slice_splicing_method // 召回切片拼接方式,默认为空字符串 // } }; const id = location?.state?.id; let res = null; if (id) { // 编辑应用 res = await apis.modifyApplicationApi(id, info); } else { // 创建应用 res = await await apis.createApplicationApi(info); } if (res.data.code !== 200) { message.error(res.data.message); } else { router.navigate({ pathname: '/questionAnswer' }); } }).catch((error) => { console.error(error); }); }} >发布应用 Prompt编写 欢迎使用 {name} { knowledgeList.map((item, index) => { return {item.label} }) } { modelList.map((item, index) => { return {item.label} }) } {/* { !isVisible && { setIsVisible(!isVisible); }} className='questionAnswerInfo-content-title'> 更多设置 } */} {/* {isVisible && {isVisibleCus && } { handleRedioClick('') }} value='strict'>严谨 { handleRedioClick('') }} value='moderate'>适中 { handleRedioClick('') }} value='flexib'>发散 { setIsVisibleCus(!isVisibleCus); }} >自定义 重排方式 {isVisibleRerank && 默认rerank模型 } 手动设置 自动设置 {isVisibleSlice && } } */} ); }; export default observer(QuestionAnswerInfo);
重排方式