Developing Intelligent Bot in Azure Bot Service

If you want to develop an Intelligent chatbot in Azure Bot Service, then this blog is for you. In this Azure AI Chatbot Tutorial, we will learn how to integrate Natural Language Processing Capabilities in the chatbot. Some good chatbot use cases can revolutionize the way we do business. If you are new to Azure AI concepts then you will learn complex concepts like intents, Utterance, Entities, and their use in Chatbot. In this blog, we will not only learn how to develop a chatbot but also how to make it more intelligent. We will explore how an intelligent chatbot can authenticate against Azure and execute the commands remotely.

What is a self-service intelligent Infrastructure Bot?

Whenever a customer needs to create infrastructure they usually reach out to the System engineer/IT Helpdesk for creating the infrastructure. The system engineer is busy with critical tasks like patching, monitoring, etc. Once the request comes he needs to go over the customer-specific standards (naming convention of the VM, Size, and location along with which resource group the VM will need to be created). System engineer works for multiple customers and each customer has its own standards sometimes these requests come from multiple customers. The customer expects to finish the VM creation request promptly. The system engineer does not have adequate time to focus on such types of requests.

At the same time if we give complete control to the customer it will not help much because he does not understand cloud jargon. He can only explain his requirements in plain English.

What makes a chatbot more intelligent?

For the chatbot to be super intelligent we need to keep in mind that it works in these two modes:

Two modes of Chatbot

  • Natural Language Mode: Understanding the natural language of the user and responding to the request.
  • Guided mode: The user is provided step-by-step instructions and menu options to go thru.

Use cases of Chatbot

There are some useful practical use cases of Chatbot:

  • Creating Azure landing zone.
  • Spinning up the infra without the help of the IT Helpdesk.
  • Responding to common queries.
  • Server management activities (i.e., patch management, provisioning infrastructure, etc). Raising Change, Problem, and Incidents tickets.

What is Natural Language Processing?

Natural Language Processing (NLP) requires a language model to interpret user input. This is the mechanism with which the application infers the intent of what the user wants from the plain English statement typed/spoken by the user. For example, If I utter Create VM, Deploy VM, or Provision VM it means I want to create a virtual Machine. So NLP tries to find out the intent of the utterance. While creating intents it needs to uniquely specify the entities (Create a VM or SQL DB so VM and SQL DB are different entities) where it can apply the intents and that is called Entities.

Language Understanding Resources in Azure

Language Understanding requires two kinds of Azure resources:

  • Authoring resource: Used to train a language model (language understanding app)
  • Prediction resource: Once the training is done you need to host a trained model and process requests from client apps so we need a Prediction resource for the hosting purpose.
    • Prediction resources can be Language Understanding or Cognitive Services resources.
    • It must be in the appropriate geographical region for the authoring resource used to train the model:

What are Intents and Utterances?

To train a language understanding model we need to utter some sentences and each sentence has some intention that a user has in his/her mind. So these intentions are also called intent. So we need two things for a meaningful conversation:

  • We need to specify utterances that represent expected natural language input.
  • Then map utterances to intents that assign semantic meaning.

What are Entities?

Entities are used to add specific context to intents Define entities to add specific context to intents

What are different Entity Types and how to use them?

List Entity: A list entity represents a fixed, closed set of related words along with their synonyms. For example, user id, login, and login id all represent username in a conversation.

Regex Entity: A regular expression entity extracts an entity based on a regular expression pattern you provide during the conversation. For example, Flight numbers and credit card numbers have some regex patterns which uniquely distinguish them from each other.

Prebuilt Entity: A set of prebuilt entities for recognizing common types of information, like dates, times, numbers, measurements, places, names, and currency.

Pattern.Any Entity:   This is a variable-length placeholder used only in a pattern’s template utterance to identify where the entity begins and ends. It follows a specific rule or pattern and is best used for sentences with fixed lexical structures. For example, Can I have a Pizza or can I have a burger have the same lexical structure and we can easily understand the entities burger or pizza? So it is easy to retrieve the entity from the utterance.

Machine Learned Entity: It uses context to extract entities based on labeled examples. It relies on machine-learning algorithms and requires labeling based on Application Logic. Use it only when data is not well formatted.

How does Bot Authenticate against Azure Environment?

For the Bot to execute the user commands in Azure we need to authenticate against it. Here is the step-by-step authentication process:

The authentication process for Azure:

  1. Create a service principal in Azure
  2. Grant contributor access to the Service principle on Azure Subscription. Here is the variable setup in the bot for service principle:

Fundamentally whether you are using Terraform or Azure Portal or Ansible all these tools call the REST API to get the work done so if you want your bot to execute the commands you can also use Azure Native APIs to execute the commands. Azure has well-documented Service Endpoints. And these endpoints can be used to execute any commands i.e. create VM, Create SQL DB, etc.

3. Call Rest API for generating the Bearer Access Token“. The Bearer Token” is the fundamental requirement for authentication and once you have the token you can use the token to call REST API and execute the specified commands in Azure.

4. Upon calling the REST API we need to know if the call was successful or failed and for this, we need to verify the return codes if the return code is 200 (depending upon the documentation) it means the call was successful otherwise it will generate the error code(apart from 200 and this is well documented (for example Virtual Machines – Create Or Update – REST API (Azure Compute)) in the Azure documentation).

This way you can execute all the commands via chatbot.

I hope this helps.

+ There are no comments

Add yours

Leave a Reply