tool.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. <template>
  2. <a-button type="text" @click="handleClick" size="small">
  3. <template #icon>
  4. <icon-tool />
  5. </template>
  6. </a-button>
  7. <a-modal
  8. v-model:visible="visible"
  9. title=" "
  10. @before-open="handleOpened"
  11. @cancel="handleCancel"
  12. :footer="false"
  13. title-align="start"
  14. width="900px"
  15. >
  16. <a-tabs default-active-key="1">
  17. <a-tab-pane key="1">
  18. <template #title>
  19. <icon-calendar/> 解析方法
  20. </template>
  21. <div style="width: 100%">
  22. <div style="display: flex;align-items: center;">
  23. <div>
  24. 解析方法:
  25. </div>
  26. <div style="margin-left: 10px">
  27. <a-select v-model="form.parser_id" placeholder="请选择" >
  28. <a-option v-for="item in parser_ids" :key="item.value" :label="item.name" :value="item.value"></a-option>
  29. </a-select>
  30. </div>
  31. </div>
  32. <div class="parser">
  33. <a-form ref="formRef" :rules="rules" :model="form" auto-label-width @submit="handleSubmit" >
  34. <a-divider style="margin-top: 10px" />
  35. <a-form-item field="slider" label="块Token数">
  36. <a-slider v-model="form.chunk_token_num" :min="0" :max="2048" show-input />
  37. </a-form-item>
  38. <a-divider style="margin-top: 10px" />
  39. <a-form-item field="raptor" label="使用召回增强RAPTOR策略">
  40. <a-space direction="vertical" size="large">
  41. <a-switch v-model="form.use_raptor" @change="onChangeRAPTOR" />
  42. </a-space>
  43. </a-form-item>
  44. <div v-if="form.use_raptor">
  45. <a-form-item field="prompt" label="提示词">
  46. <a-textarea
  47. v-model="form.prompt"
  48. style="height: 10rem;border: 1px solid var(--color-fill-3);border-radius: 4px" placeholder="请填写提示词" />
  49. </a-form-item>
  50. <a-form-item field="slider" label="最大token数">
  51. <a-slider v-model="form.max_token" :min="0" :max="2048" show-input/>
  52. </a-form-item>
  53. <a-form-item field="slider" label="阈值" >
  54. <a-slider v-model="form.threshold" :step="0.01" :min="0" :max="1" show-input/>
  55. </a-form-item>
  56. <a-form-item field="slider" label="最大聚类数">
  57. <a-slider v-model="form.max_cluster" :min="1" :max="1024" show-input/>
  58. </a-form-item>
  59. <a-form-item field="slider" label="随机种子" v-model="form.random_seed"
  60. :rules="[{type:'number', min:5,message:'slider is min than 5'}]">
  61. <a-input-number v-model="form.random_seed" :style="{width:'300px',marginRight:'1rem',borderRadius:'4px'}"
  62. placeholder="请输入" class="input-demo" :min="10" :max="100" />
  63. <a-button type="primary" @click="randomNumber">
  64. <icon-plus />
  65. </a-button>
  66. </a-form-item>
  67. </div>
  68. <a-form-item>
  69. <div style="width: 100%;text-align: right">
  70. <a-button @click="visible = false">取消</a-button>
  71. <a-button style="margin-left: 10px" type="primary" html-type="submit">确定</a-button>
  72. </div>
  73. </a-form-item>
  74. </a-form>
  75. </div>
  76. </div>
  77. </a-tab-pane>
  78. <a-tab-pane key="2">
  79. <template #title>
  80. <icon-clock-circle/> 创建解析块
  81. </template>
  82. <div class="details">
  83. <div class="details-header">
  84. <div style="display: flex; align-items: center;justify-content: flex-end;">
  85. <a-radio-group v-model="radio" type="button" style="margin-right: 10px" @change="onRadioChange">
  86. <a-radio value="1">全文</a-radio>
  87. <a-radio value="2">省略</a-radio>
  88. </a-radio-group>
  89. <a-popover position="bottom">
  90. <a-button type="outline" class="button" style="margin-right: 10px;">批量<icon-down style="margin-left: 4px" /></a-button>
  91. <template #content>
  92. <a-space direction="vertical">
  93. <a-checkbox :model-value="checkedAll" :indeterminate="indeterminate" @change="handleChangeAll" style="margin-left: 10px">
  94. 选择所有
  95. </a-checkbox>
  96. </a-space>
  97. <a-divider style="margin: 10px 0" />
  98. <p>
  99. <a-button type="text" class="button" style="color: #2a2a2b">
  100. <template #icon>
  101. <icon-check-circle />
  102. </template>
  103. 启用选定的
  104. </a-button>
  105. </p>
  106. <p>
  107. <a-button type="text" class="button" style="color: #2a2a2b">
  108. <template #icon>
  109. <icon-close-circle />
  110. </template>
  111. 禁用选定的
  112. </a-button>
  113. </p>
  114. <a-divider style="margin: 10px 0" />
  115. <p>
  116. <a-button type="text" class="button" style="color: #2a2a2b">
  117. <template #icon>
  118. <icon-delete />
  119. </template>
  120. 删除选定的
  121. </a-button>
  122. </p>
  123. </template>
  124. </a-popover>
  125. <a-button type="outline" class="button" style="margin-right: 10px">
  126. <template #icon>
  127. <icon-search />
  128. </template>
  129. </a-button>
  130. <a-popover position="bottom">
  131. <a-button type="outline" class="button" style="margin-right: 10px"><icon-sort /></a-button>
  132. <template #content>
  133. <a-radio-group v-model="available_int" direction="vertical" size="large" @change="onChangeavailable">
  134. <a-radio value="">所有</a-radio>
  135. <a-radio value="1">启用</a-radio>
  136. <a-radio value="0">禁用</a-radio>
  137. </a-radio-group>
  138. </template>
  139. </a-popover>
  140. <addDetails :item="item"></addDetails>
  141. </div>
  142. </div>
  143. <a-divider style="margin-top: 10px" />
  144. <div class="groupMain">
  145. <a-checkbox-group v-model="data" @change="handleChange" >
  146. <div class="groupList" :class="{groupActive:keyBg=='1',groupNoActive:keyBg!='1'}">
  147. <a-checkbox value="1"></a-checkbox>
  148. <div class="groupList-content" @click="groupListContentClick('1')" @dblclick="contentClick(1)">
  149. 而 stable version 是最新稳定版,经过充分测试和验证,bug 较少,
  150. 适合用于生产环境。其版本号通常为双数,如 1.26。legacy versions
  151. 则是之前发布的稳定版,对于需要
  152. 特定旧版本的兼容性或安全性支持的用户有用,但一般不
  153. 推荐用于新项目,除非有特殊需求。在实际使用中,如果追求最新功能
  154. 且愿意面对可能存在的一些不稳定因素,可以尝试使用主线版本进行测试和研究;如果是用于生产环境
  155. </div>
  156. <div class="groupList-right">
  157. <a-switch v-model="switchType" checked-value="1" unchecked-value="0" @change="handleChangeStatus()"/>
  158. </div>
  159. </div>
  160. <div class="groupList" :class="{groupActive:keyBg=='2',groupNoActive:keyBg!='2'}">
  161. <a-checkbox value="1"></a-checkbox>
  162. <div class="groupList-content" @click="groupListContentClick('2')" @dblclick="contentClick(1)">
  163. 而 stable version 是最新稳定版,经过充分测试和验证,bug 较少,
  164. 适合用于生产环境。其版本号通常为双数,如 1.26。legacy versions
  165. 则是之前发布的稳定版,对于需要
  166. </div>
  167. <div class="groupList-right">
  168. <a-switch v-model="switchType" checked-value="1" unchecked-value="0" @change="handleChangeStatus()"/>
  169. </div>
  170. </div>
  171. </a-checkbox-group>
  172. </div>
  173. </div>
  174. <eidtDetails ref="eidtDil"></eidtDetails>
  175. </a-tab-pane>
  176. </a-tabs>
  177. </a-modal>
  178. </template>
  179. <script lang="ts" setup>
  180. import { onMounted, onBeforeMount, reactive, ref, computed } from "vue";
  181. import { Message } from "@arco-design/web-vue";
  182. import {kbdocumentchangeparser} from "@/api/kbList";
  183. import addDetails from '@/views/dmx/knowledgeLib/addDetails.vue'
  184. import eidtDetails from '@/views/dmx/knowledgeLib/eidtDetails.vue'
  185. const visible = ref(false);
  186. const loading = ref(false);
  187. const radio = ref('1');
  188. const keyBg = ref('');
  189. const eidtDil = ref();
  190. const props = defineProps(['kbtenantInfo','item','kbdetail'])
  191. // const emit = defineEmits(['upTabdateItem'])
  192. let threshold = computed(()=>{
  193. return form.threshold/100;
  194. })
  195. const kbtenantInfo = props.kbtenantInfo;
  196. let parser_ids = kbtenantInfo.parser_ids.split(',').map((item) => {
  197. const [value1, value2] = item.split(':');
  198. return {
  199. name: value2,
  200. value: value1,
  201. };
  202. });
  203. const form = reactive({
  204. parser_id: props.item.parser_id,
  205. doc_id: props.item.id,
  206. max_token: 698,
  207. threshold: 0.30,
  208. max_cluster: 233,
  209. random_seed: 1500,
  210. chunk_token_num: 128,
  211. use_raptor: false,
  212. pages: {},
  213. prompt: '请总结以下段落。 小心数字,不要编造。 段落如下:\n' +
  214. ' {cluster_content}\n' +
  215. '以上就是你需要总结的内容。',
  216. });
  217. const formRef = ref(null);
  218. const rules = {
  219. prompt: [
  220. {
  221. required: true,
  222. message:'提示词不允许为空',
  223. },
  224. ],
  225. }
  226. const formatter = (value) => {
  227. return value / 100
  228. };
  229. function randomNumber() {
  230. // 生成一个介于min和max之间的随机整数(包含min和max)
  231. const min = 1; // 最小值
  232. const max = 10000; // 最大值
  233. form.random_seed = Math.floor(Math.random() * (max - min + 1)) + min;
  234. }
  235. const handleSubmit = async ({values, errors}) => {
  236. if(!errors){
  237. let data = await kbdocumentchangeparser({
  238. parser_id: form.parser_id,
  239. doc_id: form.doc_id,
  240. parser_config: {
  241. raptor: {
  242. use_raptor: form.use_raptor,
  243. prompt: form.prompt,
  244. max_token: form.max_token,
  245. threshold: form.threshold,
  246. max_cluster: form.max_cluster,
  247. random_seed: form.random_seed,
  248. },
  249. chunk_token_num: form.chunk_token_num,
  250. pages: [
  251. ]
  252. }
  253. })
  254. if(data.code == 0){
  255. Message.success('配置成功');
  256. }else{
  257. Message.error('配置失败');
  258. }
  259. visible.value = false;
  260. }
  261. }
  262. const handleClick = () => {
  263. visible.value = true;
  264. };
  265. const handleCancel = () => {
  266. visible.value = false;
  267. }
  268. const contentClick = (done) => {
  269. eidtDil.value.handleClick();
  270. }
  271. const handleOpened =(el) => {
  272. // console.log('props',props.kbtenantInfo);
  273. // console.log('props',props.item);
  274. // console.log('props',props.kbdetail);
  275. console.log(parser_ids, 'parser_ids');
  276. // Object.assign(form,{
  277. // name: '',// 用户名
  278. // nameJoin: '',// 昵称
  279. // post: '',// 岗位
  280. // txt: '',// 备注
  281. // });
  282. // formRef.value.resetFields();
  283. console.log(props.item.id);
  284. }
  285. const onChangeRAPTOR = () => {
  286. };
  287. const indeterminate = ref(false)
  288. const checkedAll = ref(false)
  289. const data = ref([])
  290. const switchType = ref(false)
  291. const available_int = ref('')
  292. const onRadioChange = () => {
  293. console.log(radio.value);
  294. };
  295. const handleChangeAll = (value) => {
  296. indeterminate.value = false;
  297. if (value) {
  298. checkedAll.value = true;
  299. data.value = ['1', '2', '3']
  300. } else {
  301. checkedAll.value = false;
  302. data.value = []
  303. }
  304. }
  305. const handleChange = (values) => {
  306. if (values.length === 3) {
  307. checkedAll.value = true
  308. indeterminate.value = false;
  309. } else if (values.length === 0) {
  310. checkedAll.value = false
  311. indeterminate.value = false;
  312. } else {
  313. checkedAll.value = false
  314. indeterminate.value = true;
  315. }
  316. }
  317. const groupListContentClick = (value) => {
  318. keyBg.value = value;
  319. }
  320. const onChangeavailable = ()=>{
  321. console.log(available_int.value);
  322. }
  323. const handleChangeStatus = ()=>{
  324. console.log(switchType.value);
  325. }
  326. onBeforeMount(()=>{
  327. })
  328. onMounted(()=>{
  329. })
  330. </script>
  331. <style scoped lang="less">
  332. .parser{
  333. width: 100%;
  334. ::v-deep .arco-btn-outline:hover, .arco-btn-outline, .arco-btn-outline[type='button']{
  335. color: #2a2a2b;
  336. border: 1px solid #2a2a2b;
  337. }
  338. .button{
  339. //color: #2a2a2b!important;
  340. }
  341. }
  342. .groupMain{
  343. width: 100%;
  344. height: 500px;
  345. overflow: auto;
  346. display: flex;
  347. justify-content: center;
  348. .groupList{
  349. display: flex;
  350. padding: 24px;
  351. border-radius: 8px;
  352. //background: #eff8ff;
  353. border: 1px solid #f0f0f0;
  354. margin-bottom: 20px;
  355. overflow: auto;
  356. .groupList-content{
  357. width: 700px;
  358. //height: 100px;
  359. overflow: auto;
  360. box-sizing: border-box;
  361. margin: 0;
  362. padding: 0;
  363. color: #2a2a2b;
  364. font-size: 14px;
  365. font-family: Inter;
  366. position: relative;
  367. }
  368. }
  369. }
  370. .groupActive{
  371. background: #eff8ff;
  372. }
  373. .groupNoActive{
  374. background: var(--color-bg-1);
  375. color: var(--color-text-1);
  376. }
  377. </style>