AsianPlayer/TriDrive / code /weak /gpt_reconcile_incomplete.py
AsianPlayer's picture
download
raw
1.94 kB
"""cwm3/weak/gpt_reconcile_incomplete.py — close `needs_reconcile` rows whose response DID report usage (status incomplete, reason
max_output_tokens) with the cost computed from that usage at the ledger's price list (pkg_common.cost_usd), via the package's own
operator path Ledger.reconcile (status -> 'incomplete', billed). Rows with all-zero usage are left open and listed.
python gpt_reconcile_incomplete.py [--apply] # default: dry listing
"""
import argparse, sys
from pathlib import Path
CWM3 = Path(__file__).resolve().parents[1]; PKG = CWM3.parent / "cwm2" / "annotation_package"
sys.path.insert(0, str(CWM3 / "weak")); sys.path.insert(0, str(PKG))
sys.argv, _argv = sys.argv[:1], sys.argv
import run_gpt # noqa: E402,F401 (pricing for gpt-5, ledger path)
import pkg_common as pc # noqa: E402
from budget import Ledger # noqa: E402
sys.argv = _argv
ap = argparse.ArgumentParser(); ap.add_argument("--apply", action="store_true"); a = ap.parse_args()
led = Ledger(pc.LEDGER_PATH); rows = led.list(status="needs_reconcile"); tot = 0.0; n = 0
for r in rows:
zero = not any(r[k] for k in ("actual_in", "actual_out"))
if zero:
print(f"OPEN (zero usage, cost unknown): {r['cache_key'][:12]} {r['clip_id']} {r['pass']}"); continue
cost = pc.cost_usd(r["model"], r["tier"] or "standard", r["actual_in"], r["actual_cached"] or 0, r["actual_out"])
print(f"{'RECONCILE' if a.apply else 'would reconcile'} {r['cache_key'][:12]} {r['clip_id']} {r['pass']} in={r['actual_in']} cached={r['actual_cached']} "
f"out={r['actual_out']} -> ${cost:.4f} status incomplete ({r['error']})")
if a.apply:
led.reconcile(r["cache_key"], cost, "incomplete", f"usage-reported incomplete (max_output_tokens); cost from usage at {pc.PRICING['price_snapshot_date']} prices; 2026-09-13 calibration")
tot += cost; n += 1
print(f"{n} row(s), total ${tot:.4f}; ledger spent now ${led.spent_usd():.4f}")

Xet Storage Details

Size:
1.94 kB
·
Xet hash:
ec242ab4cfc74fdf9b61393259a70152ed3693000e53d8e60bda7b695f1274e2

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.