bep40 commited on
Commit
e9e0d7a
·
verified ·
1 Parent(s): ef9206b

Upload patch_frontend.py

Browse files
Files changed (1) hide show
  1. patch_frontend.py +73 -67
patch_frontend.py CHANGED
@@ -1,7 +1,12 @@
1
- """Patch frontend: Remove Owl Alpha, add working free model Llama 3.3 70B:free."""
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
 
@@ -24,13 +29,23 @@ model_content = model_content.replace(
24
 
25
  with open(MODEL_FILE, "w") as f:
26
  f.write(model_content)
27
- print(" model.ts constants updated")
28
 
29
  # === Step 2: Patch ChatInput.tsx ===
30
- FILE = "/source/frontend/src/components/Chat/ChatInput.tsx"
31
- with open(FILE, "r") as f:
32
  content = f.read()
33
 
 
 
 
 
 
 
 
 
 
 
 
34
  # Remove Owl Alpha references
35
  content = content.replace("'Owl Alpha'", "'Claude Opus 4.8'")
36
  content = content.replace('"Owl Alpha"', '"Claude Opus 4.8"')
@@ -53,74 +68,57 @@ content = content.replace(
53
  " {\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 },"
54
  )
55
 
56
- # Remove all broken model blocks
57
  old_blocks = [
58
- """ {
59
- id: 'tencent-hy3',
60
- name: 'Tencent HY3',
61
- modelPath: 'openai/tencent/hy3:free',
62
- avatarUrl: 'https://huggingface.co/api/avatars/tencent',
63
- },""",
64
- """ {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  id: 'gemma-4-31b',
66
  name: 'Gemma 4 31B:free',
67
- modelPath: 'google/gemma-4-31b-it:free',
68
  avatarUrl: 'https://huggingface.co/api/avatars/google',
69
  recommended: true,
70
- },""",
71
- """ {
72
- id: 'tencent-hy3',
73
- name: 'Tencent HY3:free',
74
- modelPath: 'tencent/hy3:free',
75
- avatarUrl: 'https://huggingface.co/api/avatars/tencent',
76
- },""",
77
- """ {
78
- id: 'llama-3.1-8b',
79
- name: 'Llama 3.1 8B',
80
- modelPath: 'meta-llama/llama-3.1-8b-instruct',
81
- avatarUrl: 'https://huggingface.co/api/avatars/meta-llama',
82
- recommended: true,
83
- },""",
84
- """ {
85
- id: 'nemotron-70b',
86
- name: 'Nemotron 70B',
87
- modelPath: 'nvidia/llama-3.1-nemotron-70b-instruct',
88
- avatarUrl: 'https://huggingface.co/api/avatars/nvidia',
89
- },""",
90
- """ {
91
- id: 'gemma-2-9b',
92
- name: 'Gemma 2 9B',
93
- modelPath: 'google/gemma-2-9b-it',
94
- avatarUrl: 'https://huggingface.co/api/avatars/google',
95
- },""",
96
- """ {
97
- id: 'gemma-3-1b',
98
- name: 'Gemma 3 1B',
99
- modelPath: 'google/gemma-3-1b-it',
100
- avatarUrl: 'https://huggingface.co/api/avatars/google',
101
- },""",
102
- ]
103
- for block in old_blocks:
104
- content = content.replace(block, "")
105
-
106
- # === Add working free models at end of DEFAULT_MODEL_OPTIONS array ===
107
- idx_end = content.find("];", content.find("DEFAULT_MODEL_OPTIONS") if "DEFAULT_MODEL_OPTIONS" in content else 0)
108
- if idx_end == -1:
109
- idx_end = content.rfind("];", 0, content.find("export") if "export" in content else len(content))
110
-
111
- if idx_end > 0:
112
- new_models = """ {
113
  id: 'llama-3.3-70b',
114
  name: 'Llama 3.3 70B:free',
115
- modelPath: 'meta-llama/llama-3.3-70b-instruct:free',
116
  avatarUrl: 'https://huggingface.co/api/avatars/meta-llama',
117
  recommended: true,
118
  },
119
  {
120
- id: 'gemma-3-1b',
121
- name: 'Gemma 3 1B',
122
- modelPath: 'google/gemma-3-1b-it',
123
- avatarUrl: 'https://huggingface.co/api/avatars/google',
 
 
 
 
 
 
124
  },
125
  {
126
  id: 'qwen3-coder-next',
@@ -134,11 +132,19 @@ if idx_end > 0:
134
  modelPath: 'openai/google/gemini-2.0-flash-001',
135
  avatarUrl: 'https://huggingface.co/api/avatars/google',
136
  },
137
- """
138
- content = content[:idx_end] + new_models + content[idx_end:]
 
 
 
 
 
 
 
 
 
139
 
140
- with open(FILE, "w") as f:
141
  f.write(content)
142
 
143
- print(" Frontend patched:")
144
- print(" NEW DEFAULT: Llama 3.3 70B:free (meta-llama/llama-3.3-70b-instruct:free) — free variant thật")
 
1
+ """Patch frontend: Remove Owl Alpha, add models with openai/ prefix for OpenRouter routing."""
2
 
3
+ import re
4
+ import sys
5
+
6
+ FILE = "/source/frontend/src/components/Chat/ChatInput.tsx"
7
  MODEL_FILE = "/source/frontend/src/utils/model.ts"
8
+
9
+ # === Step 1: Patch model.ts constants ===
10
  with open(MODEL_FILE, "r") as f:
11
  model_content = f.read()
12
 
 
29
 
30
  with open(MODEL_FILE, "w") as f:
31
  f.write(model_content)
32
+ print("OK: model.ts constants updated")
33
 
34
  # === Step 2: Patch ChatInput.tsx ===
35
+ with open(FILE, "r", encoding="utf-8") as f:
 
36
  content = f.read()
37
 
38
+ # Fix imports — replace model constants imports with just isClaudePath
39
+ import_pattern = re.compile(
40
+ r'import\s*\{[^}]+\}\s*from\s*[\'"]@/utils/model[\'"];'
41
+ )
42
+ match = import_pattern.search(content)
43
+ if match:
44
+ content = content.replace(match.group(0), "import { isClaudePath } from '@/utils/model';")
45
+ print("OK: Replaced imports")
46
+ else:
47
+ print("OK: Imports not found")
48
+
49
  # Remove Owl Alpha references
50
  content = content.replace("'Owl Alpha'", "'Claude Opus 4.8'")
51
  content = content.replace('"Owl Alpha"', '"Claude Opus 4.8"')
 
68
  " {\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 },"
69
  )
