Rasa is a Python framework for training and building an AI-powered chatbot integrated into various platforms.
Training and building AI-powered applications such as chatbots can be expensive. It requires high computational power and supported firmware. Okteto provides you with a development environment where you can train, build and deploy your models remotely on the Cloud.
In this article, we’ll show you how you can build a simple rasa chatbot, Oktebot, remotely in Okteto.
Want to see this built live? Watch the recorded live-stream on our Youtube channel!
Prerequisites
To follow this tutorial, you should have:
- An Okteto Cloud account (It’s free! )
- Okteto CLI installed
- Basic knowledge of Python
Setting up
We’ll start by creating a project directory to house our application:
$ mkdir oktebot
$ cd oktebot
Building Oktebot in Okteto’s development environment
Now that we have created the project directory, the next step is to sign in to our Okteto account via Okteto CLI from our local terminal:
$ okteto context use https://cloud.okteto.com
In the project directory, we’ll create an Okteto manifest as the first step in creating our development container:
$ okteto init
The first prompt asks us to select the language we'll be working with:
This is to enable Okteto provide the necessary toolings for our remote development session.
In the prompt from the command above, select Use default values:
Select the resource you want to develop:
▸ Use default values
In the newly created manifest file, okteto.yml
, modify the image name:
image: rasa/rasa
We have successfully created the manifest file. The next step is to start our development container and select Python as the default language in the prompt:
$ okteto up
The okteto up
command creates a new development container in your dashboard from the parameters included in the okteto.yml
manifest file and then starts a remote development session:
i Using youngestdev @ cloud.okteto.com as context
✓ Persistent volume successfully attached
✓ Images successfully pulled
✓ Files synchronized
Context: cloud.okteto.com
Namespace: youngestdev
Name: oktebot
Forward: 8080 -> 8080
Reverse: 9000 <- 9000
root@oktebot-okteto-7bbddd5c59-d7bmx:~#
In the remote development container, we’ll create a new rasa bot in the project directory:
root@oktebot-okteto-7bbddd5c59-d7bmx:~# rasa init
In the prompt in the remote terminal, select the current directory and train the initial model:
? Please enter a path where the project will be created [default: current direct
ory]
? Directory’/app’ is not empty. Continue? (Y/n) Y
? Do you want to train an initial model? Y
Once the training is complete, the rasa tool prompts us to ask if we’d like to speak to the trained assistant:
Do you want to speak to the trained assistant on the command line? Y
Let’s speak with the trained assistant:
Training Oktebot
The data
folder contains our bot's training data and responses in our project folder. There are three files currently present:
-
nlu.yml
: This file contains the sample data for Natural Language Understanding. -
stories.yml
: This file includes example conversations with the bot to train the assistant to respond correctly depending on the preceding text. -
domain.yml
: This file defines the scenario in which the bot acts. This file defines intents from our NLU files and accompanying responses.
Now that we have successfully created our chatbot, let’s train the bot with our data. In the data
folder, create two new files from your remote development container terminal:
root@oktebot-okteto-7bbddd5c59-d7bmx:~# touch {chat,faq}.yml
The newly created files will contain the intent and examples for training our bot similar to nlu.yml
. The chat.yml
file will house the intent for when a user starts a conversation with the bot, and faq.yml
will contain the training data for when a user asks a question.
In the chat.yml
file, add the following:
version: "3.0"
nlu:
- intent: chat/hello
examples: |
- How can we help
- we're glad we can help
- please hold on while I get you an engineer
- glad you love okteto
- intent: chat/bye
examples: |
- do come back next time
- intent: chat/sales
examples: |
- the sales rep will respond in a moment
- you can pay using your credit card too
- schedule a meeting with our sales team
In the code block above, we have defined three conversation intents in our chatbot. The examples listed are used to train the bot to respond appropriatelys to a similar message.
In faq.yml
, add the following:
version: "3.0"
nlu:
- intent: faq/more_resources
examples: |
- how much does the developer pro plan cost
- I'll like to increase my bandwidth
- What plans can give more benefit than the free plan
- I'm hitting my limits easily. What can I do
- intent: faq/plan_expires
examples: |
- what happens after my plan expires
- can i renew my subscription
- intent: faq/application_status
examples: |
- what happens to my applications after 24 hours
- how can i check my deployment
- intent: faq/restart_application
examples: |
- how can i restart my application
- my application is asleep
In the code block above, we have defined three frequently asked questions ( FAQ ) intents in our chatbot. The examples listed are used to train the bot to respond to a similar message properly.
With the natural learning understanding files populated, let’s update the rules.yml
guiding the chatbot. In rules.yml
, add the following:
version: "3.0"
rules:
- rule: Say goodbye anytime the user says goodbye
steps:
- intent: goodbye
- action: utter_goodbye
- rule: faq
steps:
- intent: faq
- action: utter_faq
- rule: chat
steps:
- intent: chat
- action: utter_chat
Lastly, let’s update the stories in stories.yml
:
version: "3.0"
stories:
- story: faq
steps:
- intent: greet
- action: utter_greet
- intent: faq
- action: utter_faq
- story: chat
steps:
- intent: greet
- action: utter_greet
- intent: chat
- action: utter_chat
To wrap up the training data, let’s update the domain.yml
file in the project directory:
version: "3.0"
intents:
- greet
- chat
- goodbye
- affirm
- deny
- faq
responses:
utter_greet:
- text: "Hi! How can I help you today?"
utter_chat/hello:
- text: "Hi, welcome to Oktebot. How may I be of help?"
utter_chat/bye:
- text: "Thanks for stopping by!"
utter_chat/sales:
- text: "The sales rep will respond in a moment"
utter_cheer_up:
- text: "We hope you enjoy the Okteto platform!"
utter_did_that_help:
- text: "Did that help you?"
utter_happy:
- text: "Great, carry on!"
utter_goodbye:
- text: "Bye. See you soon!"
utter_faq/more_resources:
- text: "You can request for more resources by either changing your plan or contacting the team at support@okteto.com"
utter_faq/plan_expires:
- text: "Your account automatically reverts to the free developer plan once the previous plan expires. You can renew to avoid that"
utter_faq/application_status:
- text: "Your application automatically goes to sleep after 24 hours of inactivity on the free plan only"
utter_faq/restart_application:
- text: "You can restart your application from the dashboard or wake them by visiting the endpoint"
session_config:
session_expiration_time: 60
carry_over_slots_to_new_session: true
By updating the domain.yml
, we have updated the intent and responses our bot returns.
Retraining our bot
After populating our sample training data, the next step is to train the bot. Run the command in your development environment shell:
root@oktebot-okteto-7bbddd5c59-d7bmx:~# rasa train
Your Rasa model is trained and saved at 'models/20220113-053154-formal-sequence.tar.gz'.
Now that we have retrained our bot, we can test it from the shell:
root@oktebot-okteto-7bbddd5c59-d7bmx:~# rasa shell
We have interacted with the bot in the screenshot above, and it works according to the trained data. We can now exit the development container and start it whenever we introduce a model before deploying it.
The chatbot files created in our development environment are now available locally. This is as a result of the synchronization feature.
Conclusion
This article taught you how to train, build, and test a Rasa chatbot remotely using Okteto’s development environment. You also learned how Okteto synchronizes from the development environment to your local environment and vice versa.
Now that you have learned how to train and develop a rasa chatbot in Okteto, create a personal virtual assistant using rasa in Okteto and share it with us on our slack channel.
Sign up on Okteto today to improve your development process experience using development environments and preview environmemts!
You can find the code used for this article on GitHub.
Top comments (1)
I have a telegram bot in okteto, the cons is my namespace goes sleep if in 24 hours no request to my bot. Any suggestions to prevent namespace sleeps?