Download test_runtime.py from DevGwardo/minicpm5-toolcall-code: direct link, hf CLI and curl.
- Browser
- Download file 1.39 kB
-
https://huggingface.co/datasets/DevGwardo/minicpm5-toolcall-code/resolve/main/test_runtime.py
- Command line
-
hf download hf://datasets/DevGwardo/minicpm5-toolcall-code/test_runtime.py
-
curl -L -o test_runtime.py https://huggingface.co/datasets/DevGwardo/minicpm5-toolcall-code/resolve/main/test_runtime.py
1.39 kB
| """End-to-end check: call the merged GGUF through llama-server's OpenAI endpoint.""" | |
| import json | |
| import sys | |
| import requests | |
| URL = sys.argv[1] if len(sys.argv) > 1 else "http://127.0.0.1:8080/v1/chat/completions" | |
| tools = [ | |
| { | |
| "type": "function", | |
| "function": { | |
| "name": "get_weather", | |
| "description": "Get the current weather for a city", | |
| "parameters": { | |
| "type": "object", | |
| "properties": { | |
| "location": {"type": "string"}, | |
| "units": {"type": "string", "enum": ["celsius", "fahrenheit"]}, | |
| }, | |
| "required": ["location"], | |
| }, | |
| }, | |
| } | |
| ] | |
| cases = [ | |
| ("What's the weather in Paris in celsius?", True), | |
| ("What is the capital of France?", False), | |
| ] | |
| for q, expect in cases: | |
| r = requests.post( | |
| URL, | |
| json={ | |
| "messages": [{"role": "user", "content": q}], | |
| "tools": tools, | |
| "tool_choice": "auto", | |
| "temperature": 0, | |
| "max_tokens": 192, | |
| }, | |
| timeout=300, | |
| ) | |
| r.raise_for_status() | |
| msg = r.json()["choices"][0]["message"] | |
| calls = msg.get("tool_calls") or [] | |
| print(f"\nQ: {q}") | |
| print("expect call:", expect, "| got:", len(calls)) | |
| print(json.dumps(calls or msg.get("content", "")[:300], ensure_ascii=False, indent=2)) | |