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

Fix patch_frontend.py - handle edge cases in string search

Browse files
Files changed (1) hide show
  1. patch_frontend.py +96 -38
patch_frontend.py CHANGED
@@ -1,47 +1,110 @@
1
- """Patch frontend ChatInput.tsx: Rename ClaudeDeepSeek V3, remove Kimi, add new 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 entirely
9
- kimi_start = content.find("id: 'kimi-k2.6'")
10
- if kimi_start > -1:
11
- # Find the opening { before it
12
- brace_start = content.rfind("{", 0, kimi_start)
13
- # Find the closing }, after it
14
- brace_end = content.find("},", kimi_start) + 2
15
- content = content[:brace_start] + content[brace_end:]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  print("✅ Removed Kimi K2.6")
 
 
17
 
18
- # 2. Replace Claude Opus entry with DeepSeek V3
19
- claude_start = content.find("id: 'claude-opus'")
20
- if claude_start > -1:
21
- brace_start = content.rfind("{", 0, claude_start)
22
- brace_end = content.find("},", claude_start) + 2
23
- deepseek_entry = """ {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  id: 'deepseek-v3',
25
  name: 'DeepSeek V3',
26
- description: 'OpenRouter · Mặc định',
27
  modelPath: 'openai/deepseek/deepseek-chat-v3-0324',
28
  avatarUrl: 'https://huggingface.co/api/avatars/deepseek-ai',
29
  recommended: true,
30
  },"""
31
- content = content[:brace_start] + deepseek_entry + content[brace_end:]
32
- print("✅ Replaced Claude Opus with DeepSeek V3")
 
 
33
 
34
- # 3. Add new models at end of array
35
- idx_deepseek = content.find("'deepseek-v4-pro'")
36
- if idx_deepseek == -1:
37
- idx_deepseek = content.find("deepseek-ai/DeepSeek-V4")
38
- if idx_deepseek == -1:
39
- # Try finding end of array another way
40
- idx_deepseek = content.find("DEFAULT_MODEL_OPTIONS")
41
-
42
- idx_end = content.find("];", idx_deepseek)
43
- if idx_end == -1:
44
- print("❌ Cannot find end of array!")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  import sys; sys.exit(1)
46
 
47
  new_models = """ {
@@ -82,21 +145,16 @@ new_models = """ {
82
  },
83
  """
84
 
85
- content = content[:idx_end] + new_models + content[idx_end:]
86
-
87
- # 4. Fix FIRST_FREE_MODEL_PATH reference (was Kimi, now DeepSeek V3)
88
- content = content.replace(
89
- "m.modelPath === FIRST_FREE_MODEL_PATH",
90
- "m.modelPath === 'openai/deepseek/deepseek-chat-v3-0324'"
91
- )
92
 
93
  with open(FILE, "w") as f:
94
  f.write(content)
95
 
96
  # Verify
97
- assert "kimi-k2.6" not in content, "Kimi still present!"
98
  assert "deepseek-v3" in content, "DeepSeek V3 missing!"
99
  assert "grok-4.3" in content, "Grok missing!"
100
  assert "qwen3.7-max" in content, "Qwen 3.7 missing!"
101
  assert "gemini-2.0-flash" in content, "Gemini missing!"
102
- print("\n✅ Frontend complete: DeepSeek V3 default, Kimi removed, all models added")
 
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 = """ {
 
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")