Update app.py
Browse files
app.py
CHANGED
|
@@ -369,26 +369,33 @@ def _register_providers() -> None:
|
|
| 369 |
|
| 370 |
def _route(model_class: str, *, explicit_model: Optional[str] = None
|
| 371 |
) -> List[Tuple[Provider, str]]:
|
| 372 |
-
"""Return [(provider, model_to_use)] sorted by cost_score asc.
|
| 373 |
-
|
| 374 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 375 |
cands = [p for p in PROVIDERS.values() if p.enabled]
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 381 |
for p in cands:
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
for p in cands:
|
| 389 |
-
for cls in ("balanced", "premium", "reasoning", "cheap"):
|
| 390 |
-
if cls in p.model_for:
|
| 391 |
-
out.append((p, p.model_for[cls])); break
|
| 392 |
out.sort(key=lambda t: t[0].cost_score)
|
| 393 |
return out
|
| 394 |
|
|
|
|
| 369 |
|
| 370 |
def _route(model_class: str, *, explicit_model: Optional[str] = None
|
| 371 |
) -> List[Tuple[Provider, str]]:
|
| 372 |
+
"""Return [(provider, model_to_use)] sorted by cost_score asc."""
|
| 373 |
+
|
| 374 |
+
# ── OMEGA FIX: ANNIHILATE HARDCODED MODELS ──
|
| 375 |
+
# Forge aggressively requests paid models like Claude explicitly.
|
| 376 |
+
# We intercept and destroy those explicit requests so Forge is FORCED
|
| 377 |
+
# to fall into our cost-ascending DeepSeek / Free-Tier waterfall.
|
| 378 |
+
explicit_model = None
|
| 379 |
+
|
| 380 |
cands = [p for p in PROVIDERS.values() if p.enabled]
|
| 381 |
+
out = []
|
| 382 |
+
|
| 383 |
+
# Map the requested class (e.g. "reasoning") to our configured waterfall models
|
| 384 |
+
for p in cands:
|
| 385 |
+
if model_class in p.classes:
|
| 386 |
+
model = p.model_for.get(model_class)
|
| 387 |
+
if model:
|
| 388 |
+
out.append((p, model))
|
| 389 |
+
|
| 390 |
+
# If no class matches perfectly, aggressively fall back to ANY available model
|
| 391 |
+
if not out:
|
| 392 |
for p in cands:
|
| 393 |
+
for cls in ("balanced", "premium", "reasoning", "cheap"):
|
| 394 |
+
if cls in p.model_for:
|
| 395 |
+
out.append((p, p.model_for[cls]))
|
| 396 |
+
break
|
| 397 |
+
|
| 398 |
+
# Sort strictly by the cost scores we assigned (OpenRouter/DeepSeek first)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 399 |
out.sort(key=lambda t: t[0].cost_score)
|
| 400 |
return out
|
| 401 |
|