我如何使用QnAMaker为同一查询提供随机答案 [英] How can i use QnAMaker to provide random answers to same query
问题描述
我一直在思考,因为机器人有一些通用的问题,例如,你好吗?可能我有大约10个答案,我希望问与答制造商不能每次都选择相同的答案就随机选择.
I was thinking as bots have some generic questions like how are you ? may be i have around 10 answers which i would like Q&A maker to choose randomly not every time same answer.
或者还有其他类似问题,例如,告诉我一个故事
or also questions like tell me a story
推荐答案
一些通用问题,例如您好吗?可能我有大约10个答案,我希望问与答制造商不能每次都选择相同的答案就随机选择.
some generic questions like how are you ? may be i have around 10 answers which i would like Q&A maker to choose randomly not every time same answer.
要达到此要求,您可以尝试以下方法:
To achieve this requirement, you can try this approach:
1)添加一个QnA对,并使用特殊字符(例如|
)来拆分问题how are you?
1) Add a QnA pair and use a special character (such as |
) to split answers for question how are you?
2)覆盖RespondFromQnAMakerResultAsync
方法,并在此方法中拆分响应并随机检索答案
2) Override the RespondFromQnAMakerResultAsync
method, and split response and retrieve answer randomly in this method
protected override async Task RespondFromQnAMakerResultAsync(IDialogContext context, IMessageActivity message, QnAMakerResults result)
{
// This will only be called if Answers isn't empty
var response = result.Answers.First().Answer;
var answersforhowareyou = response.Split('|');
if (answersforhowareyou.Count() > 1)
{
Random rnd = new Random();
int index = rnd.Next(answersforhowareyou.Count());
response = answersforhowareyou[index];
}
await context.PostAsync(response);
}
测试结果:
Test result:
这篇关于我如何使用QnAMaker为同一查询提供随机答案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!