Spaces:
Running
Running
Upload patch_frontend.py
Browse files- patch_frontend.py +120 -153
patch_frontend.py
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import sys
|
| 2 |
|
| 3 |
FILE = "/source/frontend/src/components/Chat/ChatInput.tsx"
|
|
@@ -6,173 +9,137 @@ with open(FILE, "r", encoding="utf-8") as f:
|
|
| 6 |
content = f.read()
|
| 7 |
|
| 8 |
# === Step 1: Fix imports ===
|
| 9 |
-
|
| 10 |
"import {\n"
|
| 11 |
" CLAUDE_OPUS_48_MODEL_PATH,\n"
|
| 12 |
" GPT_55_MODEL_PATH,\n"
|
| 13 |
" KIMI_K26_MODEL_PATH,\n"
|
| 14 |
" isClaudePath,\n"
|
| 15 |
-
"} from '@/utils/model';"
|
|
|
|
| 16 |
)
|
| 17 |
-
new_import = "import { isClaudePath } from '@/utils/model';"
|
| 18 |
-
|
| 19 |
-
if old_import in content:
|
| 20 |
-
content = content.replace(old_import, new_import)
|
| 21 |
-
print("OK: Fixed imports")
|
| 22 |
-
else:
|
| 23 |
-
alt = "import { CLAUDE_OPUS_48_MODEL_PATH, GPT_55_MODEL_PATH, KIMI_K26_MODEL_PATH, isClaudePath } from '@/utils/model';"
|
| 24 |
-
if alt in content:
|
| 25 |
-
content = content.replace(alt, new_import)
|
| 26 |
-
print("OK: Fixed imports (single-line)")
|
| 27 |
-
elif "import { isClaudePath }" in content:
|
| 28 |
-
print("OK: Already patched imports")
|
| 29 |
-
else:
|
| 30 |
-
print("WARN: Import line not found!")
|
| 31 |
|
| 32 |
-
# === Step 2: Replace DEFAULT_MODEL_OPTIONS array ===
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
print("FAIL: = [ not found!")
|
| 41 |
sys.exit(1)
|
| 42 |
|
| 43 |
-
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
-
|
| 60 |
-
print("FAIL: Could not find matching closing bracket!")
|
| 61 |
-
sys.exit(1)
|
| 62 |
-
|
| 63 |
-
# Build new array as list of single-quote strings only (no triple-quotes)
|
| 64 |
-
new_array_body = "\n".join([
|
| 65 |
-
"",
|
| 66 |
-
" {",
|
| 67 |
-
" id: 'deepseek-v4-pro',",
|
| 68 |
-
" name: 'DeepSeek V4 Pro',",
|
| 69 |
-
" modelPath: 'deepseek-ai/DeepSeek-V4-Pro',",
|
| 70 |
-
" avatarUrl: 'https://huggingface.co/api/avatars/deepseek-ai',",
|
| 71 |
-
" recommended: true,",
|
| 72 |
-
" },",
|
| 73 |
-
" {",
|
| 74 |
-
" id: 'deepseek-v4-flash',",
|
| 75 |
-
" name: 'DeepSeek V4 Flash',",
|
| 76 |
-
" modelPath: 'deepseek-ai/DeepSeek-V4-Flash',",
|
| 77 |
-
" avatarUrl: 'https://huggingface.co/api/avatars/deepseek-ai',",
|
| 78 |
-
" },",
|
| 79 |
-
" {",
|
| 80 |
-
" id: 'gpt-5.5',",
|
| 81 |
-
" name: 'GPT-5.5',",
|
| 82 |
-
" modelPath: 'openai/gpt-5.5:fal-ai',",
|
| 83 |
-
" avatarUrl: 'https://huggingface.co/api/avatars/openai',",
|
| 84 |
-
" },",
|
| 85 |
-
" {",
|
| 86 |
-
" id: 'qwen3-coder-next',",
|
| 87 |
-
" name: 'Qwen3 Coder Next',",
|
| 88 |
-
" modelPath: 'Qwen/Qwen3-Coder-Next',",
|
| 89 |
-
" avatarUrl: 'https://huggingface.co/api/avatars/Qwen',",
|
| 90 |
-
" recommended: true,",
|
| 91 |
-
" },",
|
| 92 |
-
" {",
|
| 93 |
-
" id: 'gemma-3-1b',",
|
| 94 |
-
" name: 'Gemma 3 1B',",
|
| 95 |
-
" modelPath: 'google/gemma-3-1b-it',",
|
| 96 |
-
" avatarUrl: 'https://huggingface.co/api/avatars/google',",
|
| 97 |
-
" recommended: true,",
|
| 98 |
-
" },",
|
| 99 |
-
" {",
|
| 100 |
-
" id: 'gemini-2.0-flash',",
|
| 101 |
-
" name: 'Gemini 2.0 Flash',",
|
| 102 |
-
" modelPath: 'openai/google/gemini-2.0-flash-001',",
|
| 103 |
-
" avatarUrl: 'https://huggingface.co/api/avatars/google',",
|
| 104 |
-
" },",
|
| 105 |
-
" {",
|
| 106 |
-
" id: 'deepseek-v4-flash-or',",
|
| 107 |
-
" name: 'DeepSeek V4 Flash (OR)',",
|
| 108 |
-
" modelPath: 'openai/deepseek/deepseek-v4-flash:free',",
|
| 109 |
-
" avatarUrl: 'https://huggingface.co/api/avatars/deepseek-ai',",
|
| 110 |
-
" },",
|
| 111 |
-
" {",
|
| 112 |
-
" id: 'gemma-4-9b',",
|
| 113 |
-
" name: 'Gemma 4 9B',",
|
| 114 |
-
" modelPath: 'openai/google/gemma-4-9b-it:free',",
|
| 115 |
-
" avatarUrl: 'https://huggingface.co/api/avatars/google',",
|
| 116 |
-
" recommended: true,",
|
| 117 |
-
" },",
|
| 118 |
-
" {",
|
| 119 |
-
" id: 'gemma-4-31b',",
|
| 120 |
-
" name: 'Gemma 4 31B',",
|
| 121 |
-
" modelPath: 'openai/google/gemma-4-31b-it:free',",
|
| 122 |
-
" avatarUrl: 'https://huggingface.co/api/avatars/google',",
|
| 123 |
-
" recommended: true,",
|
| 124 |
-
" },",
|
| 125 |
-
" {",
|
| 126 |
-
" id: 'riverflow-fast',",
|
| 127 |
-
" name: 'Riverflow V2.5 Fast',",
|
| 128 |
-
" modelPath: 'openai/sourceful/riverflow-v2.5-fast:free',",
|
| 129 |
-
" avatarUrl: 'https://huggingface.co/api/avatars/sourceful',",
|
| 130 |
-
" recommended: true,",
|
| 131 |
-
" },",
|
| 132 |
-
" {",
|
| 133 |
-
" id: 'riverflow-pro',",
|
| 134 |
-
" name: 'Riverflow V2.5 Pro',",
|
| 135 |
-
" modelPath: 'openai/sourceful/riverflow-v2.5-pro:free',",
|
| 136 |
-
" avatarUrl: 'https://huggingface.co/api/avatars/sourceful',",
|
| 137 |
-
" recommended: true,",
|
| 138 |
-
" },",
|
| 139 |
-
" {",
|
| 140 |
-
" id: 'nemotron-120b',",
|
| 141 |
-
" name: 'Nemotron 3 Super 120B',",
|
| 142 |
-
" modelPath: 'openai/nvidia/nemotron-3-super-120b-a12b:free',",
|
| 143 |
-
" avatarUrl: 'https://huggingface.co/api/avatars/nvidia',",
|
| 144 |
-
" },",
|
| 145 |
-
" {",
|
| 146 |
-
" id: 'nemotron-3-ultra',",
|
| 147 |
-
" name: 'Nemotron 3 Ultra 550B',",
|
| 148 |
-
" modelPath: 'openai/nvidia/nemotron-3-ultra-550b-a55b:free',",
|
| 149 |
-
" avatarUrl: 'https://huggingface.co/api/avatars/nvidia',",
|
| 150 |
-
" recommended: true,",
|
| 151 |
-
" },",
|
| 152 |
-
" {",
|
| 153 |
-
" id: 'laguna-m',",
|
| 154 |
-
" name: 'Laguna M.1',",
|
| 155 |
-
" modelPath: 'openai/poolside/laguna-m.1:free',",
|
| 156 |
-
" avatarUrl: 'https://huggingface.co/api/avatars/poolside',",
|
| 157 |
-
" recommended: true,",
|
| 158 |
-
" },",
|
| 159 |
-
" {",
|
| 160 |
-
" id: 'laguna-xs',",
|
| 161 |
-
" name: 'Laguna XS.2',",
|
| 162 |
-
" modelPath: 'openai/poolside/laguna-xs.2:free',",
|
| 163 |
-
" avatarUrl: 'https://huggingface.co/api/avatars/poolside',",
|
| 164 |
-
" },",
|
| 165 |
-
"]",
|
| 166 |
-
])
|
| 167 |
-
|
| 168 |
-
content = content[:bracket_start] + new_array_body + content[bracket_end + 1:]
|
| 169 |
|
| 170 |
# === Step 3: DEFAULT_FREE_MODEL_OPTION_ID ===
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
print("OK: Set default free model to DeepSeek V4 Pro")
|
| 176 |
|
| 177 |
with open(FILE, "w", encoding="utf-8") as f:
|
| 178 |
f.write(content)
|
|
|
|
| 1 |
+
"""Patch frontend ChatInput.tsx: Replace DEFAULT_MODEL_OPTIONS array + fix imports."""
|
| 2 |
+
|
| 3 |
+
import re
|
| 4 |
import sys
|
| 5 |
|
| 6 |
FILE = "/source/frontend/src/components/Chat/ChatInput.tsx"
|
|
|
|
| 9 |
content = f.read()
|
| 10 |
|
| 11 |
# === Step 1: Fix imports ===
|
| 12 |
+
content = content.replace(
|
| 13 |
"import {\n"
|
| 14 |
" CLAUDE_OPUS_48_MODEL_PATH,\n"
|
| 15 |
" GPT_55_MODEL_PATH,\n"
|
| 16 |
" KIMI_K26_MODEL_PATH,\n"
|
| 17 |
" isClaudePath,\n"
|
| 18 |
+
"} from '@/utils/model';",
|
| 19 |
+
"import { isClaudePath } from '@/utils/model';"
|
| 20 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
# === Step 2: Replace DEFAULT_MODEL_OPTIONS array using regex ===
|
| 23 |
+
# Match from "const DEFAULT_MODEL_OPTIONS" to the closing "];"
|
| 24 |
+
# The regex finds: const DEFAULT_MODEL_OPTIONS: ModelOption[] = [ ... ];
|
| 25 |
+
pattern = r'const DEFAULT_MODEL_OPTIONS: ModelOption\[\] = \[.*?\];'
|
| 26 |
+
match = re.search(pattern, content, re.DOTALL)
|
| 27 |
|
| 28 |
+
if not match:
|
| 29 |
+
print("FAIL: Could not find DEFAULT_MODEL_OPTIONS array!")
|
|
|
|
| 30 |
sys.exit(1)
|
| 31 |
|
| 32 |
+
print(f"OK: Found array at pos {match.start()}-{match.end()}")
|
| 33 |
|
| 34 |
+
new_array = """const DEFAULT_MODEL_OPTIONS: ModelOption[] = [
|
| 35 |
+
{
|
| 36 |
+
id: 'deepseek-v4-pro',
|
| 37 |
+
name: 'DeepSeek V4 Pro',
|
| 38 |
+
modelPath: 'deepseek-ai/DeepSeek-V4-Pro',
|
| 39 |
+
avatarUrl: 'https://huggingface.co/api/avatars/deepseek-ai',
|
| 40 |
+
recommended: true,
|
| 41 |
+
},
|
| 42 |
+
{
|
| 43 |
+
id: 'deepseek-v4-flash',
|
| 44 |
+
name: 'DeepSeek V4 Flash',
|
| 45 |
+
modelPath: 'deepseek-ai/DeepSeek-V4-Flash',
|
| 46 |
+
avatarUrl: 'https://huggingface.co/api/avatars/deepseek-ai',
|
| 47 |
+
},
|
| 48 |
+
{
|
| 49 |
+
id: 'gpt-5.5',
|
| 50 |
+
name: 'GPT-5.5',
|
| 51 |
+
modelPath: 'openai/gpt-5.5:fal-ai',
|
| 52 |
+
avatarUrl: 'https://huggingface.co/api/avatars/openai',
|
| 53 |
+
},
|
| 54 |
+
{
|
| 55 |
+
id: 'qwen3-coder-next',
|
| 56 |
+
name: 'Qwen3 Coder Next',
|
| 57 |
+
modelPath: 'Qwen/Qwen3-Coder-Next',
|
| 58 |
+
avatarUrl: 'https://huggingface.co/api/avatars/Qwen',
|
| 59 |
+
recommended: true,
|
| 60 |
+
},
|
| 61 |
+
{
|
| 62 |
+
id: 'gemma-3-1b',
|
| 63 |
+
name: 'Gemma 3 1B',
|
| 64 |
+
modelPath: 'google/gemma-3-1b-it',
|
| 65 |
+
avatarUrl: 'https://huggingface.co/api/avatars/google',
|
| 66 |
+
recommended: true,
|
| 67 |
+
},
|
| 68 |
+
{
|
| 69 |
+
id: 'gemini-2.0-flash',
|
| 70 |
+
name: 'Gemini 2.0 Flash',
|
| 71 |
+
modelPath: 'openai/google/gemini-2.0-flash-001',
|
| 72 |
+
avatarUrl: 'https://huggingface.co/api/avatars/google',
|
| 73 |
+
},
|
| 74 |
+
{
|
| 75 |
+
id: 'deepseek-v4-flash-or',
|
| 76 |
+
name: 'DeepSeek V4 Flash (OR)',
|
| 77 |
+
modelPath: 'openai/deepseek/deepseek-v4-flash:free',
|
| 78 |
+
avatarUrl: 'https://huggingface.co/api/avatars/deepseek-ai',
|
| 79 |
+
},
|
| 80 |
+
{
|
| 81 |
+
id: 'gemma-4-9b',
|
| 82 |
+
name: 'Gemma 4 9B',
|
| 83 |
+
modelPath: 'openai/google/gemma-4-9b-it:free',
|
| 84 |
+
avatarUrl: 'https://huggingface.co/api/avatars/google',
|
| 85 |
+
recommended: true,
|
| 86 |
+
},
|
| 87 |
+
{
|
| 88 |
+
id: 'gemma-4-31b',
|
| 89 |
+
name: 'Gemma 4 31B',
|
| 90 |
+
modelPath: 'openai/google/gemma-4-31b-it:free',
|
| 91 |
+
avatarUrl: 'https://huggingface.co/api/avatars/google',
|
| 92 |
+
recommended: true,
|
| 93 |
+
},
|
| 94 |
+
{
|
| 95 |
+
id: 'riverflow-fast',
|
| 96 |
+
name: 'Riverflow V2.5 Fast',
|
| 97 |
+
modelPath: 'openai/sourceful/riverflow-v2.5-fast:free',
|
| 98 |
+
avatarUrl: 'https://huggingface.co/api/avatars/sourceful',
|
| 99 |
+
recommended: true,
|
| 100 |
+
},
|
| 101 |
+
{
|
| 102 |
+
id: 'riverflow-pro',
|
| 103 |
+
name: 'Riverflow V2.5 Pro',
|
| 104 |
+
modelPath: 'openai/sourceful/riverflow-v2.5-pro:free',
|
| 105 |
+
avatarUrl: 'https://huggingface.co/api/avatars/sourceful',
|
| 106 |
+
recommended: true,
|
| 107 |
+
},
|
| 108 |
+
{
|
| 109 |
+
id: 'nemotron-120b',
|
| 110 |
+
name: 'Nemotron 3 Super 120B',
|
| 111 |
+
modelPath: 'openai/nvidia/nemotron-3-super-120b-a12b:free',
|
| 112 |
+
avatarUrl: 'https://huggingface.co/api/avatars/nvidia',
|
| 113 |
+
},
|
| 114 |
+
{
|
| 115 |
+
id: 'nemotron-3-ultra',
|
| 116 |
+
name: 'Nemotron 3 Ultra 550B',
|
| 117 |
+
modelPath: 'openai/nvidia/nemotron-3-ultra-550b-a55b:free',
|
| 118 |
+
avatarUrl: 'https://huggingface.co/api/avatars/nvidia',
|
| 119 |
+
recommended: true,
|
| 120 |
+
},
|
| 121 |
+
{
|
| 122 |
+
id: 'laguna-m',
|
| 123 |
+
name: 'Laguna M.1',
|
| 124 |
+
modelPath: 'openai/poolside/laguna-m.1:free',
|
| 125 |
+
avatarUrl: 'https://huggingface.co/api/avatars/poolside',
|
| 126 |
+
recommended: true,
|
| 127 |
+
},
|
| 128 |
+
{
|
| 129 |
+
id: 'laguna-xs',
|
| 130 |
+
name: 'Laguna XS.2',
|
| 131 |
+
modelPath: 'openai/poolside/laguna-xs.2:free',
|
| 132 |
+
avatarUrl: 'https://huggingface.co/api/avatars/poolside',
|
| 133 |
+
},
|
| 134 |
+
];"""
|
| 135 |
|
| 136 |
+
content = content[:match.start()] + new_array + content[match.end():]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
|
| 138 |
# === Step 3: DEFAULT_FREE_MODEL_OPTION_ID ===
|
| 139 |
+
content = content.replace(
|
| 140 |
+
"DEFAULT_FREE_MODEL_OPTION_ID = 'kimi-k2.6'",
|
| 141 |
+
"DEFAULT_FREE_MODEL_OPTION_ID = 'deepseek-v4-pro'"
|
| 142 |
+
)
|
|
|
|
| 143 |
|
| 144 |
with open(FILE, "w", encoding="utf-8") as f:
|
| 145 |
f.write(content)
|