Dynamic Slot filling

Hello everyone,

I’ve been following the official documentation to create a Form for my Chatbot, and I need to add some different required slots for each entity value. E.g if entity city = “New York” add an additional slot to fill, if entity city = any other city than NY, don’t add anything.

In the documentation, I found this note:

Note: you can customise the required slots function not to be static. E.g. if the job_function is a developer, you could add a required_slot about the users experience level with Rasa.

But no details are given on how to do it. Can someone help ?

Thanks.

Hi @forwitai. You can write some custom logic in the required_slots() method. Since it inherits from tracker you get all the tracker methods available for you - you can return the values of the most recent entities with tracker.latest_message.get('entities') and use the values to define which slots should be required (for example, write if statement to return a specific list of required slots).

Thanks @Juste, I will try to do it this way !

Hi @forwitai were you able to achieve your result? I’m stuck at the same thing too

Hello @webdev-rohit, yes it eventually worked. All you have to do is add these lines in the required_slots() method :

def required_slots(tracker)-> List[Text]:

    if tracker.get_slot('city) == 'NY':
        return ["slot1", "slot2", "slot3","slot4"]
    elif tracker.get_slot('city') == 'Barcelona':
        return ["slot1", "slot2","slot5","slot6"]

Hope this helps !