我正在尝试使用来自nodejs-dialogflow存储库的示例代码创建EXTRACTIVE_QA
类型的知识库文章。但是,当我尝试使用特定的MIME类型创建它时,它将失败。 EXTRACTIVE_QA
支持哪些MIME类型?
我尝试过text / plain和text / html都没有运气。创建FAQ类型的文档不会遇到相同的问题,并且通过从Dialogflow控制台上载HTML文件来创建文档可以正常工作。
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
源类型创建文档。将请求更改为:
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.
错误。
任何帮助将不胜感激!
答案 0 :(得分:0)
我遇到了一个非常相似的问题。
我需要通读nodejs库代码来解决这个问题。
Here我们可以看到rawContent
尚未在库中实现,因此我们仍然需要使用content
(根据文档将不推荐使用)。这应该可以解决问题:
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();
}
答案 1 :(得分:0)
引用我对其他答案的评论:
rawContent
似乎是在最新版本的npm软件包(0.9.1
)中实现的。 @ emilianop11的答案对于版本0.6.0
仍然是正确的,但是您必须使用原始内容(传递给rawContent
函数的createDocument
,而不是base64编码的内容({{1 }}变量。