fix: strip stray trailing } from reply when LLM botches JSON
This commit is contained in:
parent
5f0c419986
commit
6f717f1d13
@ -164,6 +164,8 @@ def _parse(raw):
|
|||||||
# Strip any {"action":"tool_call"...} JSON fragments from reply text
|
# Strip any {"action":"tool_call"...} JSON fragments from reply text
|
||||||
import re as _re2
|
import re as _re2
|
||||||
clean = _re2.sub(r'\s*\{[^}]*"action"\s*:\s*"tool_call"[^}]*\}\s*', ' ', raw).strip()
|
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}
|
return {"action":"reply","message":clean or raw}
|
||||||
|
|
||||||
def _w_text(t): return {"widgettype":"Text","options":{"text":t,"css":"agent-text","halign":"left"}}
|
def _w_text(t): return {"widgettype":"Text","options":{"text":t,"css":"agent-text","halign":"left"}}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user