From 86670c06f44f0e488e3ffbcaf032e39ae29bd1b0 Mon Sep 17 00:00:00 2001 From: Tobias Wochinger Date: Mon, 14 Mar 2022 15:09:13 +0100 Subject: [PATCH] deprecate: deprecate NLU JSON format NLU data in JSON format is deprecated and will be removed in Rasa Open Source 4.0. Refs: ATO-26 --- docs/docs/migration-guide.mdx | 8 ++- rasa/shared/nlu/training_data/formats/rasa.py | 58 ++++++++++++++++++- tests/cli/test_rasa_data.py | 3 +- 3 files changed, 66 insertions(+), 3 deletions(-) diff --git a/docs/docs/migration-guide.mdx b/docs/docs/migration-guide.mdx index 8409736b91dc..9a40a005cbd1 100644 --- a/docs/docs/migration-guide.mdx +++ b/docs/docs/migration-guide.mdx @@ -12,7 +12,6 @@ import TabItem from '@theme/TabItem'; This page contains information about changes between major versions and how you can migrate from one version to another. - ## Rasa 3.0 to 3.1 ### Machine Learning Components @@ -28,6 +27,13 @@ this new version for inference. Please check whether your trained model still performs as expected and retrain if needed. +### NLU JSON Format + +[NLU training data](nlu-training-data.mdx) in JSON format is deprecated and will be +removed in Rasa Open Source 4.0. +Please use `rasa data convert nlu -f yaml --data ` to convert your +NLU JSON data to YAML format before support for NLU JSON data is removed. + ## Rasa 2.x to 3.0 ### Markdown Data diff --git a/rasa/shared/nlu/training_data/formats/rasa.py b/rasa/shared/nlu/training_data/formats/rasa.py index 7a6d50a2b581..cfefbde7b24e 100644 --- a/rasa/shared/nlu/training_data/formats/rasa.py +++ b/rasa/shared/nlu/training_data/formats/rasa.py @@ -2,6 +2,7 @@ from collections import defaultdict from typing import Any, Dict, Text +from rasa.shared.constants import DOCS_URL_MIGRATION_GUIDE from rasa.shared.nlu.constants import TEXT, INTENT, ENTITIES from rasa.shared.nlu.training_data.formats.readerwriter import ( JsonTrainingDataReader, @@ -12,11 +13,55 @@ from rasa.shared.nlu.training_data.training_data import TrainingData from rasa.shared.nlu.training_data.message import Message +import rasa.shared.utils.io logger = logging.getLogger(__name__) class RasaReader(JsonTrainingDataReader): + """Reader for Rasa NLU training data in JSON format. + + Example: + { + "rasa_nlu_data": { + "regex_features": [ + { + "name": "zipcode", + "pattern": "[0-9]{5}" + } + ], + "entity_synonyms": [ + { + "value": "chinese", + "synonyms": ["Chinese", "Chines", "chines"] + } + ], + "common_examples": [ + { + "text": "hey", + "intent": "greet", + "entities": [] + }, + { + "text": "howdy", + "intent": "greet", + "entities": [] + } + ] + } + } + """ + + def __init__(self) -> None: + """Creates reader.""" + super().__init__() + rasa.shared.utils.io.raise_deprecation_warning( + "NLU data in Rasa JSON format is deprecated and will be removed in Rasa " + "Open Source 4.0.0. Please convert your JSON NLU data to the " + "Rasa YAML format.", + docs=DOCS_URL_MIGRATION_GUIDE, + ) + def read_from_json(self, js: Dict[Text, Any], **_: Any) -> "TrainingData": """Loads training data stored in the rasa NLU data format.""" import rasa.shared.nlu.training_data.schemas.data_schema as schema @@ -49,9 +94,20 @@ def read_from_json(self, js: Dict[Text, Any], **_: Any) -> "TrainingData": class RasaWriter(TrainingDataWriter): + """Dumps NLU data as Rasa JSON string.""" + + def __init__(self) -> None: + """Creates writer.""" + super().__init__() + rasa.shared.utils.io.raise_deprecation_warning( + "NLU data in Rasa JSON format is deprecated and will be removed in Rasa " + "Open Source 4.0.0. Please convert your JSON NLU data to the " + "Rasa YAML format.", + docs=DOCS_URL_MIGRATION_GUIDE, + ) + def dumps(self, training_data: "TrainingData", **kwargs: Any) -> Text: """Writes Training Data to a string in json format.""" - js_entity_synonyms = defaultdict(list) for k, v in training_data.entity_synonyms.items(): if k != v: diff --git a/tests/cli/test_rasa_data.py b/tests/cli/test_rasa_data.py index d042c164b82d..45aa035cd937 100644 --- a/tests/cli/test_rasa_data.py +++ b/tests/cli/test_rasa_data.py @@ -55,7 +55,7 @@ def test_data_split_nlu(run_in_simple_project: Callable[..., RunResult]): def test_data_convert_nlu(run_in_simple_project: Callable[..., RunResult]): - run_in_simple_project( + result = run_in_simple_project( "data", "convert", "nlu", @@ -67,6 +67,7 @@ def test_data_convert_nlu(run_in_simple_project: Callable[..., RunResult]): "json", ) + assert "NLU data in Rasa JSON format is deprecated" in str(result.stderr) assert os.path.exists("out_nlu_data.json")