Skip to content

Commit

Permalink
Merge pull request #6255 from RasaHQ/fix-responses-to-utterances
Browse files Browse the repository at this point in the history
fix responses being added to actions
  • Loading branch information
rasabot authored Jul 29, 2020
2 parents 4c62cf4 + affa4b6 commit 280b125
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 19 deletions.
4 changes: 4 additions & 0 deletions changelog/6255.improvement.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Rasa Open Source will no longer add ``responses`` to the ``actions`` section of the
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 ``actions`` section.
4 changes: 3 additions & 1 deletion rasa/core/actions/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
4 changes: 3 additions & 1 deletion rasa/core/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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,
}

Expand Down
65 changes: 48 additions & 17 deletions tests/core/test_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: []
Expand All @@ -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():
Expand Down Expand Up @@ -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"]},
},
),
Expand All @@ -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: []},
},
),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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: []
Expand Down

0 comments on commit 280b125

Please sign in to comment.