forked from anomalyco/models.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate
More file actions
executable file
·79 lines (65 loc) · 2.55 KB
/
Copy pathvalidate
File metadata and controls
executable file
·79 lines (65 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env bun
import { join } from "path";
import { readdir, stat } from "fs/promises";
import { parse } from "@iarna/toml";
import { file } from "bun";
import { ModelSchema, ProviderSchema } from "../app/schemas";
import { z } from "zod";
async function validate() {
const providersDir = join(import.meta.dir, "..", "providers");
try {
const providers = await readdir(providersDir);
for (const provider of providers) {
const providerPath = join(providersDir, provider);
const providerStat = await stat(providerPath);
if (!providerStat.isDirectory()) continue;
console.log(`Checking provider: ${provider}`);
// Validate provider.toml
const providerTomlPath = join(providerPath, "provider.toml");
const providerTomlFile = file(providerTomlPath);
const providerExists = await providerTomlFile.exists();
if (!providerExists)
throw new Error(`Missing provider.toml in ${provider}`);
// Validate provider.toml against schema
const providerContent = parse(await providerTomlFile.text());
validateSchema(ProviderSchema, providerContent, providerTomlPath);
// Check for models directory
const modelsPath = join(providerPath, "models");
const modelsStat = await stat(modelsPath);
if (!modelsStat.isDirectory()) {
throw new Error(`Missing "models" directory in ${provider}`);
}
// Validate model files
const modelFiles = await readdir(modelsPath);
const tomlFiles = modelFiles.filter((file) => file.endsWith(".toml"));
if (tomlFiles.length === 0) {
throw new Error(`No model files found in ${provider}/models`);
}
for (const modelFile of tomlFiles) {
const modelPath = join(modelsPath, modelFile);
console.log(` Checking model: ${modelFile}`);
const modelTomlFile = file(modelPath);
const modelContent = parse(await modelTomlFile.text());
validateSchema(ModelSchema, modelContent, modelPath);
}
}
console.log("\n✅ All providers and models validated successfully!");
} catch (err) {
console.error(`❌ Error: ${err.message}`);
process.exit(1);
}
}
function validateSchema(schema, data, filePath) {
try {
schema.parse(data);
} catch (validationError) {
if (validationError instanceof z.ZodError) {
const errors = validationError.errors
.map((err) => `${err.path.join(".")}: ${err.message}`)
.join(", ");
throw new Error(`Validation failed for ${filePath}: ${errors}`);
}
throw validationError;
}
}
validate();