"""Patch backend: add 3 new OpenRouter models (openai/ prefix routes to OpenRouter). New models: - openai/upstage/solar-pro4 - openai/nvidia/nemotron-3.5-lightning:free - openai/liquid/lfm-2.5-2.6b:free The `openai/` prefix is already stripped in _resolve_llm_params and routed to OpenRouter, so we only need to register the model IDs, imports, and the available-models list. """ import ast import os IDS_FILE = "/app/agent/core/model_ids.py" AGENT_FILE = "/app/backend/routes/agent.py" # ---------- 1. model_ids.py ---------- with open(IDS_FILE) as f: c = f.read() new_constants = '''UPSTAGE_SOLAR_PRO4_MODEL_ID = "openai/upstage/solar-pro4" NEMOTRON_3_5_LIGHTNING_FREE_MODEL_ID = "openai/nvidia/nemotron-3.5-lightning:free" LIQUID_LFM_2_5_2_6B_FREE_MODEL_ID = "openai/liquid/lfm-2.5-2.6b:free" ''' if "UPSTAGE_SOLAR_PRO4_MODEL_ID" not in c: # Insert before DEEPSEEK_V4_PRO_MODEL_ID definition target = 'DEEPSEEK_V4_PRO_MODEL_ID = "nvidia/nemotron-3-super-120b-a12b:free"' if target in c: c = c.replace(target, new_constants + target) print("OK: added 3 new model constants to model_ids.py") else: # fallback: append at end of constants near TENCENT/HY3 block anchor = 'LING_3_0_FLASH_FREE_MODEL_ID = "openai/inclusionai/ling-3.0-flash:free"' if anchor in c: c = c.replace(anchor, anchor + "\n" + new_constants) print("OK: added constants after LING block") else: print("FAIL: could not find insertion anchor in model_ids.py") else: print("OK: constants already present") with open(IDS_FILE, "w") as f: f.write(c) ast.parse(c) print("OK: model_ids.py syntax OK") # ---------- 2. agent.py : imports + _available_models ---------- with open(AGENT_FILE) as f: ac = f.read() # Add imports if "UPSTAGE_SOLAR_PRO4_MODEL_ID" not in ac: old_imp = " NEX_N2_MINI_MODEL_ID,\n LING_3_0_FLASH_FREE_MODEL_ID,\n" new_imp = ( " NEX_N2_MINI_MODEL_ID,\n" " LING_3_0_FLASH_FREE_MODEL_ID,\n" " UPSTAGE_SOLAR_PRO4_MODEL_ID,\n" " NEMOTRON_3_5_LIGHTNING_FREE_MODEL_ID,\n" " LIQUID_LFM_2_5_2_6B_FREE_MODEL_ID,\n" ) if old_imp in ac: ac = ac.replace(old_imp, new_imp) print("OK: added new model imports") else: print("WARN: import anchor not matched") # Add to _available_models list - insert after LING_3_0_FLASH line old_line = ' {"id": LING_3_0_FLASH_FREE_MODEL_ID, "label": "inclusionai/ling-3.0-flash:free", "recommended": True},\n' new_line = old_line + ( ' {"id": UPSTAGE_SOLAR_PRO4_MODEL_ID, "label": "UPSTAGE Solar Pro 4", "recommended": True},\n' ' {"id": NEMOTRON_3_5_LIGHTNING_FREE_MODEL_ID, "label": "NVIDIA Nemotron 3.5 Lightning:free", "recommended": True},\n' ' {"id": LIQUID_LFM_2_5_2_6B_FREE_MODEL_ID, "label": "Liquid LFM 2.5 2.6B:free", "recommended": True},\n' ) if old_line in ac: ac = ac.replace(old_line, new_line) print("OK: added 3 new models to _available_models") else: print("WARN: _available_models LING line not matched (check exact text)") with open(AGENT_FILE, "w") as f: f.write(ac) ast.parse(ac) print("OK: agent.py syntax OK") print("DONE: 3 new OpenRouter models added (backend)")