- 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>
96 lines
4.1 KiB
Python
96 lines
4.1 KiB
Python
"""Lead scoring with OpenJev typed decisions (Python, standard library only).
|
|
|
|
Each inbound lead (company + message) gets three typed judgments in one request: buying
|
|
stage (score), company segment (choice) and whether it is a real inquiry or a vendor
|
|
pitch (choice). The points formula is ordinary code, so sales can re-weight it without
|
|
re-running inference, and uncertain leads are flagged for a human look.
|
|
|
|
npm run dev # in the repo root (or: docker compose up -> port 3000)
|
|
OPENJEV_BASE_URL=http://localhost:8080 python3 examples/lead-scoring/score.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")
|
|
|
|
STAGES = ["just curious", "researching", "evaluating vendors", "ready to buy"]
|
|
QUESTIONS = {
|
|
"stage": {"type": "score", "instructions": "How close is this lead to buying?", "criteria": STAGES},
|
|
"segment": {
|
|
"type": "choice",
|
|
"instructions": "What kind of organisation is this lead from?",
|
|
"criteria": {
|
|
"enterprise": "large company, hundreds or thousands of employees, procurement",
|
|
"smb": "small or mid-sized business, startup, SaaS team",
|
|
"individual": "hobbyist, indie developer, student, personal email",
|
|
},
|
|
},
|
|
"kind": {
|
|
"type": "choice",
|
|
"instructions": "What is this inbound message?",
|
|
"criteria": {
|
|
"inquiry": "a potential customer asking about our product, pricing, demo, evaluation or use",
|
|
"vendor_pitch": "someone advertising their own services to us: SEO, outsourcing, developers for hire, marketing",
|
|
},
|
|
},
|
|
}
|
|
|
|
# Scoring policy: plain code, easy to re-weight.
|
|
SEGMENT_POINTS = {"enterprise": 30, "smb": 20, "individual": 0}
|
|
PITCH_MIN_CONFIDENCE = 0.7 # only a confident "vendor_pitch" marks a lead as junk
|
|
REVIEW_BELOW = 0.7 # uncertain segment or kind -> a person takes a look
|
|
|
|
|
|
def grade(points: int) -> str:
|
|
if points >= 70:
|
|
return "hot"
|
|
if points >= 45:
|
|
return "warm"
|
|
return "cold"
|
|
|
|
|
|
def judge(lead: dict) -> dict:
|
|
state = f"Company: {lead['company']}\nMessage: {lead['message']}"
|
|
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 / "leads.jsonl").read_text().splitlines()
|
|
leads = [json.loads(line) for line in lines if line.strip()]
|
|
ranked = []
|
|
agree = 0
|
|
engine = "unknown"
|
|
for lead in leads:
|
|
out = judge(lead)
|
|
engine = out.get("engine", {}).get("kind", engine)
|
|
stage, segment, kind = (out["answers"][k] for k in ("stage", "segment", "kind"))
|
|
# stage["score"] is the expected position on the 0..3 scale, already a smooth value.
|
|
stage_points = stage["score"] / (len(STAGES) - 1) * 70
|
|
points = round(stage_points + SEGMENT_POINTS.get(segment["choice"], 0))
|
|
is_pitch = kind["choice"] == "vendor_pitch" and kind["confidence"] >= PITCH_MIN_CONFIDENCE
|
|
label = "junk" if is_pitch else grade(points)
|
|
review = segment["confidence"] < REVIEW_BELOW or kind["confidence"] < REVIEW_BELOW or stage["ood"] >= 0.6
|
|
agree += label == lead["expected"]
|
|
ranked.append((-1 if label == "junk" else points, lead, label, review))
|
|
ranked.sort(key=lambda r: r[0], reverse=True)
|
|
for points, lead, label, review in ranked:
|
|
flag = " [check by hand]" if review else ""
|
|
miss = "" if label == lead["expected"] else f" (labelled {lead['expected']})"
|
|
print(f"{lead['id']} {label:<5} {max(points, 0):>3} pts {lead['company']}{flag}{miss}")
|
|
print(f"\nengine={engine} agrees with the hand labels on {agree}/{len(leads)} sample leads")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|