@llmops/cli 1.0.0-beta.2 ā 1.0.0-beta.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +156 -40
- package/package.json +11 -20
- package/dist/index.d.mts +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,37 +1,29 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { command, run, string } from "@drizzle-team/brocli";
|
|
2
|
+
import { boolean, command, run, string } from "@drizzle-team/brocli";
|
|
3
3
|
import { logger } from "@llmops/core";
|
|
4
|
-
import {
|
|
5
|
-
import { existsSync } from "node:fs";
|
|
4
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync } from "node:fs";
|
|
6
5
|
import yoctoSpinner from "yocto-spinner";
|
|
7
|
-
import chalk from "chalk";
|
|
8
6
|
import prompts from "prompts";
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
7
|
+
import path, { basename, join, resolve } from "node:path";
|
|
8
|
+
import { pathToFileURL } from "node:url";
|
|
9
|
+
import { execSync } from "node:child_process";
|
|
10
|
+
import chalk from "chalk";
|
|
11
11
|
|
|
12
12
|
//#region src/lib/get-config.ts
|
|
13
13
|
const getConfig = async ({ cwd, configPath }) => {
|
|
14
|
-
if (configPath)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
if (!configPath) return void 0;
|
|
15
|
+
const resolvedPath = existsSync(configPath) ? path.resolve(configPath) : path.resolve(cwd, configPath);
|
|
16
|
+
if (!existsSync(resolvedPath)) throw new Error(`Config file not found: ${resolvedPath}`);
|
|
17
|
+
const mod = await import(pathToFileURL(resolvedPath).href);
|
|
18
|
+
if (mod.config) return mod.config;
|
|
19
|
+
if (mod.default) {
|
|
20
|
+
if (typeof mod.default === "object" && mod.default !== null && "config" in mod.default && mod.default.config) return mod.default.config;
|
|
21
|
+
return mod.default;
|
|
19
22
|
}
|
|
20
23
|
};
|
|
21
24
|
|
|
22
25
|
//#endregion
|
|
23
26
|
//#region src/commands/migrate.ts
|
|
24
|
-
/**
|
|
25
|
-
* @fileoverview This file defines the 'migrate' command for the CLI application.
|
|
26
|
-
* Steps:
|
|
27
|
-
* 1. Look for package.json and @llmops/sdk in the current directory.
|
|
28
|
-
* 2. Check if the @llmops/sdk version works with the current CLI version.
|
|
29
|
-
* 3. If compatible, check for the config file passed as an argument.
|
|
30
|
-
* 4. If the config file exists, read and parse it.
|
|
31
|
-
* 5. If not passed, look for default config file locations.
|
|
32
|
-
* 6. Use zod to validate the existing configuration schema.
|
|
33
|
-
* 7. If valid, get the telemetry store from the config.
|
|
34
|
-
*/
|
|
35
27
|
const migrateCommand = command({
|
|
36
28
|
name: "migrate",
|
|
37
29
|
desc: "Run database migrations based on LLMOps configuration",
|
|
@@ -61,43 +53,167 @@ const migrateCommand = command({
|
|
|
61
53
|
}
|
|
62
54
|
const telemetry = config.telemetry;
|
|
63
55
|
const store = Array.isArray(telemetry) ? telemetry[0] : telemetry;
|
|
64
|
-
if (!store || !store.
|
|
56
|
+
if (!store || !store._pool) {
|
|
65
57
|
logger.error("No telemetry store with database found. Configure pgStore in your config.");
|
|
66
58
|
process.exit(1);
|
|
67
59
|
}
|
|
68
|
-
const db = store._db;
|
|
69
|
-
const spinner = yoctoSpinner({ text: "preparing migration..." }).start();
|
|
70
|
-
const { toBeAdded, toBeCreated, runMigrations } = await getMigrations(db, "postgres", { schema: "llmops" });
|
|
71
|
-
if (!toBeAdded.length && !toBeCreated.length) {
|
|
72
|
-
spinner.stop();
|
|
73
|
-
console.log("š No migrations needed.");
|
|
74
|
-
process.exit(0);
|
|
75
|
-
}
|
|
76
|
-
spinner.stop();
|
|
77
|
-
console.log(`š The migration will affect the following:`);
|
|
78
|
-
for (const table of [...toBeCreated, ...toBeAdded]) console.log("->", chalk.magenta(Object.keys(table.fields).join(", ")), chalk.white("fields on"), chalk.yellow(`${table.table}`), chalk.white("table."));
|
|
79
60
|
let migrate = opts.yes;
|
|
80
61
|
if (!opts.yes) migrate = (await prompts({
|
|
81
62
|
type: "confirm",
|
|
82
63
|
name: "migrate",
|
|
83
|
-
message: "Do you want to
|
|
64
|
+
message: "Do you want to run pending migrations?",
|
|
84
65
|
initial: false
|
|
85
66
|
})).migrate;
|
|
86
67
|
if (!migrate) {
|
|
87
68
|
console.log("Migration cancelled.");
|
|
88
69
|
process.exit(0);
|
|
89
70
|
}
|
|
90
|
-
spinner
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
71
|
+
const spinner = yoctoSpinner({ text: "running migrations..." }).start();
|
|
72
|
+
try {
|
|
73
|
+
const { runMigrations } = await import("@llmops/sdk/store/pg");
|
|
74
|
+
const { applied } = await runMigrations(store._pool, store._schema ?? "llmops");
|
|
75
|
+
spinner.stop();
|
|
76
|
+
if (applied.length === 0) console.log("š No pending migrations.");
|
|
77
|
+
else console.log(`ā
Applied ${applied.length} migration(s): ${applied.join(", ")}`);
|
|
78
|
+
} catch (error) {
|
|
79
|
+
spinner.stop();
|
|
80
|
+
logger.error(`Migration failed: ${error}`);
|
|
81
|
+
process.exit(1);
|
|
82
|
+
}
|
|
94
83
|
process.exit(0);
|
|
95
84
|
}
|
|
96
85
|
});
|
|
97
86
|
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/commands/eval.ts
|
|
89
|
+
/**
|
|
90
|
+
* Find eval files from a path (file or directory).
|
|
91
|
+
* Default pattern: *.eval.ts, *.eval.js
|
|
92
|
+
*/
|
|
93
|
+
function findEvalFiles(target) {
|
|
94
|
+
const resolved = resolve(target);
|
|
95
|
+
if (!existsSync(resolved)) {
|
|
96
|
+
console.error(chalk.red(`Path not found: ${target}`));
|
|
97
|
+
process.exit(1);
|
|
98
|
+
}
|
|
99
|
+
const stat = statSync(resolved);
|
|
100
|
+
if (stat.isFile()) return [resolved];
|
|
101
|
+
if (stat.isDirectory()) return collectEvalFiles(resolved);
|
|
102
|
+
return [];
|
|
103
|
+
}
|
|
104
|
+
function collectEvalFiles(dir) {
|
|
105
|
+
const files = [];
|
|
106
|
+
const entries = readdirSync(dir, { withFileTypes: true });
|
|
107
|
+
for (const entry of entries) {
|
|
108
|
+
const fullPath = join(dir, entry.name);
|
|
109
|
+
if (entry.isDirectory() && !entry.name.startsWith(".") && entry.name !== "node_modules") files.push(...collectEvalFiles(fullPath));
|
|
110
|
+
else if (entry.isFile() && (entry.name.endsWith(".eval.ts") || entry.name.endsWith(".eval.js"))) files.push(fullPath);
|
|
111
|
+
}
|
|
112
|
+
return files.sort();
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Bundle and run an eval file using esbuild.
|
|
116
|
+
* Bundles to a temp file, executes with node, then cleans up.
|
|
117
|
+
*/
|
|
118
|
+
async function bundleAndRun(file, env) {
|
|
119
|
+
const esbuild = await import("esbuild");
|
|
120
|
+
const tmpDir = join(process.cwd(), ".llmops-eval-tmp");
|
|
121
|
+
mkdirSync(tmpDir, { recursive: true });
|
|
122
|
+
const outFile = join(tmpDir, `${basename(file, ".ts").replace(".eval", "")}_eval.mjs`);
|
|
123
|
+
try {
|
|
124
|
+
await esbuild.build({
|
|
125
|
+
entryPoints: [file],
|
|
126
|
+
bundle: true,
|
|
127
|
+
platform: "node",
|
|
128
|
+
format: "esm",
|
|
129
|
+
outfile: outFile,
|
|
130
|
+
external: [
|
|
131
|
+
"@llmops/sdk",
|
|
132
|
+
"@llmops/sdk/*",
|
|
133
|
+
"@llmops/core",
|
|
134
|
+
"@llmops/core/*",
|
|
135
|
+
"openai",
|
|
136
|
+
"esbuild",
|
|
137
|
+
"fsevents",
|
|
138
|
+
"dotenv",
|
|
139
|
+
"dotenv/*"
|
|
140
|
+
],
|
|
141
|
+
treeShaking: true,
|
|
142
|
+
sourcemap: false,
|
|
143
|
+
banner: { js: "" }
|
|
144
|
+
});
|
|
145
|
+
execSync(`node ${outFile}`, {
|
|
146
|
+
stdio: "inherit",
|
|
147
|
+
env,
|
|
148
|
+
cwd: process.cwd()
|
|
149
|
+
});
|
|
150
|
+
} finally {
|
|
151
|
+
try {
|
|
152
|
+
rmSync(tmpDir, {
|
|
153
|
+
recursive: true,
|
|
154
|
+
force: true
|
|
155
|
+
});
|
|
156
|
+
} catch {}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
const evalCommand = command({
|
|
160
|
+
name: "eval",
|
|
161
|
+
desc: "Run evaluation files",
|
|
162
|
+
options: {
|
|
163
|
+
target: string().default("./evals").desc("File or directory to run. Default: ./evals").alias("t"),
|
|
164
|
+
outputDir: string().default("./llmops-evals").desc("Output directory for results").alias("o"),
|
|
165
|
+
json: boolean().desc("Output results as JSON to stdout").alias("j")
|
|
166
|
+
},
|
|
167
|
+
handler: async (opts) => {
|
|
168
|
+
const target = opts.target;
|
|
169
|
+
const files = findEvalFiles(target);
|
|
170
|
+
if (files.length === 0) {
|
|
171
|
+
console.error(chalk.yellow(`No eval files found. Create files matching *.eval.ts or *.eval.js in ${target}`));
|
|
172
|
+
process.exit(1);
|
|
173
|
+
}
|
|
174
|
+
console.log(chalk.dim(`Found ${files.length} eval file${files.length > 1 ? "s" : ""}`));
|
|
175
|
+
const env = {
|
|
176
|
+
...process.env,
|
|
177
|
+
LLMOPS_EVAL_OUTPUT_DIR: resolve(opts.outputDir),
|
|
178
|
+
...opts.json ? { LLMOPS_EVAL_OUTPUT: "json" } : {}
|
|
179
|
+
};
|
|
180
|
+
let hasErrors = false;
|
|
181
|
+
for (const file of files) {
|
|
182
|
+
const name = basename(file);
|
|
183
|
+
console.log(chalk.dim(`\nRunning ${name}...`));
|
|
184
|
+
try {
|
|
185
|
+
await bundleAndRun(file, env);
|
|
186
|
+
} catch (err) {
|
|
187
|
+
hasErrors = true;
|
|
188
|
+
console.error(chalk.red(`\nā ${name} failed`));
|
|
189
|
+
if (err instanceof Error && !("status" in err)) console.error(err.message);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
const outputDir = resolve(opts.outputDir);
|
|
193
|
+
if (existsSync(outputDir) && !opts.json) {
|
|
194
|
+
const evalDirs = readdirSync(outputDir, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => d.name);
|
|
195
|
+
if (evalDirs.length > 0) {
|
|
196
|
+
console.log(chalk.dim("\nāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā"));
|
|
197
|
+
console.log(chalk.dim(`Results saved to ${opts.outputDir}/`));
|
|
198
|
+
for (const evalDir of evalDirs) {
|
|
199
|
+
const resultFiles = readdirSync(join(outputDir, evalDir)).filter((f) => f.endsWith(".json")).sort().reverse();
|
|
200
|
+
if (resultFiles.length > 0) try {
|
|
201
|
+
const scores = JSON.parse(readFileSync(join(outputDir, evalDir, resultFiles[0]), "utf-8")).scores;
|
|
202
|
+
const scoreStr = Object.entries(scores).map(([k, v]) => `${k}=${v.mean.toFixed(2)}`).join(" ");
|
|
203
|
+
console.log(` ${chalk.white(evalDir)} ${chalk.cyan(scoreStr)}`);
|
|
204
|
+
} catch {
|
|
205
|
+
console.log(` ${chalk.white(evalDir)} ${chalk.dim(resultFiles[0])}`);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
if (hasErrors) process.exit(1);
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
|
|
98
214
|
//#endregion
|
|
99
215
|
//#region src/index.ts
|
|
100
|
-
run([migrateCommand], {
|
|
216
|
+
run([migrateCommand, evalCommand], {
|
|
101
217
|
name: "llmops",
|
|
102
218
|
description: "LLMOps CLI - A pluggable LLMOps toolkit for TypeScript teams",
|
|
103
219
|
version: "0.0.1"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@llmops/cli",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.23",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "LLMOps CLI - A pluggable LLMOps toolkit for TypeScript teams",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -14,23 +14,13 @@
|
|
|
14
14
|
"directory": "packages/cli"
|
|
15
15
|
},
|
|
16
16
|
"author": "chtushar",
|
|
17
|
+
"bin": {
|
|
18
|
+
"llmops": "./dist/index.mjs"
|
|
19
|
+
},
|
|
17
20
|
"files": [
|
|
18
21
|
"dist"
|
|
19
22
|
],
|
|
20
23
|
"main": "./dist/index.mjs",
|
|
21
|
-
"module": "./dist/index.mjs",
|
|
22
|
-
"types": "./dist/index.d.mts",
|
|
23
|
-
"exports": "./dist/index.mjs",
|
|
24
|
-
"bin": {
|
|
25
|
-
"cli": "./dist/index.mjs",
|
|
26
|
-
"llmops": "./dist/index.mjs"
|
|
27
|
-
},
|
|
28
|
-
"publishConfig": {
|
|
29
|
-
"access": "public",
|
|
30
|
-
"executableFiles": [
|
|
31
|
-
"./dist/index.mjs"
|
|
32
|
-
]
|
|
33
|
-
},
|
|
34
24
|
"keywords": [
|
|
35
25
|
"llmops",
|
|
36
26
|
"cli",
|
|
@@ -38,15 +28,17 @@
|
|
|
38
28
|
"llm",
|
|
39
29
|
"typescript"
|
|
40
30
|
],
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
},
|
|
41
34
|
"dependencies": {
|
|
42
35
|
"@drizzle-team/brocli": "^0.11.0",
|
|
43
|
-
"c12": "^3.3.2",
|
|
44
36
|
"chalk": "^5.6.2",
|
|
45
|
-
"
|
|
37
|
+
"esbuild": "^0.25.0",
|
|
46
38
|
"prompts": "^2.4.2",
|
|
47
39
|
"yocto-spinner": "^1.0.0",
|
|
48
|
-
"@llmops/core": "^1.0.0-beta.
|
|
49
|
-
"@llmops/sdk": "^1.0.0-beta.
|
|
40
|
+
"@llmops/core": "^1.0.0-beta.23",
|
|
41
|
+
"@llmops/sdk": "^1.0.0-beta.23"
|
|
50
42
|
},
|
|
51
43
|
"devDependencies": {
|
|
52
44
|
"@types/pg": "^8.15.6",
|
|
@@ -55,9 +47,8 @@
|
|
|
55
47
|
},
|
|
56
48
|
"scripts": {
|
|
57
49
|
"build": "tsdown",
|
|
58
|
-
"start": "node ./dist/index.mjs",
|
|
59
50
|
"clean": "rm -rf dist",
|
|
60
|
-
"dev": "
|
|
51
|
+
"dev": "tsx src/index.ts",
|
|
61
52
|
"test": "vitest",
|
|
62
53
|
"typecheck": "tsc --noEmit"
|
|
63
54
|
}
|
package/dist/index.d.mts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|