Building a Next Level Intelligent RASA Chatbot with TigerGraph
Did you know how easy it is to create a conversational assistant? With machine learning/Artificial intelligence.
Building a powerful chatbot Assistant has always been a motivation for all kinds of Businesses, with such tool we can:
- Automate Sales Inquiry and boost conversion
- Automate Tech Support and create Happy customers
- Answer Knowledge Base questions (KB’s) Internally
Today we will be dealing with linking the most famous open-source conversational AI framework (Rasa) with a TigerGraph database.
Having such a Connector/Pipe will allow us to create :
- A Knowledge Graph that keeps on growing and maturing
- An assistant that gets trained each time on “Auto-growing” datasets
- An assistant able to query data in real Time from TigerGraph Database
- An assistant Rules/Actions Triggered is a multi-turn conversation Assistant
The previous key features allow us to create a Scalable, Intelligent auto-learning assistant that dynamically adapts to the needs of your business!
What is Rasa?
Rasa is a conversational assistant framework brought up by startups and backed up by a fast-growing community.
The framework has these modules :
- Rasa NLU : Handles the Natural Language Processing
- RASA Core : Handles data storing , piping , API , and basically the Assistant
Many AI assistants don’t use as much machine learning as you might think. While it’s common practice to apply machine learning to NLU, when it comes to dialogue management, many developers still fall back to rules and state machines.
Instead of adding more and more rules over time. with Rasa using machine learning to select the assistant’s response presents a flexible and scalable alternative. The reason for this is one of the core concepts of machine learning: generalization.
In the above illustration (flowchart) we can clearly see how Rasa components interacts in order to drive a successful conversation with the user:
- NLU module: captures and analyses User Intent
- Core module: deals with the Next Step
And the next step could be :
- Fetching data from a database
- Interacting with an API ( Ex: restaurant booking system )
- Answering the user with a text
- Offering the user different options to drive the conversation flow
Creating your first Rasa Assistant
To create a RASA chatbot you don’t have to be a Machine Learning expert, yet with very minimal programming knowledge you can develop an interactive Conversational Assistant.
Let’s see the step by step how to create a simple healthcare chatbot.
$ python3 -m virtualenv -p python3 .
$ source bin/activate
$ pip install rasa
$ rasa init
Getting Rasa to train data from TigerGraph
Rasa Framework trains data stored in NLU, domain, actions, rules and stories files in order to make the assistant operational.
The limitation here is that the Rasa takes these data from Markdown (Md for Rasa < 1.9) or YAML (yml for Rasa > 2.0) formatted files, which limits the scalability and evolution of intents and dialogues scenarios.
In order to make our assistant learn and evolve in a dynamic way, we will create a connector to pipe data from TigerGraph directly into the Rasa Framework to be trained.
These data are stored in vertices in the Graph and have a certain structure to deliver the expected YML/MD file.
In other words, we made a Script that gets training data from a TigerGraph database and feed them to Rasa framework for training, and for the sake of compatibility, we made the script able to generate YML files (Rasa >= 2.0) and md files (Rasa < 2.0).
Recovering data from TigerGraph in real Time
Querying the data from TigerGraph (or any other API) is made simple using a simple step:
- Define the action in the domain.yml
- Write the class function responsible for analyzing that message context
- Call the TigerGraph query or run GSQL command
The intent is extracted from the message using the RegexClassifier and passed to the Action using the Rules set in the screenshot below:
TigerGraph credentials in actions.py:
TigerGraph Connection Initialization in actions.py:
Class ActionSearchPatients used by rule:
Rasa Flask/Web Sample chat Widget
To implement our little chatbot in action will install Flask and run a sample flask website using our chatbot.
We need to create a virtual environment for flask:
$ python3 –m virtualenv –p python3 .
Activate the virtual environment
$ source bin/activate
And then we install Flask using pip
$ pip install Flask
Create the template
We create a file called app.py as follows
And we create a directory called templates and in that folder, we create our index.html as follow
Run the chatbot and the actions server
To run the rasa server locally and the endpoint of the action we need to run this:
$ rasa run — endpoints endpoints.yml — connector socketio — credentials credentials.yml — port 5005 — cors “*” — enable-api
$ rasa run actions
Run the flask Server
To run our small web demo, we activate our virtual environment and we launch the webapp as follows:
$ source bin/activate
$ python3 app.py
The Bot in Action
Below the links to the GitHub repository to download:
YML AND MD Connector
RASA TG Assistant ( Covid 19 Template Demo )