Skip to content

Commit

Permalink
add SlotSet step in story with null active_loop
Browse files Browse the repository at this point in the history
in mapping conditions
  • Loading branch information
Tawakalt committed Oct 19, 2023
1 parent 77f593f commit fd87fa2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
9 changes: 6 additions & 3 deletions rasa/shared/core/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
SlotMappingType,
MAPPING_TYPE,
MAPPING_CONDITIONS,
ACTIVE_LOOP,
)
from rasa.shared.exceptions import (
RasaException,
Expand Down Expand Up @@ -1408,9 +1409,11 @@ def slots_for_entities(self, entities: List[Dict[Text, Any]]) -> List[SlotSet]:
matching_entities = []

for mapping in slot.mappings:
if mapping[MAPPING_TYPE] != str(
SlotMappingType.FROM_ENTITY
) or mapping.get(MAPPING_CONDITIONS):
mapping_conditions = mapping.get(MAPPING_CONDITIONS)
if mapping[MAPPING_TYPE] != str(SlotMappingType.FROM_ENTITY) or (
mapping_conditions
and mapping_conditions[0].get(ACTIVE_LOOP) is not None
):
continue

for entity in entities:
Expand Down
27 changes: 27 additions & 0 deletions tests/shared/core/test_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -1977,6 +1977,33 @@ def test_domain_slots_for_entities_with_mapping_conditions_no_slot_set():
assert len(events) == 0


def test_domain_slots_for_entities_with_mapping_conditions_no_active_loop():
domain = Domain.from_yaml(
textwrap.dedent(
f"""
version: "{LATEST_TRAINING_DATA_FORMAT_VERSION}"
entities:
- city
slots:
location:
type: text
influence_conversation: false
mappings:
- type: from_entity
entity: city
conditions:
- active_loop: null
forms:
booking_form:
required_slots:
- location
"""
)
)
events = domain.slots_for_entities([{"entity": "city", "value": "Berlin"}])
assert events == [SlotSet("location", "Berlin")]


def test_domain_slots_for_entities_sets_valid_slot():
domain = Domain.from_yaml(
textwrap.dedent(
Expand Down

0 comments on commit fd87fa2

Please sign in to comment.