some organization pass, still need to review a bunch
This commit is contained in:
+38
-38
@@ -6,10 +6,10 @@ class VendorMetric:
|
||||
"""Atomic vendor-state metric.
|
||||
[C: src/gui_2.py:render_vendor_state]
|
||||
"""
|
||||
key: str
|
||||
label: str
|
||||
value: str
|
||||
state: str
|
||||
key: str
|
||||
label: str
|
||||
value: str
|
||||
state: str
|
||||
tooltip: str
|
||||
|
||||
def get_vendor_state(app) -> list[VendorMetric]:
|
||||
@@ -18,64 +18,64 @@ def get_vendor_state(app) -> list[VendorMetric]:
|
||||
"""
|
||||
out: list[VendorMetric] = []
|
||||
out.append(VendorMetric(
|
||||
key="provider_model",
|
||||
label="Provider / Model",
|
||||
value=f"{app.current_provider} / {app.current_model}",
|
||||
state="info",
|
||||
tooltip="The vendor and model that will handle the next request."
|
||||
key = "provider_model",
|
||||
label = "Provider / Model",
|
||||
value = f"{app.current_provider} / {app.current_model}",
|
||||
state = "info",
|
||||
tooltip = "The vendor and model that will handle the next request."
|
||||
))
|
||||
ctrl = getattr(app, "controller", None)
|
||||
tt = getattr(ctrl, "token_tracker", None) if ctrl else None
|
||||
tt = getattr(ctrl, "token_tracker", None) if ctrl else None
|
||||
if tt and getattr(tt, "limit", 0):
|
||||
pct = 100.0 * getattr(tt, "used", 0) / tt.limit
|
||||
pct = 100.0 * getattr(tt, "used", 0) / tt.limit
|
||||
state = "warn" if pct > 75 else "ok"
|
||||
out.append(VendorMetric(
|
||||
key="context_window",
|
||||
label="Context Window",
|
||||
value=f"{tt.used:,} / {tt.limit:,} ({pct:.0f}%)",
|
||||
state=state,
|
||||
tooltip="Used vs total context window for the current session."
|
||||
key = "context_window",
|
||||
label = "Context Window",
|
||||
value = f"{tt.used:,} / {tt.limit:,} ({pct:.0f}%)",
|
||||
state = state,
|
||||
tooltip = "Used vs total context window for the current session."
|
||||
))
|
||||
else:
|
||||
out.append(VendorMetric(
|
||||
key="context_window", label="Context Window", value="—", state="info",
|
||||
tooltip="No token tracker attached for the current provider."
|
||||
key = "context_window", label="Context Window", value="—", state="info",
|
||||
tooltip = "No token tracker attached for the current provider."
|
||||
))
|
||||
if tt is not None:
|
||||
hits = getattr(tt, "cache_hits", 0)
|
||||
miss = getattr(tt, "cache_misses", 0)
|
||||
hits = getattr(tt, "cache_hits", 0)
|
||||
miss = getattr(tt, "cache_misses", 0)
|
||||
total = hits + miss
|
||||
rate = (100.0 * hits / total) if total else 0.0
|
||||
rate = (100.0 * hits / total) if total else 0.0
|
||||
out.append(VendorMetric(
|
||||
key="cache", label="Cache Hit Rate",
|
||||
value=f"{rate:.0f}% ({hits:,}/{total:,})",
|
||||
state="ok" if rate > 50 else "info",
|
||||
tooltip="Server-side prompt cache hit rate for the current session."
|
||||
key = "cache", label="Cache Hit Rate",
|
||||
value = f"{rate:.0f}% ({hits:,}/{total:,})",
|
||||
state = "ok" if rate > 50 else "info",
|
||||
tooltip = "Server-side prompt cache hit rate for the current session."
|
||||
))
|
||||
else:
|
||||
out.append(VendorMetric(
|
||||
key="cache", label="Cache Hit Rate", value="—", state="info",
|
||||
tooltip="No token tracker attached for the current provider."
|
||||
key = "cache", label="Cache Hit Rate", value="—", state="info",
|
||||
tooltip = "No token tracker attached for the current provider."
|
||||
))
|
||||
quota = (getattr(ctrl, "vendor_quota", {}) or {}) if ctrl else {}
|
||||
quota = (getattr(ctrl, "vendor_quota", {}) or {}) if ctrl else {}
|
||||
pct_left = quota.get("remaining_pct")
|
||||
if pct_left is None:
|
||||
out.append(VendorMetric(
|
||||
key="quota", label="Vendor Quota", value="—", state="info",
|
||||
tooltip="Vendor did not report quota for the current billing period."
|
||||
key = "quota", label="Vendor Quota", value="—", state="info",
|
||||
tooltip = "Vendor did not report quota for the current billing period."
|
||||
))
|
||||
else:
|
||||
out.append(VendorMetric(
|
||||
key="quota", label="Vendor Quota",
|
||||
value=f"{pct_left}% remaining",
|
||||
state="ok" if pct_left > 25 else "warn",
|
||||
tooltip="Approximate quota remaining for the current billing period."
|
||||
key = "quota", label="Vendor Quota",
|
||||
value = f"{pct_left}% remaining",
|
||||
state = "ok" if pct_left > 25 else "warn",
|
||||
tooltip = "Approximate quota remaining for the current billing period."
|
||||
))
|
||||
err = getattr(ctrl, "last_error", None) if ctrl else None
|
||||
out.append(VendorMetric(
|
||||
key="last_error", label="Last Error",
|
||||
value=err.get("class", "none") if err else "none",
|
||||
state="error" if err else "ok",
|
||||
tooltip=err.get("message", "No error since session start.") if err else "No error since session start."
|
||||
key = "last_error", label="Last Error",
|
||||
value = err.get("class", "none") if err else "none",
|
||||
state = "error" if err else "ok",
|
||||
tooltip = err.get("message", "No error since session start.") if err else "No error since session start."
|
||||
))
|
||||
return out
|
||||
|
||||
Reference in New Issue
Block a user