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

Function main

packages/core/script/generate-friendli.ts:377–503  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

375}
376
377async function main() {
378 const args = process.argv.slice(2);
379 const dryRun = args.includes("--dry-run");
380
381 const modelsDir = path.join(
382 import.meta.dirname,
383 "..",
384 "..",
385 "..",
386 "providers",
387 "friendli",
388 "models",
389 );
390
391 if (dryRun) {
392 console.log(`[DRY RUN] Fetching Friendli models from API...`);
393 } else {
394 console.log(`Fetching Friendli models from API...`);
395 }
396
397 // Fetch API data
398 const res = await fetch(API_ENDPOINT);
399 if (!res.ok) {
400 console.error(`Failed to fetch API: ${res.status} ${res.statusText}`);
401 process.exit(1);
402 }
403
404 const json = await res.json();
405 const parsed = FriendliResponse.safeParse(json);
406 if (!parsed.success) {
407 console.error("Invalid API response:", parsed.error.errors);
408 process.exit(1);
409 }
410
411 const apiModels = parsed.data.data;
412
413 // Get existing files (recursively)
414 const existingFiles = new Set<string>();
415 try {
416 for await (const file of new Bun.Glob("**/*.toml").scan({
417 cwd: modelsDir,
418 absolute: false,
419 })) {
420 existingFiles.add(file);
421 }
422 } catch {
423 // Directory might not exist yet
424 }
425
426 console.log(
427 `Found ${apiModels.length} models in API, ${existingFiles.size} existing files\n`,
428 );
429
430 // Track API model IDs for orphan detection
431 const apiModelIds = new Set<string>();
432
433 let created = 0;
434 let updated = 0;

Callers 1

Calls 5

loadExistingModelFunction · 0.70
mergeModelFunction · 0.70
formatTomlFunction · 0.70
detectChangesFunction · 0.70
fetchFunction · 0.50

Tested by

no test coverage detected