Spaces:
Running
Running
REAL FIX: Keep old model IDs in available list (frontend hardcodes them) but route ALL through OpenRouter
Browse files- patch_agent.py +45 -13
patch_agent.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
"""Patch backend/routes/agent.py
|
| 2 |
import re
|
| 3 |
|
| 4 |
AGENT_FILE = "/app/backend/routes/agent.py"
|
|
@@ -12,7 +12,8 @@ content = content.replace(
|
|
| 12 |
'DEFAULT_FREE_MODEL_ID = "deepseek/deepseek-chat-v3-0324"'
|
| 13 |
)
|
| 14 |
|
| 15 |
-
# 2. Replace the entire _available_models function
|
|
|
|
| 16 |
old_func_pattern = r'def _available_models\(\).*?return models'
|
| 17 |
new_func = '''def _available_models() -> list[dict[str, Any]]:
|
| 18 |
models = [
|
|
@@ -42,31 +43,62 @@ new_func = '''def _available_models() -> list[dict[str, Any]]:
|
|
| 42 |
"provider": "openrouter",
|
| 43 |
"tier": "pro",
|
| 44 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
]
|
| 46 |
return models'''
|
| 47 |
|
| 48 |
content = re.sub(old_func_pattern, new_func, content, flags=re.DOTALL)
|
| 49 |
|
| 50 |
-
# 3.
|
| 51 |
content = re.sub(
|
| 52 |
r'PREMIUM_MODEL_IDS = \{[^}]+\}',
|
| 53 |
-
'PREMIUM_MODEL_IDS =
|
| 54 |
content
|
| 55 |
)
|
| 56 |
|
| 57 |
# Verify
|
| 58 |
-
assert "deepseek/deepseek-chat-v3-0324" in content
|
| 59 |
-
assert "
|
| 60 |
-
assert "
|
| 61 |
|
| 62 |
with open(AGENT_FILE, "w") as f:
|
| 63 |
f.write(content)
|
| 64 |
|
| 65 |
-
# Validate syntax
|
| 66 |
import ast
|
| 67 |
ast.parse(content)
|
| 68 |
-
print("✅ agent.py patched
|
| 69 |
-
print(f" - DeepSeek V3: ✓")
|
| 70 |
-
print(f" - Gemini 2.0 Flash: ✓")
|
| 71 |
-
print(f" - Qwen3 30B: ✓")
|
| 72 |
-
print(f" - Claude Sonnet 4: ✓")
|
|
|
|
| 1 |
+
"""Patch backend/routes/agent.py: Keep frontend-compatible model IDs but route all via OpenRouter."""
|
| 2 |
import re
|
| 3 |
|
| 4 |
AGENT_FILE = "/app/backend/routes/agent.py"
|
|
|
|
| 12 |
'DEFAULT_FREE_MODEL_ID = "deepseek/deepseek-chat-v3-0324"'
|
| 13 |
)
|
| 14 |
|
| 15 |
+
# 2. Replace the entire _available_models function - KEEP OLD IDs that frontend expects
|
| 16 |
+
# PLUS add new ones. Frontend shows what it wants, backend accepts all.
|
| 17 |
old_func_pattern = r'def _available_models\(\).*?return models'
|
| 18 |
new_func = '''def _available_models() -> list[dict[str, Any]]:
|
| 19 |
models = [
|
|
|
|
| 43 |
"provider": "openrouter",
|
| 44 |
"tier": "pro",
|
| 45 |
},
|
| 46 |
+
{
|
| 47 |
+
"id": "moonshotai/Kimi-K2.6",
|
| 48 |
+
"label": "Kimi K2.6 (→DeepSeek V3)",
|
| 49 |
+
"provider": "openrouter",
|
| 50 |
+
"tier": "free",
|
| 51 |
+
},
|
| 52 |
+
{
|
| 53 |
+
"id": _claude_picker_model_id(),
|
| 54 |
+
"label": "Claude (→DeepSeek V3)",
|
| 55 |
+
"provider": "openrouter",
|
| 56 |
+
"tier": "free",
|
| 57 |
+
},
|
| 58 |
+
{
|
| 59 |
+
"id": "openai/gpt-5.5",
|
| 60 |
+
"label": "GPT-5.5 (→DeepSeek V3)",
|
| 61 |
+
"provider": "openrouter",
|
| 62 |
+
"tier": "free",
|
| 63 |
+
},
|
| 64 |
+
{
|
| 65 |
+
"id": "MiniMaxAI/MiniMax-M2.7",
|
| 66 |
+
"label": "MiniMax (→DeepSeek V3)",
|
| 67 |
+
"provider": "openrouter",
|
| 68 |
+
"tier": "free",
|
| 69 |
+
},
|
| 70 |
+
{
|
| 71 |
+
"id": "zai-org/GLM-5.1",
|
| 72 |
+
"label": "GLM 5.1 (→DeepSeek V3)",
|
| 73 |
+
"provider": "openrouter",
|
| 74 |
+
"tier": "free",
|
| 75 |
+
},
|
| 76 |
+
{
|
| 77 |
+
"id": "deepseek-ai/DeepSeek-V4-Pro:deepinfra",
|
| 78 |
+
"label": "DeepSeek V4 (→DeepSeek V3)",
|
| 79 |
+
"provider": "openrouter",
|
| 80 |
+
"tier": "free",
|
| 81 |
+
},
|
| 82 |
]
|
| 83 |
return models'''
|
| 84 |
|
| 85 |
content = re.sub(old_func_pattern, new_func, content, flags=re.DOTALL)
|
| 86 |
|
| 87 |
+
# 3. Remove PREMIUM_MODEL_IDS gate so no model gets blocked
|
| 88 |
content = re.sub(
|
| 89 |
r'PREMIUM_MODEL_IDS = \{[^}]+\}',
|
| 90 |
+
'PREMIUM_MODEL_IDS = set() # No premium gate - all free via OpenRouter',
|
| 91 |
content
|
| 92 |
)
|
| 93 |
|
| 94 |
# Verify
|
| 95 |
+
assert "deepseek/deepseek-chat-v3-0324" in content
|
| 96 |
+
assert "moonshotai/Kimi-K2.6" in content # Keep old ID
|
| 97 |
+
assert "openai/gpt-5.5" in content # Keep old ID
|
| 98 |
|
| 99 |
with open(AGENT_FILE, "w") as f:
|
| 100 |
f.write(content)
|
| 101 |
|
|
|
|
| 102 |
import ast
|
| 103 |
ast.parse(content)
|
| 104 |
+
print("✅ agent.py patched - all old model IDs kept + routed via OpenRouter")
|
|
|
|
|
|
|
|
|
|
|
|