dc6079821b
Docs Tests / Check for file changes (push) Has been cancelled
Docs Tests / Test Documentation (push) Has been cancelled
Docs Tests / Documentation Linting Checks (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-performance) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-policies) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-cli) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-core-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-full-model-training) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-nlu-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-nlu-predictors) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-other-unit-tests) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-performance) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-policies) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-cli) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-core-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-full-model-training) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-nlu-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-nlu-predictors) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-other-unit-tests) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-performance) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-policies) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-cli) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-core-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-full-model-training) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-nlu-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-nlu-predictors) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-other-unit-tests) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-performance) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-policies) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-cli) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-core-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-full-model-training) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-nlu-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-nlu-predictors) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-other-unit-tests) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-performance) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-policies) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-cli) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-core-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-full-model-training) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-nlu-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-nlu-predictors) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-other-unit-tests) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-performance) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-policies) (push) Has been cancelled
Continuous Integration / Run Flaky Tests (ubuntu-24.04, 3.10) (push) Has been cancelled
Continuous Integration / Run Flaky Tests (ubuntu-24.04, 3.8) (push) Has been cancelled
Continuous Integration / Run Flaky Tests (ubuntu-24.04, 3.9) (push) Has been cancelled
Continuous Integration / Run Flaky Tests (windows-2022, 3.10) (push) Has been cancelled
Continuous Integration / Run Flaky Tests (windows-2022, 3.8) (push) Has been cancelled
Continuous Integration / Run Flaky Tests (windows-2022, 3.9) (push) Has been cancelled
Continuous Integration / Check for file changes (push) Has been cancelled
Continuous Integration / Wait for docs tests (push) Has been cancelled
Continuous Integration / Code Quality (push) Has been cancelled
Continuous Integration / Check for changelog (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-cli) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-core-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-full-model-training) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-nlu-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-nlu-predictors) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-other-unit-tests) (push) Has been cancelled
Continuous Integration / Upload coverage reports to codeclimate (push) Has been cancelled
Continuous Integration / Run Non-Sequential Integration Tests (push) Has been cancelled
Continuous Integration / Run Broker Integration Tests (push) Has been cancelled
Continuous Integration / Run Sequential Integration Tests (push) Has been cancelled
Continuous Integration / Build Docker base images and setup environment (push) Has been cancelled
Continuous Integration / Build Docker (default) (push) Has been cancelled
Continuous Integration / Build Docker (full) (push) Has been cancelled
Continuous Integration / Build Docker (mitie-en) (push) Has been cancelled
Continuous Integration / Build Docker (spacy-de) (push) Has been cancelled
Continuous Integration / Build Docker (spacy-en) (push) Has been cancelled
Continuous Integration / Build Docker (spacy-it) (push) Has been cancelled
Continuous Integration / Deploy to PyPI (push) Has been cancelled
Continuous Integration / Notify Slack & Publish Release Notes (push) Has been cancelled
Publish Documentation / Evaluate release tag (push) Has been cancelled
Publish Documentation / Prebuild Docs (push) Has been cancelled
Publish Documentation / Preview Docs (push) Has been cancelled
Publish Documentation / Check for file changes (push) Has been cancelled
Publish Documentation / Publish Docs (push) Has been cancelled
Automatic PR Merger / mergepal (push) Has been cancelled
CI Github Actions / Run Tests (push) Has been cancelled
Semgrep / Semgrep Workflow Security Scan (push) Has been cancelled
145 lines
4.1 KiB
Python
145 lines
4.1 KiB
Python
import logging
|
|
|
|
from pytest import LogCaptureFixture
|
|
from rasa.core.nlg.callback import CallbackNaturalLanguageGenerator, nlg_request_format
|
|
from rasa.shared.core.domain import Domain
|
|
from rasa.shared.core.events import UserUttered
|
|
from rasa.shared.core.slots import TextSlot
|
|
from rasa.shared.core.trackers import DialogueStateTracker, EventVerbosity
|
|
|
|
|
|
def test_nlg_request_format(
|
|
default_tracker: DialogueStateTracker,
|
|
) -> None:
|
|
assert nlg_request_format(
|
|
utter_action="utter_one_id",
|
|
tracker=default_tracker,
|
|
output_channel="test",
|
|
) == {
|
|
"response": "utter_one_id",
|
|
"id": None,
|
|
"arguments": {},
|
|
"channel": {"name": "test"},
|
|
"tracker": default_tracker.current_state(EventVerbosity.ALL),
|
|
}
|
|
|
|
|
|
def test_nlg_request_format_with_arguments(
|
|
default_tracker: DialogueStateTracker,
|
|
) -> None:
|
|
assert nlg_request_format(
|
|
utter_action="utter_one_id",
|
|
tracker=default_tracker,
|
|
output_channel="test",
|
|
some_arg="some_value",
|
|
) == {
|
|
"response": "utter_one_id",
|
|
"id": None,
|
|
"arguments": {"some_arg": "some_value"},
|
|
"channel": {"name": "test"},
|
|
"tracker": default_tracker.current_state(EventVerbosity.ALL),
|
|
}
|
|
|
|
|
|
def test_nlg_request_format_with_response_ids(
|
|
default_tracker: DialogueStateTracker,
|
|
) -> None:
|
|
assert nlg_request_format(
|
|
utter_action="utter_one_id",
|
|
tracker=default_tracker,
|
|
output_channel="test",
|
|
response_id="1",
|
|
) == {
|
|
"response": "utter_one_id",
|
|
"id": "1",
|
|
"arguments": {},
|
|
"channel": {"name": "test"},
|
|
"tracker": default_tracker.current_state(EventVerbosity.ALL),
|
|
}
|
|
|
|
|
|
def test_callback_nlg_fetch_response_id() -> None:
|
|
# Arrange
|
|
utter_action = "utter_greet"
|
|
|
|
name_slot = TextSlot(
|
|
name="name", mappings=[{}], initial_value="Bob", influence_conversation=False
|
|
)
|
|
logged_in_slot = TextSlot(
|
|
name="logged_in",
|
|
mappings=[{}],
|
|
initial_value=True,
|
|
influence_conversation=False,
|
|
)
|
|
tracker = DialogueStateTracker.from_events(
|
|
sender_id="interpolated_crv",
|
|
evts=[UserUttered("Hello")],
|
|
slots=[name_slot, logged_in_slot],
|
|
)
|
|
output_channel = "default"
|
|
domain = Domain.load("data/test_nlg/domain_with_response_ids.yml")
|
|
|
|
# Act
|
|
response_id = CallbackNaturalLanguageGenerator.fetch_response_id(
|
|
utter_action=utter_action,
|
|
tracker=tracker,
|
|
output_channel=output_channel,
|
|
domain_responses=domain.responses,
|
|
)
|
|
|
|
# Assert
|
|
assert response_id == "ID_2"
|
|
|
|
|
|
def test_callback_nlg_fetch_response_id_with_no_domain_responses(
|
|
caplog: LogCaptureFixture,
|
|
) -> None:
|
|
# Arrange
|
|
utter_action = "utter_greet"
|
|
|
|
tracker = DialogueStateTracker.from_events(
|
|
sender_id="no_domain_responses",
|
|
evts=[UserUttered("Hello")],
|
|
)
|
|
output_channel = "default"
|
|
|
|
# Act
|
|
with caplog.at_level(logging.DEBUG):
|
|
response_id = CallbackNaturalLanguageGenerator.fetch_response_id(
|
|
utter_action=utter_action,
|
|
tracker=tracker,
|
|
output_channel=output_channel,
|
|
domain_responses=None,
|
|
)
|
|
|
|
# Assert
|
|
assert response_id is None
|
|
assert "Failed to fetch response id. Responses not provided." in caplog.text
|
|
|
|
|
|
def test_callback_nlg_fetch_response_id_with_no_response_id(
|
|
caplog: LogCaptureFixture,
|
|
) -> None:
|
|
# Arrange
|
|
utter_action = "utter_goodbye"
|
|
|
|
tracker = DialogueStateTracker.from_events(
|
|
sender_id="no_response",
|
|
evts=[UserUttered("Goodbye")],
|
|
)
|
|
output_channel = "default"
|
|
domain = Domain.load("data/test_nlg/domain_with_response_ids.yml")
|
|
|
|
# Act
|
|
with caplog.at_level(logging.DEBUG):
|
|
response_id = CallbackNaturalLanguageGenerator.fetch_response_id(
|
|
utter_action=utter_action,
|
|
tracker=tracker,
|
|
output_channel=output_channel,
|
|
domain_responses=domain.responses,
|
|
)
|
|
|
|
# Assert
|
|
assert response_id is None
|
|
assert f"Failed to fetch response id for action '{utter_action}'." in caplog.text
|