diff --git a/changelog/7034.bugfix.md b/changelog/7034.bugfix.md new file mode 100644 index 000000000000..9227df2b436c --- /dev/null +++ b/changelog/7034.bugfix.md @@ -0,0 +1,2 @@ +The converter tool now converts test stories and stories that contain full retrieval intents correctly. +Previously the response keys were deleted during conversion to YAML. \ No newline at end of file diff --git a/rasa/shared/core/training_data/story_reader/markdown_story_reader.py b/rasa/shared/core/training_data/story_reader/markdown_story_reader.py index 5d4e52f20987..fe8cb2b730bc 100644 --- a/rasa/shared/core/training_data/story_reader/markdown_story_reader.py +++ b/rasa/shared/core/training_data/story_reader/markdown_story_reader.py @@ -250,12 +250,16 @@ def _parse_message(self, message: Text, line_num: int) -> UserUttered: if self.use_e2e: parsed = self.parse_e2e_message(message, self._is_used_for_training) text = parsed.get("text") - intent = {INTENT_NAME_KEY: parsed.get("intent")} + intent = { + INTENT_NAME_KEY: parsed.get( + "intent_response_key", default=parsed.get("intent") + ) + } entities = parsed.get("entities") parse_data = { "text": text, "intent": intent, - "intent_ranking": [{INTENT_NAME_KEY: parsed.get("intent")}], + "intent_ranking": [intent], "entities": entities, } else: diff --git a/tests/core/training/converters/test_story_markdown_to_yaml_converter.py b/tests/core/training/converters/test_story_markdown_to_yaml_converter.py index d0d8097f4d26..04f9a30dd2a0 100644 --- a/tests/core/training/converters/test_story_markdown_to_yaml_converter.py +++ b/tests/core/training/converters/test_story_markdown_to_yaml_converter.py @@ -116,3 +116,75 @@ async def test_test_stories(tmpdir: Path): " - action: respond_faq\n" " - action: action_set_faq_slot\n" ) + + +async def test_test_stories_conversion_response_key(tmpdir: Path): + converted_data_folder = tmpdir / "converted_data" + os.mkdir(converted_data_folder) + + test_data_folder = tmpdir / "tests" + os.makedirs(test_data_folder, exist_ok=True) + test_data_file = Path(test_data_folder / "test_stories.md") + + simple_story_md = """ + ## id + + * out_of_scope/other: hahaha + - utter_out_of_scope/other + """ + + with open(test_data_file, "w") as f: + f.write(simple_story_md) + + await StoryMarkdownToYamlConverter().convert_and_write( + test_data_file, converted_data_folder + ) + + assert len(os.listdir(converted_data_folder)) == 1 + with open(f"{converted_data_folder}/test_stories_converted.yml", "r") as f: + content = f.read() + assert content == ( + f'version: "{LATEST_TRAINING_DATA_FORMAT_VERSION}"\n' + "stories:\n" + "- story: id\n" + " steps:\n" + " - intent: out_of_scope/other\n" + " user: |-\n" + " hahaha\n" + " - action: utter_out_of_scope/other\n" + ) + + +async def test_stories_conversion_response_key(tmpdir: Path): + converted_data_folder = tmpdir / "converted_data" + os.mkdir(converted_data_folder) + + training_data_folder = tmpdir / "data/core" + os.makedirs(training_data_folder, exist_ok=True) + training_data_file = Path(training_data_folder / "stories.md") + + simple_story_md = """ + ## id + * out_of_scope/other + - utter_out_of_scope/other + """ + + with open(training_data_file, "w") as f: + f.write(simple_story_md) + + await StoryMarkdownToYamlConverter().convert_and_write( + training_data_file, converted_data_folder + ) + + assert len(os.listdir(converted_data_folder)) == 1 + + with open(f"{converted_data_folder}/stories_converted.yml", "r") as f: + content = f.read() + assert content == ( + f'version: "{LATEST_TRAINING_DATA_FORMAT_VERSION}"\n' + "stories:\n" + "- story: id\n" + " steps:\n" + " - intent: out_of_scope/other\n" + " - action: utter_out_of_scope/other\n" + )