CzRger 2 settimane fa
parent
commit
8b844f0edf

+ 12 - 12
src/api/modules/global/upload.ts

@@ -1,12 +1,12 @@
-import { handle } from '../../index'
-
-const suffix = 'bm-api'
-
-// 查询字典项
-export const axUpload = (params, onProcess) =>
-  handle({
-    url: `http://8.130.72.63:18099/api/common/upload`,
-    method: 'upload',
-    params,
-    onProcess,
-  })
+// import { handle } from '../../index'
+//
+// const suffix = 'bm-api'
+//
+// // 查询字典项
+// export const axUpload = (params, onProcess) =>
+//   handle({
+//     url: `http://8.130.72.63:18099/api/common/upload`,
+//     method: 'upload',
+//     params,
+//     onProcess,
+//   })

+ 6 - 2
src/api/modules/knowledge/index.ts

@@ -1,4 +1,4 @@
-import { get, post } from '@/api/request'
+import { del, get, post, put } from '@/api/request'
 
 // 知识库分页
 export const datasetsGetAllByPage = (params) =>
@@ -8,8 +8,12 @@ export const datasetsTagsBinding = (params) =>
   post('/datasets/tags/binding', params, {})
 // 创建知识库
 export const datasetsCreate = (params) => post('/datasets/create', params, {})
+// 编辑知识库
+export const datasetsUpdate = (params) => put('/datasets/update', params, {})
+// 删除知识库
+export const datasetsDel = (id) => del(`/datasets/${id}`, {}, {})
 // 知识库详情
-export const datasetsDetail = (id) => get('/datasets/${id}', {}, {})
+export const datasetsDetail = (id) => get(`/datasets/${id}`, {}, {})
 // 知识库取消收藏
 export const datasetsCancelCollect = (datasetId) =>
   post(`/datasets/cancelCollect/${datasetId}`, {}, {})

+ 19 - 0
src/api/modules/model/index.ts

@@ -0,0 +1,19 @@
+import { del, get, post, put } from '@/api/request'
+
+// 知识库分页
+export const datasetsGetAllByPage = (params) =>
+  post('/datasets/getAllByPage', params, {})
+// 知识库绑定标签
+export const datasetsTagsBinding = (params) =>
+  post('/datasets/tags/binding', params, {})
+// 创建知识库
+export const datasetsCreate = (params) => post('/datasets/create', params, {})
+// 编辑知识库
+export const datasetsUpdate = (params) => put('/datasets/update', params, {})
+// 删除知识库
+export const datasetsDel = (id) => del(`/datasets/${id}`, {}, {})
+// 知识库详情
+export const datasetsDetail = (id) => get(`/datasets/${id}`, {}, {})
+// 知识库取消收藏
+export const datasetsCancelCollect = (datasetId) =>
+  post(`/datasets/cancelCollect/${datasetId}`, {}, {})

+ 2 - 3
src/stores/modules/app.ts

