Skip to content

Instantly share code, notes, and snippets.

@JustinaPetr
Created January 10, 2019 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save JustinaPetr/6e29f6da5e7354dfc673a998df78d556 to your computer and use it in GitHub Desktop.
Save JustinaPetr/6e29f6da5e7354dfc673a998df78d556 to your computer and use it in GitHub Desktop.
def validate(self,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict]:
"""Validate extracted requested slot
else reject the execution of the form action
"""
# extract other slots that were not requested
# but set by corresponding entity
slot_values = self.extract_other_slots(dispatcher, tracker, domain)
# extract requested slot
slot_to_fill = tracker.get_slot(REQUESTED_SLOT)
if slot_to_fill:
slot_values.update(self.extract_requested_slot(dispatcher,
tracker, domain))
if not slot_values:
# reject form action execution
# if some slot was requested but nothing was extracted
# it will allow other policies to predict another action
raise ActionExecutionRejection(self.name(),
"Failed to validate slot {0}"
"with action {1}"
"".format(slot_to_fill,
self.name()))
# we'll check when validation failed in order
# to add appropriate utterances
for slot, value in slot_values.items():
if slot == 'num_people':
if not self.is_int(value) or int(value) <= 0:
dispatcher.utter_template('utter_wrong_num_people',
tracker)
# validation failed, set slot to None
slot_values[slot] = None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment