Skip to content

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

Merged
Soulter merged 2 commits into
AstrBotDevs:masterfrom
Blueteemo:fix/strip-segmented-reply-blank-lines
May 28, 2026
Merged

fix: strip segment text to remove extra blank lines in segmented reply#8304
Soulter merged 2 commits into
AstrBotDevs:masterfrom
Blueteemo:fix/strip-segmented-reply-blank-lines

Conversation

@Blueteemo
Copy link
Copy Markdown
Contributor

@Blueteemo Blueteemo commented May 23, 2026

修复说明

修复分段回复时 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 auto-assign Bot requested review from Soulter and anka-afk May 23, 2026 13:58
@dosubot 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 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.

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 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.

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 Outdated
@Blueteemo

This comment was marked as outdated.

@Dt8333
Copy link
Copy Markdown
Member

Dt8333 commented May 27, 2026

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

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

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

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

这里strip实际上的确调用了两次:判断时一次,构造Plain一次。
提取后应当会少许改善性能。个人推荐接受修改。

PR没问题。

@Blueteemo Blueteemo force-pushed the fix/strip-segmented-reply-blank-lines branch from 72e1990 to 8cfb5de Compare May 27, 2026 04:40
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label May 27, 2026
@Soulter Soulter force-pushed the master branch 2 times, most recently from 7c5d6bd to 0bcc662 Compare May 28, 2026 16:47
@Soulter Soulter merged commit a4c4a7d into AstrBotDevs:master May 28, 2026
21 checks passed
@Blueteemo Blueteemo deleted the fix/strip-segmented-reply-blank-lines branch May 28, 2026 16:55
Soulter pushed a commit that referenced this pull request May 28, 2026
#8304)

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

Fixes #8300

* refactor: optimize seg.strip() per PR review suggestion
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 lgtm This PR has been approved by a maintainer size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants