bep40 commited on
Commit
ef0c571
·
verified ·
1 Parent(s): 4b77e8d

Simplify: only ADD models, dont remove/edit existing entries (safest approach)

Browse files
Files changed (1) hide show
  1. patch_frontend.py +28 -109
patch_frontend.py CHANGED
@@ -1,160 +1,79 @@
1
- """Patch frontend ChatInput.tsx: Replace Claude with DeepSeek V3, remove Kimi, add models."""
2
 
3
  FILE = "/source/frontend/src/components/Chat/ChatInput.tsx"
4
 
5
  with open(FILE, "r") as f:
6
  content = f.read()
7
 
8
- # 1. Remove Kimi K2.6 entry
9
- kimi_idx = content.find("'kimi-k2.6'")
10
- if kimi_idx > -1:
11
- # Walk back to find opening {
12
- i = kimi_idx
13
- brace_count = 0
14
- while i > 0:
15
- i -= 1
16
- if content[i] == '{':
17
- brace_count += 1
18
- if brace_count == 1:
19
- break
20
- start = i
21
- # Walk forward to find closing },
22
- j = kimi_idx
23
- brace_count = 0
24
- while j < len(content):
25
- if content[j] == '{':
26
- brace_count += 1
27
- elif content[j] == '}':
28
- brace_count -= 1
29
- if brace_count == 0:
30
- break
31
- j += 1
32
- # Include the trailing comma and whitespace
33
- end = j + 1
34
- while end < len(content) and content[end] in ' ,\n':
35
- end += 1
36
- content = content[:start] + content[end:]
37
- print("✅ Removed Kimi K2.6")
38
- else:
39
- print("⚠️ Kimi not found (may already be removed)")
40
-
41
- # 2. Replace Claude entry with DeepSeek V3
42
- claude_idx = content.find("'claude-opus'")
43
- if claude_idx > -1:
44
- i = claude_idx
45
- brace_count = 0
46
- while i > 0:
47
- i -= 1
48
- if content[i] == '{':
49
- brace_count += 1
50
- if brace_count == 1:
51
- break
52
- start = i
53
- j = claude_idx
54
- brace_count = 0
55
- while j < len(content):
56
- if content[j] == '{':
57
- brace_count += 1
58
- elif content[j] == '}':
59
- brace_count -= 1
60
- if brace_count == 0:
61
- break
62
- j += 1
63
- end = j + 1
64
- # Skip trailing comma
65
- if end < len(content) and content[end] == ',':
66
- end += 1
67
-
68
- replacement = """{
69
- id: 'deepseek-v3',
70
- name: 'DeepSeek V3',
71
- description: 'OpenRouter',
72
- modelPath: 'openai/deepseek/deepseek-chat-v3-0324',
73
- avatarUrl: 'https://huggingface.co/api/avatars/deepseek-ai',
74
- recommended: true,
75
- },"""
76
- content = content[:start] + replacement + content[end:]
77
- print("✅ Replaced Claude with DeepSeek V3")
78
- else:
79
- print("⚠️ Claude entry not found")
80
-
81
- # 3. Add new models before the closing ]; of DEFAULT_MODEL_OPTIONS
82
- # Find the array end - search for "];\n" after DEFAULT_MODEL_OPTIONS
83
- arr_start = content.find("DEFAULT_MODEL_OPTIONS")
84
  if arr_start == -1:
85
  print("❌ DEFAULT_MODEL_OPTIONS not found!")
86
  import sys; sys.exit(1)
87
 
88
- # Find the closing ]; for this array
89
- idx = arr_start
90
- depth = 0
91
- found_open = False
92
- arr_end = -1
93
- while idx < len(content):
94
- if content[idx] == '[' and not found_open:
95
- found_open = True
96
- depth = 1
97
- elif content[idx] == '[':
98
  depth += 1
99
  elif content[idx] == ']':
100
  depth -= 1
101
- if depth == 0 and found_open:
102
- arr_end = idx
103
- break
104
  idx += 1
 
105
 
106
- if arr_end == -1:
107
- print("❌ Cannot find array end!")
108
- import sys; sys.exit(1)
109
-
110
  new_models = """ {
 
 
 
 
 
 
 
 
111
  id: 'grok-4.3',
112
  name: 'Grok 4.3',
113
  description: 'Tốt nhất giá rẻ · $2/$10 · 1M ctx',
114
  modelPath: 'openai/x-ai/grok-4.3',
115
- avatarUrl: 'https://huggingface.co/api/avatars/xai-org',
116
  recommended: true,
117
  },
118
  {
119
  id: 'deepseek-v4-pro-or',
120
  name: 'DeepSeek V4 Pro',
121
- description: 'Rẻ nhất mà vẫn tốt · $0.5/$2.18',
122
  modelPath: 'openai/deepseek/deepseek-v4-pro',
123
- avatarUrl: 'https://huggingface.co/api/avatars/deepseek-ai',
124
  },
125
  {
126
  id: 'qwen3.7-max',
127
  name: 'Qwen 3.7 Max',
128
  description: 'Cân bằng · $1/$4',
129
  modelPath: 'openai/qwen/qwen3.7-max',
130
- avatarUrl: 'https://huggingface.co/api/avatars/Qwen',
131
  },
132
  {
133
  id: 'qwen3-235b-hf',
134
  name: 'Qwen3 235B (HF Free)',
135
- description: 'Miễn phí qua HF Inference',
136
  modelPath: 'Qwen/Qwen3-235B-A22B',
137
- avatarUrl: 'https://huggingface.co/api/avatars/Qwen',
138
  },
139
  {
140
  id: 'gemini-2.0-flash',
141
  name: 'Gemini 2.0 Flash',
142
  description: 'Rẻ nhanh · $0.15/$0.60',
143
  modelPath: 'openai/google/gemini-2.0-flash-001',
144
- avatarUrl: 'https://huggingface.co/api/avatars/google',
145
  },
146
  """
