Skip to content

Commit b8089c2

Browse files
author
Alexander Khizov
committed
Fixed misleading error message for rasa train nlu
- Clarify a situation when the command is given a file with a wrong format
1 parent 88f94ca commit b8089c2

File tree

7 files changed

+46
-5
lines changed

7 files changed

+46
-5
lines changed

changelog/5587.misc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed misleading error message for a situation when ``rasa train nlu --nlu`` is given a file with a wrong format.
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

examples/formbot/actions.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ def slot_mappings(self) -> Dict[Text, Union[Dict, List[Dict]]]:
2929
return {
3030
"cuisine": self.from_entity(entity="cuisine", not_intent="chitchat"),
3131
"num_people": [
32-
self.from_entity(entity="number", intent=["inform", "request_restaurant"]),
32+
self.from_entity(
33+
entity="number", intent=["inform", "request_restaurant"]
34+
),
3335
],
3436
"outdoor_seating": [
3537
self.from_entity(entity="seating"),

rasa/train.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -431,10 +431,16 @@ async def _train_nlu_async(
431431

432432
training_datas = await file_importer.get_nlu_data()
433433
if training_datas.is_empty():
434-
print_error(
435-
"No NLU data given. Please provide NLU data in order to train "
436-
"a Rasa NLU model using the '--nlu' argument."
437-
)
434+
if nlu_data:
435+
print_error(
436+
f"Path '{nlu_data}' doesn't contain valid NLU data in it. "
437+
"Please verify the data format."
438+
)
439+
else:
440+
print_error(
441+
"No NLU data given. Please provide NLU data in order to train "
442+
"a Rasa NLU model using the '--nlu' argument."
443+
)
438444
return
439445

440446
return await _train_nlu_with_validated_data(

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: 20 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,22 @@ 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

0 commit comments

Comments
 (0)