od1-base / example.py
mvbalaji's picture
OD-1 release 2 (2026-09-27)
151b8ca verified
Raw History Blame Contribute Delete
1.24 kB
"""Minimal OD-1 usage (GPU recommended; CPU works but is slow). pip install torch transformers"""
import json
import os
import sys
HERE = os.path.dirname(os.path.abspath(__file__)) # abspath, not realpath: the Hub cache uses symlinks
sys.path.insert(0, HERE)
from od1.model import OD1Model # noqa: E402
m = OD1Model.load(HERE, dtype="bf16", device="cuda") # or dtype="fp32", device="cpu"
m.enable_cuda_graphs() # optional (GPU): fastest serving path
state = json.dumps({"ticket_id": "T-4821", "customer_tier": "gold", "message": "Hi, I was charged twice for my March invoice (INV-2291, $149 each). Please refund the duplicate today, this is the second time it has happened."})
print(json.dumps(m.answer(state, {"route": {"type": "choice", "instructions": "Which team should handle this ticket?", "criteria": {"billing": "payments, invoices, refunds", "tech_support": "product bugs", "sales": "new purchases", "account": "login and access"}}, "refund": {"type": "noul", "instructions": "Is the customer asking for a refund?"}, "urgency": {"type": "score", "instructions": "How urgent is this ticket?", "criteria": ["can wait a week", "within a few days", "today", "immediately"]}}), indent=1))