Files
zooqueenandHanzo Dev 45e8e6c18f Fail the curl, Go and Rust examples on an HTTP error
The curl scripts piped any response into jq and exited 0, so a refused key
read as success; they now run under set -euo pipefail with --fail-with-body.
noul.sh sent "spent 2,000" because the shell expanded $1 inside "$12,000".

Go returns errors instead of panicking and gets a go.mod so `go run .` and
the CI toolchain find it. Rust reports a missing key as an error rather than a
panic and uses rustls, so it builds without system OpenSSL. Both say in one
line why they use plain HTTP: go-sdk v8.5.623 refuses a choice question with
named criteria, and hanzo-client 8.5.156 has no /v1/decisions.

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

35 lines
1.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# Choice classification example with Kai / Jev
# Usage:
# ./choice.sh # uses default model "kai"
# KAI_MODEL="typesafe/jev-1.13" ./choice.sh # uses Jev
set -euo pipefail
MODEL="${KAI_MODEL:-kai}"
API_KEY="${HANZO_API_KEY:-${1:-}}"
if [ -z "$API_KEY" ]; then
echo "Error: HANZO_API_KEY is required (set env var or pass as first argument)" >&2
exit 1
fi
curl -sS --fail-with-body -X POST https://api.hanzo.ai/v1/decisions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d "{
\"model\": \"$MODEL\",
\"state\": \"The user submitted a support ticket asking: How do I change the billing credit card on our organization account?\",
\"questions\": {
\"department\": {
\"type\": \"choice\",
\"instructions\": \"Route this ticket to the right department\",
\"criteria\": {
\"billing\": \"credit card, invoices, receipts, payment methods\",
\"technical\": \"API errors, bugs, downtime, latency\",
\"sales\": \"upgrades, enterprise quotes, annual contracts\"
}
}
}
}" | jq .