Skip to content

Commit

Permalink
Only update flow hashes when they changed, added slot to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
twerkmeister committed Sep 25, 2023
1 parent a0b95b3 commit cba9791
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
8 changes: 4 additions & 4 deletions rasa/dialogue_understanding/processor/command_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@ def execute_commands(
# Override commands
commands = [CleanStackCommand()]

# always store current flow hashes
tracker.update_with_events(
[SlotSet(FLOW_HASHES_SLOT, calculate_flow_fingerprints(all_flows))], None
)
# store current flow hashes if they changed
new_hashes = calculate_flow_fingerprints(all_flows)
if new_hashes != (tracker.get_slot(FLOW_HASHES_SLOT) or {}):
tracker.update_with_events([SlotSet(FLOW_HASHES_SLOT, new_hashes)], None)

events: List[Event] = []

Expand Down
13 changes: 9 additions & 4 deletions tests/core/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@
ACTION_EXTRACT_SLOTS,
DIALOGUE_STACK_SLOT,
RETURN_VALUE_SLOT,
ACTION_CLEAN_STACK,
FLOW_HASHES_SLOT,
)
from rasa.shared.core.trackers import DialogueStateTracker
from rasa.shared.exceptions import RasaException
Expand Down Expand Up @@ -146,7 +148,7 @@ def test_domain_action_instantiation():
for action_name in domain.action_names_or_texts
]

assert len(instantiated_actions) == 21
assert len(instantiated_actions) == 22
assert instantiated_actions[0].name() == ACTION_LISTEN_NAME
assert instantiated_actions[1].name() == ACTION_RESTART_NAME
assert instantiated_actions[2].name() == ACTION_SESSION_START_NAME
Expand All @@ -165,9 +167,10 @@ def test_domain_action_instantiation():
assert instantiated_actions[15].name() == ACTION_CORRECT_FLOW_SLOT
assert instantiated_actions[16].name() == ACTION_CLARIFY_FLOWS
assert instantiated_actions[17].name() == ACTION_RUN_SLOT_REJECTIONS_NAME
assert instantiated_actions[18].name() == "my_module.ActionTest"
assert instantiated_actions[19].name() == "utter_test"
assert instantiated_actions[20].name() == "utter_chitchat"
assert instantiated_actions[18].name() == ACTION_CLEAN_STACK
assert instantiated_actions[19].name() == "my_module.ActionTest"
assert instantiated_actions[20].name() == "utter_test"
assert instantiated_actions[21].name() == "utter_chitchat"


@pytest.mark.parametrize(
Expand Down Expand Up @@ -248,6 +251,7 @@ async def test_remote_action_runs(
"slots": {
"name": None,
REQUESTED_SLOT: None,
FLOW_HASHES_SLOT: None,
SESSION_START_METADATA_SLOT: None,
DIALOGUE_STACK_SLOT: None,
RETURN_VALUE_SLOT: None,
Expand Down Expand Up @@ -312,6 +316,7 @@ async def test_remote_action_logs_events(
"slots": {
"name": None,
REQUESTED_SLOT: None,
FLOW_HASHES_SLOT: None,
SESSION_START_METADATA_SLOT: None,
DIALOGUE_STACK_SLOT: None,
RETURN_VALUE_SLOT: None,
Expand Down
2 changes: 2 additions & 0 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
SESSION_START_METADATA_SLOT,
DIALOGUE_STACK_SLOT,
RETURN_VALUE_SLOT,
FLOW_HASHES_SLOT,
)
from rasa.shared.core.domain import Domain, SessionConfig
from rasa.shared.core.events import (
Expand Down Expand Up @@ -1117,6 +1118,7 @@ async def test_requesting_non_existent_tracker(rasa_app: SanicASGITestClient):
assert content["slots"] == {
"name": None,
REQUESTED_SLOT: None,
FLOW_HASHES_SLOT: None,
SESSION_START_METADATA_SLOT: None,
DIALOGUE_STACK_SLOT: None,
RETURN_VALUE_SLOT: None,
Expand Down

0 comments on commit cba9791

Please sign in to comment.