Mah*_*ddy 4 microsoft-cognitive botframework azure-qna-maker
我在想机器人有一些通用的问题,比如你好吗?可能我有大约 10 个答案,我希望问答制作者随机选择而不是每次都相同的答案。
或者还有像给我讲故事这样的问题
一些通用的问题,比如你好吗?可能我有大约 10 个答案,我希望问答制作者随机选择而不是每次都相同的答案。
要实现此要求,您可以尝试以下方法:
1) 添加 QnA 对并使用特殊字符(例如|)拆分问题的答案how are you?
2)覆盖该RespondFromQnAMakerResultAsync方法,并在该方法中随机拆分响应和检索答案
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);
}
Run Code Online (Sandbox Code Playgroud)
测试结果:
| 归档时间: |
|
| 查看次数: |
701 次 |
| 最近记录: |