async def generate(self, template_name: Text, tracker: DialogueStateTracker, output_channel: Text, **kwargs: Any) -> Optional[Dict[Text, Any]]: """Generate a response for the requested template.""" filled_slots = tracker.current_slot_values() return self.generate_from_slots(template_name, filled_slots, output_channel, **kwargs)
async def generate( self, template_name: Text, tracker: DialogueStateTracker, output_channel: Text, **kwargs: Any, ) -> Optional[Dict[Text, Any]]: """Generate a response for the requested template.""" filled_slots = tracker.current_slot_values() fallback_language_slot = tracker.slots.get("fallback_language") fallback_language = fallback_language_slot.initial_value if fallback_language_slot else None language = tracker.latest_message.metadata.get( "language") or fallback_language return self.generate_from_slots( template_name, filled_slots, output_channel, **kwargs, language=language, fallback_language=fallback_language, )
def can_pass(self, tracker: DialogueStateTracker, domain_responses: Dict[Text, List], curr_state_connections: List['StateNode']) -> float: """Evaluate the truth of a state based on its list of conditions. Each state has a list of readable conditions (ex/ '![item] != None') that must be met in order to enter the state. All conditions must be met to be true. Args: tracker: rasa DialogueStateTracker Return: float: rank score if all conditions are met, 0 otherwise """ # A dict with the keys 'name' and 'confidence' for the most recent intent INTENT = adDict(tracker.latest_message.intent) # noqa: F841 # A list of dicts where each item in the list is a dict of information on one extracted # entity from the previous user utterence. Keys: 'entity', 'start', 'end', 'extractor', 'value' ENTITIES = [ entity['entity'] for entity in tracker.latest_message.entities ] # noqa: F841 # A dict of slot-name, slot-value pairs SLOTS = adDict(tracker.current_slot_values()) # noqa: F841 # A dict of response template names and utterances responses = {} for key in domain_responses.keys(): responses[key] = [value['text'] for value in domain_responses[key]] RESPONSES = adDict(responses) # noqa: F841 # A string containing the name of the most recently executed action PREV_ACTION = tracker.latest_action_name # noqa: F841 # A string containing the name of the most recent utterance said by the bot LAST_UTT = tracker.latest_bot_utterance # noqa: F841 # A string of the last action performed by the bot LAST_ACTION = tracker.latest_action_name # noqa: F841 overall_score = self.rank_score + len(self.conditions) # check all conditions and immediately return 0 if any fail for condition in self.conditions: try: if not eval(condition): # logger.debug(f"State {self.name} failed on condition: {condition}") return 0 except Exception as e: logger.error( f"The condition '{condition}' could not be evaluated: {e}") return 0 # if one of current state's connections is direct connect, prioritize it if self.direct_connection is True: if self in curr_state_connections: return 1000 else: # logger.debug(f"State {self.name} failed, direct connection not valid") return 0 # if current state has a connection but it's not a direct connect, give slight score bump if self in curr_state_connections and self.direct_connection is False: overall_score += 5 return overall_score