如何基于源过滤QnAMaker问题

时间:2018-11-05 09:30:38

标签: c# botframework azure-cognitive-services qnamaker

我正在Bot Framework中使用QnAMaker REST API来查询知识库。

它工作正常,但我想根据requestData上指定的“来源”来过滤“问题”。参考文档https://docs.microsoft.com/en-us/azure/cognitive-services/qnamaker/how-to/metadata-generateanswer-usage,我看不到任何选择。文档指出,“源”仅是响应答案的一部分,而不是请求。

我尝试将“源”作为元数据传递给strictFilters

Dictionary<string, object> requestData = new Dictionary<string, object>
{
    ["question"] = question,
    ["top"] = top,
    ["strictFilters"] = new Dictionary<string, object>
    {
        ["source"] = "test.tsv"
    }
};

string requestBody = JsonConvert.SerializeObject(requestData);
kbId = _configuration[qnaKbName];
method = "/knowledgebases/" + kbId + "/generateAnswer/";
var uri = host + method;
var response = await Post(uri, requestBody);
return response;

请求JSON格式-

{"question":"flexible working","top":5,"strictFilters":{"source":"test.tsv"}}

它不起作用,我得到以下答复-

{
  "error": {
    "code": "BadArgument",
    "message": "Parameter is null"
  }
}

试图像这样创建请求JSON-

{"question":"sabbatical","top":5,"strictFilters":[{"name":"source","value":"test.tsv"}]}

低于回应-

{
  "error": {
    "code": "Unspecified",
    "message": "Something happened. Please retry after some time."
  }
}

有什么选择吗?如果可以提供更多详细信息,请告诉我。.

1 个答案:

答案 0 :(得分:0)

当传递的输入json与QnA API请求正文不匹配时,将出现错误BadArgument, Parameter is null。例如,如果API期望{"question":"this is my question"},而我们传递{"questionAB":"this is my question"},则会抛出错误。