Skip to content

Commit a7c1c09

Browse files
authored
Merge branch 'master' into filter-operation
2 parents 03880ed + a095714 commit a7c1c09

File tree

8 files changed

+67
-6
lines changed

8 files changed

+67
-6
lines changed

changelog/5587.misc.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Fixed misleading error message for a situation when ``rasa train nlu --nlu`` is given a file with a wrong format.
2+
3+
Before this change the output message was always: ``No NLU data given.``
4+
5+
Now in case the format is wrong the command prints: ``Path `nlu_data` doesn't contain valid NLU data in it. Please verify the data format. The NLU model training will be skipped now.``
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## deny
2+
- non, merci
3+
- non merci
4+
- non

poetry.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ cloudpickle = ">=1.2,<1.4"
104104
multidict = "^4.6"
105105
aiohttp = "~3.6"
106106
questionary = "~1.5.1"
107-
python-socketio = "~4.4"
107+
python-socketio = ">=4.4,<4.6"
108108
python-engineio = ">=3.11,<3.13"
109109
pydot = "~1.4"
110110
async_generator = "~1.10"

rasa/train.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,13 @@ async def _train_nlu_async(
424424
fixed_model_name: Optional[Text] = None,
425425
persist_nlu_training_data: bool = False,
426426
):
427+
if not nlu_data:
428+
print_error(
429+
"No NLU data given. Please provide NLU data in order to train "
430+
"a Rasa NLU model using the '--nlu' argument."
431+
)
432+
return
433+
427434
# training NLU only hence the training files still have to be selected
428435
file_importer = TrainingDataImporter.load_nlu_importer_from_config(
429436
config, training_data_paths=[nlu_data]
@@ -432,8 +439,9 @@ async def _train_nlu_async(
432439
training_datas = await file_importer.get_nlu_data()
433440
if training_datas.is_empty():
434441
print_error(
435-
"No NLU data given. Please provide NLU data in order to train "
436-
"a Rasa NLU model using the '--nlu' argument."
442+
f"Path '{nlu_data}' doesn't contain valid NLU data in it. "
443+
"Please verify the data format. "
444+
"The NLU model training will be skipped now."
437445
)
438446
return
439447

tests/conftest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
DEFAULT_STORIES_FILE,
4040
END_TO_END_STORY_FILE,
4141
MOODBOT_MODEL_PATH,
42+
INCORRECT_NLU_DATA,
4243
)
4344
from tests.utilities import update_number_of_epochs
4445

@@ -142,6 +143,11 @@ def default_nlu_data() -> Text:
142143
return DEFAULT_NLU_DATA
143144

144145

146+
@pytest.fixture(scope="session")
147+
def incorrect_nlu_data() -> Text:
148+
return INCORRECT_NLU_DATA
149+
150+
145151
@pytest.fixture(scope="session")
146152
def end_to_end_story_file() -> Text:
147153
return END_TO_END_STORY_FILE

tests/core/conftest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737

3838
DEFAULT_NLU_DATA = "examples/moodbot/data/nlu.md"
3939

40+
INCORRECT_NLU_DATA = "data/test/markdown_single_sections/incorrect_nlu_format.md"
41+
4042
END_TO_END_STORY_FILE = "data/test_evaluations/end_to_end_story.md"
4143

4244
E2E_STORY_FILE_UNKNOWN_ENTITY = "data/test_evaluations/story_unknown_entity.md"

tests/test_train.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import Text
44

55
import pytest
6+
from _pytest.capture import CaptureFixture
67
from _pytest.monkeypatch import MonkeyPatch
78

89
import rasa.model
@@ -129,3 +130,38 @@ def test_train_nlu_temp_files(
129130
)
130131

131132
assert count_temp_rasa_files(tempfile.tempdir) == 0
133+
134+
135+
def test_train_nlu_wrong_format_error_message(
136+
capsys: CaptureFixture,
137+
tmp_path: Text,
138+
monkeypatch: MonkeyPatch,
139+
default_stack_config: Text,
140+
incorrect_nlu_data: Text,
141+
):
142+
monkeypatch.setattr(tempfile, "tempdir", tmp_path)
143+
144+
train_nlu(
145+
default_stack_config,
146+
incorrect_nlu_data,
147+
output="test_train_nlu_temp_files_models",
148+
)
149+
150+
captured = capsys.readouterr()
151+
assert "Please verify the data format" in captured.out
152+
153+
154+
def test_train_nlu_no_nlu_file_error_message(
155+
capsys: CaptureFixture,
156+
tmp_path: Text,
157+
monkeypatch: MonkeyPatch,
158+
default_stack_config: Text,
159+
):
160+
monkeypatch.setattr(tempfile, "tempdir", tmp_path)
161+
162+
train_nlu(
163+
default_stack_config, "", output="test_train_nlu_temp_files_models",
164+
)
165+
166+
captured = capsys.readouterr()
167+
assert "No NLU data given" in captured.out

0 commit comments

Comments
 (0)