Checking slot value with database and give desired response - Rasa Open Source - Rasa Community Forum
👋 Introducing the Rasa Playground
Checking slot value with database and give desired response
post by oldmonkABA on Oct 10, 2018
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
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
post by akelad on Oct 12, 2018
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
post by oldmonkABA on Oct 15, 2018
Thanks for your reply. Can i use that branch of rasa-core? what branch of rasa_core_sdk should i use?
post by akelad on Oct 16, 2018
both are forms_v2 there’s already some docs in the core branch too
post by oldmonkABA on Oct 25, 2018
thanks for your response… 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?
post by neerajb1 on Oct 26, 2018
Hi Aba , I am struggling with same issue. Could you please explain a bit how to use form v2 and where it is available currently.
post by oldmonkABA on Oct 26, 2018
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…
post by neerajb1 on Oct 26, 2018
Hi ABA , Thanks for reply. I tried using pip install git+https://github.com/RasaHQ/rasa_core_sdk.git@forms_v2 but no luck, when importing from rasa_core_sdk.forms import REQUESTED_SLOT I am getting error REQUESTED_SLOT not found. Please let me know where i am doing wrong.
post by oldmonkABA on Oct 26, 2018
did u do the same for rasa_core too? pip install git+https://github.com/RasaHQ/rasa_core.git@forms_v2
post by neerajb1 on Oct 26, 2018
Yes I have same branch for rasa core
post by oldmonkABA on Oct 27, 2018
then it pretty much works out of the box
post by Ghostvv on Oct 31, 2018
thank you for raising this question, it slipped out of our mind. We are working on adding such capability
post by oldmonkABA on Oct 31, 2018
Dear Vladimir
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
post by Ghostvv on Oct 31, 2018
There are two open PRs:
rasa_core: https://github.com/RasaHQ/rasa_core/pull/1013rasa_core_sdk: https://github.com/RasaHQ/rasa_core_sdk/pull/10
To handle yes/no question, we added slot filling from intent: rasa_core_sdk/forms.py at 33702f76322ad44b36ecc171362f4e661a6b0027 · RasaHQ/rasa_core_sdk · GitHub
Please take a look at outdoor_seating slot in formbot example: rasa_core/actions.py at 7c53260aae3376ec1b7c5c927bae2b1c52110cfb · RasaHQ/rasa_core · GitHub
post by oldmonkABA on Oct 31, 2018
thank you vladimir. Will keep tracking the PRs
post by oldmonkABA on Oct 31, 2018
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.
post by Ghostvv on Oct 31, 2018
that is quite complicated custom logic that should go in validate method
post by oldmonkABA on Oct 31, 2018
in the forms_v2 branch?
post by Ghostvv on Oct 31, 2018
yes