Develop a Virtual Assistant with IBM Watson and .NET Core on IBM Cloud Code Engine-Part 2
In the previous article (Part 1) we developed and published a basic website with .NET Core, Docker and IBM Cloud Code Engine. In this article I will explain how to build a basic virtual assistant with IBM Watson, integrate it with the website, publish the new image and deploy the new version to IBM Cloud Code Engine. At the end you will have a functional virtual assistant publicly available on the Internet almost with NO code.
The Virtual Assistant
Our virtual assistant will be able to assist a New Bank customer with the following:
- Report a lost or stolen card
- Provide the products and services the Bank offers
- Explain financial and banking terms
- Provide the account balance for a specific bank account
In this article we will solve the first two topics, in Part 3 we will incorporate search capabilities to explain financial and banking terms with Watson Discovery and in Part 4 we will implement a serverless function with .NET Core and deploy it to IBM Functions service.
In order to build the assistant and integrate it with the website we will execute the following steps:
- Provision an instance of Watson Assistant on IBM Cloud
- Build the virtual assistant with Dialog an Intents
- Integrate the Watson Assistant widget with the website
- Generate the new docker image and deploy it to IBM Cloud Code Engine
Provision a Watson Assistant service instance on IBM Cloud
Login to IBM Cloud and select Watson Assistant from the Catalog
Select the Plus Trial plan and click on Create to provision your instance
By now you should have an instance of Watson Assistant Plus Trial
Click on Launch Watson Assistant to open the service console.
The first screen is the Assistants screen where you will have all your assistants. Click on Create assistant to create your assistant for New Bank.
On the create assistant dialog enter the name for your assistant and click on Create assistant.
Build the virtual assistant with a Dialog skill and Intents
Watson Assistant has the concept of Skills for developing a virtual assistant. The most common used skill is the Dialog skill which allows to define a conversational workflow. The Search skills provides integration with Watson Discovery for search capabilities using Natural Language Processing (we will use a Search skill with Watson Discovery in Part 3). A new type of skill is the Actions skill (still in Beta) which provides a new approach for building virtual assistants with Watson.
For our scenario we will start with a basic assistant using the Dialog skill.
Click on Add dialog skill.
In the next screen enter the name of your dialog skill, in my case the name is newbankdialogskill. Here you can select the Language that you would like to use for your assistant. I will use English but you could use the language of your preference. Click on Create dialog skill
At this point we have our Virtual Assistant with a Dialog skill created and we are ready for its implementation.
Click on newbankdialogskill
The dialog skill interface is open, and we are ready to work with the different concepts. The most important concepts in Watson Assistant are:
- Dialog — Controls the conversation flow with the user
- Intents — Intents are phrases the user may enter and will in turn expect a single action to be performed.
- Entities — Represent synonyms and patterns
As mentioned before, in this article the first version of the assistant will assist the bank customer to report a lost or stolen card and provide information about the bank products and services. We will create one intent for each of these questions. Let’s start with the intent for a lost or stolen card.
Click on Create Intent
Enter #reportLostCard as the name for the intent, an optional description and click on Create intent
Enter the following examples to the intent in order to train Watson Assistant.
Feel free to enter more user examples as Watson Assistant will use them for improving its intent accuracy
Create the second intent for the question about products and services. In my case I used #whatProductsAndServices
Click on Create intent and add the following examples
Now we will configure the dialog which is the heart of the virtual assistant an orchestrates the conversation with the user.
Go back from the Intents screen to the main Dialog skill screen and click on Dialog on the left
On the Dialog screen click on the dots of the Welcome node and then click on Add Node Below
This new node will recognize the #reportLostCard intent. We need to populate the following fields:
· Name — Enter report a lost card
· Intent — Enter #reportLostCard
· Response — Enter Sorry to hear that. We will block your card immediately and issue a new card for you.
Now we need to add a second node below the report lost card node. Click on the dots of the report lost card node and click on add node below. Enter the following values:
· Name — New Bank Products and Services
· Intent — Enter #whatProductsAndServices
· Response — Thanks for your question. We offer personal credit cards from VISA, Mastercard and American Express, personal loans, mortgage loans and car loans.
Now we are able to test our basic virtual assistant! Click on Try it! on the top right of the screen.
Enter “Cant find my card” and wait for the assistant response.
As you can see the assistant responds to our question and we did not enter a phrase that was used for training. Watson Assistant understood that our intent was #reportLostCard ! You can try the #whatProductsAndServices intent. Remember that you can train Watson Assistant iteratively entering additional phrases to the intent in order to obtain better accuracy.
Integrate the Watson Assistant widget with the website
Watson Assistant provides an out of the box integration widget. In order to obtain the integration script for the widget go back to main screen of the virtual assistant.
Under Integrations click on the Web chat icon on the right.
Click on the Embed tab to obtain the integration script.
Copy the code provided on the screen.
In Visual Studio open the file _Layout.cshtml under the folder Views / Shared
Paste the code copied from Watson Assistant before the <\head> as shown below.
Build and test locally the website pressing F5 on Visual Studio.
Click on the Watson Blue icon on the bottom right of the screen and test the assistant.
Voila! Our assistant is working on the website!
Now that our application is working we can generate a new docker image and deploy it to IBM Code Engine as explained on the first part of this series.
Generate the new docker image and deploy it to IBM Cloud Code Engine
In order to generate the new docker image we need to delete the Publish folder in Visual Studio.
From Solution Explorer delete the Publish folder.
Open a Command Line window (cmd) and navigate to the root folder of the project where the Dockerfile resides
Execute the following command to create the publish folder with the updated artifacts (as in Part 1)
dotnet publish -o ./publish
We are ready to create and publish the new image (v2) for our virtual assistant executing the following commands.
docker build -t username/newbankvirtualassistant:v2 .
docker push -t username/newbankvirtualassistant:v2
Our new image (v2) has been published to Dockerhub.
Verify that your image has been published to your repositories in Dockerhub.
The final step is to deploy the application with the updated image on IBM Cloud Code Engine.
Navigate to IBM Cloud Code Engine at https://cloud.ibm.com/codeengine/overview
Create your project as explained in Part 1 and deploy your application pointing to the updated image (v2) — docker.io/username/newbankvirtualassistant:v2
Remember that you can configure your runtime settings in the IBM Cloud Code Engine interface.
Enter a name for your application and click on Deploy. After a few seconds the application Url link will be available to test the published application.
Click on Application URL and the internet facing application with the Virtual Assistant will pop up and it is ready to go on IBM Cloud!
So far we have developed and deployed a virtual assistant with cloud native technologies including Docker and Kubernetes without code. Very impressive (at least for me :) )
In Part 3 we will include Search capabilities to our assistant using natural language with IBM Watson Discovery. Again with NO code at all.