ml-intern / patch_frontend_apodex_ling_beatapi.py
bep40's picture
Fix: switch DEFAULT_MODEL from tencent/hy3:free (unavailable on OpenRouter) to laguna-s-2.1:free
dc7c214
Raw History Blame Contribute Delete
3.86 kB
"""Patch frontend ChatInput.tsx: add apodex-1.1-mini:free, ling-3.1-flash and
the BeatAPI space-bunny-alpha entry to the model picker.
- apodex/apodex-1.1-mini:free path: openai/apodex/apodex-1.1-mini:free
- inclusionai/ling-3.1-flash path: openai/inclusionai/ling-3.1-flash
- BeatAPI space-bunny-alpha path: beatapi/space-bunny-alpha
The first two follow the same OpenRouter `openai/` convention as the existing
models (including stealth/space-bunny-alpha). The third is a BEATAPI model:
its path starts with `beatapi/`, NOT `openai/`, so the backend routes it to
https://api.beatapi.io/v1 with BEATAPI_API_KEY instead of OpenRouter. The name
is prefixed "BeatAPI" so the picker makes the provider difference visible.
Runs AFTER patch_frontend.py and patch_frontend_new_models.py (which already
replaced DEFAULT_MODEL_OPTIONS). Idempotent.
"""
import os
import re
FILE = "/source/frontend/src/components/Chat/ChatInput.tsx"
NEW_ENTRIES = """ {
id: 'apodex-1.1-mini-free',
name: 'apodex/apodex-1.1-mini:free',
modelPath: 'openai/apodex/apodex-1.1-mini:free',
avatarUrl: 'https://huggingface.co/api/avatars/apodex',
recommended: true,
},
{
id: 'ling-3.1-flash',
name: 'inclusionai/ling-3.1-flash',
modelPath: 'openai/inclusionai/ling-3.1-flash',
avatarUrl: 'https://huggingface.co/api/avatars/inclusionai',
recommended: true,
},
{
id: 'beatapi-space-bunny-alpha',
name: 'BeatAPI space-bunny-alpha',
modelPath: 'beatapi/space-bunny-alpha',
avatarUrl: 'https://beatapi.io/favicon.ico',
recommended: true,
},
"""
def patch():
if not os.path.exists(FILE):
print(f"SKIP: {FILE} not found")
return
with open(FILE, "r", encoding="utf-8") as f:
content = f.read()
if (
"apodex/apodex-1.1-mini:free" in content
and "beatapi/space-bunny-alpha" in content
):
print("OK: new models already present in ChatInput.tsx")
return
# Insert right before the stealth/space-bunny-alpha entry so the three new
# models sit next to the existing free OpenRouter models.
anchor = " {\n id: 'space-bunny-alpha',\n"
if anchor in content:
content = content.replace(anchor, NEW_ENTRIES + anchor, 1)
print("OK: added 3 models before the stealth/space-bunny-alpha entry")
else:
# Fallback: insert before deepseek-v4-flash-latest, the other stable anchor.
alt = " {\n id: 'deepseek-v4-flash-latest',\n"
if alt in content:
content = content.replace(alt, NEW_ENTRIES + alt, 1)
print("OK: added 3 models before deepseek-v4-flash-latest (fallback)")
else:
m = re.search(
r"const DEFAULT_MODEL_OPTIONS: ModelOption\[\] = \[.*?\];",
content,
re.DOTALL,
)
if not m:
print("FAIL: could not find any model-list anchor")
return
head = m.group(0)[: m.group(0).rindex("[") + 1]
content = (
content[: m.start()]
+ head
+ "\n"
+ NEW_ENTRIES
+ content[m.start() + len(head) :]
)
print("OK: added 3 models at top of DEFAULT_MODEL_OPTIONS (fallback)")
with open(FILE, "w", encoding="utf-8") as f:
f.write(content)
print("OK: ChatInput.tsx patched")
# Verification: all three paths must be present.
for needle in (
"openai/apodex/apodex-1.1-mini:free",
"openai/inclusionai/ling-3.1-flash",
"beatapi/space-bunny-alpha",
):
if needle not in content:
print(f"FAIL: missing {needle}")
raise SystemExit(1)
print("OK: verified all 3 new model paths present")
if __name__ == "__main__":
patch()