bep40 commited on
Commit
786a4bd
Β·
verified Β·
1 Parent(s): f1d70ad

Upload patch_models.py

Browse files
Files changed (1) hide show
  1. patch_models.py +40 -36
patch_models.py CHANGED
@@ -1,48 +1,52 @@
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 HF Inference + OpenRouter models ===
12
- import os as _os
13
- AVAILABLE_MODELS.extend([
14
- {"id": "deepseek-ai/DeepSeek-V4-Pro", "label": "DeepSeek V4 Pro", "provider": "huggingface", "tier": "free", "recommended": True},
15
- {"id": "deepseek-ai/DeepSeek-V4-Flash", "label": "DeepSeek V4 Flash", "provider": "huggingface", "tier": "free"},
16
- {"id": "openai/deepseek/deepseek-v4-flash", "label": "DeepSeek V4 Flash (OR)", "provider": "openrouter", "tier": "free"},
17
- {"id": "nvidia/nemotron-3-super-120b-a12b:free", "label": "Nemotron 3 Super 120B", "provider": "openrouter", "tier": "free"},
18
- {"id": "google/gemma-4-31B-it", "label": "Gemma 4 31B", "provider": "huggingface", "tier": "free", "recommended": True},
19
- {"id": "openai/tencent/hy3:free", "label": "Tencent HY3", "provider": "openrouter", "tier": "free"},
20
- {"id": "google/gemma-3-1b-it", "label": "Gemma 3 1B", "provider": "huggingface", "tier": "free", "recommended": True},
21
- {"id": "Qwen/Qwen3-Coder-Next", "label": "Qwen3 Coder Next", "provider": "huggingface", "tier": "free", "recommended": True},
22
- {"id": "openrouter/owl-alpha", "label": "Owl Alpha", "provider": "openrouter", "tier": "free", "recommended": True},
23
- {"id": "openai/google/gemini-2.0-flash-001", "label": "Gemini 2.0 Flash", "provider": "openrouter", "tier": "free"},
24
- ])
25
- PREMIUM_MODEL_IDS = set() # No premium gate
26
- DEFAULT_FREE_MODEL_ID = "deepseek-ai/DeepSeek-V4-Pro"
27
- # === END PATCH ===
28
- '''
29
-
30
- if target in content:
31
- content = content.replace(target, target + patch)
32
- print("βœ… Added models to AVAILABLE_MODELS")
33
-
34
- # Fix title generation - use huggingface/ prefix for litellm
35
- old_title = 'model="openai/openai/gpt-oss-120b:cerebras",\n api_base="https://router.huggingface.co/v1",\n api_key=api_key,'
36
- new_title = 'model="huggingface/deepseek-ai/DeepSeek-V4-Pro",\n api_key=api_key,'
37
- if old_title in content:
38
- content = content.replace(old_title, new_title)
39
- content = content.replace(' reasoning_effort="low",\n', '')
40
- print("βœ… Title generation patched")
41
 
 
42
  import ast
43
  ast.parse(content)
44
  print("βœ… Syntax OK")
45
 
46
  with open(AGENT_FILE, "w") as f:
47
  f.write(content)
48
- print("βœ… Backend patched")
 
1
+ """Patch backend: add new model IDs to model_ids.py + agent.py models list + title gen."""
 
2
 
3
+ # === Step 1: Patch model_ids.py β€” add new model constants ===
4
+ IDS_FILE = "/app/agent/core/model_ids.py"
5
+ with open(IDS_FILE, "r") as f:
6
+ content = f.read()
7
+
8
+ # Add new model ID constants after existing ones
9
+ old_models_block = 'CLAUDE_OPUS_48_MODEL_ID = "anthropic/claude-opus-4.8:fal-ai"\nGPT_55_MODEL_ID = "openai/gpt-5.5:fal-ai"\nKIMI_K27_CODE_MODEL_ID = "moonshotai/Kimi-K2.7-Code:novita"\nMINIMAX_M3_MODEL_ID = "MiniMaxAI/MiniMax-M3:novita"\nGLM_52_MODEL_ID = "zai-org/GLM-5.2:novita"\nDEEPSEEK_V4_PRO_MODEL_ID = "deepseek-ai/DeepSeek-V4-Pro:novita"'
10
+
11
+ new_models_block = 'CLAUDE_OPUS_48_MODEL_ID = "openrouter/owl-alpha"\nGPT_55_MODEL_ID = "openai/gpt-5.5:fal-ai"\nKIMI_K27_CODE_MODEL_ID = "deepseek-ai/DeepSeek-V4-Pro"\nMINIMAX_M3_MODEL_ID = "deepseek-ai/DeepSeek-V4-Flash"\nGLM_52_MODEL_ID = "openai/deepseek/deepseek-v4-flash"\nDEEPSEEK_V4_PRO_MODEL_ID = "nvidia/nemotron-3-super-120b-a12b:free"\n\n# === PATCH: New model IDs ===\nGEMMA_4_MODEL_ID = "google/gemma-4-31B-it"\nTENCENT_HY3_MODEL_ID = "openai/tencent/hy3:free"\nGEMMA_3_1B_MODEL_ID = "google/gemma-3-1b-it"\nQWEN3_CODER_NEXT_MODEL_ID = "Qwen/Qwen3-Coder-Next"\nGEMINI_FLASH_MODEL_ID = "openai/google/gemini-2.0-flash-001"'
12
+
13
+ content = content.replace(old_models_block, new_models_block)
14
+
15
+ # Also update the HOSTED_MODEL_IDS set
16
+ old_hosted = "HOSTED_MODEL_IDS = {\n CLAUDE_OPUS_48_MODEL_ID,\n GPT_55_MODEL_ID,\n KIMI_K27_CODE_MODEL_ID,\n MINIMAX_M3_MODEL_ID,\n GLM_52_MODEL_ID,\n DEEPSEEK_V4_PRO_MODEL_ID,\n}"
17
+ new_hosted = "HOSTED_MODEL_IDS = {\n CLAUDE_OPUS_48_MODEL_ID,\n GPT_55_MODEL_ID,\n KIMI_K27_CODE_MODEL_ID,\n MINIMAX_M3_MODEL_ID,\n GLM_52_MODEL_ID,\n DEEPSEEK_V4_PRO_MODEL_ID,\n GEMMA_4_MODEL_ID,\n TENCENT_HY3_MODEL_ID,\n GEMMA_3_1B_MODEL_ID,\n QWEN3_CODER_NEXT_MODEL_ID,\n GEMINI_FLASH_MODEL_ID,\n}"
18
+ content = content.replace(old_hosted, new_hosted)
19
+
20
+ with open(IDS_FILE, "w") as f:
21
+ f.write(content)
22
+ print("βœ… model_ids.py patched")
23
+
24
+ # === Step 2: Patch agent.py β€” expand AVAILABLE_MODELS ===
25
  AGENT_FILE = "/app/backend/routes/agent.py"
26
  with open(AGENT_FILE, "r") as f:
27
  content = f.read()
28
 
29
+ # Update imports to include new model IDs
30
+ old_import = "from agent.core.model_ids import (\n CLAUDE_OPUS_48_MODEL_ID,\n DEEPSEEK_V4_PRO_MODEL_ID,\n GLM_52_MODEL_ID,\n GPT_55_MODEL_ID,\n KIMI_K27_CODE_MODEL_ID,\n MINIMAX_M3_MODEL_ID,\n strip_huggingface_model_prefix,\n)"
31
+ new_import = "from agent.core.model_ids import (\n CLAUDE_OPUS_48_MODEL_ID,\n DEEPSEEK_V4_PRO_MODEL_ID,\n GLM_52_MODEL_ID,\n GPT_55_MODEL_ID,\n KIMI_K27_CODE_MODEL_ID,\n MINIMAX_M3_MODEL_ID,\n GEMMA_4_MODEL_ID,\n TENCENT_HY3_MODEL_ID,\n GEMMA_3_1B_MODEL_ID,\n QWEN3_CODER_NEXT_MODEL_ID,\n GEMINI_FLASH_MODEL_ID,\n strip_huggingface_model_prefix,\n)"
32
+ content = content.replace(old_import, new_import)
33
+
34
+ # Expand _available_models()
35
+ old_available = 'def _available_models() -> list[dict[str, Any]]:\n models = [\n {\n "id": CLAUDE_OPUS_48_MODEL_ID,\n "label": "Claude Opus 4.8",\n },\n {\n "id": DEFAULT_GPT_MODEL_ID,\n "label": "GPT-5.5",\n },\n {\n "id": KIMI_K27_CODE_MODEL_ID,\n "label": "Kimi K2.7 Code",\n },\n {\n "id": MINIMAX_M3_MODEL_ID,\n "label": "MiniMax M3",\n },\n {\n "id": DEFAULT_MODEL_ID,\n "label": "GLM 5.2",\n "recommended": True,\n },\n {\n "id": DEEPSEEK_V4_PRO_MODEL_ID,\n "label": "DeepSeek V4 Pro",\n },\n ]\n return models'
36
+ new_available = 'def _available_models() -> list[dict[str, Any]]:\n models = [\n {\n "id": CLAUDE_OPUS_48_MODEL_ID,\n "label": "Owl Alpha",\n },\n {\n "id": DEFAULT_GPT_MODEL_ID,\n "label": "GPT-5.5",\n },\n {\n "id": KIMI_K27_CODE_MODEL_ID,\n "label": "DeepSeek V4 Pro",\n },\n {\n "id": MINIMAX_M3_MODEL_ID,\n "label": "DeepSeek V4 Flash",\n },\n {\n "id": DEFAULT_MODEL_ID,\n "label": "DeepSeek V4 Flash",\n "recommended": True,\n },\n {\n "id": DEEPSEEK_V4_PRO_MODEL_ID,\n "label": "Nemotron 3 Super 120B",\n },\n {\n "id": GEMMA_4_MODEL_ID,\n "label": "Gemma 4 31B",\n "recommended": True,\n },\n {\n "id": TENCENT_HY3_MODEL_ID,\n "label": "Tencent HY3",\n },\n {\n "id": GEMMA_3_1B_MODEL_ID,\n "label": "Gemma 3 1B",\n "recommended": True,\n },\n {\n "id": QWEN3_CODER_NEXT_MODEL_ID,\n "label": "Qwen3 Coder Next",\n "recommended": True,\n },\n {\n "id": GEMINI_FLASH_MODEL_ID,\n "label": "Gemini 2.0 Flash",\n },\n ]\n return models'
37
+ content = content.replace(old_available, new_available)
38
+
39
+ # Update title generation β€” the /title endpoint uses gpt-oss-120b:cerebras as default
40
+ # Change it to use our HF router model
41
+ old_title = '"openai/gpt-oss-120b:cerebras",'
42
+ new_title = '"huggingface/deepseek-ai/DeepSeek-V4-Pro",'
43
+ content = content.replace(old_title, new_title)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
 
45
+ # Validate syntax
46
  import ast
47
  ast.parse(content)
48
  print("βœ… Syntax OK")
49
 
50
  with open(AGENT_FILE, "w") as f:
51
  f.write(content)
52
+ print("βœ… agent.py patched")