Hi i am a trying to understand the way FormAction and FormField works by modifying the restaurantbo example.
I want to compare a slot’s value with database and ask the user to re-enter the value if it does not match with database
I am continuing from the prev forum discussion at
The custom FormField is as follows:
I just used the code for EntityFormfield and modified the validate method
class MyFormField(FormField):
def __init__(self, entity_name, slot_name):
self.entity_name = entity_name
self.slot_name = slot_name
def validate(self, entity, value):
cuis=['indian','mexican']
if entity == 'cuisine':
if value not in cuis:
value = None
return value
def extract(self, tracker):
# type: (Tracker) -> List[EventType]
value = next(tracker.get_latest_entity_values(self.entity_name), None)
validated = self.validate(self.entity_name,value)
if validated is not None:
return [SlotSet(self.slot_name, validated)]
else:
return [SlotSet(self.slot_name, None)]
class RestaurantForm(FormAction):
@staticmethod
def required_fields():
return [
MyFormField("cuisine", "cuisine"),
MyFormField("num_people", "num_people")
]
def name(self):
return 'restaurant_form'
def submit(self, dispatcher, tracker, domain):
cuis=tracker.get_slot("cuisine")
if cuis is None:
dispatcher.utter_message('You did not enter the correct cuisine')
return [UserUtteranceReverted()]
n_people=tracker.get_slot("num_people")
dispatcher.utter_message("done! with "+str(n_people)+' '+cuis)
return[]
I am able to set the slot value to None using the validate()
As mentioned in Checking slot's value using database, i check the slot in action and send a utter_message and return UserUtteranceReverted
However if i enter the wrong cuisine the bot just keeps responding with utter_ask_cuisine instead of using the response that i want.
Could someone please help me out
Hm I’m not sure it’s possible with the current version of forms, but we’re working on a new Forms v2 which is on a branch in rasa core that should be merged soon
I used the forms_v2 branch to do the trick. I have one additional query.
If the cuisine and num_people are mentioned in one sentence… for example.
“I want to book a restaurant with mexican cuisine for 3 people”
Its mentioned here also :Slot Filling
The last bullet point under “Some important things to consider”
In that case , since both the slots are directly filled, the validate function of the form is not called…
How to run validate the slots in this case?
you have to download and install the forms_v2 branch of rasa_core and rasa_core_sdk…
in rasa_core there is an examples folder which has a folder called formbot…
thanks for considering my query.
Is there some link where i can track this issue, so that i know that it is complete?
Also would it be possible to add a functionality the value of the slot in the form is set with a yes/no question.
For example…
utter_ask_num_people:
for how many people should the reservation be made.
The user enters 10.
But the hotel has only 6 seats.
So the bot replies with
"Only 6 seats. Shall i go ahead with reservation for 6?
If user says yes
Then reservation is made for 6 ppl
Else the user is asked to enter the num_people again
I checked the outdoor_seating slot.
I think i did not get my point across properly.
What i meant is following for one of slots in the form the following happens:
… User enters an input
… In the validate function that input is invalid
. The bot looks up a value which is closer to the user entered value and suggests that as a possible solution
. If user agrees to that then the value is retained , else user is asked to enter a new value all over again
. If the user entered input in stage 1 was valid then the accept/deny is not triggered.