mirror of
https://github.com/hanzoai/kai.git
synced 2026-10-17 11:18:06 +00:00
The Python and TypeScript examples imported a client that hanzoai does not ship: `from hanzoai import Hanzo` and `import Hanzo from 'hanzoai'` both fail on 8.5.704, so none of them ran. They now call AiApi.post_decisions / postDecisions, which builds every question shape the cookbook uses (choice with object or list criteria, score, noul), and package.json and requirements.txt pin the version that was checked. The noul examples read action.act_probability, which the API does not return; they print P(true) only. A failed TypeScript call now rethrows only its HTTP status and body, because the axios error holds the request's Authorization header and an uncaught one prints it. The raw HTTP clients drop model ids the API refuses and exit non-zero on failure. Co-authored-by: Hanzo Dev <[email protected]>
42 lines
1.5 KiB
Python
42 lines
1.5 KiB
Python
# The same call over plain HTTP with requests, for code that does not take the SDK.
|
|
import os
|
|
import requests
|
|
|
|
api_key = os.environ.get("HANZO_API_KEY")
|
|
if not api_key:
|
|
raise ValueError("HANZO_API_KEY environment variable is required")
|
|
|
|
model = os.environ.get("KAI_MODEL", "kai") # or "typesafe/jev-1.13"
|
|
url = os.environ.get("HANZO_BASE_URL", "https://api.hanzo.ai").rstrip("/") + "/v1/decisions"
|
|
|
|
payload = {
|
|
"model": model,
|
|
"state": {"task": "fix memory leak in postgres connection pool"},
|
|
"questions": {
|
|
"model_tier": {
|
|
"type": "choice",
|
|
"instructions": "What model tier should be routed to?",
|
|
"criteria": {
|
|
"fast": "simple typo or formatting fixes",
|
|
"standard": "standard feature implementation",
|
|
"frontier": "complex reasoning, concurrency, and memory management"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
resp = requests.post(url, headers={"Authorization": f"Bearer {api_key}"}, json=payload, timeout=30)
|
|
resp.raise_for_status()
|
|
data = resp.json()
|
|
|
|
print(f"Model: {data.get('model')}")
|
|
print("Decision ID:", data["id"])
|
|
print(f"Latency: {data.get('latency_ms', 0):.1f}ms")
|
|
answer = data["answers"]["model_tier"]
|
|
print("Selected Choice:", answer["choice"])
|
|
print(f"Confidence: {answer.get('confidence', 0):.4f}")
|
|
if "probabilities" in answer and answer["probabilities"]:
|
|
print("Probabilities:")
|
|
for opt, prob in answer["probabilities"].items():
|
|
print(f" - {opt}: {prob * 100:.2f}%")
|