7.3.5 Deploying a RASA chatbot

The instructions below assume a certain level of technical knowledge and familiarity with concepts like Docker, Git, and Rasa. The text aims to guide readers through the process of deploying and managing a Rasa chatbot, ensuring they have the necessary system requirements, and providing instructions for each step of the deployment process.

System requirements:

Docker Compose Development

Port requirements

When creating the server, make sure the following ports are open:

The minimum configuration should support up to 50 concurrent users, so it's ideal to use the minimum configuration for development and staging environments. The maximum configuration can support up to 400 concurrent users, so it can be used in a production environment. If the production load goes beyond 400 users, then it's better to look for a Kubernetes deployment.

Kubernetes deployment

We recommend a size of 10 GiB for the Rasa X volume claim and at least 30 GiB for the database volume claim.

Installation process:

Install git and clone the following repository:

git clone https://github.com/translatorswb/chatbot_deployment.git

The default installation path is /etc/rasa, however, you can install in your desired path if you set:

export RASA_HOME=~/rasa/dir
cd chatbot_deployment
sudo chmod 777 install.sh
sudo -E bash ./install.sh # -E will preserve the environment variable you set

Details about install.sh file:

This script will install:

  • Python

  • Docker

  • Docker Compose

  • Ansible

You can skip this script if you have all of them installed, or you can comment on the specific commands and continue the rest of the script.

You can skip this section if you want everything to be installed by the script automatically.

  1. set -Eeuo pipefail: This line sets some options for the script:

    • -E: Causes the script to exit immediately if any command within it exits with a non-zero status.

    • -e: Causes the script to exit immediately if any command within it returns an error.

    • -u: Treats unset variables as an error and causes the script to exit.

    • -o pipefail: Causes a pipeline to fail if any command within it fails.

  2. source /etc/os-release: This line sources the /etc/os-release file, which contains information about the operating system distribution.

  3. RUN_ANSIBLE=${RUN_ANSIBLE:-true}: This line assigns the value true to the variable RUN_ANSIBLE if it is not already set.

  4. The following lines check the value of the variable ID, which is obtained from the sourced /etc/os-release file, and install necessary dependencies based on the operating system:

    • If the ID matches "centos" or "rhel" (Red Hat Enterprise Linux), it performs a series of commands using yum package manager to update the system, install Python 3, and install python3-distutils if available.

    • If the ID matches "ubuntu" or "debian", it performs a series of commands using apt-get package manager to update the system, install Python 3, and install python3-distutils if available. It also installs wget if it is not already installed.

  5. curl -O https://bootstrap.pypa.io/get-pip.py: This line uses curl to download the get-pip.py script from the given URL.

  6. sudo python3 get-pip.py: This line executes the downloaded get-pip.py script with sudo privileges to install pip for Python 3.

  7. sudo /usr/local/bin/pip install "ansible>-2.9, <2.10": This line uses pip to install Ansible within the specified version range.

  8. sudo /usr/local/bin/ansible-galaxy install geerlingguy.docker: This line uses ansible-galaxy to install the "geerlingguy.docker" Ansible role.

  9. The following section starts with if [[ "$RUN_ANSIBLE" == "true" ]]; then and ends with fi. It checks if the RUN_ANSIBLE variable is set to true and, if so, executes the following commands related to running the Ansible playbook.

  10. sudo /usr/local/bin/ansible-playbook -i "localhost," -c local rasa_x_playbook.yml: This line uses ansible-playbook to execute the rasa_x_playbook.yml playbook, targeting the localhost inventory, and using the "local" connection method.

Then, from the command line go to /etc/rasa or $RASA_HOME and follow the steps below:

cd /etc/rasa # or cd $RASA_HOME
sudo docker-compose build

Make sure all the images are built successfully.

To run the server:

sudo docker-compose up -d

Now open localhost or the server ip/domain in your browser, and you should be able to access Rasa X.

If the server is still not up, wait for a few seconds and then try it, as some containers take some time to be up. If the problem persists, then follow the steps below:

Check running containers:

docker ps

There must be a container that might be stuck in a restart loop; just copy the name of the container and check its logs. Please make sure the name of the container matches the name of the service defined in docker-compose.yml or docker-compose.override.yml. For example: if the name of the container is rasa_nginx_1 then the name of the service is nginx. To check the logs, run the following command:

sudo docker-compose logs -f nginx

Once the app has started and database migrations are complete, visit http://YOUR_IP_OR_DOMAIN on your browser.

To reset the default password, run sudo python rasa_x_commands.py create --update admin me YOUR_PASSWORD

Integrated version control (IVC)

1. Ensure you have a deployed Rasa Enterprise instance and a Git repository with the default Rasa Open Source project layout.

2. Take caution, as connecting your remote Git repository will overwrite the existing training data in Rasa Enterprise. If you want to keep the old training data, either use a fresh Rasa Enterprise instance or export the data before connecting the repository.

Creating your Rasa project data repository

Make sure your project follows the default Rasa Open Source project layout with files like config.yml, data/nlu.yml, data/stories.yml, and domain.yml.

Some NLU data to get started with different use cases:

https://github.com/RasaHQ/NLU-training-data

If you want all the data, including stories, rules, and domains; you can use the data provided here by Rasa:

https://github.com/RasaHQ/rasa-demo/tree/main/data

Just make sure you download all the files and reformat your repo with the same structure as shown in the picture above.

Linking to Git Repository

RasaX connects to a git repository where all training data is maintained. Steps are mentioned below to link your repository.

In the Rasa Enterprise UI, click on the branch icon and select "Connect to a repository" to begin configuring the repository connection.

Rasa Enterprise supports GitHub, GitLab, and Bitbucket as Git platforms. Choose the appropriate platform and provide the necessary repository URL.

Configure your credentials based on the chosen connection method:

  • SSH: Provide the SSH URL and configure the SSH key authentication.

In case you haven't added or generated an SSH key yet, you can follow these steps:

Generate an SSH key pair using the ssh-keygen command in your terminal:

ssh-keygen -t rsa -b 4096 -C "email@example.com"

Specify the path where you want to save the SSH key. For example:

Enter file in which to save the key (/home/yourusername/.ssh/id_rsa): /path/to/your/ssh/key

You can leave the passphrase empty for no passphrase or provide a passphrase for additional security. After generating the SSH key pair, you can proceed with adding the public key to your Git server by following the aforementioned instructions.

Target Branch:

Set the target branch, which will be used to show initial data, branch off for new changes, and return to after discarding or pushing changes. Users can choose to push changes directly to the target branch or create a new branch. If you want to disable direct pushing, select the option to require users to add changes to a new branch.

After configuring the repository credentials and branch options, click the "Verify Connection" button to establish the connection between Rasa Enterprise and your Git repository.

By following these steps, you will successfully connect your Git repository to Rasa.

Rasa training

Once you connect your Rasa project with GitHub, you can start training your model by going into ‘Models’ and clicking ‘train model’.

Once the training is complete, you first need to activate your model in order to talk to your bot.

In the Rasa X UI, you can explore and interact with your assistant, review conversations, and improve its performance through the Conversations and Training Data sections.

4. Configure endpoints

To configure endpoints, open endpoints.yml in /etc/rasa or $RASA_HOME directory and add the desired configurations. A server restart is required after changing that file.

NLG Server

nlg:
    url: "http://nlg-server:6001/nlg"

Last updated