Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set a slot in a custom action in rasa

I'm new to rasa framework. I started developing a simple chatbot and i have created three slots for my chatbot. So my bot need to identify the current location and save it in the slots. My current location is taking from the conversation and i can save it in to the slots in the story.

But then i have a custom action that find the weather weather from an API call and i need to save the weather status and humidity in the relevant slots.

class ActionSomeRespThree(Action):

    def name(self) -> Text:
        return "action_some_resp_three"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:

        cityName = tracker.get_slot('city')
like image 945
cbing120 Avatar asked Aug 13 '19 04:08

cbing120


People also ask

How do you fill Rasa slots?

If you used slots in previous versions of Rasa, you may have noticed that there were several ways to fill them. If you had an entity that shared a name with a slot, whenever that entity with that name was extracted it would automatically fill the slot.

What is Slotset in Rasa?

Slots are your bot's memory. They act as a key-value store which can be used to store information the user provided (e.g their home city) as well as information gathered about the outside world (e.g. the result of a database query).


1 Answers

You can simply use setSlot method in events.

from rasa_sdk.events import SlotSet

Then in you run method, you can set your value in relevant slot.

Imagine you slot name for humidity is weather_humidity. Then imagine your humidity value from the API is extracted for a variable called humidity. Then in your custom action run method, simply set the slot value with below line.

SlotSet("weather_humidity", humidity)

Make sure that you have defined the slot values in your domain.yml file.

like image 82
Dushan Avatar answered Sep 22 '22 19:09

Dushan