def validate(self, dispatcher, tracker, domain): # type: (CollectingDispatcher, Tracker, Dict[Text, Any]) -> List[Dict] """Extract and validate value of requested slot. If nothing was extracted reject execution of the form action. Subclass this method to add custom validation and rejection logic """ # extract other slots that were not requested # but set by corresponding entity or trigger intent mapping 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 to execute the form action # if some slot was requested but nothing was extracted # it will allow other policies to predict another action raise ActionExecutionRejection( self.name(), "Failed to extract slot {0} " "with action {1}" "".format(slot_to_fill, self.name()), ) logger.debug("Validating extracted slots: {}".format(slot_values)) return self.validate_slots(slot_values, dispatcher, tracker, domain)
async def validate( self, dispatcher: "CollectingDispatcher", tracker: "Tracker", domain: "DomainDict", ) -> List[EventType]: """Extract and validate value of requested slot. If nothing was extracted reject execution of the form action. Subclass this method to add custom validation and rejection logic """ # extract other slots that were not requested # but set by corresponding entity or trigger intent mapping 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, slot_to_fill, domain)) if not slot_values: # reject to execute the form action # if some slot was requested but nothing was extracted # it will allow other policies to predict another action raise ActionExecutionRejection( self.name(), f"Failed to extract slot {slot_to_fill} with action {self.name()}." f"Allowing other policies to predict next action.", ) logger.debug(f"Validating extracted slots: {slot_values}") return await self.validate_slots(slot_values, dispatcher, tracker, domain)
def validate(self, dispatcher, tracker, domain): # type: (CollectingDispatcher, Tracker, Dict[Text, Any]) -> List[Dict] """Extract and validate value of requested slot. If nothing was extracted reject execution of the form action. Subclass this method to add custom validation and rejection logic """ # extract other slots that were not requested # but set by corresponding entity or trigger intent mapping 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 tracker.latest_message.get('text').lower() == 'exit': dispatcher.utter_message("da bam vao nut exit roi do") print("in ra cai gì nè", slot_values) raise ActionExecutionRejection( self.name(), "Failed to extract slot {0} " "with action {1}" "".format(slot_to_fill, self.name()), ) if not slot_values: print(" alo alo ") if tracker.latest_message.get('intent').get('name') == 'exit' \ or remove_tone_line(tracker.latest_message.get('text').lower()) == 'yeu cau khac': raise ActionExecutionRejection( self.name(), "Failed to extract slot {0} " "with action {1}" "".format(slot_to_fill, self.name()), ) else: pass logger.debug("Validating extracted slots: {}".format(slot_values)) return self.validate_slots(slot_values, dispatcher, tracker, domain)