0
votes

In the QnA Maker Service provided by the Microsoft's Cognitive Services, we can train our KB (Knowledge Base) by manually inserting the QnA pairs.

Is there a way to automate this process so that we can always keep our KB up-to-date please? There is an API documentation but i cannot find one for this purpose

2

2 Answers

1
votes

The new V2.0 APIs let you programmatically manage your knowledge base. Now you can do the following with the APIs:

  • Create knowledge base
  • Delete knowledge base
  • Update knowledge base
  • Download knowledge base
  • Publish knowledge base
0
votes

I have created a bot that will automatically update the QnA Maker KB. Currently supports Add operation, where you add QnA pairs in the KB and publish it. I used QnA Maker client library using C#. You can find the documentation here.

On providing the qna pairs by the user, I am calling the Client library.

if ((bool)stepContext.Result)
        {
            await stepContext.Context.SendActivityAsync(MessageFactory.Text("Here are the details you provided."), cancellationToken);

            await stepContext.Context.SendActivityAsync(MessageFactory.Text("Questions - "), cancellationToken);

            for (int i = 0; i < QnAData.QuestionPhrase.Count; i++)
            {
                await stepContext.Context.SendActivityAsync(MessageFactory.Text(QnAData.QuestionPhrase[i]), cancellationToken);
            }


            await stepContext.Context.SendActivityAsync(MessageFactory.Text("Answer - " + (string)stepContext.Values["Answer"]), cancellationToken);

            await stepContext.Context.SendActivityAsync(MessageFactory.Text("Please wait while I update your Knowledge Base."), cancellationToken);

            var authoringURL = $"https://{Configuration["ResourceName"]}.cognitiveservices.azure.com";

            // <AuthorizationAuthor>
            var client = new QnAMakerClient(new ApiKeyServiceClientCredentials(Configuration["Key"]))
            { Endpoint = authoringURL };
            // </AuthorizationAuthor>

            QnAClient.UpdateKB(client, Configuration["KnowledgeBaseId"], (string)stepContext.Values["Answer"]).Wait();
            QnAClient.PublishKb(client, Configuration["KnowledgeBaseId"]).Wait();

            await stepContext.Context.SendActivityAsync(MessageFactory.Text("I have added your qna pair in the Knowledge Base. Thank you for using QnA Updator Bot Service."));

            return await stepContext.EndDialogAsync(null, cancellationToken);
        }
        else
        {
            await stepContext.Context.SendActivityAsync(MessageFactory.Text("Request Not Confirmed."));
            return await stepContext.EndDialogAsync(cancellationToken: cancellationToken);
        }

You can find the full article here : https://jd-bots.com/auto-updater-qna-maker-kb-bot/.

You can watch the video to check the outcome of the bot : https://youtu.be/nSGgph_RXiE.