Spaces:
Paused
Paused
Fix patch: ensure models are added correctly to the list
Browse files- patch_models.py +40 -93
patch_models.py
CHANGED
|
@@ -1,118 +1,65 @@
|
|
| 1 |
-
"""Build-time patch: Add
|
| 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 |
-
"id": "deepseek-ai/DeepSeek-V4-Pro:deepinfra",
|
| 12 |
-
"label": "DeepSeek V4 Pro",
|
| 13 |
-
"provider": "huggingface",
|
| 14 |
-
"tier": "free",
|
| 15 |
-
},
|
| 16 |
-
]
|
| 17 |
-
return models"""
|
| 18 |
|
| 19 |
-
|
| 20 |
-
"id": "deepseek-ai/DeepSeek-V4-Pro:deepinfra",
|
| 21 |
-
"label": "DeepSeek V4 Pro",
|
| 22 |
-
"provider": "huggingface",
|
| 23 |
-
"tier": "free",
|
| 24 |
-
},
|
| 25 |
-
{
|
| 26 |
-
"id": "openai/deepseek/deepseek-chat-v3-0324",
|
| 27 |
-
"label": "DeepSeek V3 (OpenRouter)",
|
| 28 |
-
"provider": "openrouter",
|
| 29 |
-
"tier": "free",
|
| 30 |
-
"recommended": True,
|
| 31 |
-
},
|
| 32 |
-
{
|
| 33 |
-
"id": "openai/google/gemini-2.0-flash-001",
|
| 34 |
-
"label": "Gemini 2.0 Flash (OpenRouter)",
|
| 35 |
-
"provider": "openrouter",
|
| 36 |
-
"tier": "free",
|
| 37 |
-
},
|
| 38 |
-
{
|
| 39 |
-
"id": "openai/qwen/qwen3-30b-a3b",
|
| 40 |
-
"label": "Qwen3 30B (OpenRouter)",
|
| 41 |
-
"provider": "openrouter",
|
| 42 |
-
"tier": "free",
|
| 43 |
-
},
|
| 44 |
-
]
|
| 45 |
-
return models"""
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
"id": "openai/deepseek/deepseek-chat-v3-0324",
|
| 57 |
-
"label": "DeepSeek V3 (OpenRouter)",
|
| 58 |
-
"provider": "openrouter",
|
| 59 |
-
"tier": "free",
|
| 60 |
-
"recommended": True,
|
| 61 |
-
},
|
| 62 |
-
{
|
| 63 |
-
"id": "openai/google/gemini-2.0-flash-001",
|
| 64 |
-
"label": "Gemini 2.0 Flash (OpenRouter)",
|
| 65 |
-
"provider": "openrouter",
|
| 66 |
-
"tier": "free",
|
| 67 |
-
},
|
| 68 |
-
{
|
| 69 |
-
"id": "openai/qwen/qwen3-30b-a3b",
|
| 70 |
-
"label": "Qwen3 30B (OpenRouter)",
|
| 71 |
-
"provider": "openrouter",
|
| 72 |
-
"tier": "free",
|
| 73 |
-
},
|
| 74 |
-
]
|
| 75 |
-
return models''',
|
| 76 |
-
1 # only first occurrence
|
| 77 |
-
)
|
| 78 |
-
print("✅ Added models via alternative method")
|
| 79 |
|
| 80 |
-
#
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
api_key=
|
| 88 |
|
| 89 |
if old_title in content:
|
| 90 |
content = content.replace(old_title, new_title)
|
| 91 |
-
# Remove reasoning_effort (not supported by DeepSeek)
|
| 92 |
content = content.replace(' reasoning_effort="low",\n', '')
|
| 93 |
-
print("✅ Title generation
|
| 94 |
else:
|
| 95 |
-
print("
|
| 96 |
-
|
| 97 |
-
# 3. Add "import os" if missing
|
| 98 |
-
if "\nimport os\n" not in content and "import os," not in content:
|
| 99 |
-
content = "import os\n" + content
|
| 100 |
-
print("✅ Added import os")
|
| 101 |
|
| 102 |
# Verify syntax
|
| 103 |
import ast
|
| 104 |
try:
|
| 105 |
ast.parse(content)
|
| 106 |
-
print("✅ Syntax
|
| 107 |
except SyntaxError as e:
|
| 108 |
-
print(f"❌ Syntax error
|
| 109 |
import sys; sys.exit(1)
|
| 110 |
|
| 111 |
with open(AGENT_FILE, "w") as f:
|
| 112 |
f.write(content)
|
| 113 |
|
| 114 |
-
#
|
| 115 |
-
assert "
|
| 116 |
-
assert "
|
| 117 |
-
|
| 118 |
-
print("\n✅ All patches applied successfully")
|
|
|
|
| 1 |
+
"""Build-time patch: Add Gemini + Qwen3 to models dropdown."""
|
| 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 |
+
# Find the AVAILABLE_MODELS assignment and add models after it
|
| 9 |
+
# The pattern: AVAILABLE_MODELS = _available_models()
|
| 10 |
+
# We'll append our models directly to the list after it's created
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
patch_code = '''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
# === PATCHED: Add OpenRouter models ===
|
| 15 |
+
import os as _os
|
| 16 |
+
_extra_models = [
|
| 17 |
+
{"id": "openai/google/gemini-2.0-flash-001", "label": "Gemini 2.0 Flash", "provider": "openrouter", "tier": "free", "recommended": True},
|
| 18 |
+
{"id": "openai/qwen/qwen3-30b-a3b", "label": "Qwen3 30B", "provider": "openrouter", "tier": "free"},
|
| 19 |
+
]
|
| 20 |
+
AVAILABLE_MODELS.extend(_extra_models)
|
| 21 |
+
# === END PATCH ===
|
| 22 |
+
'''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
+
# Insert after AVAILABLE_MODELS = _available_models()
|
| 25 |
+
target = "AVAILABLE_MODELS = _available_models()\n"
|
| 26 |
+
if target in content:
|
| 27 |
+
content = content.replace(target, target + patch_code)
|
| 28 |
+
print("✅ Added Gemini 2.0 Flash + Qwen3 30B after AVAILABLE_MODELS")
|
| 29 |
+
else:
|
| 30 |
+
# Try without newline
|
| 31 |
+
target2 = "AVAILABLE_MODELS = _available_models()"
|
| 32 |
+
if target2 in content:
|
| 33 |
+
content = content.replace(target2, target2 + "\n" + patch_code)
|
| 34 |
+
print("✅ Added models (alt method)")
|
| 35 |
+
else:
|
| 36 |
+
print("❌ Cannot find AVAILABLE_MODELS assignment!")
|
| 37 |
+
import sys; sys.exit(1)
|
| 38 |
|
| 39 |
+
# Fix title generation to use OpenRouter
|
| 40 |
+
old_title = 'model="openai/openai/gpt-oss-120b:cerebras",\n api_base="https://router.huggingface.co/v1",\n api_key=api_key,'
|
| 41 |
+
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),'
|
| 42 |
|
| 43 |
if old_title in content:
|
| 44 |
content = content.replace(old_title, new_title)
|
|
|
|
| 45 |
content = content.replace(' reasoning_effort="low",\n', '')
|
| 46 |
+
print("✅ Title generation fixed for OpenRouter")
|
| 47 |
else:
|
| 48 |
+
print("⚠️ Title pattern not found (may already be different)")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
# Verify syntax
|
| 51 |
import ast
|
| 52 |
try:
|
| 53 |
ast.parse(content)
|
| 54 |
+
print("✅ Syntax OK")
|
| 55 |
except SyntaxError as e:
|
| 56 |
+
print(f"❌ Syntax error: {e}")
|
| 57 |
import sys; sys.exit(1)
|
| 58 |
|
| 59 |
with open(AGENT_FILE, "w") as f:
|
| 60 |
f.write(content)
|
| 61 |
|
| 62 |
+
# Final check
|
| 63 |
+
assert "gemini-2.0-flash" in content, "Gemini not in file!"
|
| 64 |
+
assert "qwen3-30b" in content, "Qwen3 not in file!"
|
| 65 |
+
print("\n✅ Done - Gemini 2.0 Flash + Qwen3 30B added to dropdown")
|
|
|