From e4116bf1df40ea1884ed8cdf30bfb81c7ed1333b Mon Sep 17 00:00:00 2001 From: weijia <126332148+wjl2023@users.noreply.github.com> Date: Sun, 26 Apr 2026 23:16:43 +0800 Subject: [PATCH] fix(fsapp): show truncated tail instead of silent "..." fallback (#186) When model output contains only stripped tags, surface warning + last 300 chars instead of silent "...". --- frontends/fsapp.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/frontends/fsapp.py b/frontends/fsapp.py index cce08fb0..c7f9fa1d 100644 --- a/frontends/fsapp.py +++ b/frontends/fsapp.py @@ -34,10 +34,13 @@ MEDIA_DIR = os.path.join(TEMP_DIR, "feishu_media") os.makedirs(MEDIA_DIR, exist_ok=True) +_TRUNC_TAIL = 300 # 截断兜底时保留原文尾部字符数 + + def _clean(text): for pat in _TAG_PATS: - text = re.sub(pat, "", text, flags=re.DOTALL) - return re.sub(r"\n{3,}", "\n\n", text).strip() or "..." + text = re.sub(pat, "", text or "", flags=re.DOTALL) + return re.sub(r"\n{3,}", "\n\n", text).strip() def _extract_files(text): @@ -49,7 +52,11 @@ def _strip_files(text): def _display_text(text): - return _strip_files(_clean(text)) or "..." + cleaned = _strip_files(_clean(text)) + if cleaned: + return cleaned + tail = (text or "").strip()[-_TRUNC_TAIL:] + return "⚠️ 模型输出被截断或为空" + (f"\n…{tail}" if tail else "") def _to_allowed_set(value):