mirror of
https://github.com/hanzoai/js-sdk.git
synced 2026-10-30 15:02:31 +00:00
POST /v1/decisions (DecisionsRequest, DecisionsResponse) arrives, and the trust descriptions the certclaims gate refused are gone with the stale tree that kept every dispatched run from reaching this step. Request bodies follow the cloud document's package-prefixed schema names; the three examples use them. Co-authored-by: Hanzo Dev <[email protected]>
38 lines
1.3 KiB
TypeScript
38 lines
1.3 KiB
TypeScript
// chat — one completion.
|
|
//
|
|
// POST /v1/chat/completions (post_chat_completions), the OpenAI-compatible
|
|
// route. The document states the route and not its shape, so the body rides on
|
|
// axios's `data` and the reply is read through a local type. When the schemas
|
|
// land both become generated and this file loses its casts.
|
|
//
|
|
// A model id is a string, so the wrong one type-checks perfectly and fails on
|
|
// the wire. `zen5` is served today; GET /v1/models is the only authority on the
|
|
// rest, which is what the quickstart in the README prints.
|
|
import { AiApi } from 'hanzoai';
|
|
import { config, fail } from '../client';
|
|
|
|
const model = process.env.HANZO_MODEL ?? 'zen5';
|
|
|
|
type Completion = {
|
|
model?: string;
|
|
choices?: Array<{ message?: { role?: string; content?: string } }>;
|
|
usage?: { total_tokens?: number };
|
|
};
|
|
|
|
async function main() {
|
|
const chat = new AiApi(config());
|
|
|
|
const { data } = await chat.postChatCompletions({
|
|
openaiChatCompletionRequest: {
|
|
model,
|
|
messages: [{ role: 'user', content: 'Say hello in exactly five words.' }],
|
|
},
|
|
});
|
|
|
|
const reply = data as unknown as Completion;
|
|
console.log(reply.choices?.[0]?.message?.content ?? '(no content)');
|
|
console.log(` ${reply.model ?? model} · ${reply.usage?.total_tokens ?? '?'} tokens`);
|
|
}
|
|
|
|
main().catch(fail);
|