Heya! We use cookies

Codesphere uses cookies to understand your preferences and make sure you have the best experience on our site. By using Codesphere, you accept our use of cookies.

Understood. Yum!

Create Your Own AI Chatbot in minutes with Rasa

02.07.2022

AI Chatbots are an increasingly popular way to service your users. They allow you to field diverse UX requests without pages and pages of buttons for every possible thing that a user might need.

The issue, however, is that building and training an AI chatbot can be an incredibly burdensome task that oftentimes simply isn’t worth the effort.

Rasa is attempting to change that. Rasa is an open-source tool to quickly create and train an AI chatbot for whatever purpose you need. You simply enter in near plain-english how you want your chatbot to operate, give it some example inputs, and then reap the benefits.


Setting up the Demo

You can quickly setup a demo in minutes with the following commands(Make sure you have python installed):

Setup the python environment and install Rasa via pip:

python3 -m venv ./venv

source ./venv/bin/activate

pip3 install rasa

Setup, train, and run the Rasa project:

Rasa init

From there, Rasa will run the default chatbot in the command line for you to play around with


How to Customize Your Chatbot

Okay, if you’re following along you might have realized that the demo bot is pretty limited, so how can we add more functionality?

There are five key components to build your Rasa bot:

  1. NLU data
  2. Responses
  3. Stories
  4. Forms
  5. Rules

NLU(Natural Language Understanding) Data is the training data that you feed Rasa. You simply need give it examples of ways a person might say something, and then classify what those different messages mean into intents:


Responses are the ways in which you want your bot to be able to respond:

Stories are the paths that you want a conversation to be able to take:

Odds are you’re using your chatbot to collect some sort of data from users. Forms are the way you can structure requests that you need your chatbot to make and what to do when they successfully collect that information:


Finally, rules are exactly what they sound like. They can place strict requirements on ways your bot should interact:


After you edit all these parameters to customize your bot, make sure to retrain your bot with:

rasa train


How to Deploy your Chatbot

So now that you have customized your bot, how can you actually use it? Among other ways, Rasa allows you to deploy your bot as an API!

We’d recommend using Codesphere, an all-in-one web IDE and Cloud provider that allows you to deploy any app in minutes.

You can get your project setup in Codesphere simply by connecting the github repo and installing all the necessary dependencies through the command line.

When you are ready to deploy, simply run:

rasa run -p 3000

And the api will be running on port 3000.

We can then make post requests to the chatbot at:

http://<host>:<port>/webhooks/rest/webhook

With a json with the following format:

{

"sender": "test_user",  // sender ID of the user sending the message

"message": "Hi there!"

}

Note that Rasa will automatically track user sessions from senders with the same sender ID, and will even clear inactive senders after a given time period(1 minute by default).

Rasa even provides a customizable chat widget for easy embedding:


Additionally, Rasa can be connected through Websockets, Slack, Telegram, and a myriad of other ways! You can learn more here!

And that’s all it took to get our chatbot live!