// src/arkor/trainer.ts
import { createTrainer } from "arkor";
const TRIAGE_SCHEMA: Record<string, unknown> = {
type: "object",
properties: {
category: { type: "string" },
urgency: { type: "string", enum: ["low", "medium", "high"] },
summary: { type: "string" },
nextAction: { type: "string" },
},
required: ["category", "urgency", "summary", "nextAction"],
additionalProperties: false,
};
interface TriageOutput {
category: string;
urgency: "low" | "medium" | "high";
summary: string;
nextAction: string;
}
export const trainer = createTrainer({
name: "support-bot-v1",
model: "unsloth/gemma-4-E4B-it",
dataset: { type: "huggingface", name: "arkorlab/triage-demo" },
lora: { r: 16, alpha: 16 },
maxSteps: 100,
callbacks: {
onCheckpoint: async ({ step, infer }) => {
try {
const res = await infer({
messages: [
{ role: "user", content: "I can't log in to my account." },
],
stream: false,
maxTokens: 200,
responseFormat: {
type: "json_schema",
json_schema: {
name: "triage",
schema: TRIAGE_SCHEMA,
strict: true,
},
},
});
const data = (await res.json()) as {
choices: Array<{ message: { content: string } }>;
};
const content = data.choices[0]?.message.content;
if (content === undefined || content === "") {
throw new Error("triage check returned empty content");
}
const parsed = JSON.parse(content) as TriageOutput;
console.log(`step=${step} triage=`, parsed);
} catch (err) {
console.error(`step=${step} triage check failed:`, err);
}
},
},
});