-
Notifications
You must be signed in to change notification settings - Fork 1.4k
bug: Streaming markdown formatting breaks code fences and whitespace #421
Copy link
Copy link
Open
Labels
bugSomething isn't workingSomething isn't working
Description
问题描述
When using streaming responses, markdown formatting can break in a few ways:
- fenced code blocks may lose their expected structure
- whitespace-only tokens are dropped, which removes meaningful spaces/newlines/indentation
- some plain text may get rendered as part of a code block
This is especially visible when asking the model to output multiple markdown code block examples.
复现步骤
A simple prompt that reproduces the issue:
‘‘‘最常见的ai回复的代码块有哪些,举例输出5个’’’
预期行为
- Python(最常见,AI 经常输出算法/脚本)
print("Hello, World!")- JavaScript(前端/Node.js 常用)
console.log("Hello, World!");- HTML(网页结构最常见)
<!DOCTYPE html>
<html>
<body>
<h1>Hello, World!</h1>
</body>
</html>- CSS(样式代码高频出现)
body {
color: blue;
font-family: Arial;
}- SQL(数据库查询最常见)
SELECT * FROM users WHERE id = 1;实际行为
- Python代码块```pythondef
greet(name):
return f"Hello, {name}!"
print(greet("AI"))
2. JavaScript代码块```javascriptconst
message = "Hello from JS!";
console.log(message);
- HTML代码块```html
AI回复示例
- CSS代码块```css.example
{ color: blue;
font-size:16px;
}
5. SQL查询代码块```sqlSELECT
* FROM usersWHERE created_at > '2025-01-01';
部署方式
Docker Compose
版本/提交号
相关日志/报错
The main issue appears to be that whitespace-only tokens are discarded in streaming mode:
<PYTHON>
if not in_think and not filtered.strip():
continue
This removes meaningful spaces/newlines/indentation and breaks markdown/code formatting.
There was also a related issue where tag filtering could remove surrounding text too aggressively.请求样例(可选)
Fix direction
The following changes fixed the issue in my local test:
Preserve whitespace-only tokens in stream output
Strip only the tag itself instead of dropping the whole token
Repair fragmented fenced code block starts in streaming modeReactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working