Set slot values in a form by applying arithmetic operations on a couple of entities

hey,

I want to perform some arithmetic operations on some of the entities and then save it to the slot inside a running form. Is it possible?

Thanks.

Yes, just add the entities as required slots, each one with a validate function to make sure they are numbers, and add the event SlotSet in the return of the submit function.

Hi @Gehova,

Actually, both entities are not required every time and even if one is available it will do the job. But if both the entities are present together then they need to be combined. eg. there are two entities lets say A and B. Lets assume we have a slot X to fill. Now, X needs to be filled as a required slot in form action and X can have values as given below:

  1. If A is the only entity, then reflect value of A in slot X.
  2. If B is the only entity, then reflect value of B in slot X.
  3. If both A and B are present, then reflect A+B as value of slot X.

hello,

Can anyone help?

Thanks.

X cannot be the required slot, because is not something that you ask directly to the user. Also, I cannot think of away to make A or B optional in the required_slots function.

The only way I can think of, is to ask in your form for A and B, save the value that you get or a zero if you get a negative intent.

def slot_mappings(self):
	return{ "A": [/*Your mapping to extract the number*/,self.from_intent(intent='negation', value='0') ]
	"B": [/*Your mapping to extract the number*/,self.from_intent(intent='negation', value='0') ]}

This way your form will be something like:

  • Give me the value for A?
  • 15
  • Give me the value for B?
  • I don’t have it
  • X is 15

Hi @Gehova,

Thanks for trying to help.

I cannot ask for them separately as both values are not required all the time and if I ask for both of them explicitly, it will degrade user experience.

Thanks.