Upload patch_models.py

#11
by bep40 - opened
Files changed (1) hide show
  1. patch_models.py +13 -4
patch_models.py CHANGED
@@ -26,7 +26,7 @@ content = content.replace(
26
  )
27
  content = content.replace(
28
  'GLM_52_MODEL_ID = "zai-org/GLM-5.2:novita"',
29
- 'GLM_52_MODEL_ID = "deepseek/deepseek-v4-flash"',
30
  )
31
  content = content.replace(
32
  'DEEPSEEK_V4_PRO_MODEL_ID = "deepseek-ai/DeepSeek-V4-Pro:novita"',
@@ -43,7 +43,8 @@ LAGUNA_M1_FREE_MODEL_ID = "openai/poolside/laguna-m.1:free"
43
  LAGUNA_S21_FREE_MODEL_ID = "openai/poolside/laguna-s-2.1:free"
44
  NEX_N2_MINI_MODEL_ID = "openai/nex-agi/nex-n2-mini"
45
  LING_3_0_FLASH_FREE_MODEL_ID = "openai/inclusionai/ling-3.0-flash:free"
46
- DEEPSEEK_V4_FLASH_LATEST_MODEL_ID = "~deepseek/deepseek-v4-flash-latest"
 
47
  """
48
  if "GEMMA_4_31B_FREE_MODEL_ID" not in content:
49
  content = content.replace(
@@ -104,6 +105,7 @@ new_import = (
104
  " NEX_N2_MINI_MODEL_ID,\n"
105
  " LING_3_0_FLASH_FREE_MODEL_ID,\n"
106
  " DEEPSEEK_V4_FLASH_LATEST_MODEL_ID,\n"
 
107
  " strip_huggingface_model_prefix,\n"
108
  ")"
109
  )
@@ -181,7 +183,7 @@ with open(AGENT_FILE, "w") as f:
181
  f.write(content)
182
  print("OK: agent.py patched")
183
 
184
- # === Step 3: Patch _resolve_llm_params ===
185
  with open(LLM_PARAMS_FILE) as f:
186
  llm_content = f.read()
187
 
@@ -190,13 +192,20 @@ if "normalized_model.startswith" not in llm_content:
190
  if api_key_find in llm_content:
191
  line_end = llm_content.find("\n", llm_content.find(api_key_find) + len(api_key_find)) + 1
192
  routing_insert = (
193
- ' # Route deepseek/-prefixed models to OpenRouter\n'
194
  ' if normalized_model.startswith("~deepseek/") or normalized_model.startswith("deepseek/"):\n'
195
  ' return {\n'
196
  ' "model": normalized_model,\n'
197
  ' "api_base": "https://openrouter.ai/api/v1",\n'
198
  ' "api_key": os.environ.get("OPENROUTER_API_KEY") or api_key or "",\n'
199
  ' }\n\n'
 
 
 
 
 
 
 
200
  )
201
  llm_content = llm_content[:line_end] + routing_insert + llm_content[line_end:]
202
  print("OK: Patched _resolve_llm_params")
 
26
  )
27
  content = content.replace(
28
  'GLM_52_MODEL_ID = "zai-org/GLM-5.2:novita"',
29
+ 'GLM_52_MODEL_ID = "openai/deepseek/deepseek-v4-flash"',
30
  )
31
  content = content.replace(
32
  'DEEPSEEK_V4_PRO_MODEL_ID = "deepseek-ai/DeepSeek-V4-Pro:novita"',
 
43
  LAGUNA_S21_FREE_MODEL_ID = "openai/poolside/laguna-s-2.1:free"
44
  NEX_N2_MINI_MODEL_ID = "openai/nex-agi/nex-n2-mini"
45
  LING_3_0_FLASH_FREE_MODEL_ID = "openai/inclusionai/ling-3.0-flash:free"
46
+ DEEPSEEK_V4_FLASH_LATEST_MODEL_ID = "~deepseek/deepseek-v4-flash-0731"
47
+ NO_TOOLS_MODELS = {"~deepseek/deepseek-v4-flash-0731", "openai/deepseek/deepseek-v4-flash"}
48
  """
49
  if "GEMMA_4_31B_FREE_MODEL_ID" not in content:
50
  content = content.replace(
 
105
  " NEX_N2_MINI_MODEL_ID,\n"
106
  " LING_3_0_FLASH_FREE_MODEL_ID,\n"
107
  " DEEPSEEK_V4_FLASH_LATEST_MODEL_ID,\n"
108
+ " NO_TOOLS_MODELS,\n"
109
  " strip_huggingface_model_prefix,\n"
110
  ")"
111
  )
 
183
  f.write(content)
184
  print("OK: agent.py patched")
185
 
186
+ # === Step 3: Patch _resolve_llm_params to auto-disable tools for DeepSeek ===
187
  with open(LLM_PARAMS_FILE) as f:
188
  llm_content = f.read()
189
 
 
192
  if api_key_find in llm_content:
193
  line_end = llm_content.find("\n", llm_content.find(api_key_find) + len(api_key_find)) + 1
194
  routing_insert = (
195
+ ' # Route deepseek/-prefixed models to OpenRouter (no tool use)\n'
196
  ' if normalized_model.startswith("~deepseek/") or normalized_model.startswith("deepseek/"):\n'
197
  ' return {\n'
198
  ' "model": normalized_model,\n'
199
  ' "api_base": "https://openrouter.ai/api/v1",\n'
200
  ' "api_key": os.environ.get("OPENROUTER_API_KEY") or api_key or "",\n'
201
  ' }\n\n'
202
+ ' # Route openai/-prefixed models to OpenRouter\n'
203
+ ' if normalized_model.startswith("openai/"):\n'
204
+ ' return {\n'
205
+ ' "model": normalized_model,\n'
206
+ ' "api_base": "https://openrouter.ai/api/v1",\n'
207
+ ' "api_key": os.environ.get("OPENROUTER_API_KEY") or api_key or "",\n'
208
+ ' }\n\n'
209
  )
210
  llm_content = llm_content[:line_end] + routing_insert + llm_content[line_end:]
211
  print("OK: Patched _resolve_llm_params")