Update backend patch: accept all new model IDs + HF Inference for Qwen3
Browse files- patch_models.py +36 -20
patch_models.py
CHANGED
|
@@ -1,42 +1,58 @@
|
|
| 1 |
-
"""
|
| 2 |
-
import
|
| 3 |
|
| 4 |
AGENT_FILE = "/app/backend/routes/agent.py"
|
| 5 |
with open(AGENT_FILE, "r") as f:
|
| 6 |
content = f.read()
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
# === PATCH: Add OpenRouter + HF Inference models ===
|
| 12 |
import os as _os
|
| 13 |
-
|
| 14 |
-
{"id": "openai/
|
|
|
|
|
|
|
|
|
|
| 15 |
{"id": "openai/google/gemini-2.0-flash-001", "label": "Gemini 2.0 Flash", "provider": "openrouter", "tier": "free"},
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
])
|
| 19 |
-
PREMIUM_MODEL_IDS = set() # No premium gate
|
| 20 |
-
DEFAULT_FREE_MODEL_ID = "openai/deepseek/deepseek-chat-v3-0324"
|
| 21 |
# === END PATCH ===
|
| 22 |
'''
|
| 23 |
|
|
|
|
| 24 |
if target in content:
|
| 25 |
-
content = content.replace(target, target +
|
| 26 |
-
print("β
Added
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
# Fix title generation
|
| 29 |
old_title = 'model="openai/openai/gpt-oss-120b:cerebras",\n api_base="https://router.huggingface.co/v1",\n api_key=api_key,'
|
| 30 |
new_title = 'model="openai/deepseek/deepseek-chat-v3-0324",\n api_base=_os.environ.get("OPENAI_API_BASE", "https://openrouter.ai/api/v1"),\n api_key=_os.environ.get("OPENAI_API_KEY", api_key),'
|
|
|
|
| 31 |
if old_title in content:
|
| 32 |
content = content.replace(old_title, new_title)
|
| 33 |
content = content.replace(' reasoning_effort="low",\n', '')
|
| 34 |
-
print("β
Title
|
|
|
|
|
|
|
| 35 |
|
| 36 |
import ast
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
with open(AGENT_FILE, "w") as f:
|
| 41 |
f.write(content)
|
| 42 |
-
|
|
|
|
|
|
| 1 |
+
"""Build-time patch: Add all models to backend AVAILABLE_MODELS + fix title gen."""
|
| 2 |
+
import os
|
| 3 |
|
| 4 |
AGENT_FILE = "/app/backend/routes/agent.py"
|
| 5 |
with open(AGENT_FILE, "r") as f:
|
| 6 |
content = f.read()
|
| 7 |
|
| 8 |
+
patch_code = '''
|
| 9 |
+
|
| 10 |
+
# === PATCHED: Add OpenRouter + HF Inference models ===
|
|
|
|
| 11 |
import os as _os
|
| 12 |
+
_extra_models = [
|
| 13 |
+
{"id": "openai/x-ai/grok-4.3", "label": "Grok 4.3", "provider": "openrouter", "tier": "free", "recommended": True},
|
| 14 |
+
{"id": "openai/deepseek/deepseek-v4-pro", "label": "DeepSeek V4 Pro", "provider": "openrouter", "tier": "free", "recommended": True},
|
| 15 |
+
{"id": "openai/qwen/qwen3.7-max", "label": "Qwen 3.7 Max", "provider": "openrouter", "tier": "free"},
|
| 16 |
+
{"id": "Qwen/Qwen3-235B-A22B", "label": "Qwen3 235B (HF)", "provider": "huggingface", "tier": "free"},
|
| 17 |
{"id": "openai/google/gemini-2.0-flash-001", "label": "Gemini 2.0 Flash", "provider": "openrouter", "tier": "free"},
|
| 18 |
+
]
|
| 19 |
+
AVAILABLE_MODELS.extend(_extra_models)
|
|
|
|
|
|
|
|
|
|
| 20 |
# === END PATCH ===
|
| 21 |
'''
|
| 22 |
|
| 23 |
+
target = "AVAILABLE_MODELS = _available_models()\n"
|
| 24 |
if target in content:
|
| 25 |
+
content = content.replace(target, target + patch_code)
|
| 26 |
+
print("β
Added Grok 4.3, DeepSeek V4 Pro, Qwen 3.7 Max, Qwen3 HF, Gemini Flash")
|
| 27 |
+
else:
|
| 28 |
+
target2 = "AVAILABLE_MODELS = _available_models()"
|
| 29 |
+
if target2 in content:
|
| 30 |
+
content = content.replace(target2, target2 + "\n" + patch_code)
|
| 31 |
+
print("β
Added models (alt)")
|
| 32 |
+
else:
|
| 33 |
+
print("β Cannot find AVAILABLE_MODELS!")
|
| 34 |
+
import sys; sys.exit(1)
|
| 35 |
|
| 36 |
+
# Fix title generation to use OpenRouter instead of HF Router
|
| 37 |
old_title = 'model="openai/openai/gpt-oss-120b:cerebras",\n api_base="https://router.huggingface.co/v1",\n api_key=api_key,'
|
| 38 |
new_title = 'model="openai/deepseek/deepseek-chat-v3-0324",\n api_base=_os.environ.get("OPENAI_API_BASE", "https://openrouter.ai/api/v1"),\n api_key=_os.environ.get("OPENAI_API_KEY", api_key),'
|
| 39 |
+
|
| 40 |
if old_title in content:
|
| 41 |
content = content.replace(old_title, new_title)
|
| 42 |
content = content.replace(' reasoning_effort="low",\n', '')
|
| 43 |
+
print("β
Title gen fixed for OpenRouter")
|
| 44 |
+
else:
|
| 45 |
+
print("β οΈ Title pattern not found")
|
| 46 |
|
| 47 |
import ast
|
| 48 |
+
try:
|
| 49 |
+
ast.parse(content)
|
| 50 |
+
print("β
Syntax OK")
|
| 51 |
+
except SyntaxError as e:
|
| 52 |
+
print(f"β Syntax error: {e}")
|
| 53 |
+
import sys; sys.exit(1)
|
| 54 |
|
| 55 |
with open(AGENT_FILE, "w") as f:
|
| 56 |
f.write(content)
|
| 57 |
+
|
| 58 |
+
print("\nβ
Backend patch complete")
|