Files
zooqueenandHanzo Dev b00044ece2 Check each recipe's answer against the obvious one
Every runner printed whatever came back and exited 0, and fell back to a
second raw HTTP call when the SDK import failed. Now each recipe carries
expect.json, the answers a careful reader gives on its own input: a list of
acceptable options for a choice, of level indices for a score, true or false
for a noul. run.py and run.ts send request.json through the SDK, print every
answer, and exit 1 when a checked one is wrong. A question with no obvious
answer on its input is printed and not checked.

Recipes 09 and 11 had no input with an obvious answer, so each state gains
the one fact that decides it. The recipe READMEs describe what each recipe
asks instead of capabilities it never exercised, and copy the request and
checked answers from the two JSON files.

Co-authored-by: Hanzo Dev <[email protected]>
2026-10-09 17:39:13 -07:00

41 lines
1.6 KiB
Python

"""Send request.json to Kai with the hanzoai SDK and check each answer against expect.json."""
import json
import os
import sys
from pathlib import Path
from hanzoai.cloud import ApiClient, Configuration
from hanzoai.cloud.api import AiApi
from hanzoai.cloud.models.ai_decisions_request import AiDecisionsRequest
here = Path(__file__).parent
body = json.loads((here / "request.json").read_text())
body["model"] = os.environ.get("KAI_MODEL", body["model"])
expect = json.loads((here / "expect.json").read_text())
ai = AiApi(ApiClient(Configuration(access_token=os.environ["HANZO_API_KEY"])))
decision = ai.post_decisions(AiDecisionsRequest.from_dict(body))
print(f"{decision.id} {decision.model}: {decision.usage.input_tokens} input tokens, {decision.latency_ms:.0f} ms")
wrong = 0
for name in sorted(set(expect) - set(decision.answers)):
wrong += 1
print(f" FAIL {name}: expected an answer, got none")
for name, a in decision.answers.items():
if a.type == "noul":
got, said = a.noul > 0.5, f"P(true) {a.noul:.3f}"
elif a.type == "score":
top = max(a.probabilities, key=a.probabilities.get)
got, said = int(top), f"level {top} '{a.legend[top]}' at {a.probabilities[top]:.3f} (score {a.score:.2f})"
else:
got, said = a.choice, f"{a.choice} at {a.answer_confidence:.3f}"
want = expect.get(name)
if want is None:
print(f" ---- {name}: {said} (not checked: no obvious answer on this input)")
elif got == want if isinstance(want, bool) else got in want:
print(f" pass {name}: {said}")
else:
wrong += 1
print(f" FAIL {name}: {said}, expected {want}")
sys.exit(1 if wrong else 0)