What Are Slots in Rasa?

If you are familiar with chatbot development, you must have come across Rasa at some point. Rasa is an open-source framework used for building conversational AI assistants. Slots are an important feature in Rasa which helps to store information that can be used throughout the conversation.

So what exactly are slots in Rasa?

 Exclusive Slots & Free Spins Offers: 

Slots are a key-value store in Rasa that helps to keep track of important information provided by the user during the conversation. It is similar to a variable that stores data but is used specifically for chatbots. Slots can be used to store user preferences, previous answers, and any other relevant information required during the conversation.

Let’s take an example of a pizza ordering bot. The bot asks the user for their pizza toppings preference.

The user responds with “I want a pizza with pepperoni and mushrooms”. The bot can then extract this information and store it in a slot called “toppings”. This information can be accessed throughout the conversation whenever needed.

How do slots work in Rasa?

Slots work by using entities and intents in Rasa. When a user inputs data, it is first classified into an intent which represents the purpose of their message. Then, any relevant data such as entities are extracted from the message and stored as slots.

Slots can be defined in two ways – as part of a domain file or as part of a custom action file. In the domain file, slots are defined as part of each intent or action that requires them. For example:

“`
intents:
– order_pizza:
toppings:
type: unfeaturized
“`

This code defines an intent called “order_pizza” and includes a slot called “toppings”. The type “unfeaturized” means that this slot will not be used by machine learning models.

Alternatively, slots can also be defined within custom actions using Python code. Here’s an example:

“`
from typing import Text, Dict, Any, List

from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher

class OrderPizza(Action):
def name(self) -> Text:
return “action_order_pizza”

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

toppings = tracker.get_slot(“toppings”)
# Here we can perform actions using the slot value

return [] “`

In this example code, a custom action is defined which retrieves the value of the “toppings” slot and then performs certain actions using this information.

Slots can also be used for validation purposes. For example, if the user inputs an invalid value for a slot such as a non-existent pizza topping, the bot can prompt them to provide a valid input.

Conclusion:

Slots are an essential feature in Rasa that allows chatbots to store information provided by users and use it throughout the conversation. They help in creating more personalized conversations and provide a better user experience. By using slots effectively in your Rasa chatbot development process, you can build more robust and user-friendly conversational AI assistants.