-
Notifications
You must be signed in to change notification settings - Fork 0
feat(judge): Add new metrics support #279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -190,45 +190,64 @@ export const sanitizeCSVCell = ( | |
| return `"${sanitized}"`; | ||
| }; | ||
|
|
||
| export const formatScoreValue = (score: TraceScore | undefined) => { | ||
| if (!score) return { value: "N/A", color: "#737373", bg: "transparent" }; | ||
|
|
||
| if (score.data_type === "CATEGORICAL") { | ||
| const catValue = String(score.value); | ||
| let color = "#171717"; | ||
| let bg = "#fafafa"; | ||
|
|
||
| if (catValue === "CORRECT") { | ||
| color = "#15803d"; | ||
| bg = "#dcfce7"; | ||
| } else if (catValue === "PARTIAL") { | ||
| color = "#92400e"; | ||
| bg = "#fef3c7"; | ||
| } else if (catValue === "INCORRECT") { | ||
| color = "#dc2626"; | ||
| bg = "#fee2e2"; | ||
| } | ||
| // v2 judge metrics score 0-5 (integers) instead of the legacy 0-1 cosine/correctness scale. | ||
| const FIVE_POINT_SCORE_NAMES = new Set([ | ||
| "adherence to ground truth", | ||
| "adherence to prompt", | ||
| "adherence to knowledge base", | ||
| ]); | ||
|
|
||
| return { value: catValue, color, bg }; | ||
| } | ||
| const isFivePointScore = (name?: string): boolean => | ||
| !!name && FIVE_POINT_SCORE_NAMES.has(name.toLowerCase()); | ||
|
|
||
| const numValue = Number(score.value); | ||
| const formattedValue = numValue.toFixed(2); | ||
| const formatCategoricalScore = (value: number | string) => { | ||
| const catValue = String(value); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of using the |
||
| let color = "#171717"; | ||
| let bg = "transparent"; | ||
| let bg = "#fafafa"; | ||
|
|
||
| if (numValue >= 0.7) { | ||
| if (catValue === "CORRECT") { | ||
| color = "#15803d"; | ||
| bg = "#dcfce7"; | ||
| } else if (numValue >= 0.5) { | ||
| } else if (catValue === "PARTIAL") { | ||
| color = "#92400e"; | ||
| bg = "#fef3c7"; | ||
| } else { | ||
| } else if (catValue === "INCORRECT") { | ||
| color = "#dc2626"; | ||
| bg = "#fee2e2"; | ||
| } | ||
|
|
||
| return { value: formattedValue, color, bg }; | ||
| return { value: catValue, color, bg }; | ||
| }; | ||
|
|
||
| // Traffic light thresholds for v2 judge metrics: 0-1 needs improvement, 2-3 could improve, 4-5 good. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. able to understand via function name. so need to remove this. |
||
| const formatFivePointScore = (numValue: number) => { | ||
| if (numValue >= 4) | ||
| return { value: String(numValue), color: "#15803d", bg: "#dcfce7" }; | ||
| if (numValue >= 2) | ||
| return { value: String(numValue), color: "#92400e", bg: "#fef3c7" }; | ||
| return { value: String(numValue), color: "#dc2626", bg: "#fee2e2" }; | ||
| }; | ||
|
|
||
| // Legacy thresholds for cosine similarity / correctness on a 0-1 scale. | ||
| const formatUnitScaleScore = (numValue: number) => { | ||
| const value = numValue.toFixed(2); | ||
| if (numValue >= 0.7) return { value, color: "#15803d", bg: "#dcfce7" }; | ||
| if (numValue >= 0.5) return { value, color: "#92400e", bg: "#fef3c7" }; | ||
| return { value, color: "#dc2626", bg: "#fee2e2" }; | ||
| }; | ||
|
|
||
| export const formatScoreValue = (score: TraceScore | undefined) => { | ||
| if (!score) return { value: "N/A", color: "#737373", bg: "transparent" }; | ||
|
|
||
| if (score.data_type === "CATEGORICAL") { | ||
| return formatCategoricalScore(score.value); | ||
| } | ||
|
|
||
| const numValue = Number(score.value); | ||
|
|
||
| return isFivePointScore(score.name) | ||
| ? formatFivePointScore(numValue) | ||
| : formatUnitScaleScore(numValue); | ||
| }; | ||
|
|
||
| export const getScoreByName = ( | ||
|
|
@@ -239,6 +258,14 @@ export const getScoreByName = ( | |
| return scores.find((s) => s?.name === name); | ||
| }; | ||
|
|
||
| /** | ||
| * Returns the judge's explanation for a score, preferring the v2 `reasoning` | ||
| * field over the legacy `comment` field. | ||
| */ | ||
|
Comment on lines
+261
to
+264
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not needed this comment. |
||
| export const getScoreNote = ( | ||
| score: TraceScore | undefined, | ||
| ): string | undefined => score?.reasoning || score?.comment; | ||
|
|
||
| /** | ||
| * Formats a USD cost value for display | ||
| * @param cost - Cost in USD | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in every function, not needed these types of the comments.