MCPcopy
hub / github.com/anomalyco/models.dev / main

Function main

packages/core/script/generate-helicone.ts:173–233  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

171}
172
173async function main() {
174 const endpoint = DEFAULT_ENDPOINT;
175
176 const outDir = path.join(
177 import.meta.dirname,
178 "..",
179 "..",
180 "..",
181 "providers",
182 "helicone",
183 "models",
184 );
185
186 const res = await fetch(endpoint);
187 if (!res.ok) {
188 console.error(`Failed to fetch registry: ${res.status} ${res.statusText}`);
189 process.exit(1);
190 }
191 const json = await res.json();
192
193 const parsed = HeliconeResponse.safeParse(json);
194 if (!parsed.success) {
195 parsed.error.cause = json;
196 console.error("Invalid Helicone response:", parsed.error.errors);
197 console.error("When parsing:", parsed.error.cause);
198 process.exit(1);
199 }
200
201 const models = parsed.data.data.models;
202 const existing = new Map<string, ExistingModel>();
203 await mkdir(outDir, { recursive: true });
204 for await (const file of new Bun.Glob("**/*.toml").scan({ cwd: outDir })) {
205 const filePath = path.join(outDir, file);
206 const model = await loadExistingModel(filePath);
207 if (model !== undefined) existing.set(file, model);
208 }
209
210 // Clean output directory: remove subfolders and existing TOML files
211 for (const entry of await readdir(outDir)) {
212 const p = path.join(outDir, entry);
213 const st = await stat(p);
214 if (st.isDirectory()) {
215 await rm(p, { recursive: true, force: true });
216 } else if (st.isFile() && entry.endsWith(".toml")) {
217 await rm(p, { force: true });
218 }
219 }
220 let created = 0;
221
222 for (const m of models) {
223 const fileSafeId = m.id.replaceAll("/", "-");
224 const filePath = path.join(outDir, `${fileSafeId}.toml`);
225 const toml = formatToml(m, existing.get(`${fileSafeId}.toml`));
226 await Bun.write(filePath, toml);
227 created++;
228 }
229
230 console.log(

Callers 1

Calls 3

loadExistingModelFunction · 0.70
formatTomlFunction · 0.70
fetchFunction · 0.50

Tested by

no test coverage detected