From b526be94aea35c53de15c480fd2765919b892dd6 Mon Sep 17 00:00:00 2001 From: Tobias Wochinger Date: Tue, 21 Jul 2020 18:12:02 +0200 Subject: [PATCH 1/4] only add custom actions to `actions` when converting domain to dict --- rasa/core/domain.py | 4 ++- tests/core/test_domain.py | 65 +++++++++++++++++++++++++++++---------- 2 files changed, 51 insertions(+), 18 deletions(-) diff --git a/rasa/core/domain.py b/rasa/core/domain.py index 0b070407c855..f2dc962c67f7 100644 --- a/rasa/core/domain.py +++ b/rasa/core/domain.py @@ -417,6 +417,8 @@ def __init__( self.templates = templates self.session_config = session_config + self._custom_actions = action_names + # only includes custom actions and utterance actions self.user_actions = action.combine_with_templates(action_names, templates) @@ -778,7 +780,7 @@ def as_dict(self) -> Dict[Text, Any]: "entities": self.entities, "slots": self._slot_definitions(), "responses": self.templates, - "actions": self.user_actions, # class names of the actions + "actions": self._custom_actions, "forms": self.form_names, } diff --git a/tests/core/test_domain.py b/tests/core/test_domain.py index 4953d7282374..314e5925cff9 100644 --- a/tests/core/test_domain.py +++ b/tests/core/test_domain.py @@ -11,11 +11,7 @@ SLOT_LAST_OBJECT, SLOT_LAST_OBJECT_TYPE, ) -from rasa.core.domain import ( - USED_ENTITIES_KEY, - USE_ENTITIES_KEY, - IGNORE_ENTITIES_KEY, -) +from rasa.core.domain import USED_ENTITIES_KEY, USE_ENTITIES_KEY, IGNORE_ENTITIES_KEY from rasa.core import training, utils from rasa.core.domain import Domain, InvalidDomain, SessionConfig from rasa.core.featurizers import MaxHistoryTrackerFeaturizer @@ -236,8 +232,47 @@ def test_domain_fails_on_unknown_custom_slot_type(tmpdir, domain_unkown_slot_typ Domain.load(domain_path) +def test_domain_to_dict(): + test_yaml = """ + actions: + - action_save_world + config: + store_entities_as_slots: true + entities: [] + forms: [] + intents: [] + responses: + utter_greet: + - text: hey there! + session_config: + carry_over_slots_to_new_session: true + session_expiration_time: 60 + slots: {}""" + + domain_as_dict = Domain.from_yaml(test_yaml).as_dict() + + assert domain_as_dict == { + "actions": ["action_save_world"], + "config": {"store_entities_as_slots": True}, + "entities": [], + "forms": [], + "intents": [], + "responses": {"utter_greet": [{"text": "hey there!"}]}, + "session_config": { + "carry_over_slots_to_new_session": True, + "session_expiration_time": 60, + }, + "slots": {}, + } + + def test_domain_to_yaml(): - test_yaml = """config: + test_yaml = """ +%YAML 1.2 +--- +actions: +- action_save_world +config: store_entities_as_slots: true entities: [] forms: [] @@ -251,10 +286,10 @@ def test_domain_to_yaml(): slots: {}""" 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()) - assert Domain.from_yaml(domain.as_yaml()) is not None + + actual_yaml = domain.as_yaml() + + assert actual_yaml.strip() == test_yaml.strip() def test_domain_to_yaml_deprecated_templates(): @@ -406,7 +441,7 @@ def test_merge_session_config_if_first_is_not_default(): ], ["entity", "other", "third"], { - "greet": {"triggers": "utter_goodbye", USED_ENTITIES_KEY: ["entity"],}, + "greet": {"triggers": "utter_goodbye", USED_ENTITIES_KEY: ["entity"]}, "goodbye": {USED_ENTITIES_KEY: ["entity", "other", "third"]}, }, ), @@ -417,7 +452,7 @@ def test_merge_session_config_if_first_is_not_default(): ], ["entity", "other", "third"], { - "greet": {USED_ENTITIES_KEY: [], "triggers": "utter_goodbye",}, + "greet": {USED_ENTITIES_KEY: [], "triggers": "utter_goodbye"}, "goodbye": {USED_ENTITIES_KEY: []}, }, ), @@ -641,7 +676,6 @@ def test_clean_domain_for_file(): "utter_goodbye": [{"text": "goodbye :("}], "utter_default": [{"text": "default message"}], }, - "actions": ["utter_default", "utter_goodbye", "utter_greet"], "session_config": { "carry_over_slots_to_new_session": True, "session_expiration_time": 0, @@ -765,10 +799,7 @@ def test_are_sessions_enabled(session_config: SessionConfig, enabled: bool): def test_domain_utterance_actions_deprecated_templates(): - new_yaml = """actions: -- utter_greet -- utter_goodbye -config: + new_yaml = """config: store_entities_as_slots: true entities: [] forms: [] From cd1a7656a05d44592d3c7b93b99c60c24190c322 Mon Sep 17 00:00:00 2001 From: Tobias Wochinger Date: Tue, 21 Jul 2020 18:16:24 +0200 Subject: [PATCH 2/4] add changelog --- changelog/6255.improvement.rst | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 changelog/6255.improvement.rst diff --git a/changelog/6255.improvement.rst b/changelog/6255.improvement.rst new file mode 100644 index 000000000000..d4c8d3fd06ba --- /dev/null +++ b/changelog/6255.improvement.rst @@ -0,0 +1,4 @@ +Rasa Open Source will no longer add ``responses`` to the ``actions`` section of the +domain when persisting the domain as file. This addresses related problems in Rasa X +when Integrated Version Control introduced big diffs due to the added utterances +in the ``action`` section. From c25af7a40d6de40a40c612d569d4a89025021d90 Mon Sep 17 00:00:00 2001 From: ricwo <20581300+ricwo@users.noreply.github.com> Date: Wed, 29 Jul 2020 09:53:17 +0200 Subject: [PATCH 3/4] Apply suggestions from code review --- changelog/6255.improvement.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/changelog/6255.improvement.rst b/changelog/6255.improvement.rst index d4c8d3fd06ba..74d097a36c14 100644 --- a/changelog/6255.improvement.rst +++ b/changelog/6255.improvement.rst @@ -1,4 +1,4 @@ Rasa Open Source will no longer add ``responses`` to the ``actions`` section of the -domain when persisting the domain as file. This addresses related problems in Rasa X +domain when persisting the domain as a file. This addresses related problems in Rasa X when Integrated Version Control introduced big diffs due to the added utterances -in the ``action`` section. +in the ``actions`` section. From affa4b6fd8dfa7f7ec4e275101a2fcbf5ec8a793 Mon Sep 17 00:00:00 2001 From: ricwo <20581300+ricwo@users.noreply.github.com> Date: Wed, 29 Jul 2020 12:27:19 +0200 Subject: [PATCH 4/4] sort response names in domain --- rasa/core/actions/action.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rasa/core/actions/action.py b/rasa/core/actions/action.py index 443442fe8af9..7922ee8ba130 100644 --- a/rasa/core/actions/action.py +++ b/rasa/core/actions/action.py @@ -96,7 +96,9 @@ def combine_with_templates( actions: List[Text], templates: Dict[Text, Any] ) -> List[Text]: """Combines actions with utter actions listed in responses section.""" - unique_template_names = [a for a in list(templates.keys()) if a not in actions] + unique_template_names = [ + a for a in sorted(list(templates.keys())) if a not in actions + ] return actions + unique_template_names