如何在REST API查询上添加过滤器以查看QnAmaker的答案? [英] How to Add filter on the REST API Query to view the answers from QnAmaker?
问题描述
我在聊天机器人中使用以下代码(使用v4 azure MS bot框架)来查询问题和答案(客户端代码-使用纯JavaScript和J Query),
I'm using the following code in my chat bot (using v4 azure MS bot framework), to query the question and answers (Client side code - using plain JavaScript and 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);
}
});
}
在使用此代码时,我得到以下错误响应
while using this code, i"m getting the following error response
您要查找的资源已被删除,并具有其名称 更改,或暂时不可用.
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
因此,请使用正确的语法为我提供帮助,以对我的查询应用过滤器.
推荐答案
According to https://docs.microsoft.com/en-us/azure/cognitive-services/qnamaker/how-to/metadata-generateanswer-usage, you need to specify filters in the body (the data
property)
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);
}
});
}
此外,您还缺少2件事:
Moreover, you are missing 2 things:
- 您的主机名,以替换
YourEndPointURL
- 端点键,以替换
c44444_Your_Endpoint_Key_4556
- your hostname, to replace
YourEndPointURL
- endpoint key, to replace
c44444_Your_Endpoint_Key_4556
这篇关于如何在REST API查询上添加过滤器以查看QnAmaker的答案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!