我在聊天机器人中使用以下代码(使用 v4 azure MS 机器人框架)来查询问题和答案(客户端代码 - 使用纯 JavaScript 和 J Query),
function generateAnswer()
{
var question = {
question: "will you marry me"
}
$.ajax({
type: "POST",
url: "https://YourEndPointURL/qnamaker/knowledgebases/eb895acb-e034-4f7c-asda7c-1955458ecec6/generateAnswer&$filter=source eq 'Editorial'",
data: JSON.stringify(question),
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization','EndpointKey c44444_Your_Endpoint_Key_4556');
},
dataType: "json",
contentType: "application/json",
success: function (data) {
console.log(data);
console.log(data.answers[0].answer);
}
});
}
使用此代码时,我收到以下错误响应
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
因此,请帮助我使用正确的语法来为我的查询应用过滤器。
最佳答案
根据https://learn.microsoft.com/en-us/azure/cognitive-services/qnamaker/how-to/metadata-generateanswer-usage ,您需要在正文中指定过滤器(data
属性)
function generateAnswer()
{
var data = {
question: "will you marry me",
strictFilters: [
{
"name": "source",
"value": "Editorial"
}],
}
$.ajax({
type: "POST",
url: "https://YourEndPointURL/qnamaker/knowledgebases/eb895acb-e034-4f7c-asda7c-1955458ecec6/generateAnswer",
data: JSON.stringify(data),
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization','EndpointKey c44444_Your_Endpoint_Key_4556');
},
dataType: "json",
contentType: "application/json",
success: function (data) {
console.log(data);
console.log(data.answers[0].answer);
}
});
}
此外,您还缺少两件事:
- 您的主机名,替换
YourEndPointURL
- 端点 key ,用于替换
c44444_Your_Endpoint_Key_4556
关于javascript - 如何在 REST API 查询上添加过滤器以查看 QnAmaker 的答案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59875337/