Microsoft QnA bot Node.js

时间:2017-10-26 20:21:05

标签: javascript node.js bots

好的,所以我拒绝了我能找到的所有说明,但在我设置机器人之后,我只得到了

  

{" statusCode":404," message":"资源未找到" }

var demo=JSON.stringify({"question":"Hi"});

var extServerOptionsPost={
    host:'westus.api.cognitive.microsoft.com',
    path:'/knowledgebases/*my_id*/generateAnswer',
    method:'POST',
    headers:{
        'Ocp-Apim-Subscription-Key':'*my_sub*',
        'Content-Type':'application/json',
        'Content-Length':Buffer.byteLength(demo)
}
};

var reqPost=http.request(extServerOptionsPost,function(res){
    console.log("response statusCode: ",res.statusCode);
    res.on('data',function(data){
        console.log('Posting Result:\n');
        process.stdout.write(data);
        console.log('\n\n POST Operation Completed');
    });
});


reqPost.write(demo);


reqPost.end();
reqPost.on('error',function(e){
    console.error(e);
});

有什么想法吗?谢谢!

1 个答案:

答案 0 :(得分:1)

平,

您使用的是错误的主机。 您可以使用Host:https://westus.api.cognitive.microsoft.com/qnamaker/v1.0/knowledgebases/ / generateAnswer 或https://westus.api.cognitive.microsoft.com/qnamaker/v2.0/knowledgebases/ {knowledgeBaseID} / generateAnswer

另外,您可以在此处查看v2.0的完整文档: https://westus.dev.cognitive.microsoft.com/docs/services/58994a073d9e04097c7ba6fe/operations/58994a073d9e041ad42d9baa

BR