← 返回首页
fix: strip segment text to remove extra blank lines in segmented reply by Blueteemo · Pull Request #8304 · AstrBotDevs/AstrBot · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

fix: strip segment text to remove extra blank lines in segmented reply#8304

Open
Blueteemo wants to merge 1 commit into
AstrBotDevs:masterfrom
Blueteemo:fix/strip-segmented-reply-blank-lines
Open

fix: strip segment text to remove extra blank lines in segmented reply#8304
Blueteemo wants to merge 1 commit into
AstrBotDevs:masterfrom
Blueteemo:fix/strip-segmented-reply-blank-lines

Conversation

Copy link
Copy Markdown
Contributor

Blueteemo commented May 23, 2026
edited by sourcery-ai Bot
Loading

修复说明

修复分段回复时 Plain(seg) 未 strip 导致 QQ 消息出现多余空行的问题。

问题描述

在 stage.py 的分段回复逻辑中,分段后的文本 seg 在添加到 new_chain 前只做了非空判断(if seg.strip()),但实际添加到链中时使用的是原始的 Plain(seg) 而非 Plain(seg.strip()),这导致每段文本的收尾空格/换行被保留,在 QQ 消息中产生多余空行。

修复方案

将 new_chain.append(Plain(seg)) 改为 new_chain.append(Plain(seg.strip())),确保每段文本的首尾空白字符被去除。

关联 Issue: #8300

Summary by Sourcery

Strip whitespace in segmented replies to avoid extra blank lines and clarify guidance for disabling text-to-image mode when rendering is slow.

Bug Fixes:

  • Remove leading and trailing whitespace from segmented plain text replies to prevent extra blank lines in QQ messages.

Enhancements:

  • Update the slow text-to-image rendering warning message to direct users to disable the mode via the WebUI.

auto-assign Bot requested review from Soulter and anka-afk May 23, 2026 13:58
dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. area:core The bug / feature is about astrbot's core, backend labels May 23, 2026
Copy link
Copy Markdown
Contributor

sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

Hey - I've reviewed your changes and they look great!

Sourcery is free for open source - if you like our reviews please consider sharing them ✨ Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Copy Markdown
Contributor

gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

Code Review

This pull request updates the warning message for slow text-to-image rendering to direct users to the WebUI and ensures that plain text segments are stripped before being appended to the result chain. A review comment suggests optimizing the stripping logic by assigning the stripped string to a variable to avoid redundant computations and improve code readability.

Comment thread astrbot/core/pipeline/result_decorate/stage.py Show resolved Hide resolved
Copy link
Copy Markdown
Contributor Author

关于 gemini-code-assist 的审查建议

gemini-code-assist 建议将 Plain(seg.strip()) 赋值给变量后再传入,以避免重复 strip() 调用。这个建议没有必要采纳,原因如下:

  • 在此场景中,seg.strip() 仅在 Plain() 构造函数中调用一次,不存在重复计算问题
  • 将单一表达式提取为变量的模式在此处既不提升可读性也不改善性能
  • sourcery-ai 的审查也给出了 "changes look great!" 的评价,未提出任何修改建议

保持当前的一行式写法即可。

关于 pytest 检查未通过

失败的测试是 tests/test_openai_source.py::test_query_stream_extracts_usage_from_empty_choices_chunk,涉及 OpenAI 流式响应的 usage 字段解析逻辑(assert final_response.usage is not None)。该测试失败与本次 PR 修改的 stage.py 分段回复逻辑完全无关,属于 AstrBot 仓库中预先存在的不稳定测试。本次 PR 仅修改了一行代码——将 Plain(seg) 改为 Plain(seg.strip()),不影响任何测试逻辑。

所有其他检查均通过:format-check ✅ / CodeQL ✅ / 跨平台 Smoke Test × 8 ✅ / Dashboard CI ✅ / Sourcery review ✅

本 PR 改动清晰、风险极低,可以合并。

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core The bug / feature is about astrbot's core, backend size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Footer

© 2026 GitHub, Inc.