gpt4 book ai didi

node.js - 使用请求模块从 Node.js 调用 Microsoft QnA 制造商 API

转载 作者:太空宇宙 更新时间:2023-11-04 02:04:05 27 4
gpt4 key购买 nike

下面是我使用 Node.js 中的请求模块调用 microsoft QnAmaker API 的代码。

var request=require('request');


var demo=[];
console.log("Doing the Post Operations...");
// Define an demo object with properties and values. This object will be used for POST request.

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


request({
uri:"https://westus.api.cognitive.microsoft.com/qnamaker/v2.0/knowledgebases/my_kb_id/generateAnswer",
method: "POST",
json: true,
headers:{
'Ocp-Apim-Subscription-Key':'my_key',
'Content-Type':'application/json'
},
body: demo


}, function (error, response, body){
console.log(response);
});

这给我返回了“Bad Argument”错误。我哪里出错了?

最佳答案

我编写了使用 Node.js 中的请求模块调用 Microsoft QnA Maker API 的代码。下面的代码工作正常。我没有使用 JSON.stringify 直接将演示作为 JSON 传递。

var request=require('request');

var demo={"question" : "hi",
"top": 4};

url='https://accountqna.azurewebsites.net/qnamaker/knowledgebases/my_kb_id/generateAnswer';
atuhorisationKey="EndpointKey <atuhorisationKey>"

request({
url: url,
method: "POST",
headers:{
'Authorization':atuhorisationKey,
'Content-Type': 'application/json'
},
json:demo
}, function (error, response, body) {
if (!error && response.statusCode === 200) {
console.log(body)
}
else {

console.log("error: " + error)
console.log("response.statusCode: " + response.statusCode)
console.log("response.statusText: " + response.json)
}
})

关于node.js - 使用请求模块从 Node.js 调用 Microsoft QnA 制造商 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44959488/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com