Counsel-27B / runtime /smoke_api.py
sakasurya's picture
Counsel-27B
77f47f9
Raw History Blame Contribute Delete
2.09 kB
"""API smoke test against a running Counsel server: identity, thinking split, direct mode, tool call.
usage: python smoke_api.py [base_url] [model]
"""
import json
import sys
import urllib.request
URL = sys.argv[1] if len(sys.argv) > 1 else "http://127.0.0.1:8000/v1"
MODEL = sys.argv[2] if len(sys.argv) > 2 else "counsel-27b"
def chat(messages, **kw):
body = {"model": MODEL, "messages": messages, "max_tokens": 4096, "temperature": 0.6} | kw
req = urllib.request.Request(URL + "/chat/completions", json.dumps(body).encode(), {"Content-Type": "application/json"})
return json.load(urllib.request.urlopen(req, timeout=900))["choices"][0]
ok = True
c = chat([{"role": "user", "content": "Who are you and who built you? One sentence."}],
chat_template_kwargs={"enable_thinking": False})
ans = c["message"]["content"]
print("identity:", ans.strip()[:200])
ok &= "Counsel" in ans and "Qwen" not in ans
c = chat([{"role": "user", "content": "Is a 'condition' or a 'warranty' breach grounds to terminate a contract under English law? Two sentences."}],
chat_template_kwargs={"enable_thinking": True, "reasoning_effort": "low"})
r, a = c["message"].get("reasoning_content") or c["message"].get("reasoning") or "", c["message"]["content"] or ""
print(f"thinking: reasoning {len(r)} chars, answer: {a.strip()[:200]}")
ok &= len(r) > 0 and len(a) > 0 and "<think>" not in a
tools = [{"type": "function", "function": {"name": "search_documents", "description": "Full-text search over the matter's documents.",
"parameters": {"type": "object", "properties": {"query": {"type": "string"}}, "required": ["query"]}}}]
c = chat([{"role": "user", "content": "Find every termination-for-convenience clause in the supply agreements."}], tools=tools,
chat_template_kwargs={"enable_thinking": False})
calls = c["message"].get("tool_calls") or []
print("tool call:", [(t["function"]["name"], t["function"]["arguments"]) for t in calls])
ok &= bool(calls) and calls[0]["function"]["name"] == "search_documents"
print("API_SMOKE", "PASS" if ok else "FAIL")