From f0dea091239632cb296dec70e8e472153c0e4c1c Mon Sep 17 00:00:00 2001 From: Liang Jiaqing Date: Sun, 29 Mar 2026 21:04:34 +0800 Subject: [PATCH] fix: fallback tool_use parser handles both with/without space in type key --- llmcore.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/llmcore.py b/llmcore.py index 3aa1e93..e834405 100644 --- a/llmcore.py +++ b/llmcore.py @@ -517,13 +517,15 @@ class NativeOAISession: text_parts = [b["text"] for b in content_blocks if b.get("type") == "text"] content = "\n".join(text_parts).strip() tool_calls = [MockToolCall(b["name"], b.get("input", {}), id=b.get("id", "")) for b in content_blocks if b.get("type") == "tool_use"] - if len(tool_calls) == 0 and content.endswith('}]') and '[{"type":"tool_use"' in content: - try: - idx = content.index('[{"type":"tool_use"') - raw = json.loads(content[idx:]) - tool_calls = [MockToolCall(b["name"], b.get("input", {}), id=b.get("id", "")) for b in raw if b.get("type") == "tool_use"] - content = content[:idx].strip() - except: pass + if len(tool_calls) == 0 and content.endswith('}]'): + _pat = next((p for p in ['[{"type":"tool_use"', '[{"type": "tool_use"'] if p in content), None) + if _pat: + try: + idx = content.index(_pat) + raw = json.loads(content[idx:]) + tool_calls = [MockToolCall(b["name"], b.get("input", {}), id=b.get("id", "")) for b in raw if b.get("type") == "tool_use"] + content = content[:idx].strip() + except: pass think_pattern = r"(.*?)"; thinking = '' think_match = re.search(think_pattern, content, re.DOTALL) if think_match: