oh-my-promptfoo 1.33.1 → 1.34.0
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/assertions.cjs +17 -14
- package/dist/assertions.cjs.map +1 -1
- package/dist/assertions.d.cts +1 -0
- package/dist/assertions.js +6 -3
- package/dist/assertions.js.map +1 -1
- package/dist/cli.js +1 -1
- package/dist/delegate-runner.js +13 -1
- package/dist/delegate-runner.js.map +1 -1
- package/dist/{eval-progress-Edb9hQxP.js → eval-progress-HN89k-pW.js} +60 -20
- package/dist/eval-progress-HN89k-pW.js.map +1 -0
- package/dist/eval-progress.js +1 -1
- package/dist/{fs-BKq2Z3WK.cjs → fs-B8hQjayx.cjs} +18 -18
- package/dist/{fs-BKq2Z3WK.cjs.map → fs-B8hQjayx.cjs.map} +1 -1
- package/dist/{fs-D27bgN4F.js → fs-Cn_6nhFQ.js} +2 -2
- package/dist/{fs-D27bgN4F.js.map → fs-Cn_6nhFQ.js.map} +1 -1
- package/dist/prompt-cache-4PbV5Oyp.d.cts +5 -0
- package/dist/{judge-accounting-zaF-67yN.js → prompt-cache-CEzxnn1E.js} +21 -2
- package/dist/prompt-cache-CEzxnn1E.js.map +1 -0
- package/dist/{judge-accounting-DvBOqpH8.cjs → prompt-cache-DLxlzfZl.cjs} +32 -1
- package/dist/prompt-cache-DLxlzfZl.cjs.map +1 -0
- package/dist/providers.cjs +32 -19
- package/dist/providers.cjs.map +1 -1
- package/dist/providers.js +20 -7
- package/dist/providers.js.map +1 -1
- package/dist/reporting.cjs +139 -118
- package/dist/reporting.cjs.map +1 -1
- package/dist/reporting.d.cts +2 -0
- package/dist/reporting.d.ts +5 -0
- package/dist/reporting.js +41 -20
- package/dist/reporting.js.map +1 -1
- package/package.json +1 -1
- package/dist/eval-progress-Edb9hQxP.js.map +0 -1
- package/dist/judge-accounting-DvBOqpH8.cjs.map +0 -1
- package/dist/judge-accounting-zaF-67yN.js.map +0 -1
package/dist/assertions.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_fs = require("./fs-
|
|
3
|
-
const
|
|
2
|
+
const require_fs = require("./fs-B8hQjayx.cjs");
|
|
3
|
+
const require_prompt_cache = require("./prompt-cache-DLxlzfZl.cjs");
|
|
4
4
|
let node_path = require("node:path");
|
|
5
5
|
let node_url = require("node:url");
|
|
6
6
|
let node_fs = require("node:fs");
|
|
@@ -132,28 +132,29 @@ function parseGrades(text, components) {
|
|
|
132
132
|
*/
|
|
133
133
|
async function gradeRubric(rubric, renderedGradingPrompt, request) {
|
|
134
134
|
const usages = [];
|
|
135
|
-
const accounting = new
|
|
135
|
+
const accounting = new require_prompt_cache.JudgeAccountingCollector();
|
|
136
136
|
let previousReply;
|
|
137
137
|
for (let attempt = 0; attempt < 2; attempt++) {
|
|
138
138
|
let reply;
|
|
139
|
-
const failureContext = new
|
|
139
|
+
const failureContext = new require_prompt_cache.JudgeFailureContext();
|
|
140
140
|
try {
|
|
141
141
|
reply = await failureContext.run(() => request(attempt));
|
|
142
142
|
} catch (error) {
|
|
143
143
|
if (error instanceof Error && error.name === "AbortError") throw error;
|
|
144
144
|
const evidence = failureContext.forError(error);
|
|
145
145
|
if (!accounting.hasCopilotAccounting) {
|
|
146
|
-
if (evidence)
|
|
146
|
+
if (evidence) require_prompt_cache.preserveJudgeFailure(evidence);
|
|
147
147
|
throw error;
|
|
148
148
|
}
|
|
149
149
|
accounting.record(evidence ? { judgeAccounting: evidence.ledger } : void 0);
|
|
150
150
|
usages.push(evidence?.usage ?? { numRequests: 1 });
|
|
151
|
-
return gradingFailure(
|
|
151
|
+
return gradingFailure(require_prompt_cache.judgeFailureMessage(error), usages, accounting, { metadata: previousReply?.metadata });
|
|
152
152
|
}
|
|
153
153
|
previousReply = reply;
|
|
154
154
|
accounting.record(reply.metadata, reply.cached, reply.usage?.cost);
|
|
155
155
|
usages.push({
|
|
156
156
|
...reply.usage,
|
|
157
|
+
promptCache: require_prompt_cache.readPromptCache(reply.metadata),
|
|
157
158
|
numRequests: reply.usage?.numRequests ?? (reply.cached ? 0 : 1)
|
|
158
159
|
});
|
|
159
160
|
if (reply.error !== void 0) return gradingFailure(reply.error, usages, accounting, reply);
|
|
@@ -198,7 +199,7 @@ function gradingFailure(reason, usages, accounting, reply) {
|
|
|
198
199
|
*/
|
|
199
200
|
function providerMetadata(metadata) {
|
|
200
201
|
if (typeof metadata !== "object" || metadata === null || Array.isArray(metadata)) return {};
|
|
201
|
-
const { cachedResponse: _untrusted, judgeAccounting: _ledger, ...rest } = metadata;
|
|
202
|
+
const { cachedResponse: _untrusted, judgeAccounting: _ledger, copilotPromptCache: _cache, ...rest } = metadata;
|
|
202
203
|
let copy;
|
|
203
204
|
try {
|
|
204
205
|
copy = JSON.parse(JSON.stringify(rest));
|
|
@@ -239,6 +240,7 @@ function rubricResult({ components, totalWeight }, grades, usages, renderedGradi
|
|
|
239
240
|
});
|
|
240
241
|
const score = weightedScore / totalWeight;
|
|
241
242
|
const tokensUsed = summarizeUsage(usages, accounting.cost);
|
|
243
|
+
const copilotPromptCache = require_prompt_cache.sumPromptCache(usages.map(({ promptCache }) => promptCache));
|
|
242
244
|
return {
|
|
243
245
|
pass: allPassed,
|
|
244
246
|
score,
|
|
@@ -249,6 +251,7 @@ function rubricResult({ components, totalWeight }, grades, usages, renderedGradi
|
|
|
249
251
|
...tokensUsed ? { tokensUsed } : {},
|
|
250
252
|
metadata: {
|
|
251
253
|
...providerMetadata(reply.metadata),
|
|
254
|
+
...copilotPromptCache ? { copilotPromptCache } : {},
|
|
252
255
|
judgeAccounting: accounting.ledger,
|
|
253
256
|
renderedGradingPrompt,
|
|
254
257
|
...reply.cached ? { cachedResponse: true } : {}
|
|
@@ -267,7 +270,7 @@ function summarizeUsage(usages, cost) {
|
|
|
267
270
|
let measuredTokens = false;
|
|
268
271
|
let details;
|
|
269
272
|
for (const usage of usages) {
|
|
270
|
-
details =
|
|
273
|
+
details = require_prompt_cache.addCompletionDetails(details, usage.completionDetails);
|
|
271
274
|
const prompt = tokenCount(usage.prompt);
|
|
272
275
|
const completion = tokenCount(usage.completion);
|
|
273
276
|
const total = tokenCount(usage.total) ?? (prompt === void 0 || completion === void 0 ? void 0 : prompt + completion);
|
|
@@ -777,7 +780,7 @@ async function agentAssert(output, context) {
|
|
|
777
780
|
const safeConfig = graderConfig(grader.id, grader.config ?? {});
|
|
778
781
|
const env = grader.env ?? {};
|
|
779
782
|
if (grader.id === "openai:codex-sdk" && !(typeof safeConfig.apiKey === "string" && safeConfig.apiKey.trim()) && !(typeof env.OPENAI_API_KEY === "string" && env.OPENAI_API_KEY.trim())) throw new Error("Read-only Codex grading requires an explicit grader.config.apiKey or grader.env.OPENAI_API_KEY; login auth.json is not supported");
|
|
780
|
-
const sensitive =
|
|
783
|
+
const sensitive = require_prompt_cache.secrets(safeConfig, env);
|
|
781
784
|
const workspace = context?.providerResponse?.metadata?.workspace;
|
|
782
785
|
const path = workspace?.path;
|
|
783
786
|
if (typeof path !== "string" || !path.trim() || !(0, node_path.isAbsolute)(path)) throw new Error("Agent assertion requires providerResponse.metadata.workspace.path to name an absolute live workspace");
|
|
@@ -832,7 +835,7 @@ ${rubric.user}${fileChanges === void 0 ? "" : "\n\nUntrusted evidence (JSON):\n"
|
|
|
832
835
|
let codexHome;
|
|
833
836
|
try {
|
|
834
837
|
if (grader.id === "openai:codex-sdk") codexHome = await (0, node_fs_promises.mkdtemp)((0, node_path.join)((0, node_os.tmpdir)(), "oh-my-promptfoo-grader-"));
|
|
835
|
-
const result = await gradeRubric(rubric,
|
|
838
|
+
const result = await gradeRubric(rubric, require_prompt_cache.redact(prompt, sensitive), async () => {
|
|
836
839
|
let response;
|
|
837
840
|
try {
|
|
838
841
|
const current = await liveWorkspace();
|
|
@@ -860,15 +863,15 @@ ${rubric.user}${fileChanges === void 0 ? "" : "\n\nUntrusted evidence (JSON):\n"
|
|
|
860
863
|
if (after.dev !== original.dev || after.ino !== original.ino) throw new Error("Agent assertion workspace is missing or already released");
|
|
861
864
|
if (performance.now() > deadline) throw new Error("Agent grading exceeded execution timeoutMs");
|
|
862
865
|
} catch (error) {
|
|
863
|
-
const message =
|
|
864
|
-
response = response &&
|
|
866
|
+
const message = require_prompt_cache.redact(error instanceof Error ? error.message : String(error), sensitive);
|
|
867
|
+
response = response && require_prompt_cache.copilotFailure(response, message);
|
|
865
868
|
if (!response) return { error: message };
|
|
866
869
|
}
|
|
867
870
|
const usage = response.tokenUsage && typeof response.tokenUsage === "object" && !Array.isArray(response.tokenUsage) ? response.tokenUsage : {};
|
|
868
871
|
return {
|
|
869
872
|
metadata: response.metadata,
|
|
870
873
|
cached: response.cached === true,
|
|
871
|
-
...response.error !== void 0 ? { error: `Agent grading failed: ${
|
|
874
|
+
...response.error !== void 0 ? { error: `Agent grading failed: ${require_prompt_cache.redact(String(response.error), sensitive)}` } : { text: typeof response.output === "string" ? response.output : void 0 },
|
|
872
875
|
...response.tokenUsage === void 0 && response.cost === void 0 ? {} : { usage: {
|
|
873
876
|
prompt: usage.prompt,
|
|
874
877
|
completion: usage.completion,
|
|
@@ -890,7 +893,7 @@ ${rubric.user}${fileChanges === void 0 ? "" : "\n\nUntrusted evidence (JSON):\n"
|
|
|
890
893
|
}
|
|
891
894
|
});
|
|
892
895
|
} catch (error) {
|
|
893
|
-
throw new Error(
|
|
896
|
+
throw new Error(require_prompt_cache.redact(error instanceof Error ? error.message : String(error), sensitive));
|
|
894
897
|
}
|
|
895
898
|
}
|
|
896
899
|
// packages/oh-my-promptfoo/src/assertion-integration.ts
|