aboutsummaryrefslogtreecommitdiffstats
path: root/deckit
diff options
context:
space:
mode:
Diffstat (limited to 'deckit')
-rw-r--r--deckit/modules/llm.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/deckit/modules/llm.py b/deckit/modules/llm.py
index fb2366f..310eabf 100644
--- a/deckit/modules/llm.py
+++ b/deckit/modules/llm.py
@@ -19,6 +19,24 @@ def _fetch_for(base):
return fetch
+def _opencode(rows) -> dict:
+ """Aggregate /api/summary's per-model rows into opencode's cost and tokens."""
+ picked = [r for r in rows if isinstance(r, dict) and r.get("program") == "opencode"]
+ models = [
+ {"provider": r.get("provider") or "", "model": r.get("model") or "",
+ "cost": r.get("total_cost_usd") or 0, "tokens": r.get("tokens") or 0,
+ "calls": r.get("calls") or 0}
+ for r in picked
+ ]
+ models.sort(key=lambda r: r["cost"], reverse=True)
+ return {
+ "cost": round(sum(r["cost"] for r in models), 4),
+ "tokens": sum(r["tokens"] for r in models),
+ "calls": sum(r["calls"] for r in models),
+ "models": models,
+ }
+
+
def make(cfg: dict) -> Module:
base = cfg.get("llm", {}).get("url", "http://127.0.0.1:8420").rstrip("/")
fetch = cfg.get("fetch") or _fetch_for(base)
@@ -48,7 +66,7 @@ def make(cfg: dict) -> Module:
"extra_utilization": latest.get("extra_utilization"),
"extra_currency": latest.get("extra_currency"),
},
- "opencode": data["/api/summary"],
+ "opencode": _opencode(data.get("/api/summary") or []),
}
return Module(name="llm", title="LLM usage", state=state)