bep40 commited on
Commit
64fe76f
Β·
verified Β·
1 Parent(s): 3d39bbc

Fix: patch existing dropdown items exactly as specified

Browse files
Files changed (1) hide show
  1. patch_models.py +48 -32
patch_models.py CHANGED
@@ -1,50 +1,63 @@
1
- """Patch backend: add new model IDs to AVAILABLE_MODELS + fix title generation."""
2
  import re, os
3
 
4
  AGENT_FILE = "/app/backend/routes/agent.py"
5
  with open(AGENT_FILE, "r") as f:
6
  content = f.read()
7
 
8
- # Add new models to AVAILABLE_MODELS
9
- target = "AVAILABLE_MODELS = _available_models()\n"
10
- patch = '''
11
- # === PATCH: Add models ===
12
- import os as _os
13
- AVAILABLE_MODELS.extend([
14
- {"id": "openai/openrouter/owl-alpha", "label": "Owl Alpha", "provider": "openrouter", "tier": "free", "recommended": True},
15
- {"id": "openai/nvidia/nemotron-3-super-120b-a12b:free", "label": "Nemotron 3 Super 120B", "provider": "openrouter", "tier": "free", "recommended": True},
16
- {"id": "openai/deepseek/deepseek-v4-pro", "label": "DeepSeek V4 Pro", "provider": "openrouter", "tier": "free", "recommended": True},
17
- {"id": "Qwen/Qwen3-Coder-Next", "label": "Qwen3 Coder Next", "provider": "huggingface", "tier": "free", "recommended": True},
18
- {"id": "openai/xiaomi/mimo-v2.5", "label": "Mimo V2.5", "provider": "openrouter", "tier": "free"},
19
- {"id": "google/gemma-3-1b-it", "label": "Gemma 3 1B", "provider": "huggingface", "tier": "free"},
20
- {"id": "openai/google/gemini-2.0-flash-001", "label": "Gemini 2.0 Flash", "provider": "openrouter", "tier": "free"},
21
- ])
22
- PREMIUM_MODEL_IDS = set() # No premium gate
23
- DEFAULT_FREE_MODEL_ID = "openai/openrouter/owl-alpha"
24
- # === END PATCH ===
25
- '''
26
-
27
- if target in content:
28
- content = content.replace(target, target + patch)
29
- print("βœ… Added models to AVAILABLE_MODELS")
30
-
31
- # Rename Claude β†’ Owl Alpha
32
- content = content.replace('"label": "Claude Opus 4.6"', '"label": "Owl Alpha (OpenRouter)"')
33
- content = content.replace('return session_manager.config.model_name', 'return "openai/openrouter/owl-alpha"')
34
- print("βœ… Renamed Claude β†’ Owl Alpha")
 
 
 
 
 
 
 
 
 
35
 
36
  # Fix title generation
37
  old_patterns = [
38
  'model="openai/openai/gpt-oss-120b:cerebras",\n api_base="https://router.huggingface.co/v1",\n api_key=api_key,',
39
- 'model="openai/openrouter/owl-alpha",\n api_base="https://openrouter.ai/api/v1",\n api_key=_os.environ.get("OPENROUTER_API_KEY", api_key),',
40
  ]
41
-
42
- new_title_call = 'model="openai/openrouter/owl-alpha",\n api_base="https://openrouter.ai/api/v1",\n api_key=_os.environ.get("OPENROUTER_API_KEY", api_key),'
43
 
44
  for old in old_patterns:
45
  if old in content:
46
  content = content.replace(old, new_title_call)
47
- print(f"βœ… Title generation patched")
 
 
 
 
 
 
48
  break
49
 
50
  content = content.replace(' reasoning_effort="low",\n', '')
@@ -60,3 +73,6 @@ except SyntaxError as e:
60
  with open(AGENT_FILE, "w") as f:
61
  f.write(content)
62
  print("βœ… Backend patched")
 
 
 
 
1
+ """Patch backend: modify existing AVAILABLE_MODELS entries + fix title generation."""
2
  import re, os
3
 
4
  AGENT_FILE = "/app/backend/routes/agent.py"
5
  with open(AGENT_FILE, "r") as f:
6
  content = f.read()
7
 
8
+ # Replace existing model entries in _available_models()
9
+ # 1. Kimi K2.6 β†’ DeepSeek V4 Pro (HF Inference)
10
+ content = content.replace(
11
+ '"moonshotai/Kimi-K2.6"',
12
+ '"deepseek-ai/DeepSeek-V4-Pro"'
13
+ )
14
+ content = content.replace(
15
+ '"Kimi K2.6"',
16
+ '"DeepSeek V4 Pro"'
17
+ )
18
+
19
+ # 4. MiniMax M2.7 (novita) β†’ deepseek/deepseek-v4-flash (openai/ prefix = OpenRouter)
20
+ content = content.replace(
21
+ '"MiniMaxAI/MiniMax-M2.7"',
22
+ '"openai/deepseek/deepseek-v4-flash"'
23
+ )
24
+ content = content.replace(
25
+ '"MiniMax M2.7"',
26
+ '"DeepSeek V4 Flash (OR)"'
27
+ )
28
+
29
+ # 5. GLM 5.1 (together) β†’ DeepSeek-V4-Flash (HF Inference)
30
+ content = content.replace(
31
+ '"zai-org/GLM-5.1"',
32
+ '"deepseek-ai/DeepSeek-V4-Flash"'
33
+ )
34
+ content = content.replace(
35
+ '"GLM 5.1"',
36
+ '"DeepSeek V4 Flash (HF)"'
37
+ )
38
+
39
+ # Also fix DEFAULT_FREE_MODEL_ID since Kimi no longer exists
40
+ content = content.replace(
41
+ 'DEFAULT_FREE_MODEL_ID = "moonshotai/Kimi-K2.6"',
42
+ 'DEFAULT_FREE_MODEL_ID = "deepseek-ai/DeepSeek-V4-Pro"'
43
+ )
44
 
45
  # Fix title generation
46
  old_patterns = [
47
  'model="openai/openai/gpt-oss-120b:cerebras",\n api_base="https://router.huggingface.co/v1",\n api_key=api_key,',
 
48
  ]
49
+ new_title_call = 'model="openrouter/openrouter/owl-alpha",\n api_key=_os.environ.get("OPENROUTER_API_KEY", api_key),'
 
50
 
51
  for old in old_patterns:
52
  if old in content:
53
  content = content.replace(old, new_title_call)
54
+ # Need to add import os as _os
55
+ if '_os.environ' in content and 'import os as _os' not in content:
56
+ content = content.replace(
57
+ 'AVAILABLE_MODELS = _available_models()\n',
58
+ 'AVAILABLE_MODELS = _available_models()\nimport os as _os\n'
59
+ )
60
+ print("βœ… Title generation patched")
61
  break
62
 
63
  content = content.replace(' reasoning_effort="low",\n', '')
 
73
  with open(AGENT_FILE, "w") as f:
74
  f.write(content)
75
  print("βœ… Backend patched")
76
+ print(" - Kimi K2.6 β†’ deepseek-ai/DeepSeek-V4-Pro (HF)")
77
+ print(" - MiniMax M2.7 β†’ openai/deepseek/deepseek-v4-flash (OR)")
78
+ print(" - GLM 5.1 β†’ deepseek-ai/DeepSeek-V4-Flash (HF)")