bep40 commited on
Commit
f1d70ad
·
verified ·
1 Parent(s): c88a0e0

Upload patch_frontend.py

Browse files
Files changed (1) hide show
  1. patch_frontend.py +65 -57
patch_frontend.py CHANGED
@@ -1,54 +1,71 @@
1
- """Patch frontend ChatInput.tsx: Fix model IDs and rename dropdown labels."""
2
 
3
- FILE = "/source/frontend/src/components/Chat/ChatInput.tsx"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
 
 
5
  with open(FILE, "r") as f:
6
  content = f.read()
7
 
8
- # === Row 2: Claude Opus 4.6 → Owl Alpha ===
9
- content = content.replace("'Claude Opus 4.6'", "'Owl Alpha'")
10
- content = content.replace('"Claude Opus 4.6"', '"Owl Alpha"')
11
- content = content.replace("'Claude Opus 4'", "'Owl Alpha'")
12
- content = content.replace('"Claude Opus 4"', '"Owl Alpha"')
13
- content = content.replace("'Claude Sonnet 4.5'", "'Owl Beta'")
14
- content = content.replace('"Claude Sonnet 4.5"', '"Owl Beta"')
15
- content = content.replace("claude.label ?? option.name", "option.name")
16
- content = content.replace("claude.label || option.name", "option.name")
17
- content = content.replace("description: 'Anthropic'", "description: '🦉 Top Reasoning'")
18
-
19
- # === Row 1: Kimi K2.6 → DeepSeek V4 Pro (HF Inference) ===
20
- content = content.replace("moonshotai/Kimi-K2.6", "deepseek-ai/DeepSeek-V4-Pro")
21
- content = content.replace("'Kimi K2.6'", "'DeepSeek V4 Pro'")
22
- content = content.replace('"Kimi K2.6"', '"DeepSeek V4 Pro"')
23
 
24
- # === Row 4: MiniMax M2.7 → DeepSeek V4 Flash, Novita → HF Inference ===
25
- content = content.replace("MiniMaxAI/MiniMax-M2.7", "deepseek-ai/DeepSeek-V4-Flash")
26
- content = content.replace("'MiniMax M2.7'", "'DeepSeek V4 Flash'")
27
- content = content.replace('"MiniMax M2.7"', '"DeepSeek V4 Flash"')
28
- content = content.replace("description: 'Novita'", "description: 'HF Inference'", 1)
29
 
30
- # === Row 5: GLM 5.1 → DeepSeek V4 Flash, Together → Openrouter ===
31
- content = content.replace("zai-org/GLM-5.1", "openai/deepseek/deepseek-v4-flash")
32
- content = content.replace("'GLM 5.1'", "'DeepSeek V4 Flash'")
33
- content = content.replace('"GLM 5.1"', '"DeepSeek V4 Flash"')
34
- content = content.replace("description: 'Together'", "description: 'Openrouter'")
35
 
36
- # === Row 6: DeepSeek V4 Pro (DeepInfra) → nvidia/nemotron-3-super-120b-a12b:free ===
37
- content = content.replace("deepseek-ai/DeepSeek-V4-Pro:deepinfra", "nvidia/nemotron-3-super-120b-a12b:free")
38
- content = content.replace("description: 'DeepInfra'", "description: 'Openrouter Free'")
39
- # Find the name for row 6 - it's the one with id 'deepseek-v4-pro'
40
- # In source: id: 'deepseek-v4-pro', name: 'DeepSeek V4 Pro'
41
- # We need to change name to show the nvidia model path
42
- content = content.replace("id: 'deepseek-v4-pro',\n name: 'DeepSeek V4 Pro'", "id: 'nemotron-120b',\n name: 'nvidia/nemotron-3-super-120b-a12b:free'")
43
 
44
- # === Row 1 description: second Novita (if any remains) ===
45
- content = content.replace("description: 'Novita'", "description: 'HF Inference'")
 
 
 
 
46
 
47
- # === Update generic descriptions ===
48
- content = content.replace("'Best coding model'", "'⚡ Mạnh nhất · Code + Reasoning'")
49
- content = content.replace("'Best all-around model'", "'⚡ Mạnh nhất · Code + Reasoning'")
 
 
50
 
51
- # === Add custom models at end of array ===
 
52
  idx_end = content.find("];", content.find("DEFAULT_MODEL_OPTIONS") if "DEFAULT_MODEL_OPTIONS" in content else 0)
53
  if idx_end == -1:
54
  idx_end = content.rfind("];", 0, content.find("export") if "export" in content else len(content))
