feat: intercept literal [tool_calls] arrays in generated text and map to actual function calls
This commit is contained in:
@@ -182,6 +182,20 @@ def _json_tool_candidate_from_text(text: str) -> dict[str, Any] | None:
|
||||
return None
|
||||
|
||||
|
||||
def _extract_tool_calls_from_text(text: str) -> list[dict[str, Any]] | None:
|
||||
text = text.strip()
|
||||
match = re.search(r"\[tool_calls\]\s*(\[.*\])", text, re.DOTALL)
|
||||
if not match:
|
||||
return None
|
||||
try:
|
||||
parsed = json.loads(match.group(1))
|
||||
if isinstance(parsed, list) and len(parsed) > 0 and isinstance(parsed[0], dict):
|
||||
return parsed
|
||||
except Exception:
|
||||
pass
|
||||
return None
|
||||
|
||||
|
||||
def _tool_code_single_arg_name(
|
||||
tools: list[dict[str, Any]] | None, forced_tool_name: str
|
||||
) -> str | None:
|
||||
|
||||
Reference in New Issue
Block a user