NodeJS 使用Langchain解析json文件问题

neekobn8  于 2023-06-22  发布在  Node.js
关注(0)|答案(1)|浏览(367)

我需要帮助
我在一个文件中有以下json内容,并希望使用langchain.js和gpt来解析,存储和回答以下问题
例如:
“find me jobs with 2 year experience”==>应该返回一个列表
“I have knowledge in JavaScript find me jobs”==>应该返回jobs对象
我使用langchain json loader,我看到文件被解析,但它说它找到13个文档。文件中只有3个文件。json结构不正确吗?
下面是我的解析代码片段

const loader = new DirectoryLoader(docPath, {
  ".json": (path) => new JSONLoader(path),
});

const docs = await loader.load();
console.log(docs);
console.log(docs.length);

这是我的输入数据

[
  {
    "jobid":"job1",
    "title":"software engineer"
    "skills":"java,javascript",
    "description":"this job requires a associate degrees in CS and 2 years experience"
  },
   {
    "jobid":"job2",
    "skills":"math, accounting, spreadsheet",
    "description":"this job requires a degrees in accounting and 2 years experience"
  },
   {
    "jobid":"job3",
    "title":"programmer"
    "skills":"java,javascript,cloud computing",
    "description":"this job requires a ,master degrees in CS and 3 years experience"
  }
  
]

OUTPUT
[
  Document {
    pageContent: 'job1',
    metadata: {
      source: 'langchain-document-loaders-in-node-js/documents/jobs.json',
      line: 1
    }
  },
  Document {
    pageContent: 'software engineer',
    metadata: {
      source: 'langchain-document-loaders-in-node-js/documents/jobs.json',
      line: 2
    }
  },
  Document {
    pageContent: 'java,javascript',
    metadata: {
      source: 'langchain-document-loaders-in-node-js/documents/jobs.json',
      line: 3
    }
  },
  Document {
    pageContent: 'this job requires a associate degrees in CS and 2 years experience',
    metadata: {
      source: 'langchain-document-loaders-in-node-js/documents/jobs.json',
      line: 4
    }
  },
  Document {
    pageContent: 'job2',
    metadata: {
      source: 'langchain-document-loaders-in-node-js/documents/jobs.json',
      line: 5
    }
  },

...

ewm0tg9j

ewm0tg9j1#

您的JSON包含一个由三个Javascript对象组成的JavaScript数组。其中两个有四处房产,一个有三处。所有属性都具有值的文本字符串。看起来你的解析器把每个属性都拉到它的一个文档中。
您需要找到一种方法来告诉解析器每个JavaScript对象都是它的一个文档。

相关问题