fix: fallback tool_use parser handles both with/without space in type key
This commit is contained in:
@@ -517,9 +517,11 @@ 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:
|
||||
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('[{"type":"tool_use"')
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user