问题
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
回答1:
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) Add a QnA pair and use a special character (such as |
) to split answers for question how are you?
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:
来源:https://stackoverflow.com/questions/50971837/how-can-i-use-qnamaker-to-provide-random-answers-to-same-query