Parcourir la source

fix: improve content extraction

jimmylee il y a 1 mois
Parent
commit
65d54d0d2a

+ 2 - 1
config/dev.env.js

@@ -4,5 +4,6 @@ const prodEnv = require('./prod.env')
 
 module.exports = merge(prodEnv, {
   NODE_ENV: '"development"',
-  VUE_APP_HTML2MD_API: '"http://localhost:7004"'
+  R2R_API_BASE_URL: '"http://localhost:7004"',
+  APP_CENTER_API_BASE_URL: '"http://localhost:8000"'
 })

+ 2 - 1
config/prod.env.js

@@ -1,5 +1,6 @@
 'use strict'
 module.exports = {
   NODE_ENV: '"production"',
-  VUE_APP_HTML2MD_API: '"https://r2rapi.cocorobo.cn"'
+  R2R_API_BASE_URL: '"https://r2rapi.cocorobo.cn"',
+  APP_CENTER_API_BASE_URL: '"https://appapi.cocorobo.cn"'
 }

+ 2 - 2
src/common/axios.config.js

@@ -35,11 +35,11 @@ axios.interceptors.request.use((config) => {
         config.headers = {
             'Content-Type': 'application/json',
         }
-    } else if (config.url.indexOf('https://gpt4.cocorobo.cn/') != -1 || config.url.indexOf('https://claude3.cocorobo.cn/') != -1 || config.url.indexOf('llm.cocorobo.cn/') != -1 || config.url.indexOf('https://appapi.cocorobo.cn/')!=-1) {
+    } else if (config.url.indexOf('http://localhost:8000') != -1 || config.url.indexOf('https://gpt4.cocorobo.cn/') != -1 || config.url.indexOf('https://claude3.cocorobo.cn/') != -1 || config.url.indexOf('llm.cocorobo.cn/') != -1 || config.url.indexOf('https://appapi.cocorobo.cn/')!=-1) {
         config.headers = {
             'Content-Type': 'application/json',
         }
-    } else if (config.data && config.data[0].post == '1' && config.method === 'post' ) {
+    } else if (Array.isArray(config.data) && config.data[0] && config.data[0].post == '1' && config.method === 'post' ) {
         config.data = 'mode=' + (Object.values(config.data[0]).join(','))//序列化post 参数
     } else if (config.method === 'post') {
 

+ 20 - 18
src/components/pages/knowledge/folderFileBox.vue

@@ -408,7 +408,6 @@
       :visible.sync="promptDialog"
       class="fileDialogBlock"
       :close-on-click-modal="false"
-      :before-close="handleClose" 
     >
       <span class="promptBox" v-loading="promptLoading">
         <!-- <el-input v-model="prompt" :placeholder="lang.promptPlaceholder" class="promptInput"></el-input> -->
@@ -1022,22 +1021,25 @@ export default {
       if (!dataFromForm) return;
       this.proVisible = true;
       let uuid = uuidv4();
-      let formData = new FormData();
       let string = [this.folderid, this.moFolderid].filter((id) => id);
-      formData.append("url", dataFromForm.url)
-      formData.append("collection_ids", JSON.stringify(string));
-      formData.append("id", uuid);
-      formData.append(
-        "metadata",
-        JSON.stringify({url: dataFromForm.url, collection_ids: string})
-      );
-      formData.append("ingestion_mode", "fast");
-      formData.append("run_with_orchestration", "false");
-      debugger
-      const html2mdApi = process.env.VUE_APP_HTML2MD_API || 'http://localhost:7004';
-      const url = html2mdApi + '/file/knowledge-base/html-to-markdown';
-      const headers = {'Content-Type': 'multipart/form-data'};
-      this.ajax.post(url, formData, {headers})
+
+      // 构建 JSON 请求体
+      const requestBody = {
+        url: dataFromForm.url,
+        collection_ids: string,
+        id: uuid,
+        metadata: {
+          url: dataFromForm.url,
+          collection_ids: string
+        },
+        ingestion_mode: "fast",
+        run_with_orchestration: false
+      };
+
+      console.log('环境变量 VUE_APP_HTML2MD_API:', process.env.APP_CENTER_API_BASE_URL);
+      const url = process.env.APP_CENTER_API_BASE_URL + '/api/webcrawler/knowledge-base/crawl-and-upload';
+      const headers = {'Content-Type': 'application/json'};
+      this.ajax.post(url, requestBody, {headers})
         .then(async (response) => {
           if (response && response.data && response.data.results) {
             this.$message.success('文件上传成功');
@@ -1410,9 +1412,9 @@ export default {
         this.getData();
       } catch (err) {
         this.promptLoading = false
-        
+
         console.error(err);
-      } 
+      }
     },
   },
   mounted() {