def test_last_executed_has_not_name(): events = [ ActionExecuted('one'), user_uttered('two', 1), ActionExecuted(ACTION_LISTEN_NAME) ] tracker = get_tracker(events) assert tracker.last_executed_action_has('another') is False
def test_last_executed_has_not_name(): events = [ ActionExecuted("one"), user_uttered("two", 1), ActionExecuted(ACTION_LISTEN_NAME), ] tracker = get_tracker(events) assert tracker.last_executed_action_has("another") is False
def test_get_last_event_for_with_exclude(): events = [ActionExecuted('one'), user_uttered('two', 1), ActionExecuted('three')] tracker = get_tracker(events) assert (tracker.get_last_event_for(ActionExecuted, action_names_to_exclude=['three']). action_name == 'one')
def test_get_last_event_for_with_skip(): events = [ ActionExecuted('one'), user_uttered('two', 1), ActionExecuted('three') ] tracker = get_tracker(events) assert (tracker.get_last_event_for(ActionExecuted, skip=1).action_name == 'one')
def test_get_last_event_for_with_exclude(): events = [ActionExecuted("one"), user_uttered("two", 1), ActionExecuted("three")] tracker = get_tracker(events) assert ( tracker.get_last_event_for( ActionExecuted, action_names_to_exclude=["three"] ).action_name == "one" )
def test_get_last_event_for_with_skip(): events = [ ActionExecuted("one"), user_uttered("two", 1), ActionExecuted("three") ] tracker = get_tracker(events) assert tracker.get_last_event_for(ActionExecuted, skip=1).action_name == "one"
def test_do_not_follow_other_policy(self, priority, domain_with_mapping, intent_mapping): policy = self.create_policy(None, priority) events = [ ActionExecuted(ACTION_LISTEN_NAME), user_uttered(intent_mapping[0], 1), ActionExecuted(intent_mapping[1], policy="other_policy"), ] tracker = get_tracker(events) scores = policy.predict_action_probabilities(tracker, domain_with_mapping) assert scores == [0] * domain_with_mapping.num_actions
def test_events_metadata(): # It should be possible to attach arbitrary metadata to any event and then # retrieve it after getting the tracker dict representation. events = [ ActionExecuted("one", metadata={"one": 1}), user_uttered("two", 1, metadata={"two": 2}), ActionExecuted(ACTION_LISTEN_NAME, metadata={"three": 3}), ] events = get_tracker(events).current_state(EventVerbosity.ALL)["events"] assert events[0]["metadata"] == {"one": 1} assert events[1]["metadata"] == {"two": 2} assert events[2]["metadata"] == {"three": 3}
def test_predict_action_listen(self, priority, domain_with_mapping, intent_mapping): policy = self.create_policy(None, priority) events = [ ActionExecuted(ACTION_LISTEN_NAME), user_uttered(intent_mapping[0], 1), ActionExecuted(intent_mapping[1], policy="policy_0_MappingPolicy"), ] tracker = get_tracker(events) scores = policy.predict_action_probabilities(tracker, domain_with_mapping) index = scores.index(max(scores)) action_planned = domain_with_mapping.action_names[index] assert action_planned == ACTION_LISTEN_NAME assert scores != [0] * domain_with_mapping.num_actions
def test_exception_if_intent_not_present(self, trained_policy): content = """ actions: - utter_hello intents: - greet """ domain = Domain.from_yaml(content) events = [ActionExecuted(ACTION_DEFAULT_FALLBACK_NAME)] tracker = get_tracker(events) with pytest.raises(InvalidDomain): trained_policy.predict_action_probabilities(tracker, domain)
def test_do_not_follow_other_policy( self, priority: int, domain_with_mapping: Domain, intent_mapping: Tuple[Text, Text], ): policy = self.create_policy(None, priority) events = [ ActionExecuted(ACTION_LISTEN_NAME), user_uttered(intent_mapping[0], 1), ActionExecuted(intent_mapping[1], policy="other_policy"), ] tracker = get_tracker(events) prediction = policy.predict_action_probabilities( tracker, domain_with_mapping, RegexInterpreter()) assert prediction.probabilities == [0 ] * domain_with_mapping.num_actions assert not prediction.is_end_to_end_prediction
def test_predict_action_listen( self, priority: int, domain_with_mapping: Domain, intent_mapping: Tuple[Text, Text], ): policy = self.create_policy(None, priority) events = [ ActionExecuted(ACTION_LISTEN_NAME), user_uttered(intent_mapping[0], 1), ActionExecuted(intent_mapping[1], policy="policy_0_MappingPolicy"), ] tracker = get_tracker(events) prediction = policy.predict_action_probabilities( tracker, domain_with_mapping, RegexInterpreter()) index = prediction.probabilities.index(max(prediction.probabilities)) action_planned = domain_with_mapping.action_names_or_texts[index] assert not prediction.is_end_to_end_prediction assert action_planned == ACTION_LISTEN_NAME assert prediction.probabilities != [0 ] * domain_with_mapping.num_actions
def test_get_last_event_with_reverted(): events = [ActionExecuted("one"), ActionReverted(), user_uttered("two", 1)] tracker = get_tracker(events) assert tracker.get_last_event_for(ActionExecuted) is None
def test_get_last_event_for(): events = [ActionExecuted("one"), user_uttered("two", 1)] tracker = get_tracker(events) assert tracker.get_last_event_for(ActionExecuted).action_name == "one"
async def _get_tracker_after_reverts(events, channel, nlg, domain): tracker = get_tracker(events) action = ActionRevertFallbackEvents() events += await action.run(channel, nlg, tracker, domain) return get_tracker(events)
def _get_next_action(policy, events, domain): tracker = get_tracker(events) scores = policy.predict_action_probabilities(tracker, domain) index = scores.index(max(scores)) return domain.action_names[index]
def test_get_last_event_for(): events = [ActionExecuted('one'), user_uttered('two', 1)] tracker = get_tracker(events) assert tracker.get_last_event_for(ActionExecuted).action_name == 'one'
async def _get_tracker_after_reverts(events, dispatcher, domain): tracker = get_tracker(events) action = ActionRevertFallbackEvents() events += await action.run(dispatcher, tracker, domain) return get_tracker(events)