lsc 3 months ago
parent
commit
7f46b828ad
1 changed files with 79 additions and 0 deletions
  1. 79 0
      pbl.js

+ 79 - 0
pbl.js

@@ -485,6 +485,85 @@ router.route("/getChunks").all(async (req, res, next) => {
     }
     }
 });
 });
 
 
+//获取实体
+router.route("/getEntities").all(async (req, res, next) => {
+    if (req.body[0]) {
+        try {
+            const { page = 1, limit = 10, documentId } = req.body[0];
+            const offset = (page - 1) * limit;
+            const response = await client.documents.listEntities({
+                id: documentId,
+                includeVectors: false,
+                offset,
+                limit,
+            });
+            res.status(200).json({ result: response });
+           
+        } catch (error) {
+            res.status(500).json({ error: error instanceof Error ? error.message : "An error occurred" });
+        }
+
+    }
+});
+
+
+//获取关系
+router.route("/getRelationships").all(async (req, res, next) => {
+    if (req.body[0]) {
+        try {
+            const { page = 1, limit = 10, documentId } = req.body[0];
+            const offset = (page - 1) * limit;
+            const response = await client.documents.listRelationships({
+                id: documentId,
+                includeVectors: false,
+                offset,
+                limit,
+            });
+            res.status(200).json({ result: response });
+           
+        } 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]) {
+        try {
+            const { documentId } = req.body[0];
+            const offset = (page - 1) * limit;
+            const response = await client.documents.listEntities({
+                id: documentId,
+                includeVectors: false,
+            });
+            const response2 = await client.documents.listRelationships({
+                id: documentId,
+                includeVectors: false,
+            });
+            res.status(200).json({ Entities: response,Relationships: response2 });
+           
+        } catch (error) {
+            res.status(500).json({ error: error instanceof Error ? error.message : "An error occurred" });
+        }
+
+    }
+});
+
+
+//提取功能
+router.route("/extractFile2").all(async (req, res, next) => {
+    try {
+        const response = await client.documents.extract({ id: req.body[0].documentid });
+        console.log(response);
+        
+        res.status(200).json({ result: response.results });
+    } catch (error) {
+        res.status(500).json({ error: error instanceof Error ? error.message : "An error occurred" });
+    }
+});
+
 
 
 function generateAPIKey(username) {
 function generateAPIKey(username) {
     let timeStamp = new Date().getTime();
     let timeStamp = new Date().getTime();