bep40 commited on
Commit
f15d8ed
Β·
verified Β·
1 Parent(s): 0c286f8

Update backend patch: accept all new model IDs + HF Inference for Qwen3

Browse files
Files changed (1) hide show
  1. patch_models.py +36 -20
patch_models.py CHANGED
@@ -1,42 +1,58 @@
1
- """Patch backend: add new model IDs to AVAILABLE_MODELS + fix title generation."""
2
- import re, os
3
 
4
  AGENT_FILE = "/app/backend/routes/agent.py"
5
  with open(AGENT_FILE, "r") as f:
6
  content = f.read()
7
 
8
- # Add new models to AVAILABLE_MODELS
9
- target = "AVAILABLE_MODELS = _available_models()\n"
10
- patch = '''
11
- # === PATCH: Add OpenRouter + HF Inference models ===
12
  import os as _os
13
- AVAILABLE_MODELS.extend([
14
- {"id": "openai/deepseek/deepseek-chat-v3-0324", "label": "DeepSeek V3", "provider": "openrouter", "tier": "free", "recommended": True},
 
 
 
15
  {"id": "openai/google/gemini-2.0-flash-001", "label": "Gemini 2.0 Flash", "provider": "openrouter", "tier": "free"},
16
- {"id": "openai/qwen/qwen3-30b-a3b", "label": "Qwen3 30B", "provider": "openrouter", "tier": "free"},
17
- {"id": "Qwen/Qwen3-235B-A22B", "label": "Qwen3 235B", "provider": "huggingface", "tier": "free"},
18
- ])
19
- PREMIUM_MODEL_IDS = set() # No premium gate
20
- DEFAULT_FREE_MODEL_ID = "openai/deepseek/deepseek-chat-v3-0324"
21
  # === END PATCH ===
22
  '''
23
 
 
24
  if target in content:
25
- content = content.replace(target, target + patch)
26
- print("βœ… Added models to AVAILABLE_MODELS")
 
 
 
 
 
 
 
 
27
 
28
- # Fix title generation
29
  old_title = 'model="openai/openai/gpt-oss-120b:cerebras",\n api_base="https://router.huggingface.co/v1",\n api_key=api_key,'
30
  new_title = 'model="openai/deepseek/deepseek-chat-v3-0324",\n api_base=_os.environ.get("OPENAI_API_BASE", "https://openrouter.ai/api/v1"),\n api_key=_os.environ.get("OPENAI_API_KEY", api_key),'
 
31
  if old_title in content:
32
  content = content.replace(old_title, new_title)
33
  content = content.replace(' reasoning_effort="low",\n', '')
34
- print("βœ… Title generation patched")
 
 
35
 
36
  import ast
37
- ast.parse(content)
38
- print("βœ… Syntax OK")
 
 
 
 
39
 
40
  with open(AGENT_FILE, "w") as f:
41
  f.write(content)
42
- print("βœ… Backend patched")
 
 
1
+ """Build-time patch: Add all models to backend AVAILABLE_MODELS + fix title gen."""
2
+ import os
3
 
4
  AGENT_FILE = "/app/backend/routes/agent.py"
5
  with open(AGENT_FILE, "r") as f:
6
  content = f.read()
7
 
8
+ patch_code = '''
9
+
10
+ # === PATCHED: Add OpenRouter + HF Inference models ===
 
11
  import os as _os
12
+ _extra_models = [
13
+ {"id": "openai/x-ai/grok-4.3", "label": "Grok 4.3", "provider": "openrouter", "tier": "free", "recommended": True},
14
+ {"id": "openai/deepseek/deepseek-v4-pro", "label": "DeepSeek V4 Pro", "provider": "openrouter", "tier": "free", "recommended": True},
15
+ {"id": "openai/qwen/qwen3.7-max", "label": "Qwen 3.7 Max", "provider": "openrouter", "tier": "free"},
16
+ {"id": "Qwen/Qwen3-235B-A22B", "label": "Qwen3 235B (HF)", "provider": "huggingface", "tier": "free"},
17
  {"id": "openai/google/gemini-2.0-flash-001", "label": "Gemini 2.0 Flash", "provider": "openrouter", "tier": "free"},
18
+ ]
19
+ AVAILABLE_MODELS.extend(_extra_models)
 
 
 
20
  # === END PATCH ===
21
  '''
22
 
23
+ target = "AVAILABLE_MODELS = _available_models()\n"
24
  if target in content:
25
+ content = content.replace(target, target + patch_code)
26
+ print("βœ… Added Grok 4.3, DeepSeek V4 Pro, Qwen 3.7 Max, Qwen3 HF, Gemini Flash")
27
+ else:
28
+ target2 = "AVAILABLE_MODELS = _available_models()"
29
+ if target2 in content:
30
+ content = content.replace(target2, target2 + "\n" + patch_code)
31
+ print("βœ… Added models (alt)")
32
+ else:
33
+ print("❌ Cannot find AVAILABLE_MODELS!")
34
+ import sys; sys.exit(1)
35
 
36
+ # Fix title generation to use OpenRouter instead of HF Router
37
  old_title = 'model="openai/openai/gpt-oss-120b:cerebras",\n api_base="https://router.huggingface.co/v1",\n api_key=api_key,'
38
  new_title = 'model="openai/deepseek/deepseek-chat-v3-0324",\n api_base=_os.environ.get("OPENAI_API_BASE", "https://openrouter.ai/api/v1"),\n api_key=_os.environ.get("OPENAI_API_KEY", api_key),'
39
+
40
  if old_title in content:
41
  content = content.replace(old_title, new_title)
42
  content = content.replace(' reasoning_effort="low",\n', '')
43
+ print("βœ… Title gen fixed for OpenRouter")
44
+ else:
45
+ print("⚠️ Title pattern not found")
46
 
47
  import ast
48
+ try:
49
+ ast.parse(content)
50
+ print("βœ… Syntax OK")
51
+ except SyntaxError as e:
52
+ print(f"❌ Syntax error: {e}")
53
+ import sys; sys.exit(1)
54
 
55
  with open(AGENT_FILE, "w") as f:
56
  f.write(content)
57
+
58
+ print("\nβœ… Backend patch complete")