Creating a Weather bot using RASA framework and Rasa X.
Rasa is an open-source framework that helps businesses improve their conversation and interaction with their customers or audience. It is based on natural language understanding, dialogue management and interactions. Using Rasa, it becomes easier to build conversational AI and improve it over time.
For installation and basic chatbot creation you can refer to my previous article
From the article mentioned above we get an idea related to all the files used in rasa such as the domain, actions, config, credentials, endpoints etc
After creating a separate folder called weather_bot and activating the virtual environment(rasa) run the command rasa init — no-prompt.
This command will create all the files that a rasa project needs.We need to edit the training data and few files to get our desired result.
Step 1: First let us create the training data in the nlu.md file present in the data folder.Intents such as greet goodbye are already present hence there is no need to a separate intent for greet and goodbye.
Let us create two new intents on which we will train our model.
intent inform and intent inquire
As seen in the above fig we are creating a new intent i.e inform and giving different sentences to train the model.we are also mentioning the location in brackets for the model to understand that particular word as location.
Similarly we have created another intent i.e inquire as shown in the above figure.That will conclude editing our nlu.md file.
The created intents must be added to the domain file under the intents column.In the domain file we need to create a new slot for location.
what are slots?
Slots are your bot’s memory. They act as a key-value store which can be used to store information the user provided (e.g their home city) as well as information gathered about the outside world (e.g. the result of a database query).
Slots are defined in the slots
section of your domain with their name andtype. The slot type will determine the data type of the slot and how the slotinfluences the assistant's behavior. The following example defines a slot with name slot_name
and type text
.
After finishing with the domain file now lets move on to the dialogue management part i.e the stories.md file.
we create our dialogue flow in the stories as shown in the figure above.We can add any number of stories with different locations for training purposes.
Now coming to the main part i.e the actions.py file , we need to create a class ActionWeather where we will give our api key and also the response for that particular actions.To get our api key we are using weatherstack website.
Sign up for free to get the api key.We use this key in our code.The code is very short and should be simple enough to understand.You can learn more about rasa actions here
you can access the full directory which includes all the files here.
Once we are done with the changes we need to train our model.
Train the model using the command rasa train in the command prompt and this will train the model and save it.Now to test our model use the command rasa shell to talk to the bot and in other terminal run the actions file using the command rasa run actions.
As you can see in the above figure our weather bot is completed and you can improve by adding various other changes.
Rasa X
Rasa X is a tool for Conversation-Driven Development (CDD), the process of listening to your users and using those insights to improve your AI assistant.
Rasa X can be installed in different ways the simplest one is in the local mode by using the command
pip3 install rasa-x — extra-index-url https://pypi.rasa.com/simple
Installation guide to rasa X. If you have installed in the local mode just use the command rasa x which will open a browser tab to http://localhost:5002
. which is user friendly and interactive.
References:
Github link: