Skip to content

Commit

Permalink
Merge pull request #7080 from RasaHQ/7034-test-stories-support-respon…
Browse files Browse the repository at this point in the history
…se-key

Make converter support response key for test stories
  • Loading branch information
rasabot authored Oct 30, 2020
2 parents a789072 + 0fd4643 commit 8df97d0
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 2 deletions.
2 changes: 2 additions & 0 deletions changelog/7034.bugfix.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

0 comments on commit 8df97d0

Please sign in to comment.