我有一个直接机器人连接到QnaMaker,并在来自QnaMaker的示例Qna下面测试了有关如何响应用户的新提示功能
1)
q) How to get New York Printer details(QnAID: 13)
a) details are below NY73889-B0
2)
q) How to get Dallas printer details (QnAID: 14)
a) details are below DL093883-B1
3)
q) printer location
a) please chose from the 2 options below
Dallas(QnAID: 13) New York(QnAID: 14) (Prompts)
4)
q)Dallas
a) Dallas is a beautiful city
5)
q)New York
a) City of lights
问题:用户询问“打印机位置”问题,并通过纽约和达拉斯的提示得到响应。然后,当用户选择某个地点(例如达拉斯)时,理想情况下,该地点应回答
2) q)如何获取Dallas打印机详细信息(QnAID:14) a)<详细>详细信息低于DL093883-B1 ,因为我们已将提示连接到问题4,并且我们使用了旧状态,该状态已为达拉斯选择了QnaID选项。但是相反,它给出了以下答案,因为仅与用户响应的达拉斯提示文本匹配,而无需考虑旧状态,请提供任何帮助
4) q)达拉斯 a)达拉斯是一座美丽的城市
protected override async Task<(object newState, IEnumerable<Activity> output, object result)> ProcessAsync(object oldState, Activity inputActivity)
{
Activity outputActivity = null;
QnABotState newState = null;
var query = inputActivity.Text; ;
//Step 4) We Build the json based on the value selected user so we make a call to the Qna Maker using the response from the user on the button click and the previous state
//here we check if there was a prompt from the previous question and update the state to send to the bot for response based on the option selected
if (((QnAPrompting.Models.QnABotState)oldState) != null)
{
for (int i = 0; i < ((QnABotState)oldState).PreviousPromptValues.Length; i++)
{
if (((QnABotState)oldState).PreviousPromptValues[i].DisplayText == query)
{
((QnABotState)oldState).qnaId = ((QnABotState)oldState).PreviousPromptValues[i].QnaId;
((QnABotState)oldState).question = query;
}
}
} //Step5). when we get the response from the user after the choosing an option from the prompt, it queries the qnamaker and filters based on the old state as well
//Step1). we get the prompts based on the question asked for the first time the old state is empty
var qnaResult = await _qnaService.QueryQnAServiceAsync(query, (QnABotState)oldState);
var qnaAnswer = qnaResult[0].Answer;
var prompts = qnaResult[0].Context?.Prompts;
if (prompts == null || prompts.Length < 1)
{
if (((QnAPrompting.Models.QnABotState)oldState) != null)
{
if (((QnAPrompting.Models.QnABotState)oldState).IsPreviousPrompt)
{
string method = "/knowledgebases/{0}/{1}/qna/";
var method_with_id = String.Format(method, "KBID", "prod");
var uri = "https://westus.api.cognitive.microsoft.com" + "/qnamaker/v4.0" + method_with_id;
Console.WriteLine("Calling " + uri + ".");
var response = await Get(uri);
}
}
outputActivity = MessageFactory.Text(qnaAnswer);
}
else //Step 2.)prompt parameters are stored in the state
{
ContextValues ctx = new ContextValues();
ctx.PreviousQnaId = qnaResult[0].Id;
ctx.PreviousUserQuery = query;
//store here in azure table
newState = new QnABotState
{
question = string.Empty,
top=10,
userId = "Default",
context = ctx,
PreviousPromptValues = prompts,
};
outputActivity = CardHelper.GetHeroCard(qnaAnswer, prompts);
}
//Step 3) Prompt is displayed to the user
return (newState, new Activity[] { outputActivity }, null);
}
答案 0 :(得分:0)
我从源here重新下载了代码。仅对机器人设置进行了修改,我运行了代码,它按预期运行。正如Kyle指出的那样,问题是我修改了QueryQnAServiceAsync并导致了问题。现在它可以按预期工作了。