Skip to content

Commit 07b91a4

Browse files
authored
Merge pull request RasaHQ#5868 from RasaHQ/fix-newlines-in-response
Fix newlines in response
2 parents de54134 + 373a68e commit 07b91a4

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

changelog/5521.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Responses used in ResponseSelector now support new lines with explicitly adding ``\n`` between them.

rasa/nlu/training_data/formats/markdown_nlg.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ def process_lines(lines: List[Text]) -> Dict[Text, List[Text]]:
5454

5555
# utterance might have '-' itself, so joining them back if any
5656
utterance = "-".join(line.split("- ")[1:])
57+
# utterance might contain escaped newlines that we want to unescape
58+
utterance = utterance.replace("\\n", "\n")
5759
story_bot_utterances.append(utterance)
5860

5961
elif line.startswith("*"):
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from rasa.nlu.training_data.formats import NLGMarkdownReader
2+
3+
4+
def test_markdownnlg_read_newlines():
5+
md = """
6+
## Ask something
7+
* faq/ask_something
8+
- Super answer in 2\\nlines
9+
"""
10+
reader = NLGMarkdownReader()
11+
result = reader.reads(md)
12+
13+
assert result.nlg_stories == {"faq/ask_something": ["Super answer in 2\nlines"]}

0 commit comments

Comments
 (0)