Spaces:
Paused
Paused
Fix: DeepSeek V4 Flash routing - use HF Router path instead of broken OpenRouter path
Browse files- patch_models.py +35 -8
patch_models.py
CHANGED
|
@@ -1,4 +1,17 @@
|
|
| 1 |
-
"""Patch backend: OpenRouter routing + DeepSeek V4 Flash 0731.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
import ast
|
| 4 |
import os
|
|
@@ -16,14 +29,21 @@ if "NO_TOOLS_MODELS" in content:
|
|
| 16 |
content = re.sub(r'NO_TOOLS_MODELS\s*=\s*\{[^}]*\}\n?', '', content)
|
| 17 |
print("OK: Removed old NO_TOOLS_MODELS")
|
| 18 |
|
| 19 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
replacements = [
|
| 21 |
('KIMI_K27_CODE_MODEL_ID = "moonshotai/Kimi-K2.7-Code:novita"',
|
| 22 |
-
'KIMI_K27_CODE_MODEL_ID = "deepseek-ai/DeepSeek-V4-Pro"'),
|
| 23 |
('MINIMAX_M3_MODEL_ID = "MiniMaxAI/MiniMax-M3:novita"',
|
| 24 |
-
'MINIMAX_M3_MODEL_ID = "deepseek-ai/DeepSeek-V4-Flash"'),
|
|
|
|
|
|
|
|
|
|
| 25 |
('GLM_52_MODEL_ID = "zai-org/GLM-5.2:novita"',
|
| 26 |
-
'GLM_52_MODEL_ID = "
|
| 27 |
('DEEPSEEK_V4_PRO_MODEL_ID = "deepseek-ai/DeepSeek-V4-Pro:novita"',
|
| 28 |
'DEEPSEEK_V4_PRO_MODEL_ID = "nvidia/nemotron-3-super-120b-a12b:free"'),
|
| 29 |
]
|
|
@@ -169,6 +189,9 @@ with open(AGENT_FILE, "w") as f:
|
|
| 169 |
f.write(content)
|
| 170 |
|
| 171 |
# Patch llm_params for OpenRouter routing
|
|
|
|
|
|
|
|
|
|
| 172 |
with open(LLM_PARAMS_FILE) as f:
|
| 173 |
llm_content = f.read()
|
| 174 |
|
|
@@ -185,15 +208,19 @@ if "normalized_model.startswith" not in llm_content:
|
|
| 185 |
' "api_key": os.environ.get("OPENROUTER_API_KEY") or api_key or "",\n'
|
| 186 |
' }\n\n'
|
| 187 |
' # Route openai/-prefixed models to OpenRouter\n'
|
|
|
|
|
|
|
|
|
|
| 188 |
' if normalized_model.startswith("openai/"):\n'
|
|
|
|
| 189 |
' return {\n'
|
| 190 |
-
' "model":
|
| 191 |
' "api_base": "https://openrouter.ai/api/v1",\n'
|
| 192 |
' "api_key": os.environ.get("OPENROUTER_API_KEY") or api_key or "",\n'
|
| 193 |
' }\n\n'
|
| 194 |
)
|
| 195 |
llm_content = llm_content[:line_end] + routing_insert + llm_content[line_end:]
|
| 196 |
-
print("OK: Patched _resolve_llm_params with deepseek/ routing")
|
| 197 |
else:
|
| 198 |
print("WARN: Could not find api_key line")
|
| 199 |
else:
|
|
@@ -209,4 +236,4 @@ except SyntaxError as e:
|
|
| 209 |
with open(LLM_PARAMS_FILE, "w") as f:
|
| 210 |
f.write(llm_content)
|
| 211 |
|
| 212 |
-
print("OK: ALL BACKEND PATCHES APPLIED")
|
|
|
|
| 1 |
+
"""Patch backend: OpenRouter routing + DeepSeek V4 Flash 0731 + FIX DeepSeek routing.
|
| 2 |
+
|
| 3 |
+
FIX: GLM_52_MODEL_ID was set to "openai/deepseek/deepseek-v4-flash" which routes
|
| 4 |
+
to OpenRouter via the openai/ prefix catch-all. However, OpenRouter's model ID
|
| 5 |
+
is "deepseek/deepseek-v4-flash" (without the openai/ prefix). When LiteLLM
|
| 6 |
+
sends the full "openai/deepseek/deepseek-v4-flash" as the model name to
|
| 7 |
+
OpenRouter's API, it gets a 404 because OpenRouter doesn't recognize the
|
| 8 |
+
"openai/" prefix.
|
| 9 |
+
|
| 10 |
+
Solution:
|
| 11 |
+
1. GLM_52_MODEL_ID -> "deepseek-ai/DeepSeek-V4-Flash:deepinfra" (HF Router path, model exists there, cheapest provider)
|
| 12 |
+
2. OpenRouter routing strips the "openai/" prefix before sending to OpenRouter
|
| 13 |
+
3. Add :novita tag to DeepSeek V4 Pro for deterministic routing via HF Router
|
| 14 |
+
"""
|
| 15 |
|
| 16 |
import ast
|
| 17 |
import os
|
|
|
|
| 29 |
content = re.sub(r'NO_TOOLS_MODELS\s*=\s*\{[^}]*\}\n?', '', content)
|
| 30 |
print("OK: Removed old NO_TOOLS_MODELS")
|
| 31 |
|
| 32 |
+
# FIX: Set GLM_52_MODEL_ID to HF Router path with provider tag.
|
| 33 |
+
# "deepseek-ai/DeepSeek-V4-Flash:deepinfra" IS available on HF Router
|
| 34 |
+
# (5 providers for -0731 variant, 3 for standard). All support tools, 1M context.
|
| 35 |
+
# Using :deepinfra for better pricing ($0.09/0.18 per 1M tokens)
|
| 36 |
+
# KIMI_K27_CODE_MODEL_ID -> DeepSeek V4 Pro via HF Router with :novita tag
|
| 37 |
replacements = [
|
| 38 |
('KIMI_K27_CODE_MODEL_ID = "moonshotai/Kimi-K2.7-Code:novita"',
|
| 39 |
+
'KIMI_K27_CODE_MODEL_ID = "deepseek-ai/DeepSeek-V4-Pro:novita"'),
|
| 40 |
('MINIMAX_M3_MODEL_ID = "MiniMaxAI/MiniMax-M3:novita"',
|
| 41 |
+
'MINIMAX_M3_MODEL_ID = "deepseek-ai/DeepSeek-V4-Flash:deepinfra"'),
|
| 42 |
+
# FIX: Was "openai/deepseek/deepseek-v4-flash" which routes to OpenRouter but
|
| 43 |
+
# OpenRouter model IDs don't include the "openai/" prefix, causing 404.
|
| 44 |
+
# Change to HF Router path with :deepinfra provider tag for cheaper pricing.
|
| 45 |
('GLM_52_MODEL_ID = "zai-org/GLM-5.2:novita"',
|
| 46 |
+
'GLM_52_MODEL_ID = "deepseek-ai/DeepSeek-V4-Flash:deepinfra"'),
|
| 47 |
('DEEPSEEK_V4_PRO_MODEL_ID = "deepseek-ai/DeepSeek-V4-Pro:novita"',
|
| 48 |
'DEEPSEEK_V4_PRO_MODEL_ID = "nvidia/nemotron-3-super-120b-a12b:free"'),
|
| 49 |
]
|
|
|
|
| 189 |
f.write(content)
|
| 190 |
|
| 191 |
# Patch llm_params for OpenRouter routing
|
| 192 |
+
# FIX: Strip the "openai/" prefix before sending model name to OpenRouter
|
| 193 |
+
# OpenRouter model IDs do not include the "openai/" prefix.
|
| 194 |
+
# e.g. "openai/tencent/hy3:free" -> "tencent/hy3:free"
|
| 195 |
with open(LLM_PARAMS_FILE) as f:
|
| 196 |
llm_content = f.read()
|
| 197 |
|
|
|
|
| 208 |
' "api_key": os.environ.get("OPENROUTER_API_KEY") or api_key or "",\n'
|
| 209 |
' }\n\n'
|
| 210 |
' # Route openai/-prefixed models to OpenRouter\n'
|
| 211 |
+
' # FIX: Strip the "openai/" prefix - OpenRouter model IDs do not include it.\n'
|
| 212 |
+
' # e.g. "openai/deepseek/deepseek-v4-flash" -> "deepseek/deepseek-v4-flash"\n'
|
| 213 |
+
' # e.g. "openai/tencent/hy3:free" -> "tencent/hy3:free"\n'
|
| 214 |
' if normalized_model.startswith("openai/"):\n'
|
| 215 |
+
' or_model = normalized_model[len("openai/"):]\n'
|
| 216 |
' return {\n'
|
| 217 |
+
' "model": or_model,\n'
|
| 218 |
' "api_base": "https://openrouter.ai/api/v1",\n'
|
| 219 |
' "api_key": os.environ.get("OPENROUTER_API_KEY") or api_key or "",\n'
|
| 220 |
' }\n\n'
|
| 221 |
)
|
| 222 |
llm_content = llm_content[:line_end] + routing_insert + llm_content[line_end:]
|
| 223 |
+
print("OK: Patched _resolve_llm_params with deepseek/ + fixed openai/ routing")
|
| 224 |
else:
|
| 225 |
print("WARN: Could not find api_key line")
|
| 226 |
else:
|
|
|
|
| 236 |
with open(LLM_PARAMS_FILE, "w") as f:
|
| 237 |
f.write(llm_content)
|
| 238 |
|
| 239 |
+
print("OK: ALL BACKEND PATCHES APPLIED (including DeepSeek V4 Flash routing fix)")
|