我在Bot框架中使用QnAMaker REST API来查询知识库。
它工作正常,但我想根据requestData
上指定的"来源"筛选"问题"。参考文件——https://learn.microsoft.com/en-us/azure/cognitive-services/qnamaker/how-to/metadata-generateanswer-usage我看不出有任何选择。文件指出,"来源"只是响应答案的一部分,而不是请求。
我尝试将"source"作为元数据传递给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."
}
}
有什么选择吗?如果我能提供更多细节,请告诉我。。
当传递的输入json与QnA API请求体不匹配时,会出现错误BadArgument, Parameter is null
。例如,如果API期望{"question":"this is my question"}
,而我们传递{"questionAB":"this is my question"}
,这将抛出错误。