Skip to content

Commit

Permalink
better success / failure reasoning
Browse files Browse the repository at this point in the history
  • Loading branch information
yukinagae committed Sep 26, 2024
1 parent 7d2902b commit 3cc78a0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
10 changes: 7 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
};
}
Expand Down
3 changes: 1 addition & 2 deletions tests/index_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"',
},
},
},
Expand Down

0 comments on commit 3cc78a0

Please sign in to comment.