首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >创建知识库文档

创建知识库文档
EN

Stack Overflow用户
提问于 2019-02-06 19:13:06
回答 2查看 478关注 0票数 2

我试图使用nodejs存储库中的示例代码创建一篇EXTRACTIVE_QA类型的知识库文章。但是,当我尝试用特定的MIME类型创建它时,它失败了。EXTRACTIVE_QA支持什么MIME类型?

我尝试过文本/纯文本和text/html,但都没有成功。创建FAQ类型的文档不会遇到相同的问题,通过从对话框控制台上传HTML文件来创建文档也很好。

代码语言:javascript
复制
async function createDocument(projectId, knowledgeBaseFullName, documentPath) {
  const dialogflow = require('dialogflow').v2beta1;

  // Instantiate a DialogFlow Documents client.
  const client = new dialogflow.DocumentsClient({
    projectId: projectId,
  });

  const request = {
    parent: knowledgeBaseFullName,
    document: {
      knowledgeTypes: ['EXTRACTIVE_QA'],
      displayName: 'test',
      contentUri: documentPath,
      source: 'contentUri',
      mimeType: 'text/html',
    },
  };

  const [operation] = await client.createDocument(request);
  const [response] = await operation.promise();
  console.log(`Document created`);
}

当我使用指向HTML的路径和正确的知识库全名和项目ID调用该函数时,我会得到一个Error: 3 INVALID_ARGUMENT: Documents of type text/html are not supported for EXTRACTIVE_QA.错误。有没有办法解决这个问题,或者找出哪些MIME类型是受支持的?

也有些相关,但我似乎也不能使用rawContent源类型创建文档。将请求改为:

代码语言:javascript
复制
const request = {
  parent: knowledgeBaseFullName,
  document: {
    knowledgeTypes: ['EXTRACTIVE_QA'],
    displayName: 'test',
    rawContent: base64Content,
    source: 'rawContent',
    mimeType: 'text/html',
  },
};

给出一个Error: 3 INVALID_ARGUMENT: None of the source field is defined.错误。

任何帮助都将不胜感激!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-05-24 18:02:19

引用我对另一个答案的评论:

rawContent似乎是在npm (0.9.1)的最新版本中实现的。@emilianop11 11的答案对于0.6.0版本仍然是正确的,但是您必须使用原始内容(传递给createDocument函数的rawContent,而不是base64编码的内容( base64data变量)。

票数 0
EN

Stack Overflow用户

发布于 2019-03-17 17:07:42

我遇到了一个类似的问题。我需要阅读nodejs库代码才能弄清楚这一点。这里我们可以看到,rawContent还没有在库中实现,所以我们仍然需要使用content (根据文档,content将被废弃)。这应该能起作用:

代码语言:javascript
复制
async createDocument(
  knowledgeBaseFullName,
  rawContent,
  documentName
) {

  // Instantiate a DialogFlow Documents client.
  const client = new dialogflowV2.DocumentsClient({
    projectId: this.projectId,
  });

  let buff = new Buffer(rawContent);  
  let base64data = buff.toString('base64');

  const projectId = this.projectId;
  knowledgeBaseFullName = '';
  const knowledgeTypes = 'EXTRACTIVE_QA';
  const mimeType = 'text/plain';

  const request = {
    parent: knowledgeBaseFullName,
    document: {
      knowledgeTypes: [knowledgeTypes],
      displayName: documentName,
      content: base64data,
      source: 'rawContent',
      mimeType: mimeType,
    },
  };

  const [operation] = await client.createDocument(request);
  const [response] = await operation.promise();
  }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54560945

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档