Purchase Dialog Form -- multiple slots

Hi there,

I’m trying to implement a “standard” purchase dialog, similar to what you would find in a bakery or on a market:

  • Buyer: I would like to buy some apples and 5 bananas.
  • Seller: Sure. How many apples did you want?
  • Buyer: 3.
  • Seller: Anything else?
  • Buyer: Yes. 2 Oranges.
  • Seller: That’s… $$

Unfortunately, I have trouble finding an example for this. The challenge is that there are multiple items (fruits and vegetables) and each item has it’s own properties (quantity, price).

Here is my first question: Should I use 1 form for each fruit/vegetable, or can I use a single form for the entire purchase dialog?

You can use auto_fill: true for all your slots. So if the user provides the answer to a question like “Would you like any vegetables?” and your user says “Avacado” which is classified as a fruit that the fruit slot will still be filled. To ensure that the slots are filled with the canonical form of the product in your database, you can use synonyms.

I think you can implement this as a single form. You can modify the submit() function of your form to pull the properties of each item, tally the prices, and return the total cost back to the user for confirmation. You’ll first want to read back the list to the user to ground that they intended to order all the items. Let us know if you have any other questions.

Thanks @kearnsw for replying to my post. It is very encouraging! :slight_smile:

I think I’m facing 2 challenges:

  1. I need to accumulate everything the user wants to buy rather than overwriting the slot values. Is this what the “list” type is for? But then, I would rather need to collect structures like
  • [{commodity: apple, quantity: 3}, {commodity: banana, quantity: 5}]

  • not commodities: [‘apple’, ‘banana’] and quantities: [3,5]

  1. Raza’s form customization has been updated recently. and the use of FormAction which has a submit function is discouraged: Version Migration Guide It might be worth, getting this up and running “the old way”, though :slight_smile:

Do you happen to know of any example dialogs, where information is accumulated in a slot? So far, even the pizza dialogs I found were avoiding this problem altogether - as if people would enjoy pizza with a single topping :yum:

Thanks for the extra example. I understand a bit clearer now.

  1. A list slot is a great idea. In that case, you might be interested in dynamically adding questions requesting the quantity of each item.

How many items does the store have? You could think about using boolean slots for each.

That’s all using the base functionality in Rasa.

If I were to approach this problem fresh, I’d probably write a custom NLU component that could get a dependency parse of the sentence (e.g. using Spacy) and chunk those, as you mentioned, as commodity-quantity pairs. If either the commodity or quantity were unspecified for any of the pairs, you could prompt the user for it using the dynamic form behavior linked above. My concern is that the base NLU components will not be able to properly attribute the quantities of each commodity. For example, “I want 2 bags of chips, 4 mangos, 2 avocados, and a durian.”

  1. Thanks for sharing this. I was not aware that this specific function was deprecated. I am not seeing it mentioned anywhere in the current documentation, so that must be the case. As you’re probably aware, the new way would be to add the submit functionality as a rule. There you’d want to add a custom action to calculate the total and request confirmation from the user.

Unfortunately, I don’t have any example on hand for this.

It seems what I really would like to have is called ‘slot groups’ Introducing Entity Roles and Groups Unfortunately, the feature is a) experimental and b) described for the outdated rasa version. So I guess that’s not the ideal starting point for beginner user of Rasa, like myself, who gets confused easily.

However, the recognition is working fine, at least sometimes :wink: (At this point, I don’t care about having an advanced NLU model, that could also handle “bags” or “pounds” - just commodities and quantities will be fine – neither do I distinguish between vegetables and fruits.)

The problem I would like to tackle next is that action_ask_quantity will not be called if there is at least 1 quantity set. So this is a problem, if the utterance contains more commodities than quantities, e.g. “2 apples and some pears” or “bananas and 2 apples”. Any idea where I could changes this?