pythonnlpchatbotrasarasa-core

Creating RASA Chatbot with some specific conditions


I want to create a chatbot where,

I have a branch of questions and answers like,

Q1. How are you
A1. - Fine.
    - Good.
Q2. Do you like travelling?
A2  - Yes
    - Absolutely
    - I like it.
Q3. Did you ever use RASA chatbot?
A3  - Yes
    - Almost 2 years.

now,

  1. If I ask questions to the chatbot but miss some questions like forget to ask Q2, the chatbot will say that end of the conversion that I miss that questions,

  2. After the chatbot say I miss some questions have to go throw all the questions from start again but,

  3. When I ask those questions again the chatbot will give different answers than it gives 1st time.

    Example: 1st time when I ask Q1 and Q3 it gives answers -Fine and -Yes but when 2nd time I go throw the process for Q1 and Q3 it has to give different answers than -Fine and -Yes.

Now my questions are,

  1. Is it possible to make a chatbot with RASA where it will follow the three conditions up there?
  2. If not then is any sort of alternative?

Solution

  • yes, all three conditions are possible. Please correct me as I understood your question, I am adding follow solution as per the below understanding:
    You want your assistant to ask How are you? and end-user answers Fine/Good, and so as Q2 and Q3 do.

    Solution
    For this to work, you have to use forms in Rasa. Below is a simple example for using this functionality.

    1. Make sure you have form for these questions and slots added.(facing issue, following this tutorial)
    2. Go to your actions.py
    3. Add validations for each slot you have. Here, you will find just one example here as an example.
    import os
    from pathlib import Path
    from typing import Any, Text, Dict, List
    
    from rasa_sdk import Action, Tracker, FormValidationAction
    from rasa_sdk.executor import CollectingDispatcher
    
    from utils.utils import get_html_data, send_email
    
    
    class ValidateContactUsForm(FormValidationAction):
        def name(self) -> Text:
            return "validate_contact_us_form"
    
        def validate_name(
            self,
            value: Text,
            dispatcher: "CollectingDispatcher",
            tracker: "Tracker",
            domain: "DomainDict",
        ) -> Dict[str, str]:
            if value in ["Fine", "Good"]:
                return {"name": value}
            else:
                # return {"name": None, "requested_slot": "name"}
                return {"requested_slot": "name"} # to request the same slot again, 
                # assistant will ask same question again.
    
    

    Note: return {"name": None, "requested_slot": "name"} This will close the form and restart the whole form, in this case, the form has just one slot, if you have more slots you have to nullify them too.