Fix quota endpoint: per-provider tick rates for accurate runtime estimates
Browse files- src/soci/api/routes.py +9 -3
- web/index.html +3 -3
src/soci/api/routes.py
CHANGED
|
@@ -376,12 +376,18 @@ async def get_llm_quota():
|
|
| 376 |
# Current provider's quota (for backward compat with nn_selfimprove)
|
| 377 |
cur = providers_quota.get(provider, {"daily_limit": 0, "daily_requests": 0, "remaining": 0})
|
| 378 |
|
| 379 |
-
# Estimate ticks per hour
|
| 380 |
-
|
| 381 |
-
ticks_per_hour = 3600.0 / (
|
| 382 |
max_calls_per_tick = 2 if provider in ("gemini", "groq") else 5
|
| 383 |
num_agents = len(sim.agents)
|
| 384 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 385 |
return {
|
| 386 |
"provider": provider,
|
| 387 |
"daily_limit": cur["daily_limit"],
|
|
|
|
| 376 |
# Current provider's quota (for backward compat with nn_selfimprove)
|
| 377 |
cur = providers_quota.get(provider, {"daily_limit": 0, "daily_requests": 0, "remaining": 0})
|
| 378 |
|
| 379 |
+
# Estimate ticks per hour — rate-limited providers use 4s tick delay
|
| 380 |
+
tick_delay_current = 4.0 if provider in ("gemini", "groq") else 2.0
|
| 381 |
+
ticks_per_hour = 3600.0 / (tick_delay_current * max(_sim_speed, 0.01))
|
| 382 |
max_calls_per_tick = 2 if provider in ("gemini", "groq") else 5
|
| 383 |
num_agents = len(sim.agents)
|
| 384 |
|
| 385 |
+
# Per-provider tick estimates (for frontend runtime calc when switching TO a provider)
|
| 386 |
+
for pid in providers_quota:
|
| 387 |
+
rl_delay = 4.0 if pid in ("gemini", "groq") else 2.0
|
| 388 |
+
providers_quota[pid]["ticks_per_hour"] = round(3600.0 / (rl_delay * max(_sim_speed, 0.01)), 1)
|
| 389 |
+
providers_quota[pid]["max_calls_per_tick"] = 2 if pid in ("gemini", "groq") else 5
|
| 390 |
+
|
| 391 |
return {
|
| 392 |
"provider": provider,
|
| 393 |
"daily_limit": cur["daily_limit"],
|
web/index.html
CHANGED
|
@@ -3452,10 +3452,10 @@ document.getElementById('llm-model').addEventListener('click', async (e) => {
|
|
| 3452 |
const rem = pq ? (pq.remaining || 0) : 0;
|
| 3453 |
const lim = pq ? (pq.daily_limit || 0) : 0;
|
| 3454 |
const pct = lim > 0 ? Math.round((rem / lim) * 100) : 0;
|
| 3455 |
-
// Build a quota-like object for estimateRuntime using this provider's
|
| 3456 |
const pqForCalc = {remaining: rem, daily_limit: lim,
|
| 3457 |
-
max_calls_per_tick:
|
| 3458 |
-
ticks_per_hour:
|
| 3459 |
|
| 3460 |
if (rem <= 0) {
|
| 3461 |
panel.innerHTML = `<div style="color:#e94560;margin-bottom:6px">Quota exhausted (0/${lim}). Resets daily.</div>`;
|
|
|
|
| 3452 |
const rem = pq ? (pq.remaining || 0) : 0;
|
| 3453 |
const lim = pq ? (pq.daily_limit || 0) : 0;
|
| 3454 |
const pct = lim > 0 ? Math.round((rem / lim) * 100) : 0;
|
| 3455 |
+
// Build a quota-like object for estimateRuntime using this provider's own tick rate
|
| 3456 |
const pqForCalc = {remaining: rem, daily_limit: lim,
|
| 3457 |
+
max_calls_per_tick: pq.max_calls_per_tick || 2,
|
| 3458 |
+
ticks_per_hour: pq.ticks_per_hour || 900};
|
| 3459 |
|
| 3460 |
if (rem <= 0) {
|
| 3461 |
panel.innerHTML = `<div style="color:#e94560;margin-bottom:6px">Quota exhausted (0/${lim}). Resets daily.</div>`;
|