From cba979186eea5d17c58b39b5bee4d993a59163f0 Mon Sep 17 00:00:00 2001 From: Thomas Werkmeister Date: Mon, 25 Sep 2023 10:30:36 +0200 Subject: [PATCH] Only update flow hashes when they changed, added slot to tests --- .../processor/command_processor.py | 8 ++++---- tests/core/test_actions.py | 13 +++++++++---- tests/test_server.py | 2 ++ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/rasa/dialogue_understanding/processor/command_processor.py b/rasa/dialogue_understanding/processor/command_processor.py index fe1863f5ec7f..8f029b263484 100644 --- a/rasa/dialogue_understanding/processor/command_processor.py +++ b/rasa/dialogue_understanding/processor/command_processor.py @@ -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] = [] diff --git a/tests/core/test_actions.py b/tests/core/test_actions.py index c240d065f775..85eecd683aa8 100644 --- a/tests/core/test_actions.py +++ b/tests/core/test_actions.py @@ -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 @@ -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 @@ -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( @@ -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, @@ -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, diff --git a/tests/test_server.py b/tests/test_server.py index 8467693ed24e..f7df6c69fb6f 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -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 ( @@ -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,