@@ -4,9 +4,7 @@ import { userInfo } from '@/api/modules/global/login'
 export const useAppStore = defineStore('app', {
   state: () => ({
     userInfo: null,
-    tenantInfo: {
-      id: 0,
-    },
+    tenantInfo: null,
   }),
   getters: {},
   actions: {
@@ -15,6 +13,7 @@ export const useAppStore = defineStore('app', {
         userInfo()
           .then(({ data }: any) => {
             this.userInfo = data
+            this.tenantInfo = data?.tenant
             resolve(this.userInfo)
           })
           .catch((e) => {

+ 5 - 2
src/stores/modules/dictionary.ts

@@ -99,7 +99,10 @@ export const useDictionaryStore = defineStore('dictionary', {
         setTimeout(() => {
           const arr: any = []
           for (let i = 0; i < 10; i++) {
-            arr.push({ label: 'bga-reanskada-v2-sad-m3' + ':' + i, value: i })
+            arr.push({
+              label: 'bga-reanskada-v2-sad-m3' + ':' + i,
+              value: String(i),
+            })
           }
           this.rerankModels.list = arr
           this.rerankModels.map = listToMap({ list: arr })
@@ -116,7 +119,7 @@ export const useDictionaryStore = defineStore('dictionary', {
           for (let i = 0; i < 10; i++) {
             arr.push({
               label: 'snowflake-arctic-embed2:568m' + ':' + i,
-              value: i,
+              value: String(i),
             })
           }
           this.embeddingModels.list = arr

+ 65 - 31
src/views/manage/knowledge/detail.vue

@@ -81,13 +81,18 @@ import {
   watch,
 } from 'vue'
 import { ElMessage, ElMessageBox } from 'element-plus'
-import { useDialogStore, useDictionaryStore } from '@/stores'
+import { useAppStore, useDialogStore, useDictionaryStore } from '@/stores'
 import { useRouter } from 'vue-router'
 import modelConfig from './model-config.vue'
-import { datasetsCreate, datasetsDetail } from '@/api/modules/knowledge'
+import {
+  datasetsCreate,
+  datasetsDetail,
+  datasetsUpdate,
+} from '@/api/modules/knowledge'
 import { debounce } from 'lodash'
 
 const router = useRouter()
+const AppStore = useAppStore()
 const DictionaryStore = useDictionaryStore()
 const DialogStore = useDialogStore()
 const emit = defineEmits(['update:show', 'refresh'])
@@ -136,7 +141,18 @@ watch(
 )
 const initDictionary = () => {}
 const initData = () => {
-  datasetsDetail(props.transfer.id).then((data) => {})
+  state.loading = true
+  datasetsDetail(props.transfer.id)
+    .then(({ data }: any) => {
+      state.form = data
+      ref_modelConfig.value.init(data)
+    })
+    .catch(({ message }: any) => {
+      ElMessage.error(message)
+    })
+    .finally(() => {
+      state.loading = false
+    })
 }
 const onSubmit = (isImport) => {
   ref_form.value
@@ -146,36 +162,54 @@ const onSubmit = (isImport) => {
         content: `请确认是否${titleCpt.value}?${isImport ? '创建成功后将自动跳转至文档上传页面!' : ''}`,
         onSubmit: () => {
           state.loading = true
-          datasetsCreate({
-            ...state.form,
-            ...ref_modelConfig.value.getData(),
-            contentConfig: {
-              maxParentSize: 500,
-              overlapSize: 20,
-              parentSeparator: '\n\n',
-              splitType: 'CustomSymbolSplitter',
-            },
-          })
-            .then(({ data }: any) => {
-              // ElMessage.success(`${titleCpt.value}成功!`)
-              // if (isImport) {
-              //   router.push({
-              //     name: '18e6009c-a72c-4359-864b-e7725fccca69',
-              //     params: {
-              //       id: '知识库ID',
-              //     },
-              //   })
-              // } else {
-              //   emit('update:show', false)
-              //   emit('refresh')
-              // }
-            })
-            .catch(({ message }: any) => {
-              ElMessage.error(message)
+          if (props.transfer.mode === 'add') {
+            datasetsCreate({
+              ...state.form,
+              ...ref_modelConfig.value.getData(),
+              tenantId: AppStore.tenantInfo?.id,
+              contentConfig: {
+                maxParentSize: 500,
+                overlapSize: 20,
+                parentSeparator: '\n\n',
+                splitType: 'CustomSymbolSplitter',
+              },
             })
-            .finally(() => {
-              state.loading = false
+              .then(({ data }: any) => {
+                ElMessage.success(`${titleCpt.value}成功!`)
+                if (isImport) {
+                  router.push({
+                    name: '18e6009c-a72c-4359-864b-e7725fccca69',
+                    params: {
+                      id: data.id,
+                    },
+                  })
+                } else {
+                  emit('update:show', false)
+                  emit('refresh')
+                }
+              })
+              .catch(({ message }: any) => {
+                ElMessage.error(message)
+              })
+              .finally(() => {
+                state.loading = false
+              })
+          } else {
+            datasetsUpdate({
+              ...state.form,
+              ...ref_modelConfig.value.getData(),
+              tenantId: AppStore.tenantInfo?.id,
             })
+              .then(({ data }: any) => {
+                ElMessage.success(`${titleCpt.value}成功!`)
+              })
+              .catch(({ message }: any) => {
+                ElMessage.error(message)
+              })
+              .finally(() => {
+                state.loading = false
+              })
+          }
         },
       })
     })

+ 11 - 2
src/views/manage/knowledge/index.vue

@@ -192,6 +192,7 @@ import tagsSelect from './tags-select.vue'
 import detailCom from './detail.vue'
 import {
   datasetsCancelCollect,
+  datasetsDel,
   datasetsGetAllByPage,
   datasetsTagsBinding,
 } from '@/api/modules/knowledge'
@@ -318,8 +319,16 @@ const onDel = (row: any) => {
     title: '删除确认',
     content: `${row.p6}个应用正在使用该大模型,请确认是否删除`,
     onSubmit: () => {
-      ElMessage.success('删除成功!')
-      onSearch()
+      datasetsDel(row.id)
+        .then(() => {
+          ElMessage.success('删除成功!')
+        })
+        .catch(({ message }: any) => {
+          ElMessage.error(message)
+        })
+        .finally(() => {
+          onSearch()
+        })
     },
   })
 }

+ 36 - 17
src/views/manage/knowledge/model-config.vue

@@ -611,7 +611,9 @@ const getData = () => {
     embeddingModel: DictionaryStore.embeddingModels.map.get(
       state.embedding.value,
     ),
-    indexConfig: {},
+    indexConfig: {
+      type: state.searchMethod.value,
+    },
   }
   switch (state.searchMethod.value) {
     case SearchMethodType.Vector:
@@ -666,29 +668,42 @@ const init = ({ indexingTechnique, embeddingModelId, indexConfig }) => {
   reset()
   state.indexMethod.value = indexingTechnique
   state.embedding.value = embeddingModelId
-  switch (indexConfig.type) {
+  state.searchMethod.value = indexConfig.type
+  switch (state.searchMethod.value) {
     case SearchMethodType.Vector:
       {
-        state.searchMethod[SearchMethodType.Vector].isRerank =
-          indexConfig.isRerank
+        state.searchMethod[SearchMethodType.Vector].isRerank = Number(
+          indexConfig.isRerank,
+        )
         state.searchMethod[SearchMethodType.Vector].rerank =
           indexConfig.rerankType
-        state.searchMethod[SearchMethodType.Vector].topK = indexConfig.topK
-        state.searchMethod[SearchMethodType.Vector].isScore =
-          indexConfig.isScore
-        state.searchMethod[SearchMethodType.Vector].score = indexConfig.score
+        state.searchMethod[SearchMethodType.Vector].topK = Number(
+          indexConfig.topK,
+        )
+        state.searchMethod[SearchMethodType.Vector].isScore = Number(
+          indexConfig.isScore,
+        )
+        state.searchMethod[SearchMethodType.Vector].score = Number(
+          indexConfig.score,
+        )
       }
       break
     case SearchMethodType.Global:
       {
-        state.searchMethod[SearchMethodType.Global].isRerank =
-          indexConfig.isRerank
+        state.searchMethod[SearchMethodType.Global].isRerank = Number(
+          indexConfig.isRerank,
+        )
         state.searchMethod[SearchMethodType.Global].rerank =
           indexConfig.rerankType
-        state.searchMethod[SearchMethodType.Global].topK = indexConfig.topK
-        state.searchMethod[SearchMethodType.Global].isScore =
-          indexConfig.isScore
-        state.searchMethod[SearchMethodType.Global].score = indexConfig.score
+        state.searchMethod[SearchMethodType.Global].topK = Number(
+          indexConfig.topK,
+        )
+        state.searchMethod[SearchMethodType.Global].isScore = Number(
+          indexConfig.isScore,
+        )
+        state.searchMethod[SearchMethodType.Global].score = Number(
+          indexConfig.score,
+        )
       }
       break
     case SearchMethodType.Mix:
@@ -699,9 +714,13 @@ const init = ({ indexingTechnique, embeddingModelId, indexConfig }) => {
           indexConfig.semantics,
         )
         state.searchMethod[SearchMethodType.Mix].rerank = indexConfig.rerankType
-        state.searchMethod[SearchMethodType.Mix].topK = indexConfig.topK
-        state.searchMethod[SearchMethodType.Mix].isScore = indexConfig.isScore
-        state.searchMethod[SearchMethodType.Mix].score = indexConfig.score
+        state.searchMethod[SearchMethodType.Mix].topK = Number(indexConfig.topK)
+        state.searchMethod[SearchMethodType.Mix].isScore = Number(
+          indexConfig.isScore,
+        )
+        state.searchMethod[SearchMethodType.Mix].score = Number(
+          indexConfig.score,
+        )
       }
       break
   }

+ 10 - 10
src/views/manage/knowledge/upload/index.vue

@@ -394,7 +394,7 @@ import {
 } from 'vue'
 import { useRoute, useRouter } from 'vue-router'
 import { ElMessage } from 'element-plus'
-import { axUpload } from '@/api/modules/global/upload'
+// import { axUpload } from '@/api/modules/global/upload'
 import { v4 } from 'uuid'
 import { useDialogStore } from '@/stores'
 import { comTime } from '@/utils/czr-util'
@@ -540,15 +540,15 @@ const handleHttpRequest = (options) => {
   const id = options.file.uid
   const formData = new FormData()
   formData.append('file', options.file)
-  axUpload(formData, (process) => {
-    if (state.uploadFiles.get(id)) {
-      state.uploadFiles.get(id).process = process
-    }
-  }).then((res) => {
-    if (state.uploadFiles.get(id)) {
-      state.uploadFiles.get(id).success = true
-    }
-  })
+  // axUpload(formData, (process) => {
+  //   if (state.uploadFiles.get(id)) {
+  //     state.uploadFiles.get(id).process = process
+  //   }
+  // }).then((res) => {
+  //   if (state.uploadFiles.get(id)) {
+  //     state.uploadFiles.get(id).success = true
+  //   }
+  // })
 }
 const onNextOne = () => {
   state.uploadFileList = Array.from(state.uploadFiles.values()).filter(