I have a requirement where I want to accept a list of 2 attributes from API.AI, for example, the user can say any of the following:
add 2 oranges and 3 bananas 2 my cart
add 2 oranges 3 bananas and 5 apples to my cart
So it should send a list of the combination of count and fruit-name to my application. Any suggestions?
You can do this with Composite Entities.
First, create an entity that lists all of the fruit and their synonyms (let's call it fruit
).
Then create a composite entity (let's call it number-of-fruit
) that looks like this:
You just need one value, without synonyms, and it should contain the two parameters you wish to collect:
@sys.number-integer:number
(the @sys.number-integer
part represents the System Entity for integer, the :number
part is the name we'll give this parameter)
@fruit:fruit
(the @fruit
part is the name of our fruit entity, the :fruit
part is the name we'll give this parameter)
Now, when you add an example containing items in this format to an intent, you'll see that your new composite entity is detected:
However, the occurrences in the example are currently being treated as two separate parameters, not a list. To treat these entities as a list as opposed to two discrete items, select the second highlighted example and click the item that corresponds to the first parameter (in the screenshot it's the one with the blue text saying number-of-fruit
):
Now, you'll see that the parameters section indicates that this parameter is a list:
Once you save and train, you can test that this works for an arbitrary length list via the console:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With