How can i use QnAMaker to provide random answers to same query

好久不见. 提交于 2019-12-23 03:11:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!