Skip to content

Commit fa00c49

Browse files
authored
Merge pull request #12927 from RasaHQ/ATO-1685-add-SlotSet-step-in-story-with-null-active-loop-mc
[ATO-1685] Add SlotSet step in story with active_loop:null mapping condition
2 parents 77f593f + a35ba8e commit fa00c49

7 files changed

Lines changed: 130 additions & 3 deletions

File tree

changelog/12927.bugfix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix wrong conflicts that occur when rasa validate stories is run with slots that have active_loop set to null in mapping conditions.

data/test/test_integration/data/nlu.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,10 @@ nlu:
8989
- are you a human?
9090
- am I talking to a bot?
9191
- am I talking to a human?
92+
93+
- intent: block
94+
examples: |
95+
- block my [checking](account_type) account
96+
- i want to block my [savings](account_type) account
97+
- i need to block an account
98+
- i need to block my [credit](account_type) card

data/test/test_integration/data/stories.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,29 @@ stories:
2828
- action: utter_did_that_help
2929
- intent: deny
3030
- action: utter_goodbye
31+
32+
- story: block savings
33+
steps:
34+
- intent: block
35+
entities:
36+
- account_type: savings
37+
- action: utter_block_account
38+
39+
- story: block checking
40+
steps:
41+
- intent: block
42+
entities:
43+
- account_type: checking
44+
- action: utter_checking
45+
46+
- story: block credit
47+
steps:
48+
- intent: block
49+
entities:
50+
- account_type: credit
51+
- action: utter_credit
52+
53+
- story: block no entities
54+
steps:
55+
- intent: block
56+
- action: utter_nothing

data/test/test_integration/domain.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ intents:
88
- mood_great
99
- mood_unhappy
1010
- bot_challenge
11+
- block
1112

1213
responses:
1314
utter_greet:
@@ -29,6 +30,35 @@ responses:
2930
utter_iamabot:
3031
- text: "I am a bot, powered by Rasa."
3132

33+
utter_block_account:
34+
- text: "your account has been blocked"
35+
36+
utter_checking:
37+
- text: "checking account"
38+
39+
utter_credit:
40+
- text: "credit account"
41+
42+
utter_nothing:
43+
- text: "no account type was specified"
44+
45+
entities:
46+
- account_type
47+
48+
slots:
49+
account_type:
50+
type: categorical
51+
influence_conversation: true
52+
values:
53+
- savings
54+
- checking
55+
- credit
56+
mappings:
57+
- type: from_entity
58+
entity: account_type
59+
conditions:
60+
- active_loop: null
61+
3262
session_config:
3363
session_expiration_time: 60
3464
carry_over_slots_to_new_session: true

rasa/shared/core/domain.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
SlotMappingType,
4444
MAPPING_TYPE,
4545
MAPPING_CONDITIONS,
46+
ACTIVE_LOOP,
4647
)
4748
from rasa.shared.exceptions import (
4849
RasaException,
@@ -1408,9 +1409,11 @@ def slots_for_entities(self, entities: List[Dict[Text, Any]]) -> List[SlotSet]:
14081409
matching_entities = []
14091410

14101411
for mapping in slot.mappings:
1411-
if mapping[MAPPING_TYPE] != str(
1412-
SlotMappingType.FROM_ENTITY
1413-
) or mapping.get(MAPPING_CONDITIONS):
1412+
mapping_conditions = mapping.get(MAPPING_CONDITIONS)
1413+
if mapping[MAPPING_TYPE] != str(SlotMappingType.FROM_ENTITY) or (
1414+
mapping_conditions
1415+
and mapping_conditions[0].get(ACTIVE_LOOP) is not None
1416+
):
14141417
continue
14151418

14161419
for entity in entities:

tests/integration_tests/core/test_cli_response.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,36 @@ def test_rasa_validate_quiet_no_errors(
148148
"you can use `rasa telemetry disable`." in output_text
149149
assert "To learn more, check out"
150150
"https://rasa.com/docs/rasa/telemetry/telemetry." in output_text
151+
152+
153+
def test_rasa_validate_null_active_loop_no_errors(
154+
run: Callable[..., RunResult], request: FixtureRequest
155+
):
156+
# Test captures the subprocess output for the command run
157+
# and validates that the data in 'data/test/test_integration' throws no cli errors
158+
159+
test_data_dir = Path(request.config.rootdir, "data", "test", "test_integration")
160+
test_config_dir = Path(request.config.rootdir, "data", "test_config")
161+
source_file = (test_data_dir / "data").absolute()
162+
domain_file = (test_data_dir / "domain.yml").absolute()
163+
config_file = (test_config_dir / "config_unique_assistant_id.yml").absolute()
164+
result = run(
165+
"data",
166+
"validate",
167+
"--data",
168+
str(source_file),
169+
"-d",
170+
str(domain_file),
171+
"-c",
172+
str(config_file),
173+
)
174+
assert result.ret == 0
175+
176+
stderr_text = str(result.stderr)
177+
assert "INFO" in stderr_text
178+
assert "Validating intents..." in stderr_text
179+
assert "Validating utterances..." in stderr_text
180+
assert "Story structure validation..." in stderr_text
181+
assert "Validating utterances..." in stderr_text
182+
assert "Considering all preceding turns for conflict analysis." in stderr_text
183+
assert "No story structure conflicts found." in stderr_text

tests/shared/core/test_domain.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1977,6 +1977,33 @@ def test_domain_slots_for_entities_with_mapping_conditions_no_slot_set():
19771977
assert len(events) == 0
19781978

19791979

1980+
def test_domain_slots_for_entities_with_mapping_conditions_no_active_loop():
1981+
domain = Domain.from_yaml(
1982+
textwrap.dedent(
1983+
f"""
1984+
version: "{LATEST_TRAINING_DATA_FORMAT_VERSION}"
1985+
entities:
1986+
- city
1987+
slots:
1988+
location:
1989+
type: text
1990+
influence_conversation: false
1991+
mappings:
1992+
- type: from_entity
1993+
entity: city
1994+
conditions:
1995+
- active_loop: null
1996+
forms:
1997+
booking_form:
1998+
required_slots:
1999+
- location
2000+
"""
2001+
)
2002+
)
2003+
events = domain.slots_for_entities([{"entity": "city", "value": "Berlin"}])
2004+
assert events == [SlotSet("location", "Berlin")]
2005+
2006+
19802007
def test_domain_slots_for_entities_sets_valid_slot():
19812008
domain = Domain.from_yaml(
19822009
textwrap.dedent(

0 commit comments

Comments
 (0)