def test_merge_yaml_domains(): test_yaml_1 = """actions: - utter_greet config: store_entities_as_slots: true entities: [] intents: [] slots: {} templates: utter_greet: - text: hey there!""" test_yaml_2 = """actions: - utter_greet - utter_goodbye config: store_entities_as_slots: false entities: - cuisine intents: - greet slots: cuisine: type: text templates: utter_greet: - text: hey you!""" domain_1 = Domain.from_yaml(test_yaml_1) domain_2 = Domain.from_yaml(test_yaml_2) domain = domain_1.merge(domain_2) # single attribute should be taken from domain_1 assert domain.store_entities_as_slots # conflicts should be taken from domain_1 assert domain.templates == {"utter_greet": [{"text": "hey there!"}]} # lists should be deduplicated and merged assert domain.intents == ["greet"] assert domain.entities == ["cuisine"] assert isinstance(domain.slots[0], TextSlot) assert domain.slots[0].name == "cuisine" assert sorted(domain.user_actions) == sorted( ["utter_greet", "utter_goodbye"]) domain = domain_1.merge(domain_2, override=True) # single attribute should be taken from domain_2 assert not domain.store_entities_as_slots # conflicts should take value from domain_2 assert domain.templates == {"utter_greet": [{"text": "hey you!"}]}
def test_domain_to_yaml(): test_yaml = """actions: - utter_greet config: store_entities_as_slots: true entities: [] intents: [] slots: {} templates: utter_greet: - text: hey there!""" domain = Domain.from_yaml(test_yaml) # python 3 and 2 are different here, python 3 will have a leading set # of --- at the beginning of the yml assert domain.as_yaml().strip().endswith(test_yaml.strip()) domain = Domain.from_yaml(domain.as_yaml())
def test_predict(http_app, app): client = RasaCoreClient(EndpointConfig(http_app)) cid = str(uuid.uuid1()) for event in test_events[:2]: client.append_event_to_tracker(cid, event) out = app.get('/domain', headers={'Accept': 'yml'}) domain = Domain.from_yaml(out.get_data()) tracker = client.tracker(cid, domain) event_dicts = [ev.as_dict() for ev in tracker.applied_events()] response = app.post('/predict', json=event_dicts) assert response.status_code == 200
def default_domain(self): content = """ actions: - utter_hello intents: - greet - bye - affirm - deny """ return Domain.from_yaml(content)
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)