- 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>
85 lines
3.8 KiB
TypeScript
85 lines
3.8 KiB
TypeScript
// Content-moderation TRIAGE with OpenJev typed decisions.
|
|
//
|
|
// The model sorts incoming comments; code decides what happens. Clearly fine posts
|
|
// are published, confident spam/scam is held, and harassment plus anything uncertain
|
|
// or out of scope goes to a human moderator. A small local classifier should triage
|
|
// moderation work, not make final removal decisions on its own.
|
|
//
|
|
// npm run dev # in the repo root (or: docker compose up -> port 3000)
|
|
// OPENJEV_BASE_URL=http://localhost:8080 node --experimental-strip-types examples/content-moderation/triage.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 posts, not on this sample).
|
|
const PUBLISH_MIN_CONFIDENCE = 0.8; // how sure "ok" must be to skip review
|
|
const HOLD_MIN_CONFIDENCE = 0.8; // how sure spam/scam must be to hold automatically
|
|
const MAX_OOD = 0.6;
|
|
|
|
type Post = { id: string; text: string; expected: string };
|
|
type ChoiceAnswer = { type: "choice"; choice: string; confidence: number; ood: number };
|
|
type Action = "publish" | "hold" | "human-review";
|
|
|
|
const QUESTIONS = {
|
|
category: {
|
|
type: "choice",
|
|
instructions: "Which category best describes this user comment?",
|
|
criteria: {
|
|
ok: "normal, on-topic discussion, questions, thanks, polite disagreement",
|
|
spam: "unsolicited advertising, self-promotion, selling followers or products",
|
|
harassment: "insults, personal attacks, telling someone to leave, targeting a person",
|
|
scam: "phishing, fake prizes, requests for passwords, bank details or crypto",
|
|
},
|
|
},
|
|
} as const;
|
|
|
|
async function classify(state: string): Promise<{ engine: string; category: ChoiceAnswer }> {
|
|
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()}`);
|
|
const body = (await res.json()) as { engine?: { kind: string }; answers: { category: ChoiceAnswer } };
|
|
return { engine: body.engine?.kind ?? "unknown", category: body.answers.category };
|
|
}
|
|
|
|
function decide(c: ChoiceAnswer): Action {
|
|
if (c.ood >= MAX_OOD) return "human-review";
|
|
if (c.choice === "ok" && c.confidence >= PUBLISH_MIN_CONFIDENCE) return "publish";
|
|
if ((c.choice === "spam" || c.choice === "scam") && c.confidence >= HOLD_MIN_CONFIDENCE) return "hold";
|
|
return "human-review"; // harassment and every uncertain case get a person
|
|
}
|
|
|
|
const posts: Post[] = readFileSync(new URL("./posts.jsonl", import.meta.url), "utf8")
|
|
.split("\n")
|
|
.filter((line) => line.trim())
|
|
.map((line) => JSON.parse(line));
|
|
|
|
const counts: Record<Action, number> = { publish: 0, hold: 0, "human-review": 0 };
|
|
let correctLabel = 0;
|
|
let wronglyPublished = 0;
|
|
let engine = "unknown";
|
|
for (const p of posts) {
|
|
const { engine: e, category } = await classify(p.text);
|
|
engine = e;
|
|
const action = decide(category);
|
|
counts[action]++;
|
|
if (category.choice === p.expected) correctLabel++;
|
|
if (action === "publish" && p.expected !== "ok") wronglyPublished++;
|
|
console.log(
|
|
`${p.id} ${action.padEnd(12)} ${category.choice}@${category.confidence.toFixed(2)}` +
|
|
(category.choice === p.expected ? "" : ` (labelled ${p.expected})`),
|
|
);
|
|
}
|
|
console.log(
|
|
`\nengine=${engine} label accuracy on this sample: ${correctLabel}/${posts.length}` +
|
|
` publish=${counts.publish} hold=${counts.hold} human-review=${counts["human-review"]}` +
|
|
` harmful posts auto-published: ${wronglyPublished}`,
|
|
);
|