Spaces:
Running
Running
Upload patch_frontend.py
Browse files- patch_frontend.py +33 -24
patch_frontend.py
CHANGED
|
@@ -1,14 +1,14 @@
|
|
| 1 |
-
"""Patch frontend ChatInput.tsx + model.ts:
|
| 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 |
-
|
| 9 |
-
|
| 10 |
-
|
| 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';"
|
|
@@ -26,24 +26,21 @@ model_content = model_content.replace(
|
|
| 26 |
"export const DEEPSEEK_V4_PRO_MODEL_PATH = 'nvidia/nemotron-3-super-120b-a12b:free';"
|
| 27 |
)
|
| 28 |
|
| 29 |
-
# isClaudePath
|
| 30 |
-
|
| 31 |
-
"export function isClaudePath(modelPath: string | undefined): boolean {\n return !!modelPath && modelPath.includes('anthropic');\n}",
|
| 32 |
-
"export function isClaudePath(modelPath: string | undefined): boolean {\n return !!modelPath && modelPath.includes('openrouter');\n}"
|
| 33 |
-
)
|
| 34 |
|
| 35 |
with open(MODEL_FILE, "w") as f:
|
| 36 |
f.write(model_content)
|
| 37 |
-
print("✅ model.ts constants updated")
|
| 38 |
|
| 39 |
-
# === Step 2: Patch ChatInput.tsx
|
| 40 |
FILE = "/source/frontend/src/components/Chat/ChatInput.tsx"
|
| 41 |
with open(FILE, "r") as f:
|
| 42 |
content = f.read()
|
| 43 |
|
| 44 |
-
#
|
| 45 |
-
content = content.replace("'
|
| 46 |
-
content = content.replace('"
|
| 47 |
|
| 48 |
# Row 3: Kimi K2.7 Code → DeepSeek V4 Pro
|
| 49 |
content = content.replace("'Kimi K2.7 Code'", "'DeepSeek V4 Pro'")
|
|
@@ -57,15 +54,26 @@ content = content.replace('"MiniMax M3"', '"DeepSeek V4 Flash"')
|
|
| 57 |
content = content.replace("'GLM 5.2'", "'DeepSeek V4 Flash'")
|
| 58 |
content = content.replace('"GLM 5.2"', '"DeepSeek V4 Flash"')
|
| 59 |
|
| 60 |
-
# Row 6: DeepSeek V4 Pro → Nemotron
|
| 61 |
-
# This must be done AFTER the Kimi→DeepSeek V4 Pro replacement above
|
| 62 |
content = content.replace(
|
| 63 |
" {\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 },",
|
| 64 |
" {\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 },"
|
| 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))
|
|
@@ -80,9 +88,10 @@ if idx_end > 0:
|
|
| 80 |
},
|
| 81 |
{
|
| 82 |
id: 'tencent-hy3',
|
| 83 |
-
name: 'Tencent HY3',
|
| 84 |
-
modelPath: '
|
| 85 |
avatarUrl: 'https://huggingface.co/api/avatars/tencent',
|
|
|
|
| 86 |
},
|
| 87 |
{
|
| 88 |
id: 'gemma-3-1b',
|
|
@@ -110,11 +119,11 @@ if idx_end > 0:
|
|
| 110 |
with open(FILE, "w") as f:
|
| 111 |
f.write(content)
|
| 112 |
|
| 113 |
-
print("✅ Frontend patched
|
| 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")
|
|
|
|
| 1 |
+
"""Patch frontend ChatInput.tsx + model.ts: Remove Owl Alpha, fix Tencent HY3 path, make it default."""
|
| 2 |
|
| 3 |
+
# === Step 1: Patch model.ts constants — remove Owl Alpha, fix Tencent HY3 path ===
|
| 4 |
MODEL_FILE = "/source/frontend/src/utils/model.ts"
|
| 5 |
with open(MODEL_FILE, "r") as f:
|
| 6 |
model_content = f.read()
|
| 7 |
|
| 8 |
+
# Remove Claude Opus → Owl Alpha replacement — just keep the original Claude path
|
| 9 |
+
# (no replacement needed for CLAUDE_OPUS_48_MODEL_PATH since we're removing it)
|
| 10 |
+
|
| 11 |
+
# Instead, directly set Tencent HY3 path
|
| 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';"
|
|
|
|
| 26 |
"export const DEEPSEEK_V4_PRO_MODEL_PATH = 'nvidia/nemotron-3-super-120b-a12b:free';"
|
| 27 |
)
|
| 28 |
|
| 29 |
+
# Remove isClaudePath → isOpenrouterPath change (revert to original)
|
| 30 |
+
# We keep the original isClaudePath function checking for 'anthropic'
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
with open(MODEL_FILE, "w") as f:
|
| 33 |
f.write(model_content)
|
| 34 |
+
print("✅ model.ts constants updated — no Owl Alpha, Tencent HY3 added via ChatInput.tsx")
|
| 35 |
|
| 36 |
+
# === Step 2: Patch ChatInput.tsx — remove Owl Alpha, add Tencent HY3:free as default ===
|
| 37 |
FILE = "/source/frontend/src/components/Chat/ChatInput.tsx"
|
| 38 |
with open(FILE, "r") as f:
|
| 39 |
content = f.read()
|
| 40 |
|
| 41 |
+
# Remove Owl Alpha references — revert Claude Opus name
|
| 42 |
+
content = content.replace("'Owl Alpha'", "'Claude Opus 4.8'")
|
| 43 |
+
content = content.replace('"Owl Alpha"', '"Claude Opus 4.8"')
|
| 44 |
|
| 45 |
# Row 3: Kimi K2.7 Code → DeepSeek V4 Pro
|
| 46 |
content = content.replace("'Kimi K2.7 Code'", "'DeepSeek V4 Pro'")
|
|
|
|
| 54 |
content = content.replace("'GLM 5.2'", "'DeepSeek V4 Flash'")
|
| 55 |
content = content.replace('"GLM 5.2"', '"DeepSeek V4 Flash"')
|
| 56 |
|
| 57 |
+
# Row 6: DeepSeek V4 Pro → Nemotron
|
|
|
|
| 58 |
content = content.replace(
|
| 59 |
" {\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 },",
|
| 60 |
" {\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 },"
|
| 61 |
)
|
| 62 |
|
| 63 |
+
# Remove existing Tencent HY3 entry with wrong path, add new one at the end
|
| 64 |
+
# First, find and remove the old Tencent HY3 entry that has 'openai/tencent/hy3:free'
|
| 65 |
+
# Then add the correct one at the end
|
| 66 |
+
|
| 67 |
+
# Remove old Tencent HY3 entry (with wrong path openai/tencent/hy3:free)
|
| 68 |
+
old_tencent_block = """ {
|
| 69 |
+
id: 'tencent-hy3',
|
| 70 |
+
name: 'Tencent HY3',
|
| 71 |
+
modelPath: 'openai/tencent/hy3:free',
|
| 72 |
+
avatarUrl: 'https://huggingface.co/api/avatars/tencent',
|
| 73 |
+
},"""
|
| 74 |
+
content = content.replace(old_tencent_block, "")
|
| 75 |
+
|
| 76 |
# === Add custom models at end of DEFAULT_MODEL_OPTIONS array ===
|
|
|
|
| 77 |
idx_end = content.find("];", content.find("DEFAULT_MODEL_OPTIONS") if "DEFAULT_MODEL_OPTIONS" in content else 0)
|
| 78 |
if idx_end == -1:
|
| 79 |
idx_end = content.rfind("];", 0, content.find("export") if "export" in content else len(content))
|
|
|
|
| 88 |
},
|
| 89 |
{
|
| 90 |
id: 'tencent-hy3',
|
| 91 |
+
name: 'Tencent HY3:free',
|
| 92 |
+
modelPath: 'tencent/hy3:free',
|
| 93 |
avatarUrl: 'https://huggingface.co/api/avatars/tencent',
|
| 94 |
+
recommended: true,
|
| 95 |
},
|
| 96 |
{
|
| 97 |
id: 'gemma-3-1b',
|
|
|
|
| 119 |
with open(FILE, "w") as f:
|
| 120 |
f.write(content)
|
| 121 |
|
| 122 |
+
print("✅ Frontend patched:")
|
| 123 |
+
print(" Row 1 (Claude): Claude Opus 4.8 (Owl Alpha REMOVED)")
|
| 124 |
print(" Row 2 (GPT-5.5): unchanged")
|
| 125 |
print(" Row 3 (Kimi): DeepSeek V4 Pro")
|
| 126 |
print(" Row 4 (MiniMax): DeepSeek V4 Flash")
|
| 127 |
print(" Row 5 (GLM): DeepSeek V4 Flash (OR)")
|
| 128 |
print(" Row 6 (DeepSeek): nvidia/nemotron-3-super-120b-a12b:free")
|
| 129 |
+
print(" NEW: Gemma 4 31B, Tencent HY3:free (DEFAULT), Gemma 3 1B, Qwen3 Coder Next, Gemini 2.0 Flash")
|