CzRger 1 miesiąc temu
rodzic
commit
68252ef277
2 zmienionych plików z 50 dodań i 23 usunięć
  1. 31 0
      src/stores/modules/dictionary.ts
  2. 19 23
      src/views/manage/app/make/index.vue

+ 31 - 0
src/stores/modules/dictionary.ts

@@ -18,6 +18,7 @@ import FileUnknown from '@/assets/images/file-unknown.png'
 // @ts-ignore
 import FileWord from '@/assets/images/file-word.png'
 import { tenantsPage } from '@/api/modules/center/tenant'
+import { datasetsGetAllByPage } from '@/api/modules/knowledge'
 
 const listToMap = ({
   list,
@@ -46,6 +47,12 @@ export const useDictionaryStore = defineStore('dictionary', {
       map: new Map(),
       objMap: new Map(),
     },
+    knowledges: {
+      waiting: false,
+      list: [],
+      map: new Map(),
+      objMap: new Map(),
+    },
     modelProvides: {
       waiting: false,
       list: [],
@@ -265,6 +272,30 @@ export const useDictionaryStore = defineStore('dictionary', {
           })
       }
     },
+    initKnowledges(tenantId) {
+      if (!this.knowledges.waiting) {
+        this.knowledges.waiting = true
+        datasetsGetAllByPage({
+          page: 1,
+          size: 100000,
+          tenantId,
+        })
+          .then(({ data }: any) => {
+            const arr: any = data.content.map((v) => {
+              v.label = v.name
+              v.value = v.id
+              return v
+            })
+            this.knowledges.list = arr
+            this.knowledges.map = listToMap({ list: arr })
+            this.knowledges.objMap = listToMap({ list: arr, isObj: true })
+          })
+          .catch(() => {})
+          .finally(() => {
+            this.knowledges.waiting = false
+          })
+      }
+    },
     getFileIcon(name) {
       if (name.toLowerCase().includes('.txt')) {
         return FileTxt

+ 19 - 23
src/views/manage/app/make/index.vue

@@ -165,8 +165,8 @@
                 <template v-if="state.detail.type === 0">
                   <div class="__czr-title_2 mt-4">
                     知识库
-                    <template v-if="state.form.knowledges.length > 0">
-                      ({{ state.form.knowledges.length }})
+                    <template v-if="state.form.datasetIds.length > 0">
+                      ({{ state.form.datasetIds.length }})
                     </template>
                     <CzrButton
                       type="normal"
@@ -175,11 +175,11 @@
                       @click="onAddKnowledge"
                     />
                   </div>
-                  <template v-if="state.form.knowledges.length > 0">
+                  <template v-if="state.form.datasetIds.length > 0">
                     <div
                       class="mt-2 flex max-h-42 flex-col gap-2 overflow-y-auto pr-2"
                     >
-                      <template v-for="(item, index) in state.form.knowledges">
+                      <template v-for="(id, index) in state.form.datasetIds">
                         <div class="flex items-center gap-1.5">
                           <div
                             class="flex flex-1 items-center overflow-hidden rounded-sm bg-[#F6F8FC] p-2.5"
@@ -192,14 +192,14 @@
                               class="flex-1 text-sm font-bold text-[#2E3238]"
                               v-title
                             >
-                              {{ item.name }}
+                              {{ DictionaryStore.knowledges.map.get(id) }}
                             </div>
                           </div>
                           <SvgIcon
                             class="__hover"
                             name="czr_del"
                             color="var(--czr-error-color)"
-                            @click="state.form.knowledges.splice(index, 1)"
+                            @click="state.form.datasetIds.splice(index, 1)"
                           />
                         </div>
                       </template>
@@ -506,7 +506,7 @@
                         class="mt-2 flex max-h-42 flex-col gap-2 overflow-y-auto pr-2"
                       >
                         <template
-                          v-for="(item, index) in state.form.advise.knowledges"
+                          v-for="(id, index) in state.form.advise.knowledges"
                         >
                           <div class="flex items-center gap-1.5">
                             <div
@@ -520,7 +520,7 @@
                                 class="flex-1 text-sm font-bold text-[#2E3238]"
                                 v-title
                               >
-                                {{ item.name }}
+                                {{ DictionaryStore.knowledges.map.get(id) }}
                               </div>
                             </div>
                             <SvgIcon
@@ -667,7 +667,7 @@ import {
 } from 'vue'
 import { useRoute, useRouter } from 'vue-router'
 import { ElLoading, ElMessage } from 'element-plus'
-import { useDialogStore, useDictionaryStore } from '@/stores'
+import { useAppStore, useDialogStore, useDictionaryStore } from '@/stores'
 import { Search } from '@element-plus/icons-vue'
 import knowledgeSelect from './knowledge-select.vue'
 import modelSelect from './model-select.vue'
@@ -688,6 +688,7 @@ import {
 import { appDetail } from '@/api/modules/app'
 
 const DictionaryStore = useDictionaryStore()
+const AppStore = useAppStore()
 const DialogStore = useDialogStore()
 const route = useRoute()
 const router = useRouter()
@@ -702,13 +703,7 @@ const state: any = reactive({
     tips: '',
     modelId: '',
     components: [],
-    knowledges: [
-      {
-        name: '水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水',
-        description:
-          '水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水',
-      },
-    ],
+    datasetIds: [],
     workflows: [
       {
         name: '水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水',
@@ -806,6 +801,7 @@ const autoSave = debounce((v) => {
   }
   if (state.detail.type === 0) {
     params.modelId = state.form.modelId
+    params.datasetIds = state.form.datasetIds
   } else {
   }
   appModelConfigSave(params)
@@ -830,9 +826,8 @@ const initDetail = () => {
             state.config = JSON.parse(JSON.stringify(configData))
             state.form.tips = configData.prePrompt || ''
             if (state.detail.type === 0) {
-              if (configData.modelId) {
-                state.form.modelId = configData.modelId
-              }
+              state.form.modelId = configData.modelId || ''
+              state.form.datasetIds = configData.datasetIds || []
             } else {
             }
             setTimeout(() => {
@@ -883,14 +878,14 @@ const initDrag = () => {
 }
 const onAddKnowledge = () => {
   state.knowledgeSelect.transfer = {
-    ids: state.form.knowledges.map((v) => v.id),
+    ids: state.form.datasetIds,
     type: 'knowledge',
   }
   state.knowledgeSelect.show = true
 }
 const onAddAdviseKnowledge = () => {
   state.knowledgeSelect.transfer = {
-    ids: state.form.advise.knowledges.map((v) => v.id),
+    ids: state.form.advise.knowledges,
     type: 'advise',
   }
   state.knowledgeSelect.show = true
@@ -928,12 +923,12 @@ const getKnowledge = (arr) => {
   switch (state.knowledgeSelect.transfer.type) {
     case 'knowledge':
       {
-        state.form.knowledges.push(...arr)
+        state.form.datasetIds.push(...arr.map((v) => v.id))
       }
       break
     case 'advise':
       {
-        state.form.advise.knowledges.push(...arr)
+        state.form.advise.knowledges.push(...arr.map((v) => v.id))
       }
       break
   }
@@ -1059,6 +1054,7 @@ onMounted(() => {
 })
 const initDictionary = () => {
   DictionaryStore.initModels()
+  DictionaryStore.initKnowledges(AppStore.tenantInfo?.id)
 }
 </script>