@@ -57,7 +74,6 @@ if idx_end > 0:
57
  new_models = """ {
58
  id: 'gemma-4-31b',
59
  name: 'Gemma 4 31B',
60
- description: 'HF Inference',
61
  modelPath: 'google/gemma-4-31B-it',
62
  avatarUrl: 'https://huggingface.co/api/avatars/google',
63
  recommended: true,
@@ -65,14 +81,12 @@ if idx_end > 0:
65
  {
66
  id: 'tencent-hy3',
67
  name: 'Tencent HY3',
68
- description: 'Openrouter Free',
69
  modelPath: 'openai/tencent/hy3:free',
70
  avatarUrl: 'https://huggingface.co/api/avatars/tencent',
71
  },
72
  {
73
  id: 'gemma-3-1b',
74
  name: 'Gemma 3 1B',
75
- description: 'HF Inference',
76
  modelPath: 'google/gemma-3-1b-it',
77
  avatarUrl: 'https://huggingface.co/api/avatars/google',
78
  recommended: true,
@@ -80,7 +94,6 @@ if idx_end > 0:
80
  {
81
  id: 'qwen3-coder-next',
82
  name: 'Qwen3 Coder Next',
83
- description: 'HF Inference',
84
  modelPath: 'Qwen/Qwen3-Coder-Next',
85
  avatarUrl: 'https://huggingface.co/api/avatars/Qwen',
86
  recommended: true,
@@ -88,7 +101,6 @@ if idx_end > 0:
88
  {
89
  id: 'gemini-2.0-flash',
90
  name: 'Gemini 2.0 Flash',
91
- description: 'Openrouter',
92
  modelPath: 'openai/google/gemini-2.0-flash-001',
93
  avatarUrl: 'https://huggingface.co/api/avatars/google',
94
  },
@@ -98,15 +110,11 @@ if idx_end > 0:
98
  with open(FILE, "w") as f:
99
  f.write(content)
100
 
101
- print("✅ Frontend patched:")
102
- print(" Row 1: DeepSeek V4 Pro | HF Inference")
103
- print(" Row 2: Owl Alpha | 🦉 Top Reasoning")
104
- print(" Row 3: GPT-5.5 | OpenAI")
105
- print(" Row 4: DeepSeek V4 Flash | HF Inference (was Novita)")
106
- print(" Row 5: DeepSeek V4 Flash | Openrouter (was Together)")
107
- print(" Row 6: nvidia/nemotron-3-super-120b-a12b:free | Openrouter Free")
108
- print(" Row 7: Gemma 4 31B | HF Inference (NEW)")
109
- print(" Row 8: Tencent HY3 | Openrouter Free (NEW)")
110
- print(" Row 9: Gemma 3 1B | HF Inference")
111
- print(" Row 10: Qwen3 Coder Next | HF Inference")
112
- print(" Row 11: Gemini 2.0 Flash | Openrouter")
 
1
+ """Patch frontend ChatInput.tsx + model.ts: Fix model IDs and rename dropdown labels."""
2
 
3
+ # === Step 1: Patch model.ts constants ===
4
+ MODEL_FILE = "/source/frontend/src/utils/model.ts"
5
+ with open(MODEL_FILE, "r") as f:
6
+ model_content = f.read()
7
+
8
+ model_content = model_content.replace(
9
+ "export const CLAUDE_OPUS_48_MODEL_PATH = 'anthropic/claude-opus-4.8:fal-ai';",
10
+ "export const CLAUDE_OPUS_48_MODEL_PATH = 'openrouter/owl-alpha';"
11
+ )
12
+ model_content = model_content.replace(
13
+ "export const KIMI_K27_CODE_MODEL_PATH = 'moonshotai/Kimi-K2.7-Code:novita';",
14
+ "export const KIMI_K27_CODE_MODEL_PATH = 'deepseek-ai/DeepSeek-V4-Pro';"
15
+ )
16
+ model_content = model_content.replace(
17
+ "export const MINIMAX_M3_MODEL_PATH = 'MiniMaxAI/MiniMax-M3:novita';",
18
+ "export const MINIMAX_M3_MODEL_PATH = 'deepseek-ai/DeepSeek-V4-Flash';"
19
+ )
20
+ model_content = model_content.replace(
21
+ "export const GLM_52_MODEL_PATH = 'zai-org/GLM-5.2:novita';",
22
+ "export const GLM_52_MODEL_PATH = 'openai/deepseek/deepseek-v4-flash';"
23
+ )
24
+ model_content = model_content.replace(
25
+ "export const DEEPSEEK_V4_PRO_MODEL_PATH = 'deepseek-ai/DeepSeek-V4-Pro:novita';",
26
+ "export const DEEPSEEK_V4_PRO_MODEL_PATH = 'nvidia/nemotron-3-super-120b-a12b:free';"
27
+ )
28
+
29
+ with open(MODEL_FILE, "w") as f:
30
+ f.write(model_content)
31
+ print("✅ model.ts constants updated")
32
 
33
+ # === Step 2: Patch ChatInput.tsx names and add new models ===
34
+ FILE = "/source/frontend/src/components/Chat/ChatInput.tsx"
35
  with open(FILE, "r") as f:
36
  content = f.read()
37
 
38
+ # Update model names (Row 1: Claude → Owl Alpha)
39
+ content = content.replace("'Claude Opus 4.8'", "'Owl Alpha'")
40
+ content = content.replace('"Claude Opus 4.8"', '"Owl Alpha"')
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
+ # Row 3: Kimi K2.7 Code → DeepSeek V4 Pro
43
+ content = content.replace("'Kimi K2.7 Code'", "'DeepSeek V4 Pro'")
44
+ content = content.replace('"Kimi K2.7 Code"', '"DeepSeek V4 Pro"')
 
 
45
 
46
+ # Row 4: MiniMax M3 → DeepSeek V4 Flash
47
+ content = content.replace("'MiniMax M3'", "'DeepSeek V4 Flash'")
48
+ content = content.replace('"MiniMax M3"', '"DeepSeek V4 Flash"')
 
 
49
 
50
+ # Row 5: GLM 5.2 → DeepSeek V4 Flash (also rename)
51
+ content = content.replace("'GLM 5.2'", "'DeepSeek V4 Flash'")
52
+ content = content.replace('"GLM 5.2"', '"DeepSeek V4 Flash"')
 
 
 
 
53
 
54
+ # Row 6: DeepSeek V4 Pro → Nemotron (use unique id+name pattern to avoid collision)
55
+ # This must be done AFTER the Kimi→DeepSeek V4 Pro replacement above
56
+ content = content.replace(
57
+ " {\n id: 'deepseek-v4-pro',\n name: 'DeepSeek V4 Pro',\n modelPath: DEEPSEEK_V4_PRO_MODEL_PATH,\n avatarUrl: getHfAvatarUrl('deepseek-ai/DeepSeek-V4-Pro'),\n },",
58
+ " {\n id: 'nemotron-120b',\n name: 'nvidia/nemotron-3-super-120b-a12b:free',\n modelPath: DEEPSEEK_V4_PRO_MODEL_PATH,\n avatarUrl: 'https://huggingface.co/api/avatars/nvidia',\n },"
59
+ )
60
 
61
+ # Update isClaudePath to avoid obsolete function
62
+ content = content.replace(
63
+ "export function isClaudePath(modelPath: string | undefined): boolean {\n return !!modelPath && modelPath.includes('anthropic');\n}",
64
+ "export function isClaudePath(modelPath: string | undefined): boolean {\n return !!modelPath && modelPath.includes('openrouter');\n}"
65
+ )
66
 
67
+ # === Add custom models at end of DEFAULT_MODEL_OPTIONS array ===
68
+ # ModelOption interface has no 'description' field — only: id, name, modelPath, avatarUrl, recommended?
69
  idx_end = content.find("];", content.find("DEFAULT_MODEL_OPTIONS") if "DEFAULT_MODEL_OPTIONS" in content else 0)
70
  if idx_end == -1:
71
  idx_end = content.rfind("];", 0, content.find("export") if "export" in content else len(content))
 
74
  new_models = """ {
75
  id: 'gemma-4-31b',
76
  name: 'Gemma 4 31B',
 
77
  modelPath: 'google/gemma-4-31B-it',
78
  avatarUrl: 'https://huggingface.co/api/avatars/google',
79
  recommended: true,
 
81
  {
82
  id: 'tencent-hy3',
83
  name: 'Tencent HY3',
 
84
  modelPath: 'openai/tencent/hy3:free',
85
  avatarUrl: 'https://huggingface.co/api/avatars/tencent',
86
  },
87
  {
88
  id: 'gemma-3-1b',
89
  name: 'Gemma 3 1B',
 
90
  modelPath: 'google/gemma-3-1b-it',
91
  avatarUrl: 'https://huggingface.co/api/avatars/google',
92
  recommended: true,
 
94
  {
95
  id: 'qwen3-coder-next',
96
  name: 'Qwen3 Coder Next',
 
97
  modelPath: 'Qwen/Qwen3-Coder-Next',
98
  avatarUrl: 'https://huggingface.co/api/avatars/Qwen',
99
  recommended: true,
 
101
  {
102
  id: 'gemini-2.0-flash',
103
  name: 'Gemini 2.0 Flash',
 
104
  modelPath: 'openai/google/gemini-2.0-flash-001',
105
  avatarUrl: 'https://huggingface.co/api/avatars/google',
106
  },
 
110
  with open(FILE, "w") as f:
111
  f.write(content)
112
 
113
+ print("✅ Frontend patched for current upstream:")
114
+ print(" Row 1 (Claude): Owl Alpha")
115
+ print(" Row 2 (GPT-5.5): unchanged")
116
+ print(" Row 3 (Kimi): DeepSeek V4 Pro")
117
+ print(" Row 4 (MiniMax): DeepSeek V4 Flash")
118
+ print(" Row 5 (GLM): DeepSeek V4 Flash (OR)")
119
+ print(" Row 6 (DeepSeek): nvidia/nemotron-3-super-120b-a12b:free")
120
+ print(" NEW: Gemma 4 31B, Tencent HY3, Gemma 3 1B, Qwen3 Coder Next, Gemini 2.0 Flash")