caelum0x 03c7e2c397 fix(license): consistent Apache-2.0/MIT split + migrate 3 examples from private audit
- 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>
2026-11-11 19:08:57 +03:00

86 lines
3.3 KiB
Python

"""Content-moderation triage with OpenJev typed decisions (Python, standard library only).
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 python3 examples/content-moderation/triage.py
"""
import json
import os
import urllib.request
from collections import Counter
from pathlib import Path
BASE_URL = os.environ.get("OPENJEV_BASE_URL", "http://localhost:8080").rstrip("/")
MODEL = os.environ.get("OPENJEV_MODEL", "system-one")
KEY = os.environ.get("OPENJEV_API_KEY")
# Policy knobs (tune these on your own labelled posts, not on this sample).
PUBLISH_MIN_CONFIDENCE = 0.8
HOLD_MIN_CONFIDENCE = 0.8
MAX_OOD = 0.6
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",
},
},
}
def classify(state: str) -> dict:
headers = {"content-type": "application/json"}
if KEY:
headers["authorization"] = f"Bearer {KEY}"
body = json.dumps({"model": MODEL, "state": state, "questions": QUESTIONS}).encode()
req = urllib.request.Request(f"{BASE_URL}/v1/systemone", data=body, headers=headers, method="POST")
with urllib.request.urlopen(req, timeout=30) as res:
return json.load(res)
def decide(c: dict) -> str:
if c["ood"] >= MAX_OOD:
return "human-review"
if c["choice"] == "ok" and c["confidence"] >= PUBLISH_MIN_CONFIDENCE:
return "publish"
if c["choice"] in ("spam", "scam") and c["confidence"] >= HOLD_MIN_CONFIDENCE:
return "hold"
return "human-review" # harassment and every uncertain case get a person
def main() -> None:
lines = (Path(__file__).parent / "posts.jsonl").read_text().splitlines()
posts = [json.loads(line) for line in lines if line.strip()]
counts: Counter[str] = Counter()
correct = wrongly_published = 0
engine = "unknown"
for p in posts:
out = classify(p["text"])
engine = out.get("engine", {}).get("kind", engine)
c = out["answers"]["category"]
action = decide(c)
counts[action] += 1
correct += c["choice"] == p["expected"]
wrongly_published += action == "publish" and p["expected"] != "ok"
miss = "" if c["choice"] == p["expected"] else f" (labelled {p['expected']})"
print(f"{p['id']} {action:<12} {c['choice']}@{c['confidence']:.2f}{miss}")
print(
f"\nengine={engine} label accuracy on this sample: {correct}/{len(posts)}"
f" publish={counts['publish']} hold={counts['hold']} human-review={counts['human-review']}"
f" harmful posts auto-published: {wrongly_published}"
)
if __name__ == "__main__":
main()