diff --git a/examples/package.json b/examples/package.json index 98d9065..f07e622 100644 --- a/examples/package.json +++ b/examples/package.json @@ -24,7 +24,7 @@ "@genkit-ai/googleai": "^0.5.13", "@genkit-ai/vertexai": "^0.5.13", "express": "^4.21.0", - "genkitx-promptfoo": "^0.1.8", + "genkitx-promptfoo": "^0.1.11", "zod": "^3.23.8" }, "devDependencies": { diff --git a/src/index.ts b/src/index.ts index f2e4289..5fef67e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -108,19 +108,23 @@ export async function promptfooScore( }); const score = summary.results[0].score; if (summary.results[0].error) { + const errorReason = summary.results[0].error; return { score: score, - error: 'Assertion failed', details: { - reasoning: summary.results[0].error, // error reason + reasoning: `Assertion failed: ${errorReason}`, // error reason }, }; } + const successReason = + summary.results[0].gradingResult?.componentResults?.[0]?.reason; return { score: score, details: { reasoning: - summary.results[0].gradingResult?.componentResults?.[0]?.reason, // success reason + successReason === 'Assertion passed' + ? successReason + : `Assertion passed: ${successReason}`, // success reason }, }; } diff --git a/tests/index_test.ts b/tests/index_test.ts index 88b98d7..625e67d 100644 --- a/tests/index_test.ts +++ b/tests/index_test.ts @@ -46,9 +46,8 @@ describe('promptfooScore', () => { }, expected: { score: 0, - error: 'Assertion failed', details: { - reasoning: 'Expected output to contain "Hello"', + reasoning: 'Assertion failed: Expected output to contain "Hello"', }, }, },