-1

How to communicate Single ChatBot with different QnA data sets(JSON)..

Ex : QnA1 (JSON file) QnA2 (JSON file)

and Single Bot application.

when I launch the with site1, Bot will communicate to QnA1 data. when I launch the with site2, Bot will communicate to QnA2 data.

Here I have only one Bot.

please let me know how to pass KNOWLEDGE_BASE_ID to Bot.

Bhushan
  • 1
  • 1

1 Answers1

1

when I launch the with site1, Bot will communicate to QnA1 data. when I launch the with site2, Bot will communicate to QnA2 data.

The UI of BotFramework are based on Dialog, so I can only guess that your site 1 and site 2 means two dialogs and each dialog are built based on QnA.

please let me know how to pass KNOWLEDGE_BASE_ID to Bot.

Then to pass KNOWLEDGE_BASE_ID to your bot, you can use QnAMakerAttribute for your dialog. In .Net SDK for example:

[QnAMakerAttribute("Your-subscription-key", "Your-Qna-KnowledgeBase-ID", "No Answer in Knowledgebase.", 0.5)]
[Serializable]
public class QnADialog1 : QnAMakerDialog
{

}

And if you're using node.js SDK for development, you can pass the id like this:

var recognizer = new builder_cognitiveservices.QnAMakerRecognizer({
    knowledgeBaseId: 'Your-Qna-KnowledgeBase-ID', // process.env.QnAKnowledgebaseId, 
    subscriptionKey: 'Your-Qna-KnowledgeBase-Password'}); //process.env.QnASubscriptionKey});

For more information, you can refer to the Blog samples, there're both C# and node.js version of demos.

If you still want to ask how to use two knowledge-bases in one bot, please leave a comment and tell me which sdk are you using for development, .net or node.js? I will come back and update my answer.

UPDATE:

You can code for example like this:

[Serializable]
public class RootDialog : IDialog<object>
{
    private string currentKB;
    public Task StartAsync(IDialogContext context)
    {
        context.Wait(MessageReceivedAsync);

        return Task.CompletedTask;
    }

    private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
    {
        var activity = await result as Activity;

        if (activity.Text == "reset") //handle reset
            currentKB = null;
        else if (activity.Text == "qna1" || currentKB == "qna1")
        {
            currentKB = "qna1";
            if (activity.Text == "qna1")
                await context.PostAsync("this is qna 1");
            else
                await context.Forward(new Dialogs.QnADialog1(), this.QnAReceivedAsync, activity, CancellationToken.None);
        }
        else if (activity.Text == "qna2" || currentKB == "qna2")
        {
            currentKB = "qna2";
            if (activity.Text == "qna2")
                await context.PostAsync("this is qna 2");
            else
                await context.Forward(new Dialogs.QnADialog2(), this.QnAReceivedAsync, activity, CancellationToken.None);
        }
        else
        {
            var reply = activity.CreateReply("Please choose a knowledge base...");

            var heroCard = new HeroCard
            {
                Title = "Knowledge bases",
                Text = "Which one do you want to choose?",
                Buttons = new List<CardAction>
                    {
                        new CardAction(ActionTypes.ImBack, "QnA base 1", value:"qna1"),
                        new CardAction(ActionTypes.ImBack, "QnA base 2", value:"qna2")
                    }
            };
            Attachment attachment = heroCard.ToAttachment();
            reply.Attachments.Add(attachment);

            await context.PostAsync(reply);
            context.Wait(MessageReceivedAsync);

        }

    }

    public async Task QnAReceivedAsync(IDialogContext context, IAwaitable<object> result)
    {
        context.Wait(MessageReceivedAsync);
    }

}

And in the MessagesController make the RootDialog as the root of dialog stack:

if (activity.Type == ActivityTypes.Message)
{
    await Conversation.SendAsync(activity, () => new Dialogs.RootDialog());
}

Finally by QnADialog1 and QnADialog2, I only passed knowledge base ID and key there.

Grace Feng
  • 16,564
  • 2
  • 22
  • 45
  • So one bot dialog will communicate with only one QnA data ?? – Bhushan Feb 15 '18 at 07:51
  • @Bhushan, yes it can, so if your code has problem, maybe you can share your code. And if you find this answer helpful, could you please mark this answer? Thank you. – Grace Feng Feb 15 '18 at 07:52
  • Thanks for quick response. we have done single bot dialog with single QnA data. its working for me. can we do single dialog bot with multiple QnA data sets based on user request. Please help me on this. Thank you – Bhushan Feb 15 '18 at 09:13
  • @Bhushan, then could you please tell me which sdk are you using? C# or node.js? – Grace Feng Feb 16 '18 at 01:23
  • we are using C#. – Bhushan Feb 16 '18 at 08:34
  • @Bhushan, sorry for the late response, I've updated my answer to show a demo of using two qna, if you find this answer helpful, can you please mark this answer, thank you! – Grace Feng Feb 19 '18 at 05:21