147
 
148
- # Insert before the closing ]
149
  content = content[:arr_end] + new_models + content[arr_end:]
150
 
151
  with open(FILE, "w") as f:
152
  f.write(content)
153
 
154
- # Verify
155
- assert "kimi-k2.6" not in content, "Kimi still in file!"
156
- assert "deepseek-v3" in content, "DeepSeek V3 missing!"
157
- assert "grok-4.3" in content, "Grok missing!"
158
- assert "qwen3.7-max" in content, "Qwen 3.7 missing!"
159
- assert "gemini-2.0-flash" in content, "Gemini missing!"
160
- print("\n✅ All done: DeepSeek V3 default, Kimi removed, 5 new models added")
 
1
+ """Patch frontend: ONLY add new models to end of array. Do NOT remove or modify existing entries."""
2
 
3
  FILE = "/source/frontend/src/components/Chat/ChatInput.tsx"
4
 
5
  with open(FILE, "r") as f:
6
  content = f.read()
7
 
8
+ # Find DEFAULT_MODEL_OPTIONS array end by counting brackets
9
+ arr_start = content.find("const DEFAULT_MODEL_OPTIONS")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  if arr_start == -1:
11
  print("❌ DEFAULT_MODEL_OPTIONS not found!")
12
  import sys; sys.exit(1)
13
 
14
+ # Find opening [
15
+ bracket_start = content.find("[", arr_start)
16
+ # Find matching ]
17
+ idx = bracket_start + 1
18
+ depth = 1
19
+ while idx < len(content) and depth > 0:
20
+ if content[idx] == '[':
 
 
 
21
  depth += 1
22
  elif content[idx] == ']':
23
  depth -= 1
 
 
 
24
  idx += 1
25
+ arr_end = idx - 1 # position of closing ]
26
 
27
+ # Insert new models just before ]
 
 
 
28
  new_models = """ {
29
+ id: 'deepseek-v3-or',
30
+ name: 'DeepSeek V3',
31
+ description: 'OpenRouter · Mặc định',
32
+ modelPath: 'openai/deepseek/deepseek-chat-v3-0324',
33
+ avatarUrl: getHfAvatarUrl('deepseek-ai/DeepSeek-V3'),
34
+ recommended: true,
35
+ },
36
+ {
37
  id: 'grok-4.3',
38
  name: 'Grok 4.3',
39
  description: 'Tốt nhất giá rẻ · $2/$10 · 1M ctx',
40
  modelPath: 'openai/x-ai/grok-4.3',
41
+ avatarUrl: getHfAvatarUrl('xai-org/grok'),
42
  recommended: true,
43
  },
44
  {
45
  id: 'deepseek-v4-pro-or',
46
  name: 'DeepSeek V4 Pro',
47
+ description: 'Rẻ nhất · $0.5/$2.18',
48
  modelPath: 'openai/deepseek/deepseek-v4-pro',
49
+ avatarUrl: getHfAvatarUrl('deepseek-ai/DeepSeek-V4'),
50
  },
51
  {
52
  id: 'qwen3.7-max',
53
  name: 'Qwen 3.7 Max',
54
  description: 'Cân bằng · $1/$4',
55
  modelPath: 'openai/qwen/qwen3.7-max',
56
+ avatarUrl: getHfAvatarUrl('Qwen/Qwen3'),
57
  },
58
  {
59
  id: 'qwen3-235b-hf',
60
  name: 'Qwen3 235B (HF Free)',
61
+ description: 'Miễn phí HF Inference',
62
  modelPath: 'Qwen/Qwen3-235B-A22B',
63
+ avatarUrl: getHfAvatarUrl('Qwen/Qwen3-235B-A22B'),
64
  },
65
  {
66
  id: 'gemini-2.0-flash',
67
  name: 'Gemini 2.0 Flash',
68
  description: 'Rẻ nhanh · $0.15/$0.60',
69
  modelPath: 'openai/google/gemini-2.0-flash-001',
70
+ avatarUrl: getHfAvatarUrl('google/gemini'),
71
  },
72
  """
73
 
 
74
  content = content[:arr_end] + new_models + content[arr_end:]
75
 
76
  with open(FILE, "w") as f:
77
  f.write(content)
78
 
79
+ print("✅ Added 6 new models to dropdown (existing entries untouched)")