bep40 commited on
Commit
6915e1a
·
verified ·
1 Parent(s): dfd5cb8

Upload patch_flint_free.py

Browse files
Files changed (1) hide show
  1. patch_flint_free.py +142 -0
patch_flint_free.py ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Patch backend + frontend: add recursive/flint-v1.0:free (OpenRouter).
2
+
3
+ Uses the same `openai/` path convention as Laguna S 2.1:free:
4
+ - backend constant: RECURSIVE_FLINT_V1_FREE_MODEL_ID = "openai/recursive/flint-v1.0:free"
5
+ - registered in _available_models() backend list
6
+ - frontend: new ModelOption in ChatInput.tsx DEFAULT_MODEL_OPTIONS
7
+
8
+ The `openai/` prefix is stripped in _resolve_llm_params and routed to
9
+ OpenRouter, so no changes to llm_params.py routing are needed.
10
+
11
+ Runs AFTER patch_models.py / patch_new_models.py / patch_xing_nemotron_vl.py.
12
+ Idempotent.
13
+ """
14
+
15
+ import ast
16
+ import os
17
+
18
+ IDS_FILE = "/app/agent/core/model_ids.py"
19
+ AGENT_FILE = "/app/backend/routes/agent.py"
20
+ FRONTEND_FILE = "/source/frontend/src/components/Chat/ChatInput.tsx"
21
+
22
+ # ---------- 1. model_ids.py ----------
23
+ with open(IDS_FILE) as f:
24
+ c = f.read()
25
+
26
+ new_constant = 'RECURSIVE_FLINT_V1_FREE_MODEL_ID = "openai/recursive/flint-v1.0:free"\n'
27
+
28
+ if "RECURSIVE_FLINT_V1_FREE_MODEL_ID" not in c:
29
+ # Anchor: the NEMOTRON_3_5_SUPER_VL line injected by patch_xing_nemotron_vl.py.
30
+ # Fall back to DEEPSEEK_V4_FLASH_LATEST line from patch_models.py.
31
+ anchors = [
32
+ 'NEMOTRON_3_5_SUPER_VL_FREE_MODEL_ID = "openai/nvidia/nemotron-3.5-super-vl:free"',
33
+ 'LAGUNA_S21_FREE_MODEL_ID = "openai/poolside/laguna-s-2.1:free"',
34
+ ]
35
+ inserted = False
36
+ for anchor in anchors:
37
+ if anchor in c:
38
+ c = c.replace(anchor, anchor + "\n" + new_constant, 1)
39
+ print(f"OK: added constant to model_ids.py after {anchor.split(' =')[0]}")
40
+ inserted = True
41
+ break
42
+ if not inserted:
43
+ print("FAIL: no anchor found in model_ids.py for constant insertion")
44
+ raise SystemExit(1)
45
+
46
+ with open(IDS_FILE, "w") as f:
47
+ f.write(c)
48
+ ast.parse(c)
49
+ print("OK: model_ids.py written & syntax OK")
50
+ else:
51
+ print("OK: model_ids.py already has RECURSIVE_FLINT_V1_FREE_MODEL_ID (idempotent)")
52
+
53
+ # ---------- 2. agent.py : imports ----------
54
+ with open(AGENT_FILE) as f:
55
+ ac = f.read()
56
+
57
+ if "RECURSIVE_FLINT_V1_FREE_MODEL_ID" not in ac:
58
+ # patch_xing_nemotron_vl.py injected NEMOTRON_3_5_SUPER_VL_FREE_MODEL_ID into
59
+ # the import block after LING_3_0_FLASH_FREE_MODEL_ID.
60
+ imp_anchor = " LING_3_0_FLASH_FREE_MODEL_ID,\n"
61
+ if imp_anchor in ac:
62
+ ac = ac.replace(
63
+ imp_anchor,
64
+ imp_anchor
65
+ + " NEMOTRON_3_5_SUPER_VL_FREE_MODEL_ID,\n"
66
+ + " RECURSIVE_FLINT_V1_FREE_MODEL_ID,\n",
67
+ 1,
68
+ )
69
+ print("OK: added RECURSIVE_FLINT_V1 import to agent.py")
70
+ else:
71
+ print("FAIL: import anchor not found in agent.py")
72
+ raise SystemExit(1)
73
+
74
+ # ---------- 3. agent.py : _available_models ----------
75
+ # Insert after the NEMOTRON_3_5_SUPER_VL entry in _available_models.
76
+ line_anchor = (
77
+ ' {"id": NEMOTRON_3_5_SUPER_VL_FREE_MODEL_ID, '
78
+ '"label": "nvidia/nemotron-3.5-super-vl:free", "recommended": True},\n'
79
+ )
80
+ new_line = line_anchor + (
81
+ ' {"id": RECURSIVE_FLINT_V1_FREE_MODEL_ID, '
82
+ '"label": "recursive/flint-v1.0:free", "recommended": True},\n'
83
+ )
84
+
85
+ if line_anchor in ac:
86
+ ac = ac.replace(line_anchor, new_line, 1)
87
+ print("OK: added recursive/flint-v1.0:free to _available_models()")
88
+ else:
89
+ print("WARN: NEMOTRON VL line anchor not matched, trying fallback...")
90
+ # Fallback: insert after the LING_3_0_FLASH entry (more stable across patches).
91
+ alt_anchor = (
92
+ ' {"id": LING_3_0_FLASH_FREE_MODEL_ID, '
93
+ '"label": "inclusionai/ling-3.0-flash:free", "recommended": True},\n'
94
+ )
95
+ if alt_anchor in ac:
96
+ ac = ac.replace(
97
+ alt_anchor,
98
+ alt_anchor + new_line,
99
+ 1,
100
+ )
101
+ print("OK: added recursive/flint-v1.0:free to _available_models() (fallback)")
102
+ else:
103
+ print("WARN: fallback anchor also not matched - model may already be present or patches changed")
104
+
105
+ with open(AGENT_FILE, "w") as f:
106
+ f.write(ac)
107
+ ast.parse(ac)
108
+ print("OK: agent.py written & syntax OK")
109
+ else:
110
+ print("OK: agent.py already has RECURSIVE_FLINT_V1_FREE_MODEL_ID (idempotent)")
111
+
112
+ # ---------- 4. Frontend ChatInput.tsx ----------
113
+ if os.path.exists(FRONTEND_FILE):
114
+ with open(FRONTEND_FILE, "r", encoding="utf-8") as f:
115
+ fc = f.read()
116
+
117
+ if "flint-v1.0" in fc:
118
+ print("OK: recursive/flint-v1.0:free already present in ChatInput.tsx (idempotent)")
119
+ else:
120
+ # Anchor: the deepseek-v4-flash-latest entry at the end of DEFAULT_MODEL_OPTIONS.
121
+ anchor = " {\n id: 'deepseek-v4-flash-latest',\n"
122
+ new_entry = (
123
+ " {\n"
124
+ " id: 'flint-v1.0-free',\n"
125
+ " name: 'recursive/flint-v1.0:free',\n"
126
+ " modelPath: 'openai/recursive/flint-v1.0:free',\n"
127
+ " avatarUrl: 'https://huggingface.co/api/avatars/recursive',\n"
128
+ " recommended: true,\n"
129
+ " },\n"
130
+ )
131
+
132
+ if anchor in fc:
133
+ fc = fc.replace(anchor, new_entry + anchor, 1)
134
+ with open(FRONTEND_FILE, "w", encoding="utf-8") as f:
135
+ f.write(fc)
136
+ print("OK: added recursive/flint-v1.0:free to ChatInput.tsx DEFAULT_MODEL_OPTIONS")
137
+ else:
138
+ print("WARN: deepseek anchor not found in ChatInput.tsx - frontend entry not added")
139
+ else:
140
+ print(f"WARN: {FRONTEND_FILE} not found (frontend patch skipped)")
141
+
142
+ print("DONE: recursive/flint-v1.0:free added with Laguna S 2.1:free path convention")