"""Verify a local Inkling server returns a structured tool call.""" import argparse import json from time import monotonic from urllib.request import Request, urlopen FUNCTION = { "name": "record_status", "description": "Record a status value.", "parameters": { "type": "object", "properties": {"status": {"type": "string"}}, "required": ["status"], "additionalProperties": False, }, } EXPECTED = {"status": "inkling adapter ready"} PROMPT = 'Call record_status once, with status exactly "inkling adapter ready".' def main() -> None: parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--port", type=int, required=True) parser.add_argument("--model", required=True) parser.add_argument("--effort", choices=("none", "high"), required=True) parser.add_argument("--protocol", choices=("chat", "responses"), default="chat") args = parser.parse_args() common = {"model": args.model, "temperature": 0, "stream": False} if args.protocol == "chat": endpoint = "chat/completions" payload = { **common, "messages": [{"role": "user", "content": PROMPT}], "tools": [{"type": "function", "function": FUNCTION}], "max_tokens": 2048, "chat_template_kwargs": {"reasoning_effort": args.effort}, } else: endpoint = "responses" payload = { **common, "input": PROMPT, "tools": [{"type": "function", **FUNCTION}], "max_output_tokens": 2048, "reasoning": {"effort": args.effort}, } request = Request( f"http://127.0.0.1:{args.port}/v1/{endpoint}", data=json.dumps(payload).encode(), headers={"Content-Type": "application/json"}, ) start = monotonic() with urlopen(request, timeout=90) as response: result = json.load(response) if args.protocol == "chat": calls = [ item["function"] for item in result["choices"][0]["message"].get("tool_calls", []) ] else: calls = [item for item in result["output"] if item["type"] == "function_call"] actual = [(call["name"], json.loads(call["arguments"])) for call in calls] if actual != [(FUNCTION["name"], EXPECTED)]: raise ValueError(f"Unexpected tool calls: {actual!r}") print(json.dumps({ "protocol": args.protocol, "reasoning_effort": args.effort, "structured_tool_call_passed": True, "generated_tokens": result.get("usage", {}).get( "completion_tokens" if args.protocol == "chat" else "output_tokens" ), "wall_seconds": round(monotonic() - start, 3), }, indent=2)) if __name__ == "__main__": main()