-
Notifications
You must be signed in to change notification settings - Fork 19
feat: 避免清理掉LLM回复分割标记 #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdjusts special-block protection and system-format cleaning logic so that LLM-specific reply split markers like [SPLIT] are preserved when split_mode is 'llm', avoiding them being re-protected or stripped by generic cleanup. Flow diagram for filter_system_format_content cleaning with LLM split_modeflowchart TD
A[Start filter_system_format_content] --> B[Input content]
B --> C[Apply system format specific cleanup]
C --> D{Is split_mode llm?}
D -->|Yes| F[Skip generic [.*?] removal to preserve markers like [SPLIT]]
D -->|No| E[Remove all patterns matching [.*?] using regex]
E --> F
F --> G[Remove @<...> patterns using regex]
G --> H[Return cleaned_content]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey - I've found 1 issue, and left some high level feedback:
- Consider extracting the
[SPLIT]marker into a shared constant or intoresponse_splitterconfig instead of hardcoding the string inprotect_special_blocks, so the split token stays consistent across the codebase. - The condition
if "__SPECIAL_" in match or global_config.response_splitter.split_mode == "llm" and match == "[SPLIT]":relies on operator precedence; adding parentheses or assigning intermediate booleans would improve readability and reduce the chance of future mistakes when editing this logic.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider extracting the `[SPLIT]` marker into a shared constant or into `response_splitter` config instead of hardcoding the string in `protect_special_blocks`, so the split token stays consistent across the codebase.
- The condition `if "__SPECIAL_" in match or global_config.response_splitter.split_mode == "llm" and match == "[SPLIT]":` relies on operator precedence; adding parentheses or assigning intermediate booleans would improve readability and reduce the chance of future mistakes when editing this logic.
## Individual Comments
### Comment 1
<location> `src/chat/utils/utils.py:967` </location>
<code_context>
# 在处理完回复格式后,再清理其他简单的格式
# 新增:移除所有残余的 [...] 格式,例如 [at=...] 等
- cleaned_content = re.sub(r"\[.*?\]", "", cleaned_content)
+ if global_config.response_splitter.split_mode != "llm":
+ cleaned_content = re.sub(r"\[.*?\]", "", cleaned_content)
# 移除@格式:@<xxx>
</code_context>
<issue_to_address>
**question (bug_risk):** Guarding the bracket-stripping on `split_mode` is correct but may hide unexpected formats in LLM mode.
Because we now skip `"[... ]"` cleanup when `split_mode == "llm"`, any other bracketed control sequences (not just the splitter markers) will appear in the final output. If you only need to retain the splitter markers, consider narrowing the condition or regex so that only those specific patterns are preserved, while other bracketed metadata is still stripped.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
LuisKlee
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
6786d4f to
1a8f7e2
Compare
1a8f7e2 to
9bdcdfe
Compare

Summary by Sourcery
Preserve LLM response splitter markers when protecting and cleaning chat content.
New Features:
Bug Fixes: