Update app.py
Browse files
app.py
CHANGED
|
@@ -283,26 +283,31 @@ async def call_hf(model: str, *, prompt: str, system: Optional[str],
|
|
| 283 |
# βββββββββββββββββββββββββββ PROVIDERS table ββββββββββββββββββββββββββββ
|
| 284 |
PROVIDERS: Dict[str, Provider] = {}
|
| 285 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 286 |
def _register_providers() -> None:
|
| 287 |
PROVIDERS.clear()
|
| 288 |
|
| 289 |
-
# 1.
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
classes=("cheap", "balanced", "premium", "reasoning", "vision"),
|
| 295 |
model_for={
|
| 296 |
-
"cheap": "
|
| 297 |
-
"balanced": "deepseek
|
| 298 |
-
"premium": "deepseek
|
| 299 |
-
"reasoning": "deepseek
|
| 300 |
-
"vision": "qwen/qwen2.5-vl-72b-instruct:free",
|
| 301 |
},
|
| 302 |
-
impl=
|
| 303 |
)
|
| 304 |
|
| 305 |
-
# 2.
|
| 306 |
if GROQ_API_KEY:
|
| 307 |
PROVIDERS["groq"] = Provider(
|
| 308 |
name="groq", enabled=True, cost_score=0.05,
|
|
@@ -314,23 +319,10 @@ def _register_providers() -> None:
|
|
| 314 |
impl=call_groq,
|
| 315 |
)
|
| 316 |
|
| 317 |
-
# 3.
|
| 318 |
-
PROVIDERS["hf"] = Provider(
|
| 319 |
-
name="hf", enabled=True, cost_score=0.10,
|
| 320 |
-
classes=("cheap", "balanced", "premium", "reasoning"),
|
| 321 |
-
model_for={
|
| 322 |
-
"cheap": "mistralai/Mistral-7B-Instruct-v0.3",
|
| 323 |
-
"balanced": "meta-llama/Meta-Llama-3-8B-Instruct",
|
| 324 |
-
"premium": "NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO", # Safe from 404
|
| 325 |
-
"reasoning": "Qwen/Qwen2.5-7B-Instruct", # 72B hits free limits; 7B is safe
|
| 326 |
-
},
|
| 327 |
-
impl=call_hf,
|
| 328 |
-
)
|
| 329 |
-
|
| 330 |
-
# 4. Together AI (Cheap fallback)
|
| 331 |
if TOGETHER_API_KEY:
|
| 332 |
PROVIDERS["together"] = Provider(
|
| 333 |
-
name="together", enabled=True, cost_score=0.
|
| 334 |
classes=("cheap", "balanced", "reasoning"),
|
| 335 |
model_for={
|
| 336 |
"cheap": "meta-llama/Llama-3.1-8B-Instruct-Turbo",
|
|
@@ -340,7 +332,22 @@ def _register_providers() -> None:
|
|
| 340 |
impl=call_together,
|
| 341 |
)
|
| 342 |
|
| 343 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 344 |
if OPENAI_API_KEY:
|
| 345 |
PROVIDERS["openai"] = Provider(
|
| 346 |
name="openai", enabled=True, cost_score=0.50,
|
|
@@ -353,7 +360,7 @@ def _register_providers() -> None:
|
|
| 353 |
impl=call_openai,
|
| 354 |
)
|
| 355 |
|
| 356 |
-
# 6.
|
| 357 |
if ANTHROPIC_API_KEY:
|
| 358 |
PROVIDERS["anthropic"] = Provider(
|
| 359 |
name="anthropic", enabled=True, cost_score=0.55,
|
|
@@ -366,6 +373,19 @@ def _register_providers() -> None:
|
|
| 366 |
impl=call_anthropic,
|
| 367 |
)
|
| 368 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 369 |
|
| 370 |
def _route(model_class: str, *, explicit_model: Optional[str] = None
|
| 371 |
) -> List[Tuple[Provider, str]]:
|
|
|
|
| 283 |
# βββββββββββββββββββββββββββ PROVIDERS table ββββββββββββββββββββββββββββ
|
| 284 |
PROVIDERS: Dict[str, Provider] = {}
|
| 285 |
|
| 286 |
+
API_KEY_DEEPSEEK = os.environ.get("API_KEY_DEEPSEEK", "")
|
| 287 |
+
|
| 288 |
+
async def call_deepseek(model: str, **kw) -> Tuple[str, str]:
|
| 289 |
+
"""Native DeepSeek API Client"""
|
| 290 |
+
return await _openai_compat_call("https://api.deepseek.com/v1",
|
| 291 |
+
API_KEY_DEEPSEEK, model, **kw)
|
| 292 |
+
|
| 293 |
def _register_providers() -> None:
|
| 294 |
PROVIDERS.clear()
|
| 295 |
|
| 296 |
+
# 1. NATIVE DEEPSEEK V4 (Absolute Priority - Cost Score 0.01)
|
| 297 |
+
if API_KEY_DEEPSEEK:
|
| 298 |
+
PROVIDERS["deepseek"] = Provider(
|
| 299 |
+
name="deepseek", enabled=True, cost_score=0.01,
|
| 300 |
+
classes=("cheap", "balanced", "premium", "reasoning"),
|
|
|
|
| 301 |
model_for={
|
| 302 |
+
"cheap": "deepseek-v4-flash",
|
| 303 |
+
"balanced": "deepseek-v4-pro",
|
| 304 |
+
"premium": "deepseek-v4-pro",
|
| 305 |
+
"reasoning": "deepseek-v4-pro",
|
|
|
|
| 306 |
},
|
| 307 |
+
impl=call_deepseek,
|
| 308 |
)
|
| 309 |
|
| 310 |
+
# 2. GROQ
|
| 311 |
if GROQ_API_KEY:
|
| 312 |
PROVIDERS["groq"] = Provider(
|
| 313 |
name="groq", enabled=True, cost_score=0.05,
|
|
|
|
| 319 |
impl=call_groq,
|
| 320 |
)
|
| 321 |
|
| 322 |
+
# 3. TOGETHER
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 323 |
if TOGETHER_API_KEY:
|
| 324 |
PROVIDERS["together"] = Provider(
|
| 325 |
+
name="together", enabled=True, cost_score=0.10,
|
| 326 |
classes=("cheap", "balanced", "reasoning"),
|
| 327 |
model_for={
|
| 328 |
"cheap": "meta-llama/Llama-3.1-8B-Instruct-Turbo",
|
|
|
|
| 332 |
impl=call_together,
|
| 333 |
)
|
| 334 |
|
| 335 |
+
# 4. OPENROUTER (With Free Vision Added)
|
| 336 |
+
if OPENROUTER_API_KEY:
|
| 337 |
+
PROVIDERS["openrouter"] = Provider(
|
| 338 |
+
name="openrouter", enabled=True, cost_score=0.20,
|
| 339 |
+
classes=("cheap", "balanced", "premium", "reasoning", "vision"),
|
| 340 |
+
model_for={
|
| 341 |
+
"cheap": "meta-llama/llama-3.3-70b-instruct:free",
|
| 342 |
+
"balanced": "anthropic/claude-3.5-haiku",
|
| 343 |
+
"premium": "anthropic/claude-sonnet-4.5",
|
| 344 |
+
"reasoning": "openai/o4-mini",
|
| 345 |
+
"vision": "qwen/qwen2.5-vl-72b-instruct:free",
|
| 346 |
+
},
|
| 347 |
+
impl=call_openrouter,
|
| 348 |
+
)
|
| 349 |
+
|
| 350 |
+
# 5. OPENAI
|
| 351 |
if OPENAI_API_KEY:
|
| 352 |
PROVIDERS["openai"] = Provider(
|
| 353 |
name="openai", enabled=True, cost_score=0.50,
|
|
|
|
| 360 |
impl=call_openai,
|
| 361 |
)
|
| 362 |
|
| 363 |
+
# 6. ANTHROPIC
|
| 364 |
if ANTHROPIC_API_KEY:
|
| 365 |
PROVIDERS["anthropic"] = Provider(
|
| 366 |
name="anthropic", enabled=True, cost_score=0.55,
|
|
|
|
| 373 |
impl=call_anthropic,
|
| 374 |
)
|
| 375 |
|
| 376 |
+
# 7. HF INFERENCE (100% Free Fallback)
|
| 377 |
+
PROVIDERS["hf"] = Provider(
|
| 378 |
+
name="hf", enabled=True, cost_score=0.99,
|
| 379 |
+
classes=("cheap", "balanced", "premium", "reasoning"),
|
| 380 |
+
model_for={
|
| 381 |
+
"cheap": "mistralai/Mistral-7B-Instruct-v0.3",
|
| 382 |
+
"balanced": "meta-llama/Meta-Llama-3-8B-Instruct",
|
| 383 |
+
"premium": "NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO",
|
| 384 |
+
"reasoning": "Qwen/Qwen2.5-7B-Instruct",
|
| 385 |
+
},
|
| 386 |
+
impl=call_hf,
|
| 387 |
+
)
|
| 388 |
+
|
| 389 |
|
| 390 |
def _route(model_class: str, *, explicit_model: Optional[str] = None
|
| 391 |
) -> List[Tuple[Provider, str]]:
|