Spaces:
Running
Running
Add backend patch for crouton-alpha + lfm-3-1.7b (nemotron openai/ path)
Browse files- patch_crouton_lfm.py +88 -0
patch_crouton_lfm.py
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Patch backend: add 2 new OpenRouter models (openai/ prefix routes to OpenRouter).
|
| 2 |
+
|
| 3 |
+
New models (same `openai/` path convention as nemotron / space-bunny / lfm-2.5):
|
| 4 |
+
- openai/stealth/crouton-alpha
|
| 5 |
+
- openai/liquid/lfm-3-1.7b:free
|
| 6 |
+
|
| 7 |
+
The `openai/` prefix is already stripped in _resolve_llm_params and routed to
|
| 8 |
+
OpenRouter, so we only need to register the model IDs, imports, and the
|
| 9 |
+
available-models list.
|
| 10 |
+
|
| 11 |
+
Runs AFTER patch_models.py / patch_new_models.py / patch_apodex_ling_beatapi.py /
|
| 12 |
+
patch_xing_nemotron_vl.py / patch_agent_backend.py. Idempotent.
|
| 13 |
+
"""
|
| 14 |
+
|
| 15 |
+
import ast
|
| 16 |
+
|
| 17 |
+
IDS_FILE = "/app/agent/core/model_ids.py"
|
| 18 |
+
AGENT_FILE = "/app/backend/routes/agent.py"
|
| 19 |
+
|
| 20 |
+
# ---------- 1. model_ids.py ----------
|
| 21 |
+
with open(IDS_FILE) as f:
|
| 22 |
+
c = f.read()
|
| 23 |
+
|
| 24 |
+
new_constants = (
|
| 25 |
+
'CROUTON_ALPHA_MODEL_ID = "openai/stealth/crouton-alpha"\n'
|
| 26 |
+
'LFM_3_1_7B_FREE_MODEL_ID = "openai/liquid/lfm-3-1.7b:free"\n'
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
if "CROUTON_ALPHA_MODEL_ID" not in c:
|
| 30 |
+
# Insert before DEEPSEEK_V4_PRO_MODEL_ID definition (same anchor the other
|
| 31 |
+
# model patches use).
|
| 32 |
+
target = 'DEEPSEEK_V4_PRO_MODEL_ID = "nvidia/nemotron-3-super-120b-a12b:free"'
|
| 33 |
+
if target in c:
|
| 34 |
+
c = c.replace(target, new_constants + target)
|
| 35 |
+
print("OK: added 2 new model constants to model_ids.py")
|
| 36 |
+
else:
|
| 37 |
+
# Fallback anchor: the LING_3_0_FLASH line injected by patch_models.py.
|
| 38 |
+
anchor = 'LING_3_0_FLASH_FREE_MODEL_ID = "openai/inclusionai/ling-3.0-flash:free"'
|
| 39 |
+
if anchor in c:
|
| 40 |
+
c = c.replace(anchor, anchor + "\n" + new_constants)
|
| 41 |
+
print("OK: added constants after LING block")
|
| 42 |
+
else:
|
| 43 |
+
print("FAIL: could not find insertion anchor in model_ids.py")
|
| 44 |
+
else:
|
| 45 |
+
print("OK: constants already present")
|
| 46 |
+
|
| 47 |
+
with open(IDS_FILE, "w") as f:
|
| 48 |
+
f.write(c)
|
| 49 |
+
ast.parse(c)
|
| 50 |
+
print("OK: model_ids.py syntax OK")
|
| 51 |
+
|
| 52 |
+
# ---------- 2. agent.py : imports + _available_models ----------
|
| 53 |
+
with open(AGENT_FILE) as f:
|
| 54 |
+
ac = f.read()
|
| 55 |
+
|
| 56 |
+
# Add imports
|
| 57 |
+
if "CROUTON_ALPHA_MODEL_ID" not in ac:
|
| 58 |
+
old_imp = " NEX_N2_MINI_MODEL_ID,\n LING_3_0_FLASH_FREE_MODEL_ID,\n"
|
| 59 |
+
new_imp = (
|
| 60 |
+
" NEX_N2_MINI_MODEL_ID,\n"
|
| 61 |
+
" LING_3_0_FLASH_FREE_MODEL_ID,\n"
|
| 62 |
+
" CROUTON_ALPHA_MODEL_ID,\n"
|
| 63 |
+
" LFM_3_1_7B_FREE_MODEL_ID,\n"
|
| 64 |
+
)
|
| 65 |
+
if old_imp in ac:
|
| 66 |
+
ac = ac.replace(old_imp, new_imp)
|
| 67 |
+
print("OK: added new model imports")
|
| 68 |
+
else:
|
| 69 |
+
print("WARN: import anchor not matched")
|
| 70 |
+
|
| 71 |
+
# Add to _available_models list - insert after LING_3_0_FLASH line
|
| 72 |
+
old_line = ' {"id": LING_3_0_FLASH_FREE_MODEL_ID, "label": "inclusionai/ling-3.0-flash:free", "recommended": True},\n'
|
| 73 |
+
new_line = old_line + (
|
| 74 |
+
' {"id": CROUTON_ALPHA_MODEL_ID, "label": "stealth/crouton-alpha", "recommended": True},\n'
|
| 75 |
+
' {"id": LFM_3_1_7B_FREE_MODEL_ID, "label": "liquid/lfm-3-1.7b:free", "recommended": True},\n'
|
| 76 |
+
)
|
| 77 |
+
if old_line in ac:
|
| 78 |
+
ac = ac.replace(old_line, new_line)
|
| 79 |
+
print("OK: added 2 new models to _available_models")
|
| 80 |
+
else:
|
| 81 |
+
print("WARN: _available_models LING line not matched (check exact text)")
|
| 82 |
+
|
| 83 |
+
with open(AGENT_FILE, "w") as f:
|
| 84 |
+
f.write(ac)
|
| 85 |
+
ast.parse(ac)
|
| 86 |
+
print("OK: agent.py syntax OK")
|
| 87 |
+
|
| 88 |
+
print("DONE: 2 new OpenRouter models added (backend)")
|