Upload patch_models.py

#14
by bep40 - opened
Files changed (1) hide show
  1. patch_models.py +27 -24
patch_models.py CHANGED
@@ -16,26 +16,25 @@ 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
- # Fix model IDs for OpenRouter
20
- content = content.replace(
21
- 'KIMI_K27_CODE_MODEL_ID = "moonshotai/Kimi-K2.7-Code:novita"',
22
- 'KIMI_K27_CODE_MODEL_ID = "deepseek-ai/DeepSeek-V4-Pro"'
23
- )
24
- content = content.replace(
25
- 'MINIMAX_M3_MODEL_ID = "MiniMaxAI/MiniMax-M3:novita"',
26
- 'MINIMAX_M3_MODEL_ID = "deepseek-ai/DeepSeek-V4-Flash"'
27
- )
28
- content = content.replace(
29
- 'GLM_52_MODEL_ID = "zai-org/GLM-5.2:novita"',
30
- 'GLM_52_MODEL_ID = "openai/deepseek/deepseek-v4-flash"'
31
- )
32
- content = content.replace(
33
- 'DEEPSEEK_V4_PRO_MODEL_ID = "deepseek-ai/DeepSeek-V4-Pro:novita"',
34
- 'DEEPSEEK_V4_PRO_MODEL_ID = "nvidia/nemotron-3-super-120b-a12b:free"'
35
- )
36
-
37
- # Add missing constants before DEEPSEEK_V4_PRO_MODEL_ID line
38
- insert_before = '''TENCENT_HY3_FREE_MODEL_ID = "openai/tencent/hy3:free"
39
  GEMMA_4_31B_FREE_MODEL_ID = "openai/google/gemma-4-31b-it:free"
40
  LLAMA_3_3_70B_FREE_MODEL_ID = "openai/meta-llama/llama-3.3-70b-instruct:free"
41
  LLAMA_3_1_8B_MODEL_ID = "openai/meta-llama/llama-3.1-8b-instruct"
@@ -44,16 +43,20 @@ 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
  '''
47
- if "TENCENT_HY3_FREE_MODEL_ID" not in content:
48
- content = content.replace('DEEPSEEK_V4_PRO_MODEL_ID', insert_before + 'DEEPSEEK_V4_PRO_MODEL_ID')
 
 
 
 
49
 
50
- # Replace all references to latest deepseek models with 0731 version
51
  content = content.replace('"~deepseek/deepseek-v4-flash-latest"', '"deepseek/deepseek-v4-flash-0731"')
52
  content = content.replace('"~deepseek/deepseek-v4-flash-0731"', '"deepseek/deepseek-v4-flash-0731"')
53
 
54
  with open(IDS_FILE, "w") as f:
55
  f.write(content)
56
- print("OK: model_ids.py patched")
57
 
58
  ast.parse(content) # validate syntax
59
  print("OK: model_ids.py syntax OK")
 
16
  content = re.sub(r'NO_TOOLS_MODELS\s*=\s*\{[^}]*\}\n?', '', content)
17
  print("OK: Removed old NO_TOOLS_MODELS")
18
 
19
+ # Fix model IDs for OpenRouter - use exact full-line patterns to avoid accidental partial matches
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 = "openai/deepseek/deepseek-v4-flash"'),
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
+ ]
30
+ for old, new in replacements:
31
+ content = content.replace(old, new)
32
+ print("OK: Model ID replacements applied")
33
+
34
+ # Add missing constants BEFORE the specific line DEEPSEEK_V4_PRO_MODEL_ID = "..."
35
+ if "TENCENT_HY3_FREE_MODEL_ID" not in content:
36
+ target_line = 'DEEPSEEK_V4_PRO_MODEL_ID = "nvidia/nemotron-3-super-120b-a12b:free"'
37
+ insert_block = '''TENCENT_HY3_FREE_MODEL_ID = "openai/tencent/hy3:free"
 
38
  GEMMA_4_31B_FREE_MODEL_ID = "openai/google/gemma-4-31b-it:free"
39
  LLAMA_3_3_70B_FREE_MODEL_ID = "openai/meta-llama/llama-3.3-70b-instruct:free"
40
  LLAMA_3_1_8B_MODEL_ID = "openai/meta-llama/llama-3.1-8b-instruct"
 
43
  NEX_N2_MINI_MODEL_ID = "openai/nex-agi/nex-n2-mini"
44
  LING_3_0_FLASH_FREE_MODEL_ID = "openai/inclusionai/ling-3.0-flash:free"
45
  '''
46
+ # Only replace the first occurrence (the variable definition)
47
+ if target_line in content:
48
+ content = content.replace(target_line, insert_block + target_line)
49
+ print("OK: Added missing constants")
50
+ else:
51
+ print("WARN: Could not find target line")
52
 
53
+ # Replace all references to ~deepseek deepseek models with 0731 version (quoted strings only)
54
  content = content.replace('"~deepseek/deepseek-v4-flash-latest"', '"deepseek/deepseek-v4-flash-0731"')
55
  content = content.replace('"~deepseek/deepseek-v4-flash-0731"', '"deepseek/deepseek-v4-flash-0731"')
56
 
57
  with open(IDS_FILE, "w") as f:
58
  f.write(content)
59
+ print("OK: model_ids.py written")
60
 
61
  ast.parse(content) # validate syntax
62
  print("OK: model_ids.py syntax OK")