In this workshop, you will learn how :
- Create a QnA Maker knowledge base
- Publish a QnA Maker knowledge base
- Integrate a knowledge base with Azure Bot Service
- Chat with the bot to verify the code is working
- Add Chit-chat personality at your knowledge base
- Azure Pass or subscription - Try it for Free
A bot is an autonomous program that interacts with people or computer systems in a predictable way. The logic behind a bot is designed and programmed by the bot creator, often with the help of tools like the Microsoft Bot Framework. Microsoft also has other AI services, included in Azure Cognitive Services, that can enhance the capabilities of your bots.
QnA Maker is one of the AI services that can help a bot answer your users' natural language questions by matching them with the best possible answers from your knowledge base.
QnA Maker is a cloud-based Natural Language Processing (NLP) service that easily creates a natural conversational layer over your data. It can be used to find the most appropriate answer for any given natural language input, from your custom knowledge base (KB) of information.
A client application for QnA Maker is any conversational application that communicates with a user in natural language to answer a question. Examples of client applications include social media apps, chat bots, and speech-enabled desktop applications.
-
Sign in to the QnA Maker portal.
-
Select Create a knowledge base from the top menu.
-
Select Create a QnA service. You will be redirect on Azure Portal.
-
Provide the required information:
Name: chatbot-qna-
Subscription: Select your existing subscription
Pricing tier: Select F0 (3 Calls per second)
Resource group: Clic on Create new and type the name qna-lab-rg
Resource group location: Select Canada Central
Search pricing tier: Select F (3 Indexes)
Search Location: Select Canada Central
App name: chatbot-qna-
Website Location: Select Canada Central
Application Insights Location: Select Canada Central
-
Click Create to deploy the service. This step might take a few moments.
-
Once the deployment is complete, return to QnA Maker portal and click Refresh on step 2.
-
Select your existing settings:
Setting Purpose Microsoft Azure Directory ID This ID is associated with the account you use to sign into the Azure portal and the QnA Maker portal. Azure Subscription name The billing account in which you created the QnA Maker resource. Azure QnA Service Your existing QnA Maker resource. -
Enter your knowledge base name,
AI Bootcamp kb
. -
Populate your knowledge base with the following settings:
Setting name Setting value Purpose URL https://docs.microsoft.com/azure/cognitive-services/qnamaker/faqs
The contents of the FAQ at that URL are formatted with a question followed by an answer. QnA Maker can interpret this format to extract questions and the associated answers. File not used in this tutorial This uploads files for questions and answers. Chit-chat personality None This gives a friendly and casual personality to common questions and answers. You can edit these questions and answers later. -
Select Create your KB to finish the creation process.
-
Review the questions and answers.
-
Select Test in the top menu bar.
-
Type how large on the text box.
-
Select Inspect. You can add alternative phrasing for this Answer or new answer for this question, if you think the answer is wrong.
- Select Save and train in the top menu bar.
Select the Publish button from the top menu. On the publish page, select Publish.
After the knowledge base is published, the endpoint is displayed.
Don't close this Publish page. You need it later in the tutorial, to create a bot.
- Select the Curl tab.
-
Copy the text of the Curl tab, and run it in a cURL-enabled terminal or command-line. The authorization header's value includes the text
Endpoint
, with a trailing space and then the key. -
Replace
<Your question>
withHow large can my KB be?
. This is close to the question,How large a knowledge base can I create?
, but not exactly the same. QnA Maker applies natural language processing to determine that the two questions are the same. -
Run the cURL command and receive the JSON response, including the score and answer.
% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 581 100 543 100 38 418 29 0:00:01 0:00:01 --:--:-- 447{ "answers": [ { "questions": [ "How large a knowledge base can I create?" ], "answer": "The size of the knowledge base depends on the SKU of Azure search you choose when creating the QnA Maker service. Read [here](https://docs.microsoft.com/azure/cognitive-services/qnamaker/tutorials/choosing-capacity-qnamaker-deployment)for more details.", "score": 35.92, "id": 2, "source": "https://docs.microsoft.com/azure/cognitive-services/qnamaker/faqs", "metadata": [] } ] }
QnA Maker is somewhat confident with the score of 35.92%.
Any question that QnA Maker is not confident about receives the default answer. This answer is configured in the Azure portal.
-
In the cURL-enabled terminal, replace
How large can my KB be?
withx
. -
Run the cURL command and receive the JSON response, including the score and answer.
% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 186 100 170 100 16 272 25 --:--:-- --:--:-- --:--:-- 297{ "answers": [ { "questions": [], "answer": "No good match found in KB.", "score": 0.0, "id": -1, "metadata": [] } ] }
QnA Maker returned a score of
0
, which means no confidence. It also returned the default answer.
##Create a QnA Bot with Azure Bot Service v4
Create a bot as a client application for the knowledge base.
-
In the QnA Maker portal, go to the Publish page, and publish your knowledge base. Select Create Bot.
The Azure portal opens with the bot creation configuration.
-
Enter the settings to create the bot:
Setting Value Purpose Bot name aibootcamp-qna-bot
This is the Azure resource name for the bot. Subscription See purpose. Select the same subscription as you used to create the QnA Maker resources. Resource group lab-rg-bot
The resource group used for all the bot-related Azure resources. Location Canada East
The bot's Azure resource location. Pricing tier F0
The free tier for the Azure bot service. App name aibootcamp-qna-bot-app
This is a web app to support your bot only. This should not be the same app name as your QnA Maker service is already using. Sharing QnA Maker's web app with any other resource is not supported. SDK Language C# This is the underlying programming language used by the bot framework SDK. Your choices are C# or Node.js. QnA Auth Key Do not change This value is filled in for you. App service plan/Location Do not change For this tutorial, the location is not important. Azure Storage Do not change Conversation data is stored in Azure Storage tables. Application Insights Do not change Logging is sent to Application Insights. Microsoft App ID Do not change Active directory user and password is required. Wait a couple of minutes until the bot creation process notification reports success.
-
In the Azure portal, open the new bot resource from the notification.
-
From Bot management, select Test in Web Chat and enter:
How large can my KB be?
. The bot will respond with:The size of the knowledge base depends on the SKU of Azure search you choose when creating the QnA Maker service. Read [here](https://docs.microsoft.com/azure/cognitive-services/qnamaker/tutorials/choosing-capacity-qnamaker-deployment)for more details.
For more information about Azure Bots, see Use QnA Maker to answer questions
Adding chit-chat to your bot makes it more conversational and engaging. The chit-chat feature in QnA maker allows you to easily add a pre-populated set of the top chit-chat, into your knowledge base (KB). This can be a starting point for your bot's personality, and it will save you the time and cost of writing them from scratch.
This dataset has about 100 scenarios of chit-chat in the voice of multiple personas, like Professional,Friendly and Witty.
Some examples of the different personalities are below. You can see all the personality datasets along with details of the personalities.
For the user query of When is your birthday?
, each personality has a styled response:
Personality | Example |
---|---|
Professional | Age doesn't really apply to me. |
Friendly | I don't really have an age. |
Witty | I'm age-free. |
Caring | I don't have an age. |
Enthusiastic | I'm a bot, so I don't have an age. |
-
Download the English friendly datasets on GitHub
-
Go to qnamaker.ai portal. Select your KB and select Settings from the top menu.
-
Scroll down to Manage knowledge base
-
On File name sub section, click on Add file and add qna_chitchat_friendly.tsv file.
-
Click Save and Train from top menu.
-
Click on Edit for review the questions and answers.
-
Select the last page of questions and answers from the bottom of the table. The page shows questions and answers from the Chit-chat personality.
-
From the toolbar above the list of questions and answers, select the View options icon, and then select Show metadata. This shows the metadata tags for each question and answer. The Chit-chat questions have the editorial: chit-chat metadata already set. This metadata is returned to the client application, along with the selected answer. The client application, such as a chat bot, can use this filtered metadata to determine additional processing or interactions with the user.
- Select the Publish button from the top menu. On the publish page, select Publish.
-
In the cURL-enabled terminal, replace
How large can my KB be?
with a bot conversation-ending statement from the user, such asThank you
. -
Run the cURL command and receive the JSON response, including the score and answer.
% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 525 100 501 100 24 525 25 --:--:-- --:--:-- --:--:-- 550{ "answers": [ { "questions": [ "Thank you", "Thanks", "Thnx", "Kthx", "I appreciate it", "Thank you so much", "I thank you", "My sincere thank" ], "answer": "You're very welcome.", "score": 100.0, "id": 109, "source": "qna_chitchat_the_friend.tsv", "metadata": [ { "name": "editorial", "value": "chitchat" } ] } ] }
Because the question of
Thank you
exactly matched a Chit-chat question, QnA Maker is completely confident with the score of 100. QnA Maker also returned all the related questions, as well as the metadata property containing the Chit-chat metadata tag information.
Go back in Test in Web Chat on Azure Portal and chat with your bot.
Finally, If you don't expect to need these resources in the future, you can delete them by deleting the resource group. To do so, select the resource group for this workshop, select Delete, then confirm the name of the resource group to delete.