QnA is a bot that helps you get answers based on FAQs. The bot uses Azure Cognitive knowledge base QnAMaker service. You can ask Azure Support questions and either get the answers to the question, or get proposed answer/question if the asked question doesn't have answers from the knowledge base.
To add the QnA demo bot to your Skype account, click here.
Microsoft QnA Maker is a free, easy-to-use, REST API and web-based service that trains AI to response to a user's questions in a more natural, conversational way (read more).
- Create a knowledge base
Click here to login into QnA Maker service website. Click "Create new service" to open the page for creating knowledge base. Fill in "service name" and "faq urls", then click "Create". (More details can be found here.)
- Publish the knowledge base
Click "publish" button to publish your knowledge base. (More details can be found here.)
- Get knowledge base ID and Ocp-Apim-Subscription-Key From "My services" -> "View code", you can find the knowledge base ID and Ocp-Apim-Subscription-Key. These info are needed when access your knowledge base.
-
The bot I will demonstrate is built in C#. The bot is fairly simple, but if you're new to Microsoft bot builder, several of the concepts might be foreign. For a quick ramp up check out aka.ms/botcourse, specifically the sections about setting up a C# project, using cards and using dialogs.
-
Generate answers for question: Build a POST request based on QnA Maker service generate-answer API.
See QnAService/Client.cs
client.BaseAddress = new Uri(baseUrl);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); //ACCEPT header
client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", subscriptionKey);
...
var requestUri = $"knowledgebases/{knowledgebaseId}/generateAnswer";
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, requestUri);
var body = $"{{\"question\": \"{question}\", \"top\": \"{top}\"}}";
If request succeed and answers are found in the knowledge base, then return results will be JSON of: answer, score of match. You can specify how many answers to get back in request body.
If request succeed, but no answers found in the knowledge base, it could be:
- Just there is no answer for that question
- The question doesn't really have a match in knowledge base
-
Propose question and answer If no answers found to the question, we propose 3 most frequently ask questions, together with the answers in a carousel list:
Build a GET http request based on QnA Maker service download API.
Set up the environment for your bot as described here. Install Visual Studio 2017 for Windows and update all extensions. Download the Bot Application, Bot Controller, and Bot Dialog templates and install it as instructed.
- In Web.config file, replace values from your QnA service you created above.
<add key="QnABaseUrl" value="$value$"/>
<add key="QnAKnowledgeBaseId" value="$value$"/>
<add key="QnASubscriptionKey" value="$value$"/>
Register the sample bot following this link, and make a note of the Microsoft App ID and Password to update the configurations of your bot.
- In Web.config file, replace
$MicrosoftAppId$ and$MicrosoftAppPassword$ with values obtained during the bot registration from the previous step. Also, replace$BotId$ with what you want your bot Id to be. Conventionally, Bot Id is set to "28:$MicrosoftAppId$".
<appSettings>
<!-- update these with your BotId, Microsoft App Id and your Microsoft App Password-->
<add key="BotId" value="$BotId$" />
<add key="MicrosoftAppId" value="$MicrosoftAppId$" />
<add key="MicrosoftAppPassword" value="$MicrosoftAppPassword$" />
</appSettings>
Follow the instructions here to deploy the bot to Azure.
To get more information about the Microsoft Bot Framework and the Microsoft QnA Maker, please review the following resources: