Remove trailing backticks when assistant ends with a trailing newline

This commit is contained in:
Antonio Scandurra 2023-08-30 12:08:14 +02:00
parent 5f6562c214
commit bf67d3710a

View File

@ -3216,7 +3216,8 @@ fn strip_markdown_codeblock(
let text = if starts_with_fenced_code_block {
buffer
.strip_suffix("\n```")
.strip_suffix("\n```\n")
.or_else(|| buffer.strip_suffix("\n```"))
.or_else(|| buffer.strip_suffix("\n``"))
.or_else(|| buffer.strip_suffix("\n`"))
.or_else(|| buffer.strip_suffix('\n'))
@ -3636,6 +3637,13 @@ mod tests {
.await,
"Lorem ipsum dolor"
);
assert_eq!(
strip_markdown_codeblock(chunks("```\nLorem ipsum dolor\n```\n", 2))
.map(|chunk| chunk.unwrap())
.collect::<String>()
.await,
"Lorem ipsum dolor"
);
assert_eq!(
strip_markdown_codeblock(chunks("```html\n```js\nLorem ipsum dolor\n```\n```", 2))
.map(|chunk| chunk.unwrap())