<jupyter_start><jupyter_text>Conversational AIThink about how often you communicate with other people through instant messaging, social media, email, or other online technologies. For many of us, it's our go-to form of contact. When you have a question at work, you might reach out to a colleague using a chat message, which you can use on mobile devices, so you're always in touch.![A human and a robot having a conversation](./images/conversational_ai.jpg)Bots are AI agents that communicate using these kinds of channels, enabling a natural, conversational engagement with software services. Create a QnA Maker Knowledge BaseFor customer support scenarios, it's common to create a bot that can interpret and answer frequently asked questions through a website chat window, email, or voice interface. Underlying the bot interface is a knowledge base of questions and appropriate answers that the bot can search for suitable responses.The QnA Maker service is a cognitive service in Azure that enables you to quickly create a knowledge base, either by entering question and answer pairs or from an existing document or web page. It can then use some built-in natural language processing capabilities to interpret questions and find appropriate answers.1. Open another browser tab and go to the QnA Maker portal at https://qnamaker.ai. Sign in using the Microsoft account associated with your Azure subscription.2. In the QnA Maker portal, select **Create a knowledge base**.3. If you haven't previously created a QnA service resource, select **Create a QnA service**. The Azure portal will be opened in another tab so you can create a QnA Maker service in your subscription. Use the following settings:   - **Managed (preview)**: Not selected.    - **Subscription**: *Your Azure subscription*   - **Resource group**: *Select an existing resource group or create a new one*   - **Name**: *A unique name for your QnA resource*   - **Pricing tier**: F0   - **Azure Search pricing tier**: F   - **Azure Search location**: *Any available location*   - **App name**: _Same as **Name** (".azurewebsites.net" will be appended automatically)_   - **Website location**: _Same as **Azure Search location**_   - **App insights**: Disable> **Note**: If you have already provisioned a free-tier **QnA Maker** or **Azure Search** resources, your quota may not allow you to create another one. In which case, select a tier other than **F0** / **F**.4. Wait for the deployment of the QnA Service and related resources to complete in the Azure portal.5. Return to the QnA Maker portal tab, and in the **Step 2** section, click **Refresh** to refresh the list of available QnA service resources.6. Connect your QnA service to your KB by selecting the following options:  - **Microsoft Azure Directory ID**: *The Azure directory ID for your subscription*  - **Azure subscription name**: *Your Azure subscription*  - **Azure QnA service**: *The QnA service resource you created in the previous step*  - **Language**: English (!) Check InIf a message stating that the role does not have permission to perform the action is displayed, refresh the browser page for the QnA Maker portal.7. In the **Step 3** section, enter the name **Margie's Travel KB**.8. In the **Step 4** section, in the **URL** box, type *https://github.com/MicrosoftDocs/ai-fundamentals/raw/master/data/qna_bot/margies_faq.docx* and click **+ Add URL**. Then under **Chit-chat**, select **Professional**.9. In the **Step 5** section, click **Create your KB**.10. Wait for a minute or so while your Knowledge base is created. Then review the questions and answers that have been imported from the FAQ document and the professional chit-chat pre-defined responses. Edit the Knowledge BaseYour knowledge base is based on the details in the FAQ document and some pre-defined responses. You can add custom question-and-answer pairs to supplement these.1. Click **+ Add QnA pair**.2. In the **Question** box, type `Hello`. Then click **+ Add alternative phrasing** and type `Hi`.3. In the **Answer** box, type `Hello`. Train and Test the Knowledge BaseNow that you have a knowledge base, you can test it in the QnA Maker portal.1. At the top right of the page, click **Save and train** to train your knowledge base. You may need to maximize your window to see the button.2. After training has completed, click **&larr; Test** to open the test pane.3. In the test pane, at the bottom enter the message *Hi*. The response **Hello** should be returned.4. In the test pane, at the bottom enter the message *I want to book a flight*. An appropriate response from the FAQ should be returned.5. When you're done testing the knowledge base, click **&rarr; Test** to close the test pane. Create a Bot for the Knowledge BaseThe knowledge base provides a back-end service that client applications can use to answer questions through some sort of user interface. Commonly, these client applications are bots. To make the knowledge base available to a bot, you must publish it as a service that can be accessed over HTTP. You can then use the Azure Bot Service to create and host a bot that uses the knowledge base to answer user questions.1. At the top of the QnA Make page, click **Publish**. Then in the **Margies Travel KB** page, click **Publish**.2. After the service has been deployed, click **Create Bot**. This opens the Azure portal in a new browser tab so you can create a Web App Bot in your Azure subscription.3. In the Azure portal, create a Web App Bot with the following settings (most of these will be pre-populated for you):  - **Bot handle**: *A unique name for your bot*  - **Subscription**: *Your Azure subscription*  - **Resource group**: *The resource group containing your QnA Maker resource*  - **Location**: *The same location as your QnA Maker service*.  - **Pricing tier**: F0  - **App name**: *Same as the **Bot handle** with *.azurewebsites.net* appended automatically  - **SDK language**: *Choose either C or Node.js*  - **QnA Auth Key**: *This should automatically be set to the authentication key for your QnA knowledge base*  - **App service plan/location**: *This should be set automatically to a suitable plan and location*  - **Application Insights**: Off  - **Microsoft App ID and password**: Auto create App ID and password.4. Wait for your bot to be created (the notification icon at the top right, which looks like a bell, will be animated while you wait). Then in the notification that deployment has completed, click **Go to resource** (or alternatively, on the home page, click **Resource groups*, open the resource group where you created the web app bot, and click it.)5. In the blade for your bot, view the **Test in Web Chat** page, and wait until the bot displays the message **Hello and welcome!** (it may take a few seconds to initialize).6. Use the test chat interface to ensure your bot answers questions from your knowledge base as expected. For example, try submitting *I need to cancel my hotel*. Access the Bot through a ChannelA bot can be used to provide an interface for users through one or more *channels*. For example, the same bot could support interactions through a web chat interface, email, and Microsoft Teams.1. In the Azure portal, in the blade for your bot, view the **Channels** page.2. Note that the **Web Chat** channel has been aded automatically, and that other channels for common communication platforms are available.3. Next to the **Web Chat** channel, click **Edit**. This opens a page with the settings you need to embed your bot in a web page. To embed your bot, you need the HTML embed code provided as well as one of the secret keys generated for your bot.4. Copy the **Embed code** and paste it into the cell below, replacing the comment ``.5. Click **Show** for one of your secret keys (it doesn't matter which one), and copy it. Then paste it in your HTML embed code below, replacing `YOUR_SECRET_HERE`.6. Change the **min-height** value in your HTML code to **200px** (instead of the default 500px). This will help ensure the HTML interface is visible without scrolling.7. Run the cell below by clicking the **Run cell** (&9655;) button on the left of the cell to render the HTML.8. In the HTML chat interface, test the bot by submitting a question, such as *Who is Margie?* or *What destinations can I go to?* (when the bot initializes, it may respond with the message *Hello and welcome* in addition to answering your question.).<jupyter_code>%%html

<!-- EMBED CODE GOES HERE --><jupyter_output><empty_output>