Skip to content

Commit

Permalink
implement changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ancalita authored and tabergma committed Oct 12, 2023
1 parent ca74d6f commit 0fdaa73
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
8 changes: 8 additions & 0 deletions rasa/shared/core/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
)
from rasa.shared.core.constants import (
ACTION_SHOULD_SEND_DOMAIN,
SLOT_MAPPINGS,
SlotMappingType,
MAPPING_TYPE,
MAPPING_CONDITIONS,
Expand Down Expand Up @@ -490,6 +491,13 @@ def collect_slots(slot_dict: Dict[Text, Any]) -> List[Slot]:
slot_type = slot_dict[slot_name].pop("type", None)
slot_class = Slot.resolve_by_type(slot_type)

if SLOT_MAPPINGS not in slot_dict[slot_name]:
logger.warning(
f"Slot '{slot_name}' has no mappings defined. "
f"We will continue with an empty list of mappings."
)
slot_dict[slot_name][SLOT_MAPPINGS] = []

slot = slot_class(slot_name, **slot_dict[slot_name])
slots.append(slot)
return slots
Expand Down
2 changes: 1 addition & 1 deletion rasa/shared/core/slot_mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def validate_slot_mappings(domain_slots: Dict[Text, Any]) -> None:
)

for slot_name, properties in domain_slots.items():
mappings = properties.get(SLOT_MAPPINGS)
mappings = properties.get(SLOT_MAPPINGS, [])

for slot_mapping in mappings:
SlotMapping.validate(slot_mapping, slot_name)
2 changes: 1 addition & 1 deletion rasa/shared/utils/schemas/domain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ mapping:
required: False
mappings:
type: "seq"
required: True
required: False
allowempty: False
sequence:
- type: "map"
Expand Down
19 changes: 19 additions & 0 deletions tests/shared/core/test_domain.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import copy
import json
import logging
import re
import textwrap
from pathlib import Path
import random
from typing import Dict, List, Text, Any, Union, Set, Optional

import pytest
from pytest import LogCaptureFixture
from pytest import WarningsRecorder

from rasa.shared.exceptions import YamlSyntaxException, YamlException
Expand Down Expand Up @@ -2352,3 +2354,20 @@ def test_merge_yaml_domains_loads_actions_which_explicitly_need_domain():
def test_domain_responses_with_ids_are_loaded(domain_yaml, expected) -> None:
domain = Domain.from_yaml(domain_yaml)
assert domain.responses == expected


def test_domain_with_slots_without_mappings(caplog: LogCaptureFixture) -> None:
domain_yaml = """
slots:
slot_without_mappings:
type: text
"""
with caplog.at_level(logging.WARN):
domain = Domain.from_yaml(domain_yaml)

assert isinstance(domain.slots[0].mappings, list)
assert len(domain.slots[0].mappings) == 0
assert (
"Slot 'slot_without_mappings' has no mappings defined. "
"We will continue with an empty list of mappings."
) in caplog.text
13 changes: 0 additions & 13 deletions tests/shared/core/test_slot_mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,6 @@ def test_slot_mappings_ignored_intents_during_active_loop():
)


def test_missing_slot_mappings_raises():
with pytest.raises(YamlValidationException):
Domain.from_yaml(
f"""
version: "{LATEST_TRAINING_DATA_FORMAT_VERSION}"
slots:
some_slot:
type: text
influence_conversation: False
"""
)


def test_slot_mappings_invalid_type_raises():
with pytest.raises(YamlValidationException):
Domain.from_yaml(
Expand Down

0 comments on commit 0fdaa73

Please sign in to comment.