- 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>
88 lines
3.8 KiB
Python
88 lines
3.8 KiB
Python
"""Support-ticket routing with OpenJev typed decisions (Python, standard library only).
|
|
|
|
One request per ticket asks three typed questions at once (which team, how urgent,
|
|
is it a refund request). The routing policy lives here in code: 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 python3 examples/support-ticket-routing/route.py
|
|
"""
|
|
|
|
import json
|
|
import os
|
|
import urllib.request
|
|
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")
|
|
|
|
MIN_CONFIDENCE = 0.6 # tune on your own labelled tickets, not on this sample
|
|
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.
|
|
REFUND_YES = 0.9
|
|
|
|
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?"},
|
|
}
|
|
|
|
|
|
def ask(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 main() -> None:
|
|
lines = (Path(__file__).parent / "tickets.jsonl").read_text().splitlines()
|
|
tickets = [json.loads(line) for line in lines if line.strip()]
|
|
correct = auto_routed = 0
|
|
engine = "unknown"
|
|
for t in tickets:
|
|
out = ask(t["text"])
|
|
engine = out.get("engine", {}).get("kind", engine)
|
|
team, urgency, refund = (out["answers"][k] for k in ("team", "urgency", "wants_refund"))
|
|
confident = team["confidence"] >= MIN_CONFIDENCE and team["ood"] < MAX_OOD
|
|
queue = team["choice"] if confident else "human-review"
|
|
level = urgency["legend"][str(round(urgency["score"]))]
|
|
tags = " [refund]" if refund["noul"] >= REFUND_YES else ""
|
|
# expected team "none" marks an off-topic ticket that should land in human review
|
|
expected_queue = "human-review" if t["expected"]["team"] == "none" else t["expected"]["team"]
|
|
hit = queue == expected_queue or (not confident and team["choice"] == t["expected"]["team"])
|
|
correct += hit
|
|
auto_routed += confident
|
|
miss = "" if hit else f" (expected {expected_queue})"
|
|
print(
|
|
f"{t['id']} {queue:<13} team={team['choice']}@{team['confidence']:.2f} ood={team['ood']:.2f}"
|
|
f" urgency={level}{tags}{miss}"
|
|
)
|
|
print(
|
|
f"\nengine={engine} routed correctly (or safely to a human): {correct}/{len(tickets)}"
|
|
f" auto-routed: {auto_routed}/{len(tickets)} (rest go to human review)"
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|