diff --git a/changelog/10572.misc.md b/changelog/10572.misc.md new file mode 100644 index 000000000000..98dee6355dd2 --- /dev/null +++ b/changelog/10572.misc.md @@ -0,0 +1 @@ +Add a schema for single events. \ No newline at end of file diff --git a/docs/docs/how-to-deploy.mdx b/docs/docs/how-to-deploy.mdx index f6566037b1b1..fdfc00da89e0 100644 --- a/docs/docs/how-to-deploy.mdx +++ b/docs/docs/how-to-deploy.mdx @@ -48,7 +48,7 @@ For assistants that will receive a lot of user traffic, setting up a Kubernetes our Helm charts is the best option. This provides a scalable architecture that is also straightforward to deploy. However, you can also customize the Helm charts if you have specific requirements. -* Default: Read the [Helm Chart Installation](https://rasa.com/docs/rasa-x/installation-and-setup/install/helm-chart/) docs. +* Default: Read the [Helm Chart Installation](https://rasa.com/docs/rasa-x/0.42.x/installation-and-setup/install/helm-chart) docs. * Custom: Read the above, as well as the [Advanced Configuration](https://rasa.com/docs/rasa-x/installation-and-setup/customize/#helm-chart) documentation, and customize the [open source Helm charts](https://github.com/RasaHQ/rasa-x-helm) to your needs. diff --git a/rasa/shared/utils/schemas/events.py b/rasa/shared/utils/schemas/events.py index afd53507bab2..ba039a4eac94 100644 --- a/rasa/shared/utils/schemas/events.py +++ b/rasa/shared/utils/schemas/events.py @@ -133,40 +133,39 @@ SESSION_STARTED = {"properties": {"event": {"const": "session_started"}}} AGENT_UTTERED = {"properties": {"event": {"const": "agent"}}} -EVENTS_SCHEMA = { - "type": "array", - "items": { - "type": "object", - "properties": { - "event": {"type": "string"}, - "timestamp": {"type": ["number", "null"]}, - "metadata": {"type": ["object", "null"]}, - }, - "required": ["event"], - "oneOf": [ - USER_UTTERED, - ACTION_EXECUTED, - SLOT_SET, - ENTITIES_ADDED, - USER_UTTERED_FEATURIZATION, - REMINDER_CANCELLED, - REMINDER_SCHEDULED, - ACTION_EXECUTION_REJECTED, - FORM_VALIDATION, - LOOP_INTERRUPTED, - FORM, - ACTIVE_LOOP, - ALL_SLOTS_RESET, - CONVERSATION_RESUMED, - CONVERSATION_PAUSED, - FOLLOWUP_ACTION, - STORY_EXPORTED, - RESTARTED, - ACTION_REVERTED, - USER_UTTERANCE_REVERTED, - BOT_UTTERED, - SESSION_STARTED, - AGENT_UTTERED, - ], +EVENT_SCHEMA = { + "type": "object", + "properties": { + "event": {"type": "string"}, + "timestamp": {"type": ["number", "null"]}, + "metadata": {"type": ["object", "null"]}, }, + "required": ["event"], + "oneOf": [ + USER_UTTERED, + ACTION_EXECUTED, + SLOT_SET, + ENTITIES_ADDED, + USER_UTTERED_FEATURIZATION, + REMINDER_CANCELLED, + REMINDER_SCHEDULED, + ACTION_EXECUTION_REJECTED, + FORM_VALIDATION, + LOOP_INTERRUPTED, + FORM, + ACTIVE_LOOP, + ALL_SLOTS_RESET, + CONVERSATION_RESUMED, + CONVERSATION_PAUSED, + FOLLOWUP_ACTION, + STORY_EXPORTED, + RESTARTED, + ACTION_REVERTED, + USER_UTTERANCE_REVERTED, + BOT_UTTERED, + SESSION_STARTED, + AGENT_UTTERED, + ], } + +EVENTS_SCHEMA = {"type": "array", "items": EVENT_SCHEMA} diff --git a/tests/shared/utils/schemas/test_events.py b/tests/shared/utils/schemas/test_events.py index 186232c784c3..a865ace4b310 100644 --- a/tests/shared/utils/schemas/test_events.py +++ b/tests/shared/utils/schemas/test_events.py @@ -1,12 +1,74 @@ from typing import Type import pytest -import jsonschema +from jsonschema import ValidationError, validate from rasa.core.actions.action import RemoteAction from rasa.shared.core.events import Event +from rasa.shared.utils.schemas.events import EVENT_SCHEMA import rasa.shared.utils.common +TEST_EVENT = { + "sender_id": "77bd4d3841294f1f9f82ef8cfe9321a7", + "event": "user", + "timestamp": 1640019570.8848355, + "text": "hey 👋🏻", + "parse_data": { + "intent": { + "id": 5103161883140543062, + "name": "greet", + "confidence": 0.9999818801879883, + }, + "entities": [], + "text": "hey", + "message_id": "52ec1cba47c840d798d9f612334a750d", + "metadata": {}, + "intent_ranking": [ + { + "id": 5103161883140543062, + "name": "greet", + "confidence": 0.9999818801879883, + }, + ], + "response_selector": { + "all_retrieval_intents": ["chitchat"], + "faq": { + "response": { + "id": None, + "responses": None, + "response_templates": None, + "confidence": 0.0, + "intent_response_key": None, + "utter_action": "utter_None", + "template_name": "utter_None", + }, + "ranking": [], + }, + "chitchat": { + "response": { + "id": -2223917631873543698, + "responses": [{"text": "I am called Retrieval Bot!"},], + "response_templates": [{"text": "I am called Retrieval Bot!"},], + "confidence": 0.9660752415657043, + "intent_response_key": "chitchat/ask_name", + "utter_action": "utter_chitchat/ask_name", + "template_name": "utter_chitchat/ask_name", + }, + "ranking": [ + { + "id": -2223917631873543698, + "confidence": 0.9660752415657043, + "intent_response_key": "chitchat/ask_name", + }, + ], + }, + }, + }, + "input_channel": "rasa", + "message_id": "52ec1cba47c840d798d9f612334a750d", + "metadata": {}, +} + @pytest.mark.parametrize("event_class", rasa.shared.utils.common.all_subclasses(Event)) def test_remote_action_validate_all_event_subclasses(event_class: Type[Event]): @@ -27,4 +89,16 @@ def test_remote_action_validate_all_event_subclasses(event_class: Type[Event]): "wrong_action", "warning_predicted", ]: - jsonschema.validate(response, RemoteAction.action_response_format_spec()) + validate(response, RemoteAction.action_response_format_spec()) + + +def test_validate_single_event(): + validate(TEST_EVENT, EVENT_SCHEMA) + + +def test_validate_single_event_raises(): + test_wrong_schema = TEST_EVENT.copy() + test_wrong_schema["event"] = "non-existing event 🪲" + + with pytest.raises(ValidationError): + validate(test_wrong_schema, EVENT_SCHEMA)