File size: 456 Bytes
ef41800 | 1 2 3 4 5 6 7 8 9 10 11 12 13 | """Token usage log for the cost report (evals/.usage.jsonl, not committed)."""
import json
import os
from pathlib import Path
LOG = Path(__file__).resolve().parent / ".usage.jsonl"
def log(role: str, u: dict):
model = os.environ.get("MODEL_APP" if role == "app" else "MODEL_JUDGE", "")
with open(LOG, "a") as f:
f.write(json.dumps({"role": role, "model": model, "in": u.get("input_tokens", 0), "out": u.get("output_tokens", 0)}) + "\n")
|