@grekt/cli 6.43.0-beta.2 → 6.43.0-beta.4
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.js +33 -18
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -104390,16 +104390,15 @@ function detectPromptfoo() {
|
|
|
104390
104390
|
function getCommand(mode) {
|
|
104391
104391
|
return mode === "npx" ? ["npx", "promptfoo"] : ["promptfoo"];
|
|
104392
104392
|
}
|
|
104393
|
-
function
|
|
104393
|
+
function assemblePromptMessages(config) {
|
|
104394
|
+
return [
|
|
104395
|
+
{ role: "system", content: config.systemPrompt },
|
|
104396
|
+
{ role: "user", content: "{{input}}" }
|
|
104397
|
+
];
|
|
104398
|
+
}
|
|
104399
|
+
function assemblePromptfooConfig(config, promptPath) {
|
|
104394
104400
|
return {
|
|
104395
|
-
prompts: [
|
|
104396
|
-
{
|
|
104397
|
-
raw: JSON.stringify([
|
|
104398
|
-
{ role: "system", content: config.systemPrompt },
|
|
104399
|
-
{ role: "user", content: "{{input}}" }
|
|
104400
|
-
])
|
|
104401
|
-
}
|
|
104402
|
-
],
|
|
104401
|
+
prompts: promptPath ? [promptPath] : [assemblePromptMessages(config)],
|
|
104403
104402
|
providers: [config.provider],
|
|
104404
104403
|
tests: config.tests.map((test) => ({
|
|
104405
104404
|
description: test.description,
|
|
@@ -104467,19 +104466,19 @@ function createPromptfooEngine() {
|
|
|
104467
104466
|
return mode !== "none";
|
|
104468
104467
|
},
|
|
104469
104468
|
async run(config) {
|
|
104470
|
-
const promptfooConfig = assemblePromptfooConfig(config);
|
|
104471
104469
|
if (mode === "global") {
|
|
104472
104470
|
try {
|
|
104473
104471
|
const promptfoo = await import("promptfoo");
|
|
104474
104472
|
const evaluate = promptfoo.evaluate;
|
|
104475
104473
|
if (typeof evaluate === "function") {
|
|
104476
|
-
const
|
|
104474
|
+
const nodeConfig = assemblePromptfooConfig(config);
|
|
104475
|
+
const evaluateResult = await evaluate(nodeConfig);
|
|
104477
104476
|
const results = evaluateResult.results ?? [];
|
|
104478
104477
|
return extractFailures(results);
|
|
104479
104478
|
}
|
|
104480
104479
|
} catch {}
|
|
104481
104480
|
}
|
|
104482
|
-
return runViaCli(mode,
|
|
104481
|
+
return runViaCli(mode, config);
|
|
104483
104482
|
},
|
|
104484
104483
|
openReport() {
|
|
104485
104484
|
const cmd = getCommand(mode);
|
|
@@ -104487,27 +104486,42 @@ function createPromptfooEngine() {
|
|
|
104487
104486
|
}
|
|
104488
104487
|
};
|
|
104489
104488
|
}
|
|
104490
|
-
async function runViaCli(mode,
|
|
104489
|
+
async function runViaCli(mode, config) {
|
|
104491
104490
|
const tempDir = `${process.env.TMPDIR ?? "/tmp"}/grekt-eval-${Date.now()}`;
|
|
104492
104491
|
const configPath = `${tempDir}/promptfoo-config.json`;
|
|
104492
|
+
const promptPath = `${tempDir}/prompt.json`;
|
|
104493
104493
|
const outputPath = `${tempDir}/output.json`;
|
|
104494
104494
|
const { mkdirSync: mkdirSync3, writeFileSync: writeFileSync2, readFileSync: readFileSync2, rmSync: rmSync2 } = await import("fs");
|
|
104495
104495
|
mkdirSync3(tempDir, { recursive: true });
|
|
104496
104496
|
try {
|
|
104497
|
+
writeFileSync2(promptPath, JSON.stringify(assemblePromptMessages(config), null, 2));
|
|
104498
|
+
const promptfooConfig = assemblePromptfooConfig(config, promptPath);
|
|
104497
104499
|
writeFileSync2(configPath, JSON.stringify(promptfooConfig, null, 2));
|
|
104498
104500
|
const cmd = getCommand(mode);
|
|
104499
|
-
const
|
|
104500
|
-
|
|
104501
|
-
|
|
104501
|
+
const proc2 = Bun.spawn([...cmd, "eval", "--config", configPath, "--output", outputPath, "--no-cache"], { stdout: "pipe", stderr: "pipe" });
|
|
104502
|
+
const exitCode = await proc2.exited;
|
|
104503
|
+
if (exitCode !== 0) {
|
|
104504
|
+
const stderr = await new Response(proc2.stderr).text();
|
|
104502
104505
|
throw new Error(`promptfoo eval failed: ${stderr}`);
|
|
104503
104506
|
}
|
|
104504
104507
|
const output = JSON.parse(readFileSync2(outputPath, "utf-8"));
|
|
104505
|
-
const results = output
|
|
104508
|
+
const results = extractResultsArray(output);
|
|
104506
104509
|
return extractFailures(results);
|
|
104507
104510
|
} finally {
|
|
104508
104511
|
rmSync2(tempDir, { recursive: true, force: true });
|
|
104509
104512
|
}
|
|
104510
104513
|
}
|
|
104514
|
+
function extractResultsArray(output) {
|
|
104515
|
+
if (Array.isArray(output.results))
|
|
104516
|
+
return output.results;
|
|
104517
|
+
const nested = output.results;
|
|
104518
|
+
if (nested && Array.isArray(nested.results))
|
|
104519
|
+
return nested.results;
|
|
104520
|
+
const table = nested?.table;
|
|
104521
|
+
if (table && Array.isArray(table.body))
|
|
104522
|
+
return table.body;
|
|
104523
|
+
return [];
|
|
104524
|
+
}
|
|
104511
104525
|
|
|
104512
104526
|
// src/eval/engine-resolver.ts
|
|
104513
104527
|
var AVAILABLE_ENGINES = [
|
|
@@ -104719,6 +104733,7 @@ var evalCommand = new Command("eval").description("Run eval tests against artifa
|
|
|
104719
104733
|
}
|
|
104720
104734
|
process.exit(0);
|
|
104721
104735
|
}
|
|
104736
|
+
info(`Found ${allDiscovered.length} eval${allDiscovered.length === 1 ? "" : "s"} using ${engine2.name}`);
|
|
104722
104737
|
const spin = spinner("Running evals...");
|
|
104723
104738
|
spin.start();
|
|
104724
104739
|
const results = await runAllEvals(allDiscovered, {
|
|
@@ -104971,7 +104986,7 @@ var whoamiCommand = new Command("whoami").description("Show current user").actio
|
|
|
104971
104986
|
// package.json
|
|
104972
104987
|
var package_default = {
|
|
104973
104988
|
name: "@grekt/cli",
|
|
104974
|
-
version: "6.43.0-beta.
|
|
104989
|
+
version: "6.43.0-beta.4",
|
|
104975
104990
|
description: "AI tools versioned, synced, and shared across tools and teams",
|
|
104976
104991
|
type: "module",
|
|
104977
104992
|
bin: {
|