Remove trailing backticks when assistant ends with a trailing newline
This commit is contained in:
parent
5f6562c214
commit
bf67d3710a
1 changed files with 9 additions and 1 deletions
|
@ -3216,7 +3216,8 @@ fn strip_markdown_codeblock(
|
||||||
|
|
||||||
let text = if starts_with_fenced_code_block {
|
let text = if starts_with_fenced_code_block {
|
||||||
buffer
|
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`"))
|
.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,
|
.await,
|
||||||
"Lorem ipsum dolor"
|
"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!(
|
assert_eq!(
|
||||||
strip_markdown_codeblock(chunks("```html\n```js\nLorem ipsum dolor\n```\n```", 2))
|
strip_markdown_codeblock(chunks("```html\n```js\nLorem ipsum dolor\n```\n```", 2))
|
||||||
.map(|chunk| chunk.unwrap())
|
.map(|chunk| chunk.unwrap())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue