Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for NLG change - [ENG 501] #12875

Merged
merged 5 commits into from
Oct 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions tests/core/nlg/test_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from rasa.shared.core.domain import Domain
from rasa.shared.core.slots import TextSlot, AnySlot, CategoricalSlot, BooleanSlot
from rasa.shared.core.trackers import DialogueStateTracker
from rasa.shared.utils.validation import YamlValidationException


async def test_nlg_conditional_response_variations_with_no_slots():
Expand Down Expand Up @@ -625,3 +626,93 @@ async def test_nlg_conditional_response_variations_condition_logging(
"[condition 2] type: slot | name: test_B | value: B" in message
for message in caplog.messages
)


async def test_nlg_response_with_no_text():
with pytest.raises(YamlValidationException):
Domain.from_yaml(
f"""
version: "{LATEST_TRAINING_DATA_FORMAT_VERSION}"
responses:
utter_flow_xyz:
- buttons:
- payload: "yes"
title: Yes
- payload: "no"
title: No

"""
)


async def test_nlg_response_with_default_template_engine():
domain = Domain.from_yaml(
f"""
version: "{LATEST_TRAINING_DATA_FORMAT_VERSION}"
responses:
utter_flow_xyz:
- text: "Do you want to update the values?"
"""
)
t = TemplatedNaturalLanguageGenerator(domain.responses)
r = t.generate_from_slots(
"utter_flow_xyz",
{"tm": "50"},
{
"frame_id": "XYYZABCD",
"corrected_slots": {"tm": "100"},
},
"",
)
assert r.get("text") == "Do you want to update the values?"


async def test_nlg_response_with_jinja_template():
varunshankar marked this conversation as resolved.
Show resolved Hide resolved
domain = Domain.from_yaml(
f"""
version: "{LATEST_TRAINING_DATA_FORMAT_VERSION}"
responses:
utter_flow_xyz:
- text: "Do you want to update the
{{{{ context.corrected_slots.keys()|join(', ') }}}}?"
metadata:
rephrase: true
template: jinja
"""
)
t = TemplatedNaturalLanguageGenerator(domain.responses)
r = t.generate_from_slots(
"utter_flow_xyz",
{"tm": "50"},
{
"frame_id": "XYYZABCD",
"corrected_slots": {"tm": "100"},
},
"",
)
assert r.get("text") == "Do you want to update the tm?"


async def test_nlg_response_with_unknown_var_jinja_template():
domain = Domain.from_yaml(
f"""
version: "{LATEST_TRAINING_DATA_FORMAT_VERSION}"
responses:
utter_flow_xyz:
- text: "Do you want to update the {{{{ context.unknown_key }}}}?"
metadata:
rephrase: true
template: jinja
"""
)
t = TemplatedNaturalLanguageGenerator(domain.responses)
r = t.generate_from_slots(
"utter_flow_xyz",
{"tm": "50"},
{
"frame_id": "XYYZABCD",
"corrected_slots": {"tm": "100"},
},
"",
)
assert r.get("text") == "Do you want to update the ?"
Loading