Files
zeekay 8bf2e0cfab The model card is a card: the family hero, a links row, facts in a grid, the call in four tabs, the price in a line
Every model page opens in the family pages' frame (the name, one line, two
actions) over a links row: the model's GitHub and Hugging Face, from its
catalogue record and kept only when the build reads a 200, and this site's
leaderboard and benchmarks for its family. Facts are a grid of labelled cells;
a Kai page sets what ships today beside the Kai-1.7 target, each its own
column. The quick start is a segmented control over TypeScript, Python, cURL
and Go, in the shape the model's endpoint takes: a decision model's are the
/v1/decisions severity call, each run against production and answered (the
list-shaped body the card printed was refused 422). The guest key, which
api.hanzo.ai no longer accepts, gives way to Get an API key. /kai's first action reads Get decisions, as the card's does.
2026-10-17 03:57:20 -07:00

241 lines
6.4 KiB
TypeScript

/**
* The quick start a model's page prints, in the shape its endpoint takes. A
* model whose output is a decision (`outputs: ["decision"]` on GET /v1/models:
* Kai, its opt-in ids and Jev) is called at POST /v1/decisions with
* `{ model, state, questions }`, never through chat completions; every other
* model keeps the chat-completions call.
*
* The decision is /kai's: a severity choice over an incident state. The
* TypeScript and Python calls are the cookbook's SDK calls (hanzoai/kai, the
* `hanzoai` package on npm and PyPI); Go is plain net/http, as the cookbook's
* is, because the Go SDK refuses a choice question with named criteria. Each
* was run against production before it shipped, and answered a decision.
*/
export interface Examples {
ts: string
py: string
curl: string
go: string
}
const STATE = 'checkout 5xx at 14%'
const INSTRUCTIONS = 'How severe is this incident?'
const CRITERIA = [
['low', 'cosmetic or internal; no customer is affected'],
['high', 'some customers are blocked from finishing a task'],
['critical', 'every customer is blocked and no revenue comes in'],
] as const
function decisions(id: string): Examples {
const ts = `// npm install hanzoai
import { AiApi, Configuration } from 'hanzoai'
const ai = new AiApi(new Configuration({ accessToken: process.env.HANZO_API_KEY }))
const { data: decision } = await ai.postDecisions({
aiDecisionsRequest: {
model: '${id}',
state: { incident: '${STATE}' },
questions: {
severity: {
type: 'choice',
instructions: '${INSTRUCTIONS}',
criteria: {
${CRITERIA.map(([k, v]) => ` ${k}: '${v}',`).join('\n')}
},
},
},
},
})
const { choice, probabilities } = decision.answers.severity
console.log(choice, probabilities)`
const py = `# pip install hanzoai
import os
from hanzoai.cloud import ApiClient, Configuration
from hanzoai.cloud.api import AiApi
from hanzoai.cloud.models.ai_decisions_request import AiDecisionsRequest
ai = AiApi(ApiClient(Configuration(access_token=os.environ["HANZO_API_KEY"])))
decision = ai.post_decisions(AiDecisionsRequest.from_dict({
"model": "${id}",
"state": {"incident": "${STATE}"},
"questions": {
"severity": {
"type": "choice",
"instructions": "${INSTRUCTIONS}",
"criteria": {
${CRITERIA.map(([k, v]) => ` "${k}": "${v}",`).join('\n')}
},
},
},
}))
severity = decision.answers["severity"]
print(severity.choice, severity.probabilities)`
const curl = `curl -sS --fail-with-body https://api.hanzo.ai/v1/decisions \\
-H "Authorization: Bearer $HANZO_API_KEY" \\
-H "Content-Type: application/json" \\
-d '{
"model": "${id}",
"state": { "incident": "${STATE}" },
"questions": {
"severity": {
"type": "choice",
"instructions": "${INSTRUCTIONS}",
"criteria": {
${CRITERIA.map(([k, v], i) => ` "${k}": "${v}"${i < CRITERIA.length - 1 ? ',' : ''}`).join('\n')}
}
}
}
}'`
const go = `// net/http: the Go SDK refuses a choice question with named criteria.
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"os"
)
func main() {
if err := run(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
func run() error {
body, err := json.Marshal(map[string]any{
"model": "${id}",
"state": map[string]string{"incident": "${STATE}"},
"questions": map[string]any{
"severity": map[string]any{
"type": "choice",
"instructions": "${INSTRUCTIONS}",
"criteria": map[string]string{
${CRITERIA.map(([k, v]) => ` ${`"${k}":`.padEnd(11)} "${v}",`).join('\n')}
},
},
},
})
if err != nil {
return err
}
req, err := http.NewRequest("POST", "https://api.hanzo.ai/v1/decisions", bytes.NewReader(body))
if err != nil {
return err
}
req.Header.Set("Authorization", "Bearer "+os.Getenv("HANZO_API_KEY"))
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
out, err := io.ReadAll(resp.Body)
if err != nil {
return err
}
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("HTTP %d: %s", resp.StatusCode, out)
}
var decision struct {
Answers map[string]struct {
Choice string \`json:"choice"\`
Probabilities map[string]float64 \`json:"probabilities"\`
} \`json:"answers"\`
}
if err := json.Unmarshal(out, &decision); err != nil {
return err
}
severity := decision.Answers["severity"]
fmt.Println(severity.Choice, severity.Probabilities)
return nil
}`
return { ts, py, curl, go }
}
function completions(id: string): Examples {
const ts = `import OpenAI from 'openai'
const client = new OpenAI({
apiKey: process.env.HANZO_API_KEY,
baseURL: 'https://api.hanzo.ai/v1'
})
const response = await client.chat.completions.create({
model: '${id}',
messages: [{ role: 'user', content: 'Hello!' }]
})
console.log(response.choices[0].message.content)`
const py = `from openai import OpenAI
client = OpenAI(
api_key=os.environ["HANZO_API_KEY"],
base_url="https://api.hanzo.ai/v1"
)
response = client.chat.completions.create(
model="${id}",
messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)`
const curl = `curl https://api.hanzo.ai/v1/chat/completions \\
-H "Content-Type: application/json" \\
-H "Authorization: Bearer $HANZO_API_KEY" \\
-d '{
"model": "${id}",
"messages": [{"role": "user", "content": "Hello!"}]
}'`
const go = `package main
import (
"context"
"fmt"
"os"
"github.com/sashabaranov/go-openai"
)
func main() {
cfg := openai.DefaultConfig(os.Getenv("HANZO_API_KEY"))
cfg.BaseURL = "https://api.hanzo.ai/v1"
client := openai.NewClientWithConfig(cfg)
resp, _ := client.CreateChatCompletion(context.Background(),
openai.ChatCompletionRequest{
Model: "${id}",
Messages: []openai.ChatCompletionMessage{
{Role: openai.ChatMessageRoleUser, Content: "Hello!"},
},
},
)
fmt.Println(resp.Choices[0].Message.Content)
}`
return { ts, py, curl, go }
}
/** The four calls a model's page prints, in the shape its endpoint takes. */
export function examples(model: { id: string; endpoint?: string }): Examples {
return model.endpoint === '/v1/decisions' ? decisions(model.id) : completions(model.id)
}