How to extract multiple values for one slot in same intent?

Hi,

I’m trying to save multiple entities in my slot, how can I properly do this? I don’t know how many entities will a person submit since they are entering what ingredients they have currently at their disposal.

When I check my actions console the intent is recognized but my debugger prints: “Test None” so it means that he didn’t save ingredients into my slot.

**Actions.py**

class ActionRecipeSearchByIngredients(Action):

    def name(self):

        return "action_recipe_search_by_ingredients"

    def run(self, dispatcher, tracker, domain):

        ingredients = tracker.get_slot("ingredients")

        logger.debug("Test %s",ingredients)

stories.md

## story_recipe

* ask_ingredients

    - action_recipe_search_by_ingredients

    - utter_recipe

NLU.md:

## lookup: ingredients
data/lookups/ingredients.txt

## intent:ask_ingredients

- my ingredients are (tomato)[ingredients] (bacon) [ingredients] (berries)[ingredients]

- my ingredints are (beans)[ingredients] and (baguette)[ingredients]

- i have (banana)[ingredients] (baking bar)[ingredients] and (beer)[ingredients]

- in my fridge there is (chia seeds)[ingredients] and (chestnuts)[ingredients]

- i have ingredients that are (cheese)[ingredients] (cereal)[ingredients]

- my ingredients are (yogurt)[ingredients] (bacon) [ingredients] (berries)[ingredients]

- my ingredients are (wine)[ingredients] (bacon) [ingredients] (berries)[ingredients]

- my ingredients are (walnuts)[ingredients] (raw shrimp) [ingredients] (berries)[ingredients]

- my ingredients are (turkey)[ingredients] (bacon) [ingredients] (berries)[ingredients]

- my ingredients are (toast)[ingredients] (red wine) [ingredients] (berries)[ingredients]

- my ingredients are (steaks)[ingredients] (bacon) [ingredients] (berries)[ingredients]

- my ingredients are (sugar)[ingredients] (bacon) [ingredients] (berries)[ingredients]

- my ingredients are (spaghetti)[ingredients] (bacon) [ingredients] (berries)[ingredients]

- my ingredients are (seeds)[ingredients] (pumpkin) [ingredients] (berries)[ingredients]

- my ingredients are (salsa)[ingredients] (bacon) [ingredients] (pistachios)[ingredients]

- my ingredients are (wine)[ingredients] (bacon) [ingredients] (berries)[ingredients]

- my ingredients are (walnuts)[ingredients] (raw shrimp) [ingredients] (berries)[ingredients]

- my ingredients are (turkey)[ingredients] (bacon) [ingredients] (berries)[ingredients]

- my ingredients are (toast)[ingredients] (red wine) [ingredients] (fish)[ingredients]

- my ingredients are (steaks)[ingredients] (bacon) [ingredients] (garlic)[ingredients]

- my ingredients are (sugar)[ingredients] (bacon) [ingredients] (ginger)[ingredients]

- my ingredients are (spaghetti)[ingredients] (bacon) [ingredients] (berries)[ingredients]

- my ingredients are (seeds)[ingredients] (pumpkin) [ingredients] (berries)[ingredients]

- my ingredients are (lemon)[ingredients] (ketchup) [ingredients] (juice)[ingredients]

@JiteshGaikwad I’ve seen that your Zomato chatbot does similar things, can you help maybe?

How can help you?

1 Like

Did you read my problem? :smiley:

I have similar situation like you here but I would want to parse multiple cuisines for example, so someone writes: “i want indian italian and american” and I want to store all that?

## intent:changeCuisine
- change the cuisine to [indian](cuisine)
- change the cuisine to [italian](cuisine)
- change the cuisine to [american](cuisine)
- change the cuisine to [Maharashtrian](cuisine)
- change the cuisine to [south indian](cuisine)
- change the cuisine to [North Eastern](cuisine)
- can you change the cusine to [punjabi](cuisine)
- can you change the cusine to [japanese](cuisine)
- can you change the cusine to [japanese](cuisine)
- please change the cuisine to [thai](cuisine)
- please change the cuisine to [European](cuisine)
- please change the cuisine to [BBQ](cuisine)
- please change the cuisine to [Desserts](cuisine)
- please change the cuisine to [french](cuisine)
- I changed my mind I would like to try out some [chinese](cuisine) food
- I changed my mind I would like to try out some [North Eastern](cuisine) food
- I changed my mind I would like to try out some [Hyderabadi](cuisine) food
- I changed my mind I would like to try out some [Rajasthani](cuisine) food
- I changed my mind I would like to try out [Mangalorean](cuisine) food
- I changed my mind I would like to try out [Malaysian](cuisine) food
- I changed my mind I would like to try out [Bengali](cuisine) food
- I changed my mind I would like to try out [Modern Indian](cuisine) food
- can you please change the cuisine to [italian](cuisine)
- please change the cuisine to [italian](cuisine)

I’ve tried this as stories.md too but still doesn’t work:

## story_recipe{"ingredients":"berries"}

* ask_ingredients

    - slot{"ingredients":"berries"}

    - action_recipe_search_by_ingredients

    - utter_recipe

You can use list slots to capture multiple values.

1 Like

I tried with:

ingredients:
    type: list

but the same error still persists, somehow my action does not “catch” ingredients, can I do something differently in my actions.py?

class ActionRecipeSearchByIngredients(Action):

    def name(self):

        return "action_recipe_search_by_ingredients"

    def run(self, dispatcher, tracker, domain):

        ingredients = tracker.get_slot("ingredients")

        logger.debug("Test %s",ingredients)

         if ingredients:

            return [SlotSet("recipe_info", ingredients)]

        else:

            print("No recipe found.")

            return [SlotSet("recipe_info", "not found")]

But the problem here is if user had not provided the ingredients it will take the previous ingredients value from the slot…

That is a future worry, now I send only one message when I start the bot:

“my ingredients are seed pumpkin berries”

and it doesn’t work anyway…

Why don’t you try to set the slot by extracting the ingredients from entity and then set it into the slot.

1 Like

And I see here you haven’t written the story In which it will set the slot, due to which you are not able to get the ingredient slot in your code.

1 Like

This is the error I get when I tried using get_latest_entity_values:

This are my stories.md now:

## story_recipe{"recipe_info":"berries"}

* ask_ingredients

    - action_recipe_search_by_ingredients

    - slot{"recipe_info":"berries"}

    - utter_recipe

Can you change your story as mentioned below:

* ask_ingredients

    - action_recipe_search_by_ingredients{"recipe_info":"berries"}

    - slot{"recipe_info":"berries"}

    - utter_recipe

Let me try

And this story will work for “recipe_info”

1 Like

Yes that is my:

utter_recipe:

  - text: "The recipe is {recipe_info}."

I want to get ingredients and return new entity (recipe_info) because I will add more code in custom action.py so I will use ingredients as query params and return recipe_info.

EDIT: Same error persists: @JiteshGaikwad

Did you tried to extract the ingredient entity using the below code:

next(tracker.get_latest_entity_values(“ingredient”), None)

1 Like

When I try like that:

Ok so that means your nlu model is not able to extract the ingredient entity value.

Can you just check by running the below command and check whether it’s able to extract entity:

rasa shell nlu

1 Like

It seems he hasn’t extracted them…

I see here your nlu model didn’t predicted the values for ingredients entity.