Spaces:
Paused
Paused
Add nex-agi/nex-n2-mini + inclusionai/ling-3.0-flash:free (backend)
Browse files- patch_models.py +143 -35
patch_models.py
CHANGED
|
@@ -12,25 +12,72 @@ IDS_FILE = "/app/agent/core/model_ids.py"
|
|
| 12 |
with open(IDS_FILE, "r") as f:
|
| 13 |
content = f.read()
|
| 14 |
|
| 15 |
-
old_models_block =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
new_models_block =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
content = content.replace(old_models_block, new_models_block)
|
| 20 |
|
| 21 |
-
old_hosted =
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
content = content.replace(old_hosted, new_hosted)
|
| 24 |
|
| 25 |
with open(IDS_FILE, "w") as f:
|
| 26 |
f.write(content)
|
| 27 |
-
print("OK: model_ids.py patched")
|
| 28 |
|
| 29 |
-
# === Step 2: Patch agent.py
|
| 30 |
with open(AGENT_FILE) as f:
|
| 31 |
content = f.read()
|
| 32 |
|
| 33 |
-
# Make DEFAULT_MODEL_ID and DEFAULT_GPT_MODEL_ID point to our models
|
| 34 |
content = content.replace(
|
| 35 |
"DEFAULT_MODEL_ID = GLM_52_MODEL_ID",
|
| 36 |
'DEFAULT_MODEL_ID = "openai/tencent/hy3:free"'
|
|
@@ -40,17 +87,36 @@ content = content.replace(
|
|
| 40 |
'DEFAULT_GPT_MODEL_ID = LAGUNA_S21_FREE_MODEL_ID'
|
| 41 |
)
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
)
|
|
|
|
| 54 |
|
| 55 |
new_func = '''def _available_models() -> list[dict[str, Any]]:
|
| 56 |
models = [
|
|
@@ -79,6 +145,16 @@ new_func = '''def _available_models() -> list[dict[str, Any]]:
|
|
| 79 |
"label": "Laguna S 2.1:free",
|
| 80 |
"recommended": True,
|
| 81 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
{
|
| 83 |
"id": LLAMA_3_1_8B_MODEL_ID,
|
| 84 |
"label": "Llama 3.1 8B",
|
|
@@ -102,22 +178,54 @@ new_func = '''def _available_models() -> list[dict[str, Any]]:
|
|
| 102 |
]
|
| 103 |
return models'''
|
| 104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
func_match = func_pattern.search(content)
|
| 106 |
if func_match:
|
| 107 |
content = content[:func_match.start()] + new_func + content[func_match.end():]
|
| 108 |
-
print("OK: Replaced _available_models()
|
| 109 |
else:
|
| 110 |
-
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
if old_available in content:
|
| 113 |
content = content.replace(old_available, new_func)
|
| 114 |
print("OK: String replace worked")
|
| 115 |
else:
|
| 116 |
print("FAIL: Cannot find _available_models()!")
|
| 117 |
-
import sys
|
| 118 |
-
sys.exit(1)
|
| 119 |
|
| 120 |
-
# Update title generation
|
| 121 |
old_title = '"openai/gpt-oss-120b:cerebras",'
|
| 122 |
new_title = '"huggingface/deepseek-ai/DeepSeek-V4-Pro",'
|
| 123 |
content = content.replace(old_title, new_title)
|
|
@@ -133,7 +241,7 @@ with open(AGENT_FILE, "w") as f:
|
|
| 133 |
f.write(content)
|
| 134 |
print("OK: agent.py patched")
|
| 135 |
|
| 136 |
-
# === Step 3: Patch _resolve_llm_params
|
| 137 |
with open(LLM_PARAMS_FILE) as f:
|
| 138 |
llm_content = f.read()
|
| 139 |
|
|
@@ -141,18 +249,18 @@ if "normalized_model.startswith" not in llm_content:
|
|
| 141 |
api_key_find = "api_key = _resolve_hf_router_token(session_hf_token)"
|
| 142 |
if api_key_find in llm_content:
|
| 143 |
line_end = llm_content.find('\n', llm_content.find(api_key_find) + len(api_key_find)) + 1
|
| 144 |
-
routing_insert =
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
"
|
| 149 |
-
"
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
llm_content = llm_content[:line_end] + routing_insert + llm_content[line_end:]
|
| 155 |
-
print("OK: Patched _resolve_llm_params
|
| 156 |
else:
|
| 157 |
print("WARN: Could not find api_key line")
|
| 158 |
else:
|
|
|
|
| 12 |
with open(IDS_FILE, "r") as f:
|
| 13 |
content = f.read()
|
| 14 |
|
| 15 |
+
old_models_block = (
|
| 16 |
+
'CLAUDE_OPUS_48_MODEL_ID = "anthropic/claude-opus-4.8:fal-ai"\n'
|
| 17 |
+
'GPT_55_MODEL_ID = "openai/gpt-5.5:fal-ai"\n'
|
| 18 |
+
'KIMI_K27_CODE_MODEL_ID = "moonshotai/Kimi-K2.7-Code:novita"\n'
|
| 19 |
+
'MINIMAX_M3_MODEL_ID = "MiniMaxAI/MiniMax-M3:novita"\n'
|
| 20 |
+
'GLM_52_MODEL_ID = "zai-org/GLM-5.2:novita"\n'
|
| 21 |
+
'DEEPSEEK_V4_PRO_MODEL_ID = "deepseek-ai/DeepSeek-V4-Pro:novita"'
|
| 22 |
+
)
|
| 23 |
|
| 24 |
+
new_models_block = (
|
| 25 |
+
'GPT_55_MODEL_ID = "openai/gpt-5.5:fal-ai"\n'
|
| 26 |
+
'KIMI_K27_CODE_MODEL_ID = "deepseek-ai/DeepSeek-V4-Pro"\n'
|
| 27 |
+
'MINIMAX_M3_MODEL_ID = "deepseek-ai/DeepSeek-V4-Flash"\n'
|
| 28 |
+
'GLM_52_MODEL_ID = "openai/deepseek/deepseek-v4-flash"\n'
|
| 29 |
+
'DEEPSEEK_V4_PRO_MODEL_ID = "nvidia/nemotron-3-super-120b-a12b:free"\n'
|
| 30 |
+
'\n'
|
| 31 |
+
'# === PATCH: OpenRouter models ===\n'
|
| 32 |
+
'GEMMA_4_31B_FREE_MODEL_ID = "openai/google/gemma-4-31b-it:free"\n'
|
| 33 |
+
'TENCENT_HY3_FREE_MODEL_ID = "openai/tencent/hy3:free"\n'
|
| 34 |
+
'LLAMA_3_3_70B_FREE_MODEL_ID = "openai/meta-llama/llama-3.3-70b-instruct:free"\n'
|
| 35 |
+
'LLAMA_3_1_8B_MODEL_ID = "openai/meta-llama/llama-3.1-8b-instruct"\n'
|
| 36 |
+
'LAGUNA_M1_FREE_MODEL_ID = "openai/poolside/laguna-m.1:free"\n'
|
| 37 |
+
'LAGUNA_S21_FREE_MODEL_ID = "openai/poolside/laguna-s-2.1:free"\n'
|
| 38 |
+
'NEX_N2_MINI_MODEL_ID = "openai/nex-agi/nex-n2-mini"\n'
|
| 39 |
+
'LING_3_0_FLASH_FREE_MODEL_ID = "openai/inclusionai/ling-3.0-flash:free"\n'
|
| 40 |
+
)
|
| 41 |
|
| 42 |
content = content.replace(old_models_block, new_models_block)
|
| 43 |
|
| 44 |
+
old_hosted = (
|
| 45 |
+
"HOSTED_MODEL_IDS = {\n"
|
| 46 |
+
" CLAUDE_OPUS_48_MODEL_ID,\n"
|
| 47 |
+
" GPT_55_MODEL_ID,\n"
|
| 48 |
+
" KIMI_K27_CODE_MODEL_ID,\n"
|
| 49 |
+
" MINIMAX_M3_MODEL_ID,\n"
|
| 50 |
+
" GLM_52_MODEL_ID,\n"
|
| 51 |
+
" DEEPSEEK_V4_PRO_MODEL_ID,\n"
|
| 52 |
+
"}"
|
| 53 |
+
)
|
| 54 |
+
new_hosted = (
|
| 55 |
+
"HOSTED_MODEL_IDS = {\n"
|
| 56 |
+
" GPT_55_MODEL_ID,\n"
|
| 57 |
+
" KIMI_K27_CODE_MODEL_ID,\n"
|
| 58 |
+
" MINIMAX_M3_MODEL_ID,\n"
|
| 59 |
+
" GLM_52_MODEL_ID,\n"
|
| 60 |
+
" DEEPSEEK_V4_PRO_MODEL_ID,\n"
|
| 61 |
+
" GEMMA_4_31B_FREE_MODEL_ID,\n"
|
| 62 |
+
" TENCENT_HY3_FREE_MODEL_ID,\n"
|
| 63 |
+
" LLAMA_3_3_70B_FREE_MODEL_ID,\n"
|
| 64 |
+
" LLAMA_3_1_8B_MODEL_ID,\n"
|
| 65 |
+
" LAGUNA_M1_FREE_MODEL_ID,\n"
|
| 66 |
+
" LAGUNA_S21_FREE_MODEL_ID,\n"
|
| 67 |
+
" NEX_N2_MINI_MODEL_ID,\n"
|
| 68 |
+
" LING_3_0_FLASH_FREE_MODEL_ID,\n"
|
| 69 |
+
"}"
|
| 70 |
+
)
|
| 71 |
content = content.replace(old_hosted, new_hosted)
|
| 72 |
|
| 73 |
with open(IDS_FILE, "w") as f:
|
| 74 |
f.write(content)
|
| 75 |
+
print("OK: model_ids.py patched (Nex N2 + Ling 3.0 Flash added)")
|
| 76 |
|
| 77 |
+
# === Step 2: Patch agent.py ===
|
| 78 |
with open(AGENT_FILE) as f:
|
| 79 |
content = f.read()
|
| 80 |
|
|
|
|
| 81 |
content = content.replace(
|
| 82 |
"DEFAULT_MODEL_ID = GLM_52_MODEL_ID",
|
| 83 |
'DEFAULT_MODEL_ID = "openai/tencent/hy3:free"'
|
|
|
|
| 87 |
'DEFAULT_GPT_MODEL_ID = LAGUNA_S21_FREE_MODEL_ID'
|
| 88 |
)
|
| 89 |
|
| 90 |
+
old_import = (
|
| 91 |
+
"from agent.core.model_ids import (\n"
|
| 92 |
+
" CLAUDE_OPUS_48_MODEL_ID,\n"
|
| 93 |
+
" DEEPSEEK_V4_PRO_MODEL_ID,\n"
|
| 94 |
+
" GLM_52_MODEL_ID,\n"
|
| 95 |
+
" GPT_55_MODEL_ID,\n"
|
| 96 |
+
" KIMI_K27_CODE_MODEL_ID,\n"
|
| 97 |
+
" MINIMAX_M3_MODEL_ID,\n"
|
| 98 |
+
" strip_huggingface_model_prefix,\n"
|
| 99 |
+
")"
|
| 100 |
+
)
|
| 101 |
+
new_import = (
|
| 102 |
+
"from agent.core.model_ids import (\n"
|
| 103 |
+
" DEEPSEEK_V4_PRO_MODEL_ID,\n"
|
| 104 |
+
" GLM_52_MODEL_ID,\n"
|
| 105 |
+
" GPT_55_MODEL_ID,\n"
|
| 106 |
+
" KIMI_K27_CODE_MODEL_ID,\n"
|
| 107 |
+
" MINIMAX_M3_MODEL_ID,\n"
|
| 108 |
+
" GEMMA_4_31B_FREE_MODEL_ID,\n"
|
| 109 |
+
" TENCENT_HY3_FREE_MODEL_ID,\n"
|
| 110 |
+
" LLAMA_3_3_70B_FREE_MODEL_ID,\n"
|
| 111 |
+
" LLAMA_3_1_8B_MODEL_ID,\n"
|
| 112 |
+
" LAGUNA_M1_FREE_MODEL_ID,\n"
|
| 113 |
+
" LAGUNA_S21_FREE_MODEL_ID,\n"
|
| 114 |
+
" NEX_N2_MINI_MODEL_ID,\n"
|
| 115 |
+
" LING_3_0_FLASH_FREE_MODEL_ID,\n"
|
| 116 |
+
" strip_huggingface_model_prefix,\n"
|
| 117 |
+
")"
|
| 118 |
)
|
| 119 |
+
content = content.replace(old_import, new_import)
|
| 120 |
|
| 121 |
new_func = '''def _available_models() -> list[dict[str, Any]]:
|
| 122 |
models = [
|
|
|
|
| 145 |
"label": "Laguna S 2.1:free",
|
| 146 |
"recommended": True,
|
| 147 |
},
|
| 148 |
+
{
|
| 149 |
+
"id": NEX_N2_MINI_MODEL_ID,
|
| 150 |
+
"label": "nex-agi/nex-n2-mini",
|
| 151 |
+
"recommended": True,
|
| 152 |
+
},
|
| 153 |
+
{
|
| 154 |
+
"id": LING_3_0_FLASH_FREE_MODEL_ID,
|
| 155 |
+
"label": "inclusionai/ling-3.0-flash:free",
|
| 156 |
+
"recommended": True,
|
| 157 |
+
},
|
| 158 |
{
|
| 159 |
"id": LLAMA_3_1_8B_MODEL_ID,
|
| 160 |
"label": "Llama 3.1 8B",
|
|
|
|
| 178 |
]
|
| 179 |
return models'''
|
| 180 |
|
| 181 |
+
func_pattern = re.compile(
|
| 182 |
+
r'def _available_models\(\) -> list\[dict\[str, Any\]\]:\s*\n'
|
| 183 |
+
r'\s+models\s*=\s*\[.*?\]\s*\n\s+return models',
|
| 184 |
+
re.DOTALL
|
| 185 |
+
)
|
| 186 |
+
|
| 187 |
func_match = func_pattern.search(content)
|
| 188 |
if func_match:
|
| 189 |
content = content[:func_match.start()] + new_func + content[func_match.end():]
|
| 190 |
+
print("OK: Replaced _available_models()")
|
| 191 |
else:
|
| 192 |
+
old_available = (
|
| 193 |
+
'def _available_models() -> list[dict[str, Any]]:\n'
|
| 194 |
+
' models = [\n'
|
| 195 |
+
' {\n'
|
| 196 |
+
' "id": CLAUDE_OPUS_48_MODEL_ID,\n'
|
| 197 |
+
' "label": "Claude Opus 4.8",\n'
|
| 198 |
+
' },\n'
|
| 199 |
+
' {\n'
|
| 200 |
+
' "id": DEFAULT_GPT_MODEL_ID,\n'
|
| 201 |
+
' "label": "GPT-5.5",\n'
|
| 202 |
+
' },\n'
|
| 203 |
+
' {\n'
|
| 204 |
+
' "id": KIMI_K27_CODE_MODEL_ID,\n'
|
| 205 |
+
' "label": "Kimi K2.7 Code",\n'
|
| 206 |
+
' },\n'
|
| 207 |
+
' {\n'
|
| 208 |
+
' "id": MINIMAX_M3_MODEL_ID,\n'
|
| 209 |
+
' "label": "MiniMax M3",\n'
|
| 210 |
+
' },\n'
|
| 211 |
+
' {\n'
|
| 212 |
+
' "id": DEFAULT_MODEL_ID,\n'
|
| 213 |
+
' "label": "GLM 5.2",\n'
|
| 214 |
+
' "recommended": True,\n'
|
| 215 |
+
' },\n'
|
| 216 |
+
' {\n'
|
| 217 |
+
' "id": DEEPSEEK_V4_PRO_MODEL_ID,\n'
|
| 218 |
+
' "label": "DeepSeek V4 Pro",\n'
|
| 219 |
+
' },\n'
|
| 220 |
+
' ]\n'
|
| 221 |
+
' return models'
|
| 222 |
if old_available in content:
|
| 223 |
content = content.replace(old_available, new_func)
|
| 224 |
print("OK: String replace worked")
|
| 225 |
else:
|
| 226 |
print("FAIL: Cannot find _available_models()!")
|
| 227 |
+
import sys; sys.exit(1)
|
|
|
|
| 228 |
|
|
|
|
| 229 |
old_title = '"openai/gpt-oss-120b:cerebras",'
|
| 230 |
new_title = '"huggingface/deepseek-ai/DeepSeek-V4-Pro",'
|
| 231 |
content = content.replace(old_title, new_title)
|
|
|
|
| 241 |
f.write(content)
|
| 242 |
print("OK: agent.py patched")
|
| 243 |
|
| 244 |
+
# === Step 3: Patch _resolve_llm_params ===
|
| 245 |
with open(LLM_PARAMS_FILE) as f:
|
| 246 |
llm_content = f.read()
|
| 247 |
|
|
|
|
| 249 |
api_key_find = "api_key = _resolve_hf_router_token(session_hf_token)"
|
| 250 |
if api_key_find in llm_content:
|
| 251 |
line_end = llm_content.find('\n', llm_content.find(api_key_find) + len(api_key_find)) + 1
|
| 252 |
+
routing_insert = (
|
| 253 |
+
' # === PATCH: Route openai/-prefixed models to OpenRouter ===\n'
|
| 254 |
+
' if normalized_model.startswith("openai/"):\n'
|
| 255 |
+
' return {\n'
|
| 256 |
+
' "model": normalized_model,\n'
|
| 257 |
+
' "api_base": "https://openrouter.ai/api/v1",\n'
|
| 258 |
+
' "api_key": os.environ.get("OPENROUTER_API_KEY") or api_key or "",\n'
|
| 259 |
+
' }\n'
|
| 260 |
+
' # === END PATCH ===\n\n'
|
| 261 |
+
)
|
| 262 |
llm_content = llm_content[:line_end] + routing_insert + llm_content[line_end:]
|
| 263 |
+
print("OK: Patched _resolve_llm_params")
|
| 264 |
else:
|
| 265 |
print("WARN: Could not find api_key line")
|
| 266 |
else:
|