如何在 REST API 查询上添加过滤器以查看来自 QnAmaker 的答案?

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

我在我的聊天机器人中使用以下代码(使用 v4 Azure MS 机器人框架)来查询问题和答案(客户端代码 - 使用普通 JavaScript 和 J 查询),

  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://docs.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);   
            }
        });
    }

此外,您还遗漏了两件事:

  1. 您的主机名,以替换 YourEndPointURL
  2. 端点键,替换c44444_Your_Endpoint_Key_4556