From 08c4f4485a6e7b951bdb948e67af2b5e2ab12a1f Mon Sep 17 00:00:00 2001 From: Sanchari Date: Mon, 5 Jun 2023 15:17:41 +0200 Subject: [PATCH 1/8] Skip sequential integration tests on release tag --- .github/workflows/continous-integration.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/continous-integration.yml b/.github/workflows/continous-integration.yml index f675e4bb263f..7a3bb8862eaf 100644 --- a/.github/workflows/continous-integration.yml +++ b/.github/workflows/continous-integration.yml @@ -688,6 +688,7 @@ jobs: sequential_integration_test: name: Run Sequential Integration Tests + if: github.ref_type != 'tag' runs-on: ubuntu-20.04 needs: [changes] env: From e76ee2f4579d904ff4eeea79b2d738ebf8a06b99 Mon Sep 17 00:00:00 2001 From: Sanchari Date: Thu, 8 Jun 2023 11:41:17 +0200 Subject: [PATCH 2/8] Update setup-poetry version to v8 --- .github/workflows/continous-integration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/continous-integration.yml b/.github/workflows/continous-integration.yml index 7a3bb8862eaf..8141fb3be854 100644 --- a/.github/workflows/continous-integration.yml +++ b/.github/workflows/continous-integration.yml @@ -733,7 +733,7 @@ jobs: - name: Install poetry 🦄 if: needs.changes.outputs.backend == 'true' - uses: Gr1N/setup-poetry@09236184f6c1ab47c0dc9c1001c7fe200cf2afb0 # v7 + uses: Gr1N/setup-poetry@15821dc8a61bc630db542ae4baf6a7c19a994844 # v8 with: poetry-version: ${{ env.POETRY_VERSION }} From f6d9cd266d234ec6d373f4609efb1898e9ebe61d Mon Sep 17 00:00:00 2001 From: Varun Shankar S Date: Fri, 9 Jun 2023 00:35:48 +0200 Subject: [PATCH 3/8] Update processor --- rasa/core/processor.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/rasa/core/processor.py b/rasa/core/processor.py index 4f257758500f..10ff35550bfc 100644 --- a/rasa/core/processor.py +++ b/rasa/core/processor.py @@ -59,6 +59,9 @@ import rasa.core.actions.action import rasa.shared.core.trackers from rasa.shared.core.trackers import DialogueStateTracker, EventVerbosity +from rasa.shared.core.training_data.story_reader.yaml_story_reader import ( + YAMLStoryReader, +) from rasa.shared.nlu.constants import ( ENTITIES, INTENT, @@ -66,6 +69,7 @@ PREDICTED_CONFIDENCE_KEY, TEXT, ) +from rasa.shared.nlu.training_data.message import Message from rasa.utils.endpoints import EndpointConfig logger = logging.getLogger(__name__) @@ -682,8 +686,23 @@ async def parse_message( if self.http_interpreter: parse_data = await self.http_interpreter.parse(message) else: - parse_data = self._parse_message_with_graph(message, only_output_properties) - + msg = YAMLStoryReader.unpack_regex_message( + message=Message({TEXT: message.text}) + ) + # Intent is not explicitly present. Pass message to graph. + if msg.data.get(INTENT) is None: + parse_data = self._parse_message_with_graph( + message, only_output_properties + ) + else: + parse_data = { + TEXT: "", + INTENT: {INTENT_NAME_KEY: None, PREDICTED_CONFIDENCE_KEY: 0.0}, + ENTITIES: [], + } + parse_data.update( + msg.as_dict(only_output_properties=only_output_properties) + ) logger.debug( "Received user message '{}' with intent '{}' " "and entities '{}'".format( From 00ee79fc220bc9b33284a30d263b5378b31f9c16 Mon Sep 17 00:00:00 2001 From: Varun Shankar S Date: Tue, 13 Jun 2023 18:12:58 +0200 Subject: [PATCH 4/8] add tests --- changelog/12480.improvement.md | 1 + tests/core/test_processor.py | 37 +++++++++++++++++++++++++++------- 2 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 changelog/12480.improvement.md diff --git a/changelog/12480.improvement.md b/changelog/12480.improvement.md new file mode 100644 index 000000000000..8a55039f89cb --- /dev/null +++ b/changelog/12480.improvement.md @@ -0,0 +1 @@ +Skip executing the pipeline when the user message is of the form /intent or /intent + entities. \ No newline at end of file diff --git a/tests/core/test_processor.py b/tests/core/test_processor.py index b0414cea9c95..e1f473a1afaf 100644 --- a/tests/core/test_processor.py +++ b/tests/core/test_processor.py @@ -15,6 +15,7 @@ from _pytest.logging import LogCaptureFixture from aioresponses import aioresponses from typing import Optional, Text, List, Callable, Type, Any +from unittest import mock from rasa.core.lock_store import InMemoryLockStore from rasa.core.policies.ensemble import DefaultPolicyPredictionEnsemble @@ -110,10 +111,25 @@ async def test_message_id_logging(default_processor: MessageProcessor): async def test_parsing(default_processor: MessageProcessor): + MessageProcessor._parse_message_with_graph = mock.Mock() + + # Case1: message has intent and entities explicitly set. message = UserMessage('/greet{"name": "boy"}') parsed = await default_processor.parse_message(message) assert parsed["intent"][INTENT_NAME_KEY] == "greet" assert parsed["entities"][0]["entity"] == "name" + MessageProcessor._parse_message_with_graph.assert_not_called() + + # Case2: Normal user message. + parse_data = { + "text": "mocked", + "intent": {"name": None, "confidence": 0.0}, + "entities": [], + } + MessageProcessor._parse_message_with_graph.return_value = parse_data + message = UserMessage("hi hello how are you?") + parsed = await default_processor.parse_message(message) + MessageProcessor._parse_message_with_graph.assert_called() async def test_check_for_unseen_feature(default_processor: MessageProcessor): @@ -871,7 +887,7 @@ async def test_handle_message_with_session_start( # make sure the sequence of events is as expected with_model_ids_expected = with_model_ids( [ - ActionExecuted(ACTION_SESSION_START_NAME), + ActionExecuted(ACTION_SESSION_START_NAME, confidence=1.0), SessionStarted(), ActionExecuted(ACTION_LISTEN_NAME), UserUttered( @@ -883,15 +899,18 @@ async def test_handle_message_with_session_start( "start": 6, "end": 22, "value": "Core", - "extractor": "RegexMessageHandler", } ], ), SlotSet(entity, slot_1[entity]), DefinePrevUserUtteredFeaturization(False), - ActionExecuted("utter_greet"), - BotUttered("hey there Core!", metadata={"utter_action": "utter_greet"}), - ActionExecuted(ACTION_LISTEN_NAME), + ActionExecuted( + "utter_greet", policy="AugmentedMemoizationPolicy", confidence=1.0 + ), + BotUttered( + "hey there Core!", data={}, metadata={"utter_action": "utter_greet"} + ), + ActionExecuted(ACTION_LISTEN_NAME, confidence=1.0), ActionExecuted(ACTION_SESSION_START_NAME), SessionStarted(), # the initial SlotSet is reapplied after the SessionStarted sequence @@ -906,15 +925,17 @@ async def test_handle_message_with_session_start( "start": 6, "end": 42, "value": "post-session start hello", - "extractor": "RegexMessageHandler", } ], ), SlotSet(entity, slot_2[entity]), DefinePrevUserUtteredFeaturization(False), - ActionExecuted("utter_greet"), + ActionExecuted( + "utter_greet", policy="AugmentedMemoizationPolicy", confidence=1.0 + ), BotUttered( "hey there post-session start hello!", + data={}, metadata={"utter_action": "utter_greet"}, ), ActionExecuted(ACTION_LISTEN_NAME), @@ -922,6 +943,8 @@ async def test_handle_message_with_session_start( model_id, ) expected = with_assistant_ids(with_model_ids_expected, assistant_id=assistant_id) + print("tracker.events", list(tracker.events)) + print("expected", expected) assert list(tracker.events) == expected From e9ed922469f952c5f42cf4c15f40c5eea7e70e1c Mon Sep 17 00:00:00 2001 From: Varun Shankar S Date: Wed, 14 Jun 2023 01:11:52 +0200 Subject: [PATCH 5/8] fix tests --- tests/core/test_agent.py | 12 +++++++++-- tests/core/test_processor.py | 39 ++++++++++++++++++------------------ 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/tests/core/test_agent.py b/tests/core/test_agent.py index 21b42d690a96..9241f8f950b3 100644 --- a/tests/core/test_agent.py +++ b/tests/core/test_agent.py @@ -98,11 +98,19 @@ async def test_agent_train(default_agent: Agent): "start": 6, "end": 21, "value": "Rasa", - "extractor": "RegexMessageHandler", } ], }, - ) + ), + ( + "hi hello", + { + "text": "hi hello", + "intent": {"name": "greet", "confidence": 1.0}, + "text_tokens": [(0, 2), (3, 8)], + "entities": [], + }, + ), ], ) async def test_agent_parse_message( diff --git a/tests/core/test_processor.py b/tests/core/test_processor.py index e1f473a1afaf..74e7db687a8f 100644 --- a/tests/core/test_processor.py +++ b/tests/core/test_processor.py @@ -111,25 +111,26 @@ async def test_message_id_logging(default_processor: MessageProcessor): async def test_parsing(default_processor: MessageProcessor): - MessageProcessor._parse_message_with_graph = mock.Mock() - - # Case1: message has intent and entities explicitly set. - message = UserMessage('/greet{"name": "boy"}') - parsed = await default_processor.parse_message(message) - assert parsed["intent"][INTENT_NAME_KEY] == "greet" - assert parsed["entities"][0]["entity"] == "name" - MessageProcessor._parse_message_with_graph.assert_not_called() - - # Case2: Normal user message. - parse_data = { - "text": "mocked", - "intent": {"name": None, "confidence": 0.0}, - "entities": [], - } - MessageProcessor._parse_message_with_graph.return_value = parse_data - message = UserMessage("hi hello how are you?") - parsed = await default_processor.parse_message(message) - MessageProcessor._parse_message_with_graph.assert_called() + with mock.patch( + "rasa.core.processor.MessageProcessor._parse_message_with_graph" + ) as mocked_function: + # Case1: message has intent and entities explicitly set. + message = UserMessage('/greet{"name": "boy"}') + parsed = await default_processor.parse_message(message) + assert parsed["intent"][INTENT_NAME_KEY] == "greet" + assert parsed["entities"][0]["entity"] == "name" + mocked_function.assert_not_called() + + # Case2: Normal user message. + parse_data = { + "text": "mocked", + "intent": {"name": None, "confidence": 0.0}, + "entities": [], + } + mocked_function.return_value = parse_data + message = UserMessage("hi hello how are you?") + parsed = await default_processor.parse_message(message) + mocked_function.assert_called() async def test_check_for_unseen_feature(default_processor: MessageProcessor): From 0833466c926c055ef0518f9daf8fcf92ad2b1527 Mon Sep 17 00:00:00 2001 From: Varun Shankar S Date: Wed, 14 Jun 2023 01:14:12 +0200 Subject: [PATCH 6/8] modify test --- tests/core/test_processor.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/core/test_processor.py b/tests/core/test_processor.py index 74e7db687a8f..b63715800097 100644 --- a/tests/core/test_processor.py +++ b/tests/core/test_processor.py @@ -944,8 +944,6 @@ async def test_handle_message_with_session_start( model_id, ) expected = with_assistant_ids(with_model_ids_expected, assistant_id=assistant_id) - print("tracker.events", list(tracker.events)) - print("expected", expected) assert list(tracker.events) == expected From 6545b168bb5885fb0cdaea14278165f7bc81fcb5 Mon Sep 17 00:00:00 2001 From: Varun Shankar S Date: Mon, 19 Jun 2023 13:32:27 +0200 Subject: [PATCH 7/8] Fix log --- rasa/core/processor.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/rasa/core/processor.py b/rasa/core/processor.py index 5878c1e42dbb..4e80a1c04825 100644 --- a/rasa/core/processor.py +++ b/rasa/core/processor.py @@ -733,11 +733,6 @@ async def parse_message( parse_data.update( msg.as_dict(only_output_properties=only_output_properties) ) - logger.debug( - "Received user message '{}' with intent '{}' " - "and entities '{}'".format( - parse_data["text"], parse_data["intent"], parse_data["entities"] - ) structlogger.debug( "processor.message.parse", From 013ec44461e3565a25a8b793214d6dba2c0159fa Mon Sep 17 00:00:00 2001 From: Varun Shankar S Date: Thu, 22 Jun 2023 13:05:08 +0200 Subject: [PATCH 8/8] Fix tests --- rasa/core/processor.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rasa/core/processor.py b/rasa/core/processor.py index 4e80a1c04825..7b688cfd6adf 100644 --- a/rasa/core/processor.py +++ b/rasa/core/processor.py @@ -721,8 +721,10 @@ async def parse_message( ) # Intent is not explicitly present. Pass message to graph. if msg.data.get(INTENT) is None: + if tracker is None: + tracker = DialogueStateTracker.from_events(message.sender_id, []) parse_data = self._parse_message_with_graph( - message, only_output_properties + message, tracker, only_output_properties ) else: parse_data = {