Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
500 views
in Technique[技术] by (71.8m points)

javascript - How to Add filter on the REST API Query to view the answers from QnAmaker?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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:

  1. your hostname, to replace YourEndPointURL
  2. endpoint key, to replace c44444_Your_Endpoint_Key_4556

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...