index.tsx 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986
  1. import * as React from 'react';
  2. import { useLocation } from 'react-router-dom';
  3. import { observer } from 'mobx-react';
  4. import './style.less';
  5. import {
  6. Button, Input, Form, Divider, Splitter, Select, InputNumber, InputNumberProps,
  7. Radio, Switch, Row, Col, Slider, Space, RadioChangeEvent,
  8. Spin, message, Typography
  9. } from 'antd';
  10. import { PlusCircleOutlined, MinusCircleOutlined, ArrowLeftOutlined } from '@ant-design/icons';
  11. import { apis } from '@/apis';
  12. import router from '@/router';
  13. import LocalStorage from '@/LocalStorage';
  14. const { TextArea } = Input;
  15. const FormItem = Form.Item;
  16. const { Option } = Select;
  17. const MAX_COUNT = 10;
  18. const Index = 1;
  19. const QuestionAnswerInfo: React.FC = () => {
  20. const [form] = Form.useForm();
  21. // top_p
  22. const [topPValue, setTopPValue] = React.useState(0.1);
  23. const TopPDecimalStep: React.FC = () => {
  24. const onChange: InputNumberProps['onChange'] = (value) => {
  25. if (Number.isNaN(value)) {
  26. return;
  27. }
  28. setTopPValue(value as number);
  29. };
  30. return (
  31. <Row>
  32. <Col span={12}>
  33. <Slider
  34. min={0}
  35. max={1}
  36. onChange={onChange}
  37. // value={typeof topPValue === 'number' ? topPValue : 0}
  38. value={topPValue}
  39. step={0.1}
  40. />
  41. </Col>
  42. <Col span={4}>
  43. <InputNumber
  44. min={0}
  45. max={1}
  46. className='form-input-number-small'
  47. step={0.01}
  48. value={topPValue}
  49. onChange={onChange}
  50. />
  51. </Col>
  52. </Row>
  53. );
  54. };
  55. const [tempValue, setTempValue] = React.useState(0.01);
  56. // temperature
  57. const TempDecimalStep: React.FC = () => {
  58. const onChange: InputNumberProps['onChange'] = (value) => {
  59. if (Number.isNaN(value)) {
  60. return;
  61. }
  62. setTempValue(value as number);
  63. };
  64. return (
  65. <Row>
  66. <Col span={12}>
  67. <Slider
  68. min={0}
  69. max={1}
  70. onChange={onChange}
  71. // value={typeof tempValue === 'number' ? tempValue : 0}
  72. value={tempValue}
  73. step={0.01}
  74. />
  75. </Col>
  76. <Col span={4}>
  77. <InputNumber
  78. min={0}
  79. max={1}
  80. className='form-input-number-small'
  81. step={0.01}
  82. value={tempValue}
  83. onChange={onChange}
  84. />
  85. </Col>
  86. </Row>
  87. );
  88. };
  89. type ModelList = {
  90. label: string,
  91. value: string,
  92. }[];
  93. type KnowledgeList = {
  94. label: string,
  95. value: string,
  96. }[];
  97. type AppTypeList = {
  98. label: string,
  99. value: string,
  100. }[];
  101. const [step, setStep] = React.useState(1);
  102. const [pageLoading, setPageLoading] = React.useState(false);
  103. const [modelList, setModelList] = React.useState<ModelList>([]);
  104. const [knowledgeList, setKnowledgeList] = React.useState<KnowledgeList>([]);
  105. const [isVisible, setIsVisible] = React.useState(false);
  106. const [isVisibleCus, setIsVisibleCus] = React.useState(false);
  107. const [isVisibleSlice, setIsVisibleSlice] = React.useState(false);
  108. const [isVisibleRerank, setIsVisibleRerank] = React.useState(false);
  109. const [isDeepThinkVisible, setIsDeepThinkVisible] = React.useState(false);
  110. const [name, setName] = React.useState('');
  111. const [appTypeList, setAppTypeList] = React.useState<AppTypeList>([]);
  112. const [updateFlag, setUpdateFlag] = React.useState<boolean>();
  113. const [createFlag, setCreateFlag] = React.useState<boolean>();
  114. const [appProjectList, setAppProjectList] = React.useState<AppTypeList>([]);
  115. const [isAppPro, setIsAppPro] = React.useState<boolean>(false);
  116. const [selectedAppProId, setSelectedAppProId] = React.useState<string | undefined>(undefined); // 新增状态变量用于绑定 Select 值
  117. const style: React.CSSProperties = {
  118. display: 'flex',
  119. flexDirection: 'column',
  120. gap: 8,
  121. width: 300,
  122. };
  123. const location = useLocation();
  124. const init = async (id: string) => {
  125. await Promise.all([
  126. api.fetchKnowlegde(),
  127. api.fetchAppType(),
  128. // api.fetchModelList(),
  129. api.fetchAppProType(),
  130. ])
  131. if (id) {
  132. await api.fetchDetail(id);
  133. }
  134. }
  135. React.useEffect(() => {
  136. const id = location?.state?.id;
  137. init(id);
  138. const uFlag = LocalStorage.getStatusFlag('deepseek:application:update');
  139. setUpdateFlag(uFlag);
  140. const cFlag = LocalStorage.getStatusFlag('deepseek:application:create');
  141. setCreateFlag(cFlag);
  142. }, []);
  143. // 定义一个状态来存储输入框数组
  144. const [inputs, setInputs] = React.useState([{ id: 1, value: '' }]);
  145. // 添加新输入框的函数
  146. const addInput = () => {
  147. const newId = inputs.length + 1; // 生成新的唯一ID
  148. setInputs([...inputs, { id: newId, value: '' }]);
  149. };
  150. const delInput = () => {
  151. const newId = inputs.length - 1; // 生成新的唯一ID
  152. setInputs(inputs.slice(0, inputs.length - 1));
  153. };
  154. // 处理输入变更的函数
  155. const handleChange = (id: number, value: string) => {
  156. setInputs(inputs.map(input => (input.id === id ? { ...input, value } : input)));
  157. };
  158. const handleAppChange = (typeId: number) => {
  159. if (typeId === 41) { // 根据实际值进行判断
  160. setIsAppPro(true);
  161. } else {
  162. setIsAppPro(false);
  163. }
  164. };
  165. // const onChange: InputNumberProps['onChange'] = (value) => {
  166. // console.log('changed', value);
  167. // };
  168. const onChangeShow = (checked: boolean) => {
  169. console.log(`switch to ${checked}`);
  170. };
  171. const onChangeModel = (checked: boolean) => {
  172. setIsVisibleRerank(!isVisibleRerank);
  173. };
  174. const onChangeCount = (value: string) => {
  175. if (value === 'fixed') {
  176. setIsVisibleSlice(!isVisibleSlice);
  177. } else {
  178. setIsVisibleSlice(false);
  179. }
  180. };
  181. // 召回方式
  182. const onChangeRecallMethod = (e: RadioChangeEvent) => {
  183. };
  184. // 获取应用详情
  185. const api = {
  186. fetchDetail: async (app_id: string) => {
  187. setPageLoading(true);
  188. try {
  189. const res = await apis.fetchTakaiApplicationDetail(app_id)
  190. console.log(res.data);
  191. const sd = res.data.questionlist.map((item: any, index: number) => {
  192. return {
  193. "id": index + 1,
  194. "value": item.question,
  195. }
  196. });
  197. const info = res.data.detail;
  198. setTopPValue(info.topP as number);
  199. setTempValue(info.temperature as number);
  200. setName(info.name);
  201. interface Item2 {
  202. index_type_id: number,
  203. knowledge_id: string
  204. }
  205. interface Item {
  206. show_recall_result: boolean,
  207. recall_method: string,
  208. rerank_status: boolean,
  209. slice_config_type: string,
  210. slice_count: number,
  211. recall_slice_splicing_method: string,
  212. param_desc: string,
  213. rerank_model_name: string,
  214. rerank_index_type_list: [Item2],
  215. recall_index_type_list: [Item2]
  216. }
  217. const data_info: Item = JSON.parse(info.knowledgeInfo);
  218. if (data_info.param_desc === 'custom') {
  219. setIsVisibleCus(!isVisibleCus); //自定义回答风格
  220. }
  221. if (data_info.rerank_status === true) {
  222. setIsVisibleRerank(!isVisibleRerank) //模型
  223. }
  224. //召回切片数量
  225. if (data_info.slice_config_type === 'fixed') {
  226. setIsVisibleSlice(!isVisibleSlice);
  227. } else {
  228. setIsVisibleSlice(false);
  229. }
  230. if(info.typeId === 42 || info.typeId === 43){
  231. setIsAppPro(true);
  232. }else{
  233. setIsAppPro(false);
  234. }
  235. if(info.model === 'Qwen3-30B') {
  236. setIsDeepThinkVisible(true);
  237. } else {
  238. setIsDeepThinkVisible(false);
  239. }
  240. form.setFieldsValue({
  241. id: info.id,
  242. name: info.name, //应用名称
  243. desc: info.desc, //应用描述
  244. prompt: info.prompt, //应用提示语
  245. top_p: info.topP as number, //topP
  246. temperature: info.temperature as number, //温度
  247. knowledge_ids: info.knowledgeIds,
  248. model: info.model,
  249. isDeepThink: info.isDeepThink,
  250. icon_color: info.icon_color,
  251. icon_type: info.icon_type,
  252. questionList: sd, //问题列表
  253. max_token: info.maxToken, //应用最大token
  254. updateDate: info.updateDate, // 更新时间
  255. appProId: info.typeId, //项目级应用类型
  256. typeId: info.typeId === 42 || info.typeId === 43 ? 41 : info.typeId, //应用类型
  257. param_desc: data_info.param_desc, //回答风格
  258. show_recall_result: data_info.show_recall_result, //是否展示召回结果
  259. recall_method: data_info.recall_method, //召回方式
  260. rerank_status: data_info.rerank_status, //开启rerank
  261. rerank_model_name: data_info.rerank_model_name, //模型名称
  262. slice_config_type: data_info.slice_config_type, // 召回切片数量
  263. slice_count: data_info.slice_count, // 切片数量
  264. recall_slice_splicing_method: data_info.recall_slice_splicing_method, // 切片内容
  265. // rerank_status = 1 rerank_index_type_list
  266. // recall_method = 'embedding' || 'mixed' recall_index_type_list
  267. //recall_index_type_list: info.recall_index_type_list, //知识库id
  268. //rerank_index_type_list: info.rerank_index_type_list, //知识库id
  269. })
  270. if (sd.length > 0) {
  271. setInputs(sd);
  272. }
  273. } catch (error) {
  274. console.error(error);
  275. } finally {
  276. setPageLoading(false);
  277. }
  278. },
  279. //获取知识库列表
  280. fetchKnowlegde: async () => {
  281. try {
  282. const res = await apis.fetchTakaiKnowledgeList();
  283. const list = res.data.map((item: any) => {
  284. return {
  285. label: item.name,
  286. value: item.knowledgeId,
  287. }
  288. });
  289. setKnowledgeList(list);
  290. } catch (error: any) {
  291. console.error(error);
  292. }
  293. },
  294. // 获取应用类型
  295. fetchAppType: async () => {
  296. try {
  297. const res = await apis.fetchTakaiAppTypeList('app_type');
  298. const list = res.data.map((item: any) => {
  299. return {
  300. label: item.dictLabel,
  301. value: item.dictCode,
  302. }
  303. });
  304. setAppTypeList(list);
  305. } catch (error: any) {
  306. console.error(error);
  307. }
  308. },
  309. // 获取模型列表
  310. fetchModelList: async () => {
  311. try {
  312. const res = await apis.fetchModelList();
  313. const list = res.data.data.map((item: any) => {
  314. return {
  315. label: item.modelName,
  316. value: item.modelCode,
  317. }
  318. });
  319. setModelList(list);
  320. } catch (error: any) {
  321. console.error(error);
  322. }
  323. },
  324. // 项目级应用下的类型
  325. fetchAppProType: async () => {
  326. try {
  327. const res = await apis.fetchTakaiAppTypeList('project_type');
  328. const list = res.data.map((item: any) => {
  329. return {
  330. label: item.dictLabel,
  331. value: item.dictCode,
  332. }
  333. });
  334. console.log(list, 'project_type');
  335. setAppProjectList(list);
  336. } catch (error: any) {
  337. console.error(error);
  338. }
  339. },
  340. }
  341. const handleRedioClick = (value: string) => {
  342. setIsVisibleCus(false);
  343. if (value === 'strict') {
  344. setTopPValue(0.5);
  345. setTempValue(0.01);
  346. } else if (value === 'moderate') {
  347. setTopPValue(0.7);
  348. setTempValue(0.50);
  349. } else if (value === 'flexib') {
  350. setTopPValue(0.9);
  351. setTempValue(0.90);
  352. }
  353. }
  354. // const [modelValue, setModelValue] = useState('');
  355. //
  356. // // 监听表单中模型值的变化
  357. // useEffect(() => {
  358. // const currentModel = form.getFieldValue('model');
  359. // setModelValue(currentModel);
  360. // }, [form]); // 依赖表单实例,当表单值变化时重新执行
  361. return (
  362. <div className='questionAnswerInfo'>
  363. <Spin spinning={pageLoading}>
  364. <Form
  365. form={form}
  366. layout='vertical'
  367. initialValues={{
  368. max_token: 1024
  369. }}
  370. >
  371. <div style={{ display: step === 1 ? 'block' : 'none' }} className='questionAnswerInfo-content'>
  372. <FormItem
  373. label='问答应用名称'
  374. name='name'
  375. rules={[{ required: true, message: '问答应用名称不能为空' }]}
  376. >
  377. <Input placeholder="请输入问答应用名称" className='form-input-large' />
  378. </FormItem>
  379. <FormItem
  380. label='应用类型'
  381. name='typeId'
  382. >
  383. <Select
  384. className='questionAnswerInfo-content-title'
  385. placeholder='请选择问答应用类型'
  386. onChange={handleAppChange}
  387. allowClear={true}
  388. >
  389. {
  390. appTypeList.map((item, index) => {
  391. return <Option value={item.value} key={index}>
  392. {item.label}
  393. </Option>
  394. })
  395. }
  396. </Select>
  397. </FormItem>
  398. {
  399. isAppPro &&
  400. <FormItem
  401. label='类型'
  402. name='appProId'
  403. rules={[{ required: true, message: '项目类型不能为空' }]}
  404. >
  405. <Select
  406. className='questionAnswerInfo-content-title'
  407. placeholder='请选择项目类型'
  408. value={selectedAppProId}
  409. onChange={(value) => setSelectedAppProId(value)}
  410. >
  411. {appProjectList.map((item, index) => (
  412. <Option value={item.value} key={index}>
  413. {item.label}
  414. </Option>
  415. ))}
  416. </Select>
  417. </FormItem>
  418. }
  419. <FormItem
  420. label='问答应用描述'
  421. name='desc'
  422. rules={[{ required: true, message: '问答应用描述不能为空' }]}
  423. >
  424. <TextArea
  425. showCount
  426. maxLength={500}
  427. placeholder="请输入当前应用的描述"
  428. className='form-textarea-large'
  429. />
  430. </FormItem>
  431. <div className='preset-questions'>
  432. <h4>添加预设问题</h4>
  433. <div>
  434. {
  435. inputs.map(input => (
  436. <div key={input.id} className='question-item'>
  437. <label>问题 {input.id}</label>
  438. <Input
  439. className='question-input'
  440. type="text"
  441. value={input.value}
  442. onChange={e => handleChange(input.id, e.target.value)}
  443. />
  444. <div className='question-actions'>
  445. <PlusCircleOutlined className='question-icon' onClick={addInput} />
  446. <MinusCircleOutlined className='question-icon' onClick={delInput} />
  447. </div>
  448. </div>
  449. ))}
  450. </div>
  451. </div>
  452. <div style={{ display: 'flex', gap: '12px', marginTop: '24px', paddingTop: '24px', borderTop: '1px solid #f0f0f0' }}>
  453. <Button
  454. className='btn-cancel'
  455. onClick={() => {
  456. router.navigate({ pathname: '/deepseek/questionAnswer' });
  457. }}
  458. >
  459. 返回
  460. </Button>
  461. <Button
  462. type='primary'
  463. onClick={() => {
  464. form.validateFields(['name', 'desc', 'appProId']).then(async (values) => {
  465. setStep(2);
  466. setInputs(inputs);
  467. }).catch((error) => {
  468. console.error(error);
  469. });
  470. }}
  471. >
  472. 下一步
  473. </Button>
  474. </div>
  475. </div>
  476. <div style={{ display: step === 2 ? 'block' : 'none' }} className='questionAnswerInfo-content'>
  477. <div className='flex-between padding-bottom-10'>
  478. <div>
  479. <Button
  480. className='btn-back'
  481. icon={<ArrowLeftOutlined />}
  482. onClick={() => {
  483. setStep(1);
  484. }}
  485. >
  486. 上一步
  487. </Button>
  488. </div>
  489. <div style={{ display: 'flex', gap: '12px' }}>
  490. <Button
  491. className='btn-cancel'
  492. onClick={() => {
  493. router.navigate({ pathname: '/deepseek/questionAnswer' });
  494. }}
  495. >
  496. 取消
  497. </Button>
  498. {createFlag && (
  499. <Button
  500. type='primary'
  501. onClick={() => {
  502. form.validateFields().then(async (values) => {
  503. const data = values;
  504. console.log(values, 'values');
  505. // 问题列表
  506. const question: string[] = [];
  507. if (inputs) {
  508. inputs.map((item, index) => {
  509. question.push(item.value);
  510. });
  511. }
  512. console.log(question, 'question');
  513. interface Item {
  514. index_type_id: number,
  515. knowledge_id: string
  516. }
  517. const indexTypeList: Item[] = [];
  518. if (values.knowledge_ids && values.knowledge_ids.length > 0) {
  519. const index_type: Item = {
  520. index_type_id: 0,
  521. knowledge_id: values.knowledge_ids
  522. };
  523. indexTypeList.push(index_type);
  524. }
  525. const userInfo = LocalStorage.getUserInfo();
  526. const userId = (userInfo?.id ?? '').toString();
  527. const data_info = {
  528. param_desc: values.param_desc, //回答风格
  529. show_recall_result: values.show_recall_result, //是否展示召回结果
  530. recall_method: values.recall_method, //召回方式
  531. rerank_status: values.rerank_status, //开启rerank
  532. rerank_model_name: values.rerank_model_name, //模型名称
  533. slice_config_type: values.slice_config_type, // 召回切片数量
  534. slice_count: values.slice_count, // 切片数量
  535. recall_slice_splicing_method: values.recall_slice_splicing_method, // 切片内容
  536. rerank_index_type_list: values.rerank_status === true ? indexTypeList : [], //知识库id
  537. recall_index_type_list: values.recall_method === 'embedding' || 'mixed' ? indexTypeList : []
  538. // rerank_status = 1 rerank_index_type_list
  539. // recall_method = 'embedding' || 'embedding' recall_index_type_list
  540. };
  541. // const knowledgeIds: string[] = [];
  542. // knowledgeIds.push(values.knowledge_ids);
  543. console.log(values.appProId , 'values.appProId ');
  544. const info = {
  545. id: values.id,
  546. name: values.name, //应用名称
  547. desc: values.desc, //应用描述
  548. prompt: values.prompt, //应用提示语
  549. top_p: topPValue.toString(), //topP
  550. temperature: tempValue.toString(), //温度
  551. knowledge_ids: values.knowledge_ids,
  552. slice_count: values.slice_count,
  553. model: values.model,
  554. isDeepThink:values.isDeepThink,
  555. icon_color: values.icon_color,
  556. icon_type: values.icon_type,
  557. questionList: question,
  558. knowledge_info: JSON.stringify(data_info),
  559. max_token: values.max_token, //应用最大token
  560. typeId: values.appProId === 42 || values.appProId === 43 ? values.appProId : values.typeId, // 应用类型
  561. userId: userId, // 用户id
  562. };
  563. console.log(info, 'info data');
  564. const id = location?.state?.id;
  565. let res = null;
  566. if (id) {
  567. // 编辑应用
  568. res = await apis.modifyTakaiApplicationApi(id, info);
  569. } else {
  570. // 创建应用
  571. res = await await apis.createTakaiApplicationApi(info);
  572. }
  573. console.log(res, 'create or modify');
  574. if (res.data === 9) {
  575. message.error('没有配置审核人,请联系管理员');
  576. } else if (res.data === 1) {
  577. message.success('操作成功')
  578. } else {
  579. message.error('操作失败');
  580. }
  581. router.navigate({ pathname: '/deepseek/questionAnswer' });
  582. }).catch((error) => {
  583. console.error(error);
  584. error.errorFields && error.errorFields.map((item: any) => {
  585. console.log(item, 'item');
  586. message.error(`字段 ${item.name} ${item.errors[0]}`);
  587. });
  588. });
  589. }}
  590. >提交应用</Button>
  591. )}
  592. </div>
  593. </div>
  594. <h3>Prompt编写</h3>
  595. <Splitter style={{ border: '1px solid #d9d9d9', borderRadius: '6px' }}>
  596. <Splitter.Panel defaultSize="75%">
  597. <div className='prompt'>
  598. <div className='prompt-info'>
  599. <div className='prompt-info-text'>
  600. <Typography.Paragraph style={{ fontSize: '12px', lineHeight: '1.6', color: '#999' }}>
  601. 编写Prompt过程中可以引入2项变量:
  602. <span className='variable-highlight'>{'{{知识}}'}</span>
  603. 代表知识库中检索到的知识内容,
  604. <span className='variable-highlight'>{'{{用户}}'}</span>
  605. 代表用户输入的内容。您可以在编写Prompt过程中将变量拼接在合适的位置。
  606. </Typography.Paragraph>
  607. <div className='variable-insert-buttons'>
  608. <Button type="link" size="small" className='insert-variable-btn'>
  609. 插入:<span className='variable-highlight'>{'{{知识}}'}</span>
  610. </Button>
  611. <Button type="link" size="small" className='insert-variable-btn'>
  612. 插入:<span className='variable-highlight'>{'{{用户}}'}</span>
  613. </Button>
  614. </div>
  615. </div>
  616. </div>
  617. <div className='prompt-editor-area'>
  618. <FormItem name='prompt'
  619. initialValue={
  620. `你是一位知识检索助手,你必须并且只能从我发送的众多知识片段中寻找能够解决用户输入问题的最优答案,并且在执行任务的过程中严格执行规定的要求。 \n
  621. 知识片段如下:
  622. {{知识}}
  623. 规定要求:
  624. - 找到答案就仅使用知识片段中的原文回答用户的提问;- 找不到答案就用自身知识并且告诉用户该信息不是来自文档;
  625. - 所引用的文本片段中所包含的示意图占位符必须进行返回,占位符格式参考:【示意图序号_编号】
  626. - 严禁输出任何知识片段中不存在的示意图占位符;
  627. - 输出的内容必须删除其中包含的任何图注、序号等信息。例如:“进入登录页面(图1.1)”需要从文字中删除图序,回复效果为:“进入登录页面”;“如图所示1.1”,回复效果为:“如图所示”;
  628. 格式规范:
  629. - 文档中会出现包含表格的情况,表格是以图片标识符的形式呈现,表格中缺失数据时候返回空单元格;
  630. - 如果需要用到表格中的数据,以代码块语法输出表格中的数据;
  631. - 避免使用代码块语法回复信息;
  632. - 回复的开头语不要输出诸如:“我想”,“我认为”,“think”等相关语义的文本。
  633. 严格执行规定要求,不要复述问题,直接开始回答。
  634. 用户输入问题:
  635. {{用户}}`
  636. }
  637. rules={[{ required: true, message: '提示词不能为空' }]}>
  638. <TextArea
  639. placeholder="提示词"
  640. rows={50}
  641. />
  642. </FormItem>
  643. </div>
  644. </div>
  645. </Splitter.Panel>
  646. <Splitter.Panel defaultSize="60%">
  647. <div className='flex-center-container'>
  648. <div className='half-width'>
  649. <div className='flex-center-top'>
  650. 欢迎使用 {name}
  651. </div>
  652. <div className='flex-center padding-top-20'>
  653. <FormItem
  654. label='引用知识库'
  655. name='knowledge_ids'
  656. rules={[{ required: true, message: '知识库不能为空' }]}>
  657. <Select
  658. // mode='multiple'
  659. // maxCount={MAX_COUNT}
  660. // suffixIcon={suffix}
  661. className='questionAnswerInfo-content-title'
  662. placeholder='请选择知识库'
  663. >
  664. {
  665. knowledgeList.map((item, index) => {
  666. return <Option value={item.value} key={index}>
  667. {item.label}
  668. </Option>
  669. })
  670. }
  671. </Select>
  672. </FormItem>
  673. </div>
  674. <div className='flex-center'>
  675. <FormItem
  676. label='调用模型'
  677. name="model"
  678. rules={[{required: true, message: '模型不能为空'}]}>
  679. <Select
  680. placeholder='请选择模型'
  681. allowClear={true}
  682. className='questionAnswerInfo-content-title'
  683. onChange={(value) => {
  684. if (value === 'Qwen3-30B') {
  685. setIsDeepThinkVisible(true);
  686. } else {
  687. setIsDeepThinkVisible(false);
  688. }
  689. }}
  690. >
  691. <Option value='Qwen3-30B'>Qwen3-30B</Option>
  692. <Option value='Qwen2-72B'>Qwen2-72B</Option>
  693. </Select>
  694. </FormItem>
  695. </div>
  696. <div className='flex-center' style={{
  697. display: isDeepThinkVisible ? 'flex' : 'none'
  698. }}>
  699. <FormItem
  700. label='深度思考'
  701. name='isDeepThink'
  702. rules={[{ required: true, message: '请选择是否深度思考' }]}>
  703. <Radio.Group buttonStyle="solid" className='form-control-width'>
  704. <Radio.Button value='Y'>是</Radio.Button>
  705. <Radio.Button value='N'>否</Radio.Button>
  706. </Radio.Group>
  707. </FormItem>
  708. </div>
  709. <div className='flex-center'>
  710. <FormItem
  711. label='max token'
  712. name='max_token'
  713. rules={[{required: true, message: 'max token不能为空'}]}>
  714. <InputNumber
  715. className='questionAnswerInfo-content-title'
  716. />
  717. </FormItem>
  718. </div>
  719. {
  720. !isVisible &&
  721. <div className='flex-center'>
  722. <a onClick={() => {
  723. setIsVisible(!isVisible);
  724. }} className='link-more-settings'>
  725. 更多设置
  726. </a>
  727. </div>
  728. }
  729. {/* {isVisible && */}
  730. <div style={{display: isVisible ? 'block' : 'none', paddingTop: '20px'}}>
  731. {isVisibleCus &&
  732. <Space style={{width: '100%'}} direction="vertical">
  733. <div className='flex-center'>
  734. <FormItem
  735. label='Top-p'
  736. name='topP'
  737. className='form-control-width'
  738. >
  739. <TopPDecimalStep/>
  740. </FormItem>
  741. </div>
  742. <div className='flex-center'>
  743. <FormItem
  744. label='Temperature'
  745. name='temperature'
  746. className='form-control-width'
  747. >
  748. <TempDecimalStep/>
  749. </FormItem>
  750. </div>
  751. </Space>
  752. }
  753. <div style={{
  754. display: 'flex',
  755. justifyContent: 'center',
  756. alignItems: 'center'
  757. }}>
  758. <FormItem
  759. label='回答风格'
  760. name='param_desc'
  761. rules={[{required: true, message: '回答风格不能为空'}]}>
  762. <Radio.Group buttonStyle="solid"
  763. className='form-control-width'>
  764. <Radio.Button onClick={() => {
  765. handleRedioClick('strict')
  766. }} value='strict'>严谨</Radio.Button>
  767. <Radio.Button onClick={() => {
  768. handleRedioClick('moderate')
  769. }} value='moderate'>适中</Radio.Button>
  770. <Radio.Button onClick={() => {
  771. handleRedioClick('flexib')
  772. }} value='flexib'>发散</Radio.Button>
  773. <Radio.Button value='custom'
  774. onClick={() => {
  775. setIsVisibleCus(!isVisibleCus);
  776. setTopPValue(0.1);
  777. setTempValue(0.01);
  778. }}
  779. >自定义
  780. </Radio.Button>
  781. </Radio.Group>
  782. </FormItem>
  783. </div>
  784. <div style={{
  785. display: 'flex',
  786. justifyContent: 'center',
  787. alignItems: 'center'
  788. }}>
  789. <FormItem
  790. label='展示引用知识'
  791. name='show_recall_result'
  792. className='form-control-width'>
  793. <Switch onChange={onChangeShow}/>
  794. </FormItem>
  795. </div>
  796. <div style={{
  797. display: 'flex',
  798. justifyContent: 'center',
  799. alignItems: 'center'
  800. }}>
  801. <FormItem
  802. label='召回方式'
  803. name='recall_method'
  804. rules={[{required: true, message: '召回方式不能为空'}]}>
  805. <Radio.Group
  806. style={style}
  807. onChange={onChangeRecallMethod}
  808. options={[
  809. {value: 'embedding', label: '向量化检索'},
  810. {value: 'keyword', label: '关键词检索'},
  811. {value: 'mixed', label: '混合检索'},
  812. ]}
  813. />
  814. </FormItem>
  815. </div>
  816. <div style={{
  817. display: 'flex',
  818. justifyContent: 'center',
  819. alignItems: 'center'
  820. }}>
  821. <div className='section-title'>重排方式</div>
  822. </div>
  823. <div style={{
  824. display: 'flex',
  825. justifyContent: 'center',
  826. alignItems: 'center'
  827. }}>
  828. <FormItem
  829. label='Rerank模型'
  830. name='rerank_status'
  831. valuePropName='checked'
  832. className='form-control-width'
  833. >
  834. <Switch onChange={onChangeModel}/>
  835. </FormItem>
  836. </div>
  837. {isVisibleRerank &&
  838. <div style={{
  839. display: 'flex',
  840. justifyContent: 'center',
  841. alignItems: 'center'
  842. }}>
  843. <FormItem
  844. label='模型选择'
  845. name='rerank_model_name'
  846. >
  847. <Select
  848. className='questionAnswerInfo-content-title'
  849. placeholder='请选择模型'
  850. // defaultValue={'rerank'}
  851. >
  852. <Option value='rerank'>默认rerank模型</Option>
  853. </Select>
  854. </FormItem>
  855. </div>
  856. }
  857. <div style={{
  858. display: 'flex',
  859. justifyContent: 'center',
  860. alignItems: 'center'
  861. }}>
  862. <FormItem
  863. label='召回切片数量'
  864. name='slice_config_type'
  865. rules={[{required: true, message: '召回方式不能为空'}]}>
  866. <Select
  867. className='questionAnswerInfo-content-title'
  868. placeholder='请选择'
  869. onChange={onChangeCount}>
  870. <Option value="fixed">手动设置</Option>
  871. <Option value="customized">自动设置</Option>
  872. </Select>
  873. </FormItem>
  874. </div>
  875. {isVisibleSlice &&
  876. <div style={{
  877. display: 'flex',
  878. justifyContent: 'center',
  879. alignItems: 'center'
  880. }}>
  881. <FormItem
  882. label='召回切片数'
  883. name='slice_count'
  884. rules={[{required: true, message: '切片数不能为空'}]}>
  885. <InputNumber max={1024} changeOnWheel
  886. className='questionAnswerInfo-content-title'/>
  887. </FormItem>
  888. </div>
  889. }
  890. <div style={{
  891. display: 'flex',
  892. justifyContent: 'center',
  893. alignItems: 'center'
  894. }}>
  895. <FormItem
  896. label='召回切片拼接方式'
  897. name='recall_slice_splicing_method'
  898. >
  899. <TextArea
  900. rows={4}
  901. className='form-textarea-large'
  902. placeholder="请输入内容"
  903. />
  904. </FormItem>
  905. </div>
  906. </div>
  907. {/* } */}
  908. </div>
  909. </div>
  910. </Splitter.Panel>
  911. </Splitter>
  912. </div>
  913. </Form>
  914. </Spin>
  915. </div >
  916. );
  917. };
  918. export default observer(QuestionAnswerInfo);