70
 
71
+ # Remove ALL old custom model blocks
72
  old_blocks = [
73
+ 'modelPath: \'google/gemma-4-31b-it:free\'',
74
+ 'modelPath: \'tencent/hy3:free\'',
75
+ 'modelPath: \'tencent/hy3\'',
76
+ 'modelPath: \'meta-llama/llama-3.1-8b-instruct\'',
77
+ 'modelPath: \'meta-llama/llama-3.3-70b-instruct:free\'',
78
+ 'modelPath: \'google/gemma-2-9b-it\'',
79
+ 'modelPath: \'nvidia/llama-3.1-nemotron-70b-instruct\'',
80
+ 'modelPath: \'openai/tencent/hy3:free\'',
81
+ 'id: \'gemma-4-31b\'',
82
+ 'id: \'llama-3.1-8b\'',
83
+ 'id: \'llama-3.3-70b\'',
84
+ 'id: \'nemotron-70b\'',
85
+ 'id: \'gemma-2-9b\'',
86
+ 'id: \'tencent-hy3\'',
87
+ ]
88
+ # Use simpler approach: find and replace entire DEFAULT_MODEL_OPTIONS array
89
+ pattern = r'const DEFAULT_MODEL_OPTIONS: ModelOption\[\] = \[.*?\];'
90
+ match = re.search(pattern, content, re.DOTALL)
91
+
92
+ if not match:
93
+ print("FAIL: Could not find DEFAULT_MODEL_OPTIONS array!")
94
+ sys.exit(1)
95
+
96
+ new_array = """const DEFAULT_MODEL_OPTIONS: ModelOption[] = [
97
+ {
98
  id: 'gemma-4-31b',
99
  name: 'Gemma 4 31B:free',
100
+ modelPath: 'openai/google/gemma-4-31b-it:free',
101
  avatarUrl: 'https://huggingface.co/api/avatars/google',
102
  recommended: true,
103
+ },
104
+ {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
  id: 'llama-3.3-70b',
106
  name: 'Llama 3.3 70B:free',
107
+ modelPath: 'openai/meta-llama/llama-3.3-70b-instruct:free',
108
  avatarUrl: 'https://huggingface.co/api/avatars/meta-llama',
109
  recommended: true,
110
  },
111
  {
112
+ id: 'llama-3.1-8b',
113
+ name: 'Llama 3.1 8B',
114
+ modelPath: 'openai/meta-llama/llama-3.1-8b-instruct',
115
+ avatarUrl: 'https://huggingface.co/api/avatars/meta-llama',
116
+ },
117
+ {
118
+ id: 'tencent-hy3',
119
+ name: 'Tencent HY3:free',
120
+ modelPath: 'openai/tencent/hy3:free',
121
+ avatarUrl: 'https://huggingface.co/api/avatars/tencent',
122
  },
123
  {
124
  id: 'qwen3-coder-next',
 
132
  modelPath: 'openai/google/gemini-2.0-flash-001',
133
  avatarUrl: 'https://huggingface.co/api/avatars/google',
134
  },
135
+ ];"""
136
+
137
+ content = content[:match.start()] + new_array + content[match.end():]
138
+
139
+ # Update DEFAULT_MODEL_PATH
140
+ dm_path = re.search(r'const DEFAULT_MODEL_PATH\s*=.*?;', content)
141
+ if dm_path:
142
+ content = content.replace(dm_path.group(0), "const DEFAULT_MODEL_PATH = 'openai/google/gemma-4-31b-it:free';")
143
+ print("OK: Replaced DEFAULT_MODEL_PATH")
144
+ else:
145
+ print("OK: DEFAULT_MODEL_PATH not found")
146
 
147
+ with open(FILE, "w", encoding="utf-8") as f:
148
  f.write(content)
149
 
150
+ print("OK: Frontend patched - Gemma 4 31B:free DEFAULT (openai/ prefix for OpenRouter routing)")