lsc 3 giorni fa
parent
commit
3e0784a8f6
1 ha cambiato i file con 34 aggiunte e 0 eliminazioni
  1. 34 0
      pbl.js

+ 34 - 0
pbl.js

@@ -942,6 +942,40 @@ router.route("/getGraphs").all(async (req, res, next) => {
     }
 });
 
+
+//提取知识图谱
+router.route("/getGraphs2").all(async (req, res, next) => {
+    console.log(req.body);
+    
+    //mode的处理
+    if (req.body[0]) {
+        try {
+
+            let documentIds = decodeURIComponent(req.body[0].fileids).split(",");
+
+            // 使用 Promise.all 并通过 map 返回新的 results 数组
+            let results = await Promise.all(documentIds.map(async documentId => {
+                const response = await client.documents.listRelationships({
+                    id: documentId,
+                    includeVectors: false,
+                    limit: 1000,  // 修正这里的参数
+                });
+                return response.results;
+            }));
+            
+            // 使用 flat() 合并所有数组
+            results = results.flat();
+            
+            res.status(200).json({ result: results });
+
+        } catch (error) {
+            res.status(500).json({ error: error instanceof Error ? error.message : "An error occurred" });
+        }
+
+    }
+});
+
+
 //获取实体和关系
 router.route("/getEntitiesAndRelationships").all(async (req, res, next) => {
     if (req.body[0]) {