# -*- coding: utf-8 -*- """Проверка нативного tool use (function calling) у моделей пула DeepAI через new-api. Запуск на проде: python3 /tmp/tooltest.py [model1 model2 ...] """ import json import sys import urllib.request BASE = "http://127.0.0.1:48005/v1/chat/completions" TOK = open("/tmp/tok.txt").read().strip() TOOLS = [{ "type": "function", "function": { "name": "get_weather", "description": "Get current weather for a city", "parameters": { "type": "object", "properties": {"city": {"type": "string", "description": "city name"}}, "required": ["city"], }, }, }] DEFAULT_MODELS = [ "claude-opus-5-5", "claude-sonnet-5-5", "gpt-6.1-sol", "gpt-6-astra", "gemini-4-argon", "gemini-4-hydrogen", "kimi-k3.1-pro", "glm-5.3", "minimax-m3", "qwen-3.8-max-prime", "glm-5.3-flash", "gpt-6-luna", "deepseek-v4.1-flash", "mimo-2.6-flash", "qwen-3.8-flash", "minimax-m3.1-flash", ] def post(body, timeout=180): req = urllib.request.Request( BASE, data=json.dumps(body).encode(), headers={"Authorization": "Bearer " + TOK, "Content-Type": "application/json"}) with urllib.request.urlopen(req, timeout=timeout) as r: return json.loads(r.read().decode()) def test(model): body = { "model": model, "messages": [{"role": "user", "content": "What's the weather in Paris? Use the tool."}], "tools": TOOLS, "tool_choice": "auto", "max_tokens": 250, } try: d = post(body) except Exception as e: return "ERR", str(e)[:90] ch = (d.get("choices") or [{}])[0] msg = ch.get("message") or {} tc = msg.get("tool_calls") or [] if not tc: return "NO_TOOL", "finish=%s content=%r" % (ch.get("finish_reason"), (msg.get("content") or "")[:60]) fn = tc[0].get("function") or {} name = fn.get("name") args = fn.get("arguments") # round-trip: отдаём результат инструмента и ждём финальный текст rt = "n/a" try: body2 = dict(body) body2["messages"] = body["messages"] + [ {"role": "assistant", "content": None, "tool_calls": tc}, {"role": "tool", "tool_call_id": tc[0].get("id", "call_1"), "content": json.dumps({"city": "Paris", "temp_c": 11, "sky": "cloudy"})}, ] body2.pop("tools", None) d2 = post(body2) c2 = ((d2.get("choices") or [{}])[0].get("message") or {}).get("content") or "" rt = "rt_ok" if c2.strip() else "rt_empty" except Exception as e: rt = "rt_err:" + str(e)[:40] return "TOOL", "%s(%s) %s" % (name, args, rt) def main(): models = sys.argv[1:] or DEFAULT_MODELS res = {} for m in models: st, info = test(m) res[m] = st print("%-22s %-8s %s" % (m, st, info), flush=True) ok = [m for m, s in res.items() if s == "TOOL"] print("\nTOOL_SUPPORT %d/%d: %s" % (len(ok), len(res), ",".join(ok))) if __name__ == "__main__": main()