mirror of
https://github.com/hanzoai/laya.git
synced 2026-10-30 19:33:31 +00:00
Pure-TS port of Python inference (Agent, Router, lang, email, presets, shortlist) as npm package for Node and browser embed. Split ONNX backend: onnxruntime-node (CPU/CUDA) + onnxruntime-web (WebGPU/WASM). Includes HF-to-ONNX export script with torch-vs-ONNX verification, verified byte-parity vs Python on multilingual (billing 0.9944, 42 tests green). Co-authored-by: nnlgsakib <[email protected]>
37 lines
1.4 KiB
JavaScript
37 lines
1.4 KiB
JavaScript
import { Agent, Router } from "../dist/index.js";
|
|
|
|
const agent = await Agent.load("./model-ml"); // run as: node laya-ts/examples/try-ml.mjs (repo root)
|
|
console.log("loaded:", agent.cfg.encoder ?? "multilingual");
|
|
|
|
// Direct predict (Hindi -> multilingual weights)
|
|
const direct = await agent.predict(
|
|
{ body: "मुझसे दो बार शुल्क लिया गया, कृपया पैसे वापस करें।" },
|
|
{
|
|
department: {
|
|
type: "choice",
|
|
instructions: "Which department should handle this request?",
|
|
criteria: {
|
|
billing: "invoices, payments, refunds",
|
|
technical: "bugs, outages, system errors",
|
|
sales: "pricing, new contracts",
|
|
other: "everything else",
|
|
},
|
|
},
|
|
churn_risk: { type: "noul", instructions: "Does the user threaten to cancel or leave?" },
|
|
}
|
|
);
|
|
console.log(JSON.stringify(direct, null, 2));
|
|
|
|
// Router path (auto language detect + routing metadata)
|
|
const router = new Router();
|
|
router.attach("multilingual", agent);
|
|
const routed = await router.predict({ body: "Der Kunde wurde zweimal belastet" }, {
|
|
department: {
|
|
type: "choice",
|
|
instructions: "Which department should handle this request?",
|
|
criteria: { billing: "invoices, payments, refunds", technical: "bugs, outages", other: "rest" },
|
|
},
|
|
});
|
|
console.log("routing:", JSON.stringify(routed.routing));
|
|
console.log("answer:", JSON.stringify(routed.answers.department));
|