Skip to content

Latest commit

 

History

History
121 lines (73 loc) · 10.3 KB

05-FaQBuilder.md

File metadata and controls

121 lines (73 loc) · 10.3 KB

Microsoft QnA Maker

In this section we will have some hands on experience with the QnA Maker.

The documentation explains QnA Maker with these words: "Microsoft QnA Maker is a free, easy-to-use, REST API and web-based service that trains AI to respond to user's questions in a more natural, conversational way. Compatible across development platforms, hosting services, and channels, QnA Maker is the only question and answer service with a graphical user interface—meaning you don’t need to be a developer to train, manage, and use it for a wide range of solutions."

Please find the Documentation to QnA Maker in the link below; https://qnamaker.ai/Documentation

Create a new QnA Service

Please move on to the website below to start creating a QnA Service.

https://qnamaker.ai

From the main page click the "Sign In" button on the right top of the page. You can use your Avanade credentials to sign in to the QnA Maker. After you login please click Create new service from the tab on the top of the page.

Create a QnA Service

In the page that opens enter a Service Name for your QnA Service and then click the Create button.

Tap Create Button

Improve the Knowledge Base of your QnA Service

After creating your new QnA Service you will be forwarded to the main page of your QnA Service. You should see a similar menu on the left of the screen as shown in the image below. You can also reach your QnA Service by clicking the My Services tab from the top of the screen and lastly by clicking the Edit Button next to your QnA Service Name.

QnA Sevice Main Menu

Make sure that Knowledge Base is selected from the side menu as shown above. Now we will add a new question and answer to improve our Knowledge Base. We simply do this by clicking the + Add new QnA pair button on the right top as shown in the image below. After clicking this button we will have a new empty line visible in our Knowledge Base. Enter your question under the Question header and enter your response under the Answer header. Once you are done with improving your QnA Service click the Save and retrain button on the top of the page which you can also find below.

Add Question and Answer

If you made a mistake don't worry because you always have the chance to delete your Question and Answer. You can do this my clicking the Delete QnA pair button that opens a drop-down when you click the three dots on the corner of the Question or Answer box. Please check the image below to see the drop-down.

If you are satisfied with your answer and you want your client to reach this answer by asking anohter question, you might aswell use the Add alternative phrasing button which is visible in the drop-down that opens when you click the three dots on the corner of the Question box. This will create a new line with the same Answer box but an empty Question box. Please check the image below to see the drop-down.

Don't forget to save your work after you do the necessary changes to Knowledge Base.

Delete Question/Answer or add an Alternative

Test your QnA Service

On the main screen of your QnA Service click the Test header on the right menu. From this screen you can test the questions and answers of your Knowledge Base. You can change the answer from the left side of the chat box. You can add an alternative question from the right side of the screen. Please find the this page in the image below.

Don't forget to save your work after you do the necessary changes to Knowledge Base.

Test your QnA Service

Publish your QnA Service

Once your done with adding data to the Knowledge Base and the testing of your Knowledge Base this means that you are ready to Publish your QnA Service. We do this by clicking the Publish button on the right top of the page.

Publish button for the QnA Service

After clicking the Publish button from the main page you will be forwarded to the page with the Review your changes header. On this screen you are able to see the newly added, deleted and current number of QnA's. Please check the image below to see this page. Once you are sure with the changes you can click the Publish button.

See changes before publishing the QnA Service

Congratulations! If you see a similar screen to the image below this means that you have your QnA Service up and running. There two important keys we have to note down on this page which will help us communicate with our VS project. The first key is the string between POST/knowledgebases/ and /generateAnswer. The second key is the Ocp-Apim-Subscription-Key

QnA Service Keys

Add Keys to Microsoft Azure Web App

You should have the two keys mentioned in the section above. The first key is the string between POST/knowledgebases/ and /generateAnswer. The second key is the Ocp-Apim-Subscription-Key.

We need to enter those keys to the Web.config - File in our Solution.

<appSettings>
  <!-- ... -->
  <add key="QnaAppId" value="Here goes the GUID from the first string" />
  <add key="QnaKey" value="Here goes the Ocp-Apim-Subscription-Key" />
  <add key="DefaultQnAResponse" value="Nothing found :(" />
</appSettings>

If you have different Models for Development, than you have for Production you're always able to override those Values for the Azure App Service through the Application Settings. But in this sample we will deliver our Keys while Deployment - *just be sure to not check-in those Keys in a public repository like Github. Elsewise other People are able to take those keys and create costs by using your services.

Understanding the VS code

This is the last part of the QnA Maker section. Now that we have everything ready it's time to add some codes to VS so that we can forward the user to our QnA Maker.

As you can remember from the LUIS section of this document, the communication between the LUIS and VS is don by using the LUIS Intents. This is very similar for the QnA Maker as well. If the Intent is not found in LUIS so if the intent is None then VS forwards us to the QnA Maker.

To give you the big picture, VS first checks if the dialog entered by the user is connected to any LUIS intent. If it is then we are forwarded to the specific LUIS intent. If nothing is found we are forwarded to the QnA Maker. Please find the piece of code below where we get forwarded to the QnA Maker dialog.

[LuisIntent("None")]
public async Task NoneIntent(IDialogContext context, IAwaitable<IMessageActivity> activity, LuisResult result)
{
    var item = await activity;
    await context.Forward(new QnaDialog(), Resume, item);
}

As you can see in the image below it is important to give reference to the Web.config file because that is where we stored our keys. You can also find a DefualtQnAResponse in the Web.config file. This is the response sent to the user if the QnA Maker cannot generate and answer. This means that if we cannot find the corresponding LUIS intent we are forwarded to the Qna Maker and if QnA Maker also cannot give a response the worst case scenario is the DefualtQnAResponse.

 [Serializable]
  public class QnaDialog : QnAMakerDialog
  {
      public QnaDialog() : base(new QnAMakerService(
          new QnAMakerAttribute(
              ConfigurationManager.AppSettings["QnaKey"],
              ConfigurationManager.AppSettings["QnaAppId"],
              ConfigurationManager.AppSettings["DefaultQnAResponse"], 0.3, 1)))
      {
      }
  }

Note that the QnaKey Setting comes first, followed by the AppId. If you mix them up, you will recognize some Exceptions. The Value 0.3 defines the Score Treshhold . If more than one confident QnA Pair is identified the last number declares how many QnA Pairs should be retrieved. Since we only want to output the most confident QnA Pair - we limit this to 1.