Spaces:
Paused
Paused
Restore patch_models.py from commit 36e2e7f8
Browse files- patch_models.py +48 -0
patch_models.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Patch backend: add new model IDs to AVAILABLE_MODELS + fix title generation."""
|
| 2 |
+
import re, os
|
| 3 |
+
|
| 4 |
+
AGENT_FILE = "/app/backend/routes/agent.py"
|
| 5 |
+
with open(AGENT_FILE, "r") as f:
|
| 6 |
+
content = f.read()
|
| 7 |
+
|
| 8 |
+
# Add new models to AVAILABLE_MODELS
|
| 9 |
+
target = "AVAILABLE_MODELS = _available_models()\n"
|
| 10 |
+
patch = '''
|
| 11 |
+
# === PATCH: Add HF Inference + OpenRouter models ===
|
| 12 |
+
import os as _os
|
| 13 |
+
AVAILABLE_MODELS.extend([
|
| 14 |
+
{"id": "deepseek-ai/DeepSeek-V4-Pro", "label": "DeepSeek V4 Pro", "provider": "huggingface", "tier": "free", "recommended": True},
|
| 15 |
+
{"id": "deepseek-ai/DeepSeek-V4-Flash", "label": "DeepSeek V4 Flash", "provider": "huggingface", "tier": "free"},
|
| 16 |
+
{"id": "openai/deepseek/deepseek-v4-flash", "label": "DeepSeek V4 Flash (OR)", "provider": "openrouter", "tier": "free"},
|
| 17 |
+
{"id": "nvidia/nemotron-3-super-120b-a12b:free", "label": "Nemotron 3 Super 120B", "provider": "openrouter", "tier": "free"},
|
| 18 |
+
{"id": "google/gemma-4-31B-it", "label": "Gemma 4 31B", "provider": "huggingface", "tier": "free", "recommended": True},
|
| 19 |
+
{"id": "openai/tencent/hy3:free", "label": "Tencent HY3", "provider": "openrouter", "tier": "free"},
|
| 20 |
+
{"id": "google/gemma-3-1b-it", "label": "Gemma 3 1B", "provider": "huggingface", "tier": "free", "recommended": True},
|
| 21 |
+
{"id": "Qwen/Qwen3-Coder-Next", "label": "Qwen3 Coder Next", "provider": "huggingface", "tier": "free", "recommended": True},
|
| 22 |
+
{"id": "openrouter/owl-alpha", "label": "Owl Alpha", "provider": "openrouter", "tier": "free", "recommended": True},
|
| 23 |
+
{"id": "openai/google/gemini-2.0-flash-001", "label": "Gemini 2.0 Flash", "provider": "openrouter", "tier": "free"},
|
| 24 |
+
])
|
| 25 |
+
PREMIUM_MODEL_IDS = set() # No premium gate
|
| 26 |
+
DEFAULT_FREE_MODEL_ID = "deepseek-ai/DeepSeek-V4-Pro"
|
| 27 |
+
# === END PATCH ===
|
| 28 |
+
'''
|
| 29 |
+
|
| 30 |
+
if target in content:
|
| 31 |
+
content = content.replace(target, target + patch)
|
| 32 |
+
print("✅ Added models to AVAILABLE_MODELS")
|
| 33 |
+
|
| 34 |
+
# Fix title generation - use huggingface/ prefix for litellm
|
| 35 |
+
old_title = 'model="openai/openai/gpt-oss-120b:cerebras",\n api_base="https://router.huggingface.co/v1",\n api_key=api_key,'
|
| 36 |
+
new_title = 'model="huggingface/deepseek-ai/DeepSeek-V4-Pro",\n api_key=api_key,'
|
| 37 |
+
if old_title in content:
|
| 38 |
+
content = content.replace(old_title, new_title)
|
| 39 |
+
content = content.replace(' reasoning_effort="low",\n', '')
|
| 40 |
+
print("✅ Title generation patched")
|
| 41 |
+
|
| 42 |
+
import ast
|
| 43 |
+
ast.parse(content)
|
| 44 |
+
print("✅ Syntax OK")
|
| 45 |
+
|
| 46 |
+
with open(AGENT_FILE, "w") as f:
|
| 47 |
+
f.write(content)
|
| 48 |
+
print("✅ Backend patched")
|