From 6f717f1d13b05f6694d7d571647231d15e51799e Mon Sep 17 00:00:00 2001 From: ymq Date: Mon, 10 Aug 2026 08:31:35 +0800 Subject: [PATCH] fix: strip stray trailing } from reply when LLM botches JSON --- wwwroot/api/cockpit_chat.dspy | 2 ++ 1 file changed, 2 insertions(+) diff --git a/wwwroot/api/cockpit_chat.dspy b/wwwroot/api/cockpit_chat.dspy index 295d428..7426b0e 100644 --- a/wwwroot/api/cockpit_chat.dspy +++ b/wwwroot/api/cockpit_chat.dspy @@ -164,6 +164,8 @@ def _parse(raw): # Strip any {"action":"tool_call"...} JSON fragments from reply text import re as _re2 clean = _re2.sub(r'\s*\{[^}]*"action"\s*:\s*"tool_call"[^}]*\}\s*', ' ', raw).strip() + # Remove stray trailing braces from malformed JSON attempts + clean = clean.rstrip().rstrip('}').strip() return {"action":"reply","message":clean or raw} def _w_text(t): return {"widgettype":"Text","options":{"text":t,"css":"agent-text","halign":"left"}}