A lot of conversational assistants have user goals that involve collecting a bunch of information from the user before being able to do something for them. This is called slot filling.
For example, in the banking industry, you may have a user goal of transferring money, where you need to collect information about which account to transfer from, whom to transfer to and the amount to transfer. This type of behavior can and should be handled in a rule-based way, as it is clear how this information should be collected.
For this type of use case, we can use Forms and our FormPolicy. The FormPolicy works by predicting the form as the next action until all information is gathered from the user.
As an example, we will build out the SalesForm. The user wants to contact our sales team, and for this, we need to gather the following pieces of information:
- Their name
- Their job
- Their use case
- Their contact number
Note: If you are a beginner first go through Basics of Rasa and then get started with coding.
Start coding
- Install and start a New Rasa Project. Ref ⇒ click here
- Start declaring form in
actions.py
— The first method we need to define is the name, which like in a regular Action returns the name that will be used in our stories.
- Next, we have to define the
required_slots
the method which specifies which pieces of information to ask for, i.e. which slots to fill.
- You’ll need to specify how the bot should ask for this information. This is done by specifying
utter_ask_{slotname}
responses in yourdomain.yml
file.
- Define all these slots in our
domain.yml
file.
- Create a new section in domail.yml file
- Create an intent to activate the form. Add the following code in nlu.md file.
- Also, create an intent to get the form slot details.
- Add the intent and entities in domain.yml.
- Add the story to your
stories.md
file.
- Add policies in the config.yml file.
- Uncomment the following line in your
endpoints.yml
to make Rasa aware of the action server that will run our form.
Test your chatbot
- Run action server in terminal using following CLI command.
If the action is running in the server, change the URL in the endpoints.yml file.
- Then you can retrain and talk to your bot.
Getting the form data
Many ways to retrieve data of the forms. Mostly we need all the data at the moment of submitting. So I used this method at the submit method.
Edit action.py
file:
Deploy your chatbot
The recommended way to deploy an assistant is using either the One-Line Deployment or Kubernetes/Openshift options we support. Both deploy Rasa X and your assistant. They are the easiest ways to deploy your assistant, allow you to use Rasa X to view conversations and turn them into training data, and are production-ready.
For the above-discussed use case, we have to deploy two different servers: one is for the NLU core another is for the actions.
In this article, let us discuss how to deploy RASA using docker.
- Install docker and verify its version.
- Setting up your project.
Init project inside docker image using:
-v $(pwd):/app
mounts your current working directory to the working directory in the Docker container. This means that the files you create on your computer will be visible inside the container, and files created in the container will get synced back to your computer.rasa/rasa
is the name of the docker image to run. ‘1.10.7-full’ is the name of the tag, which specifies the version and dependencies.- the Docker image has the
rasa
command as its entry point, which means you don’t have to typerasa init
, justinit
is enough.
- Talk with assistant
- Train your model
If you edit the NLU or Core training data or edit the config.yml
file, you’ll need to retrain your Rasa model. You can do so by running:
-v $(pwd):/app
: Mounts your project directory into the Docker container so that Rasa can train a model on your training data- rasa/rasa:1.10.7-full: Use the Rasa image with the tag ‘1.10.7-full’
train
: Execute therasa train
command within the container.
Deploy your chatbot in Heroku with docker
- Click below link to deploy the initial rasa docker in Heroku.
DEPLOY- https://heroku.com/deploy?template=https://github.com/just-ai/rasa-heroku-template
- Inside the project folder, create a file called Dockerfile. Inside that folder copy the following code
- Inside the same folder, create a server.sh, file and copy the following code.
If you want to deploy action instead of that copy the following code
- Open terminal and change directory to the project folder.
Your project got deployed successfully on the Heroku server🎉 .
Note: First deploy the action server and then replace the URL with action_endpoint in the endpoins.yml file. And then deploy the NLU server.
You can test your bot by running the APIs using CURL or Postman
In this article, we have discussed how to make a form and get the slot data from the user and how to use that data.