Spaces:
Running
Running
Fix patch_frontend.py for current upstream (regex-based import fix)
Browse files- patch_frontend.py +17 -15
patch_frontend.py
CHANGED
|
@@ -8,16 +8,16 @@ FILE = "/source/frontend/src/components/Chat/ChatInput.tsx"
|
|
| 8 |
with open(FILE, "r", encoding="utf-8") as f:
|
| 9 |
content = f.read()
|
| 10 |
|
| 11 |
-
# === Step 1: Fix imports ===
|
| 12 |
-
|
| 13 |
-
|
| 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 |
pattern = r'const DEFAULT_MODEL_OPTIONS: ModelOption\[\] = \[.*?\];'
|
|
@@ -140,13 +140,15 @@ new_array = """const DEFAULT_MODEL_OPTIONS: ModelOption[] = [
|
|
| 140 |
|
| 141 |
content = content[:match.start()] + new_array + content[match.end():]
|
| 142 |
|
| 143 |
-
# === Step 3:
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
"
|
| 147 |
-
)
|
|
|
|
|
|
|
| 148 |
|
| 149 |
with open(FILE, "w", encoding="utf-8") as f:
|
| 150 |
f.write(content)
|
| 151 |
|
| 152 |
-
print("OK: Frontend patched - 16 models,
|
|
|
|
| 8 |
with open(FILE, "r", encoding="utf-8") as f:
|
| 9 |
content = f.read()
|
| 10 |
|
| 11 |
+
# === Step 1: Fix imports — replace any model-constants import block ===
|
| 12 |
+
import_pattern = re.compile(
|
| 13 |
+
r'import\s*\{[^}]+\}\s*from\s*[\'"]@/utils/model[\'"];'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
)
|
| 15 |
+
match = import_pattern.search(content)
|
| 16 |
+
if match:
|
| 17 |
+
content = content.replace(match.group(0), "import { isClaudePath } from '@/utils/model';")
|
| 18 |
+
print("OK: Replaced imports with just isClaudePath")
|
| 19 |
+
else:
|
| 20 |
+
print("OK: Imports already clean or not found")
|
| 21 |
|
| 22 |
# === Step 2: Replace DEFAULT_MODEL_OPTIONS array using regex ===
|
| 23 |
pattern = r'const DEFAULT_MODEL_OPTIONS: ModelOption\[\] = \[.*?\];'
|
|
|
|
| 140 |
|
| 141 |
content = content[:match.start()] + new_array + content[match.end():]
|
| 142 |
|
| 143 |
+
# === Step 3: Replace DEFAULT_MODEL_PATH = first recommended model ===
|
| 144 |
+
dm_path = re.search(r'const DEFAULT_MODEL_PATH\s*=.*?;', content)
|
| 145 |
+
if dm_path:
|
| 146 |
+
content = content.replace(dm_path.group(0), "const DEFAULT_MODEL_PATH = 'deepseek-ai/DeepSeek-V4-Pro';")
|
| 147 |
+
print("OK: Replaced DEFAULT_MODEL_PATH")
|
| 148 |
+
else:
|
| 149 |
+
print("OK: DEFAULT_MODEL_PATH not found")
|
| 150 |
|
| 151 |
with open(FILE, "w", encoding="utf-8") as f:
|
| 152 |
f.write(content)
|
| 153 |
|
| 154 |
+
print("OK: Frontend patched - 16 models, deepseek-ai/DeepSeek-V4-Pro default")
|