MCPcopy Index your code
hub / github.com/Sophomoresty/gemini-web2api / parse_tool_calls

Function parse_tool_calls

gemini_web2api.py:404–422  ·  view source on GitHub ↗

Extract tool_call blocks. Returns (clean_text, tool_calls_list).

(text: str)

Source from the content-addressed store, hash-verified

402
403
404def parse_tool_calls(text: str) -> tuple:
405 """Extract tool_call blocks. Returns (clean_text, tool_calls_list)."""
406 tool_calls = []
407 pattern = r'```tool_call\s*\n(.*?)\n```'
408 for match in re.findall(pattern, text, re.DOTALL):
409 try:
410 data = json.loads(match.strip())
411 tool_calls.append({
412 "id": f"call_{uuid.uuid4().hex[:8]}",
413 "type": "function",
414 "function": {
415 "name": data["name"],
416 "arguments": json.dumps(data.get("arguments", {}), ensure_ascii=False),
417 },
418 })
419 except (json.JSONDecodeError, KeyError):
420 pass
421 clean = re.sub(pattern, '', text, flags=re.DOTALL).strip()
422 return clean, tool_calls
423
424
425# ─── HTTP Handler ────────────────────────────────────────────────────────────

Callers 1

_call_geminiMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected