MCPcopy Create free account
hub / github.com/anomalyco/models.dev / generateModels

Function generateModels

packages/core/src/generate.ts:33–59  ·  view source on GitHub ↗
(directory: string)

Source from the content-addressed store, hash-verified

31}
32
33export async function generateModels(directory: string) {
34 const result: Record<string, ModelMetadata> = {};
35 if (!existsSync(directory)) return result;
36
37 for await (const modelPath of new Bun.Glob("**/*.toml").scan({
38 cwd: directory,
39 absolute: true,
40 followSymlinks: true,
41 })) {
42 const modelID = path.relative(directory, modelPath).split(path.sep).join("/").slice(0, -5);
43 const toml = await import(modelPath, {
44 with: {
45 type: "toml",
46 },
47 }).then((mod) => mod.default);
48 toml.id = modelID;
49
50 const model = ModelMetadata.safeParse(toml);
51 if (!model.success) {
52 model.error.cause = { modelPath, toml };
53 throw model.error;
54 }
55 result[modelID] = model.data;
56 }
57
58 return result;
59}
60
61export async function generate(directory: string) {
62 const modelsDirectory = path.join(path.dirname(directory), "models");

Callers 2

generateCatalogFunction · 0.85
generateFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected