- Root LICENSE: replace the short-form notice with the full canonical Apache-2.0 text (fixes GitHub's "Other" license detection); update the OpenJev -> Umpirix copyright line in LICENSE/NOTICE, otsone/NOTICE and sdk/python/LICENSE+NOTICE (missed by the rebrand pass). - sdk/ai-sdk: was MIT with no LICENSE/NOTICE and no upstream fork trail (unlike sdk/js, sdk/python, adapters/python, skills, which are real TypeSafe AI SDK forks and correctly keep MIT per their NOTICE). It is original Umpirix code, so switch it to Apache-2.0 with its own LICENSE/NOTICE, matching the root. - README Licensing section: list sdk/ai-sdk under Apache-2.0 and sdk/scribase-decisions under MIT, and spell out why the TypeSafe-forked directories stay MIT (their MIT terms require preserving the notice). - Audited caelum0x/openjev-private (read-only clone): it's an older, mostly-superseded snapshot of this repo. Migrated the 3 self-contained, secret-free example scripts it had that this repo didn't (raw-HTTP, no SDK dependency): content-moderation, lead-scoring, support-ticket-routing (Python + Node.js, each with a sample JSONL), plus scripts/reproduce-leaderboard.mjs (wired to a new `npm run bench:reproduce`) for leaderboard reproducibility. Left behind in private: src/lib/seo/retired.ts (a reversed decision - this repo now has live /compare pages) and the hosted-SaaS pieces already superseded by this repo's own, newer versions of the same files. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
93 lines
4.2 KiB
TypeScript
93 lines
4.2 KiB
TypeScript
// Support-ticket routing with OpenJev typed decisions.
|
|
//
|
|
// One request per ticket asks three typed questions at once (which team, how urgent,
|
|
// is it a refund request). The routing POLICY lives in this file, not in a prompt:
|
|
// confident, in-scope answers are auto-routed; everything else goes to a human queue.
|
|
//
|
|
// npm run dev # in the repo root (or: docker compose up -> port 3000)
|
|
// OPENJEV_BASE_URL=http://localhost:8080 node --experimental-strip-types examples/support-ticket-routing/route.ts
|
|
//
|
|
// Zero dependencies: Node 22.6+ (built-in fetch and type stripping).
|
|
|
|
import { readFileSync } from "node:fs";
|
|
|
|
const BASE_URL = (process.env.OPENJEV_BASE_URL ?? "http://localhost:8080").replace(/\/$/, "");
|
|
const MODEL = process.env.OPENJEV_MODEL ?? "system-one";
|
|
const KEY = process.env.OPENJEV_API_KEY;
|
|
|
|
// Policy knobs (tune these on your own labelled tickets, not on this sample).
|
|
const MIN_CONFIDENCE = 0.6;
|
|
const MAX_OOD = 0.6; // the server's shipped out-of-scope threshold
|
|
// A noul is a probability, not a boolean. Values near 0.5 mean "the engine cannot tell",
|
|
// so only a clearly high value adds the refund tag; the uncertain middle is left alone.
|
|
const REFUND_YES = 0.9;
|
|
|
|
// expected.team "none" marks an off-topic ticket that should land in human review.
|
|
type Ticket = { id: string; text: string; expected: { team: string } };
|
|
type ChoiceAnswer = { type: "choice"; choice: string; confidence: number; ood: number; probabilities: Record<string, number> };
|
|
type ScoreAnswer = { type: "score"; score: number; legend: Record<string, string>; confidence: number; ood: number };
|
|
type NoulAnswer = { type: "noul"; noul: number; ood: number };
|
|
|
|
const QUESTIONS = {
|
|
team: {
|
|
type: "choice",
|
|
instructions: "Which team should handle this support ticket?",
|
|
criteria: {
|
|
billing: "charges, invoices, refunds, payments, subscriptions being billed",
|
|
technical: "bugs, errors, crashes, outages, API or app not working",
|
|
account: "login, password, email change, account deletion, personal data",
|
|
shipping: "delivery, tracking, damaged or missing items, replacements",
|
|
sales: "pricing, quotes, plans, discounts, talking to sales",
|
|
},
|
|
},
|
|
urgency: {
|
|
type: "score",
|
|
instructions: "How urgent is this ticket for the customer?",
|
|
criteria: ["low", "medium", "high", "critical"],
|
|
},
|
|
wants_refund: { type: "noul", instructions: "Is the customer asking for money back?" },
|
|
} as const;
|
|
|
|
async function ask(state: string) {
|
|
const res = await fetch(`${BASE_URL}/v1/systemone`, {
|
|
method: "POST",
|
|
headers: { "content-type": "application/json", ...(KEY ? { authorization: `Bearer ${KEY}` } : {}) },
|
|
body: JSON.stringify({ model: MODEL, state, questions: QUESTIONS }),
|
|
});
|
|
if (!res.ok) throw new Error(`OpenJev ${res.status}: ${await res.text()}`);
|
|
return (await res.json()) as {
|
|
engine?: { kind: string };
|
|
answers: { team: ChoiceAnswer; urgency: ScoreAnswer; wants_refund: NoulAnswer };
|
|
};
|
|
}
|
|
|
|
const tickets: Ticket[] = readFileSync(new URL("./tickets.jsonl", import.meta.url), "utf8")
|
|
.split("\n")
|
|
.filter((line) => line.trim())
|
|
.map((line) => JSON.parse(line));
|
|
|
|
let correct = 0;
|
|
let autoRouted = 0;
|
|
let engine = "unknown";
|
|
for (const t of tickets) {
|
|
const { engine: e, answers } = await ask(t.text);
|
|
engine = e?.kind ?? engine;
|
|
const { team, urgency, wants_refund } = answers;
|
|
const confident = team.confidence >= MIN_CONFIDENCE && team.ood < MAX_OOD;
|
|
const queue = confident ? team.choice : "human-review";
|
|
const level = urgency.legend[String(Math.round(urgency.score))];
|
|
const tags = wants_refund.noul >= REFUND_YES ? " [refund]" : "";
|
|
const expectedQueue = t.expected.team === "none" ? "human-review" : t.expected.team;
|
|
const hit = queue === expectedQueue || (!confident && team.choice === t.expected.team);
|
|
if (hit) correct++;
|
|
if (confident) autoRouted++;
|
|
console.log(
|
|
`${t.id} ${queue.padEnd(13)} team=${team.choice}@${team.confidence.toFixed(2)} ood=${team.ood.toFixed(2)} urgency=${level}${tags}` +
|
|
(hit ? "" : ` (expected ${expectedQueue})`),
|
|
);
|
|
}
|
|
console.log(
|
|
`\nengine=${engine} routed correctly (or safely to a human): ${correct}/${tickets.length}` +
|
|
` auto-routed: ${autoRouted}/${tickets.length} (rest go to human review)`,
|
|
);
|