fix: fallback tool_use parser handles both with/without space in type key
This commit is contained in:
16
llmcore.py
16
llmcore.py
@@ -517,13 +517,15 @@ class NativeOAISession:
|
|||||||
text_parts = [b["text"] for b in content_blocks if b.get("type") == "text"]
|
text_parts = [b["text"] for b in content_blocks if b.get("type") == "text"]
|
||||||
content = "\n".join(text_parts).strip()
|
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"]
|
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('}]'):
|
||||||
try:
|
_pat = next((p for p in ['[{"type":"tool_use"', '[{"type": "tool_use"'] if p in content), None)
|
||||||
idx = content.index('[{"type":"tool_use"')
|
if _pat:
|
||||||
raw = json.loads(content[idx:])
|
try:
|
||||||
tool_calls = [MockToolCall(b["name"], b.get("input", {}), id=b.get("id", "")) for b in raw if b.get("type") == "tool_use"]
|
idx = content.index(_pat)
|
||||||
content = content[:idx].strip()
|
raw = json.loads(content[idx:])
|
||||||
except: pass
|
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"<think(?:ing)?>(.*?)</think(?:ing)?>"; thinking = ''
|
think_pattern = r"<think(?:ing)?>(.*?)</think(?:ing)?>"; thinking = ''
|
||||||
think_match = re.search(think_pattern, content, re.DOTALL)
|
think_match = re.search(think_pattern, content, re.DOTALL)
|
||||||
if think_match:
|
if think_match:
|
||||||
|
|||||||
Reference in New Issue
Block a user