feat:截断优化

This commit is contained in:
2025-12-30 18:21:58 +08:00
parent dffb610408
commit f9fbdfef8a

View File

@@ -880,25 +880,6 @@ class AIChat(PluginBase):
if strip_thinking and cleaned and self._contains_thinking_markers(cleaned):
return ""
# 长度限制:避免刷屏/上下文污染
max_chars = output_cfg.get("max_reply_chars")
try:
max_chars = int(max_chars) if max_chars is not None else 0
except Exception:
max_chars = 0
if max_chars and max_chars > 0 and cleaned and len(cleaned) > max_chars:
trimmed = cleaned[:max_chars].rstrip()
# 尽量在句末截断,避免半句被硬切(仍保证不超过上限)
cut_idx = -1
for ch in ("", "", "", "!", "?", "\n"):
idx = trimmed.rfind(ch)
if idx > cut_idx:
cut_idx = idx
if cut_idx >= max_chars * 0.5:
trimmed = trimmed[:cut_idx + 1].rstrip()
cleaned = trimmed
if cleaned:
return cleaned