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]>
35 lines
1.3 KiB
TypeScript
35 lines
1.3 KiB
TypeScript
import { AiApi, Configuration } from 'hanzoai';
|
|
|
|
const ai = new AiApi(new Configuration({ accessToken: process.env.HANZO_API_KEY }));
|
|
const model = process.env.KAI_MODEL || 'kai'; // or "typesafe/jev-1.13"
|
|
|
|
// The SDK's HTTP error carries the request headers, the API key among them, so keep only status and body.
|
|
const { data: decision } = await ai
|
|
.postDecisions({
|
|
aiDecisionsRequest: {
|
|
model,
|
|
state: 'Customer inquiry: We are building an autonomous agent with 50 tools. Which model family should we use?',
|
|
questions: {
|
|
recommendation: {
|
|
type: 'choice',
|
|
instructions: 'Recommend appropriate model family',
|
|
criteria: {
|
|
zen_coder: 'programming, tool calling, and MCP tasks',
|
|
enso_ultra: 'general reasoning and planning',
|
|
kai: 'deterministic classification and policy gates',
|
|
},
|
|
},
|
|
},
|
|
},
|
|
})
|
|
.catch((e) => {
|
|
throw new Error(e.response ? `HTTP ${e.response.status} ${JSON.stringify(e.response.data)}` : e.message);
|
|
});
|
|
|
|
const ans = decision.answers.recommendation;
|
|
console.log(`Model: ${decision.model}`);
|
|
console.log(`Decision ID: ${decision.id}`);
|
|
console.log(`Choice: ${ans.choice}`);
|
|
console.log(`Confidence: ${ans.confidence}`);
|
|
console.log('Probabilities:', ans.probabilities);
|