问题
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.
So please help me with the correct syntax to apply filter for my query.
回答1:
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);
}
});
}
Moreover, you are missing 2 things:
- your hostname, to replace
YourEndPointURL
- endpoint key, to replace
c44444_Your_Endpoint_Key_4556
来源:https://stackoverflow.com/questions/59875337/how-to-add-filter-on-the-rest-api-query-to-view-the-answers-from-qnamaker