oh-my-promptfoo 1.19.0 → 1.20.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/README.md CHANGED
@@ -75,7 +75,8 @@ in `defaultTest.options.provider` as above, or with
75
75
  `OPENAI_BASE_URL` to the full `https://<resource>.openai.azure.com/openai/v1`
76
76
  address and use `openai:chat:<deployment>`. The
77
77
  [grading guide](https://github.com/allagentsdev/oh-my-promptfoo/blob/main/docs/grading-guide.md#choosing-llmasserts-judge)
78
- covers per-test judges and falling back to another judge during an outage.
78
+ covers per-test and per-assertion judges and falling back to another judge
79
+ during an outage.
79
80
 
80
81
  The [examples](https://github.com/allagentsdev/oh-my-promptfoo/tree/main/examples) include configs for Codex, Claude Code, Copilot,
81
82
  pinned Git and OCI sources, and larger runs.
@@ -2975,6 +2975,12 @@ async function loadJudge(spec, context2 = {}) {
2975
2975
  `A judge must be a provider id, a provider object with an id, or a { text: \u2026 } map; received ${JSON.stringify(spec) ?? String(spec)}`
2976
2976
  );
2977
2977
  }
2978
+ function judgeName(spec, judge) {
2979
+ if (judge.label) return judge.label;
2980
+ if (typeof spec === "object" && spec !== null && !isJudge(spec) && "label" in spec && typeof spec.label === "string" && spec.label)
2981
+ return spec.label;
2982
+ return judge.id();
2983
+ }
2978
2984
 
2979
2985
  // packages/oh-my-promptfoo/src/rubric-contract.ts
2980
2986
  var import_node_module2 = require("module");
@@ -3598,7 +3604,7 @@ ${rubric.user}${fileChanges === void 0 ? "" : "\n\nUntrusted evidence (JSON):\n"
3598
3604
 
3599
3605
  // packages/oh-my-promptfoo/src/assertions.ts
3600
3606
  var SELF = /^package:oh-my-promptfoo\/assertions:llmAssert$/;
3601
- var PER_ASSERTION_JUDGE_ERROR = "llmAssert takes no per-assertion judge: remove provider from this assertion and set the judge in defaultTest.options.provider for the suite, in a test's options.provider, or with --grader for the run";
3607
+ var MISPLACED_PROVIDER_ERROR = "llmAssert does not see provider: beside config: (Promptfoo does not pass it to package assertions): move it into this assertion's config.provider, or set the judge for the suite in defaultTest.options.provider, for a test in its options.provider, or for the run with --grader";
3602
3608
  function misplacedProvider(assertions) {
3603
3609
  if (!Array.isArray(assertions)) return false;
3604
3610
  return assertions.some(
@@ -3606,8 +3612,9 @@ function misplacedProvider(assertions) {
3606
3612
  );
3607
3613
  }
3608
3614
  function judgeSpec(context2) {
3609
- if (context2?.config && Object.hasOwn(context2.config, "provider") || misplacedProvider(context2?.test?.assert))
3610
- throw new Error(PER_ASSERTION_JUDGE_ERROR);
3615
+ if (misplacedProvider(context2?.test?.assert)) throw new Error(MISPLACED_PROVIDER_ERROR);
3616
+ const own3 = context2?.config?.provider;
3617
+ if (own3) return own3;
3611
3618
  const spec = context2?.test?.options?.provider;
3612
3619
  if (spec === void 0 || spec === null || spec === "")
3613
3620
  throw new Error(
@@ -3618,12 +3625,13 @@ function judgeSpec(context2) {
3618
3625
  }
3619
3626
  async function llmAssert(output, context2) {
3620
3627
  const rubric = prepareRubric(output, context2);
3621
- const judge = await loadJudge(judgeSpec(context2));
3628
+ const spec = judgeSpec(context2);
3629
+ const judge = await loadJudge(spec);
3622
3630
  const prompt = JSON.stringify([
3623
3631
  { role: "system", content: rubric.system },
3624
3632
  { role: "user", content: rubric.user }
3625
3633
  ]);
3626
- return gradeRubric(rubric, prompt, async (attempt) => {
3634
+ const result = await gradeRubric(rubric, prompt, async (attempt) => {
3627
3635
  const response = await judge.callApi(prompt, {
3628
3636
  prompt: { raw: prompt, label: "llmAssert" },
3629
3637
  vars: context2?.vars ?? {},
@@ -3638,6 +3646,8 @@ async function llmAssert(output, context2) {
3638
3646
  metadata: response.metadata
3639
3647
  };
3640
3648
  });
3649
+ result.metadata.judge = judgeName(spec, judge);
3650
+ return result;
3641
3651
  }
3642
3652
  // Annotate the CommonJS export names for ESM import in node:
3643
3653
  0 && (module.exports = {