Custom Rasa 1.x Training and Testing

This document explains how you can test the API of Custom Rasa 1.x Hybrid bot.

Limitations

Currently there is a limitations which is mentioned below

  1. Rasa bot connector is not yet developed for this version of Rasa so you cant test it with the chat solution yet so you have to test it by calling the APIs from Postman

Training Rasa Hybrid Bot Via Rasa X

Rasa X is a tool that helps you build, improve, and deploy AI Assistants that are powered by the Rasa framework.

Deploy Rasa X

To deploy Rasa X on the server Please follow below mentioned steps

  1.  Clone the Rasa X repository from gitlab
    $ git clone https://gitlab.expertflow.com/chat-solution/rasa-x.git
    
  2. Go to the folder rasa-x start the docker containers
    $ docker-compose up -d
    
  3. When all the services are up you have to create a password for Admin login of Rasa X by the following command
    $ sudo python rasa_x_commands.py create --update admin me PASSWORD
    

Access Rasa X GUI and Train a Bot

Following are the steps and features of Rasa X gui

  • To Access the Rasa X gui Enter the IP of machine on which Rasa X is deployed. The login screen will appear on the browser write the password and enter login
  • Following Dashboard will appear after login in which there are options to train a bot

  • In Config Tab You can add the configuration of your NLU Pipeline, Language and Action Policies


  • In NLU Training Tab You can add example assign intents and can change the intents of already assigned example

You can also watch already labeled examples by switching into Training Data Tab


  • In Stories Tab You can View, Edit and Compare the stories. Currently in Rasa X CE there is not option to delete the story



  • You Can Edit the Domain of your Bot in Domain Tab.


  • Add Templates in Responses Tabs. To add the response first its name has to be added in Domain Tab with prefix utter_ (e.g utter_greet)




  • Train the the Bot here

  • After training is Done Go To Models Tab You will see the newly trained model there just assign the production Tag to it

Deploy Custom Rasa 1.x Without Rasa X

Following are the steps to Deplay this version


  1. Clone the rasa hybrid bot repository from gitlab and checkout 3.7.0.CSN-1631 branch
    $ git clone https://gitlab.expertflow.com/chat-solution/rasa-hybrid-bot.git --branch 3.7.0.CSN-163
    
  2. Go to the folder rasa-hybrid-bot and create folders

    $ cd rasa-hybrid-bot
    
    $ mkdir -p rasa-app-data/models
    
    $ mkdir -p rasa-app-data/config
    
    $ mkdir -p rasa-app-data/actions
    
  3. The Chatbot Developer (feroze.waris@expertflow.com) will provide you 1 trained model zipped file (e.g 20190723-173716.tar.gz), 1 configuration file (e.g endpoints.yml) and actions files (python actions) if there are any, you have to put these in above created folders. Put trained model zipped file in rasa-app-data/models/ folder, configuration file in rasa-app-data/config/ folder and action files in rasa-app-data/actions/ folder
  4. Run the following command to start the containers
    $ docker-compose up -d
    

Testing Custom Rasa 1.x

After the Training and Deployment of Rasa 1.x whether with or without Rasa X Following are the APIs you need to call to test it

  1. To test the bot response run the following Post request to the bot

    http://IP-of-BOT-machine:5005/webhooks/rest/webhook
    
    JSON body
    {
    "message": "Hello",
    "sender": "sender-id"
    }
    Sender parameter above is the user id which is sending the request
    
    Sample response of the request
    
    [
        {
            "intent_name": "greet",
            "intent_confidence": 0.8292936625,
            "action_policy": "policy_1_MemoizationPolicy",
            "actions": [
                {
                    "confidence": 1,
                    "message": "hello how are you ?",
                    "name": "action_greet"
                },
                {
                    "confidence": 0,
                    "message": "I'm on it",
                    "name": "utter_on_it"
                },
                {
                    "confidence": 0,
                    "message": "hey there!",
                    "name": "utter_greet"
                }
            ]
        },
        {
            "intent_name": "affirm",
            "intent_confidence": 0.0604753572,
            "action_policy": "policy_0_KerasPolicy",
            "actions": [
                {
                    "confidence": 0.1690512449,
                    "message": "I'm on it",
                    "name": "utter_on_it"
                },
                {
                    "confidence": 0.1021741778,
                    "message": "hello how are you ?",
                    "name": "action_greet"
                },
                {
                    "confidence": 0.0752383247,
                    "message": "here's what I found:",
                    "name": "action_suggest"
                }
            ]
        },
        {
            "intent_name": "deny",
            "intent_confidence": 0.0591876297,
            "action_policy": "policy_0_KerasPolicy",
            "actions": [
                {
                    "confidence": 0.1615992337,
                    "message": "here's what I found:",
                    "name": "action_suggest"
                },
                {
                    "confidence": 0.1076792032,
                    "message": "I'm on it",
                    "name": "utter_on_it"
                },
                {
                    "confidence": 0.1047502384,
                    "message": "looking for restaurants",
                    "name": "action_search_restaurants"
                }
            ]
        },
        {
            "recipient_id": "123",
            "text": "hello how are you ?",
            "action": "action_greet"
        },
        {
            "intent": {
                "name": "greet",
                "confidence": 0.8292936625
            },
            "entities": [],
            "intent_ranking": [
                {
                    "name": "greet",
                    "confidence": 0.8292936625
                },
                {
                    "name": "affirm",
                    "confidence": 0.0604753572
                },
                {
                    "name": "deny",
                    "confidence": 0.0591876297
                },
                {
                    "name": "thankyou",
                    "confidence": 0.0338862209
                },
                {
                    "name": "inform",
                    "confidence": 0.0150911644
                },
                {
                    "name": "request_info",
                    "confidence": 0.0020659653
                }
            ],
            "text": "hello"
        }
    ]
  2.  You will see the 3 most probable actions against each top 3 intents from which you have to select the only one action. To select the action please call the following APIs in order
    POST http://IP-of-BOT-machine:5005/conversations/sender-id/tracker/events
    
    JSON body
    {
        "event": "action",
        "name": "action_greet",
        "confidence": 1.0,
        "policy": "policy_1_MemoizationPolicy"
    }
    Please Note: Write the selected action name, confidence, and policy from API response in step 6 against "name", "confidence" and "policy" parameter in above JSON body 
    
    POST http://IP-of-BOT-machine:5005/conversations/sender-id/tracker/events
    
    JSON body
    {
        "event": "bot",
        "text": "hello how are you ?"
    }
    
    Please Note: Write the message of selected action against "text" parameter in above JSON body
    
    POST http://IP-of-BOT-machine:5005/conversations/sender-id/tracker/events
    
    JSON body
    {
        "event": "action",
        "name": "action_listen"
    }
  3. Repeat step 1 and 2 for Testing the bot multiple times