Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 347
Mahender Reddy Malreddy Avatar asked Jun 21 '18 15:06

Mahender Reddy Malreddy


People also ask

Which service is used when building and no code question and answers bot for microsoft Teams?

QnA Maker provides a conversational question and answer layer over your data. This allows your bot to send a question to the QnA Maker and receive an answer without needing to parse and interpret the question intent.

How does QnA maker work?

QnA Maker uses the trained knowledge base to provide the correct answer and any follow-up prompts that can be used to refine the search for the best answer. QnA Maker returns a JSON-formatted response. The client application uses the JSON response to make decisions about how to continue the conversation.

Which among the following kinds of documents can be used by QnA maker?

QnAs in the form of structured . txt, . tsv or . xls files can also be uploaded to QnA Maker to create or augment a knowledge base.


1 Answers

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?

enter image description here

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:

enter image description here

like image 151
Fei Han Avatar answered Oct 19 '22 19:10

Fei Han