Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion app/(main)/evaluations/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
DownloadIcon,
} from "@/app/components/icons";

export default function EvaluationReport() {

Check warning on line 54 in app/(main)/evaluations/[id]/page.tsx

View workflow job for this annotation

GitHub Actions / lint-and-build

Function 'EvaluationReport' has too many statements (35). Maximum allowed is 20
const router = useRouter();
const params = useParams();
const toast = useToast();
Expand Down Expand Up @@ -399,7 +399,10 @@
onResync={handleResync}
/>
{categoryMetrics.length > 0 && (
<CategoryMetricsTable categoryMetrics={categoryMetrics} />
<CategoryMetricsTable
categoryMetrics={categoryMetrics}
isJudgeRun={job.is_judge_run}
/>
)}
</>
) : (
Expand Down
18 changes: 12 additions & 6 deletions app/components/evaluations/CategoryMetricsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { CategoryMetric } from "@/app/lib/types/evaluation";

interface CategoryMetricsTableProps {
categoryMetrics: CategoryMetric[];
isJudgeRun?: boolean;
}

function formatScore(value: number | null): string {
Expand All @@ -13,6 +14,7 @@ function formatScore(value: number | null): string {

export default function CategoryMetricsTable({
categoryMetrics,
isJudgeRun,
}: CategoryMetricsTableProps) {
if (!categoryMetrics || categoryMetrics.length === 0) return null;

Expand All @@ -36,9 +38,11 @@ export default function CategoryMetricsTable({
<th className="px-5 py-2.5 text-right text-[11px] font-semibold uppercase tracking-wide text-text-secondary">
Total Questions
</th>
<th className="px-5 py-2.5 text-right text-[11px] font-semibold uppercase tracking-wide text-text-secondary">
Avg Cosine
</th>
{!isJudgeRun && (
<th className="px-5 py-2.5 text-right text-[11px] font-semibold uppercase tracking-wide text-text-secondary">
Avg Cosine
</th>
)}
<th className="px-5 py-2.5 text-right text-[11px] font-semibold uppercase tracking-wide text-text-secondary">
Avg Correctness
</th>
Expand All @@ -56,9 +60,11 @@ export default function CategoryMetricsTable({
<td className="px-5 py-2.5 text-sm text-right tabular-nums text-text-primary">
{row.total_evals}
</td>
<td className="px-5 py-2.5 text-sm text-right tabular-nums text-text-primary">
{formatScore(row.avg_cosine)}
</td>
{!isJudgeRun && (
<td className="px-5 py-2.5 text-sm text-right tabular-nums text-text-primary">
{formatScore(row.avg_cosine)}
</td>
)}
<td className="px-5 py-2.5 text-sm text-right tabular-nums text-text-primary">
{formatScore(row.avg_correctness)}
</td>
Expand Down
39 changes: 37 additions & 2 deletions app/components/evaluations/DetailedResultsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ import {
hasSummaryScores,
isNewScoreObjectV2,
isGroupedFormat,
isCosineScoreName,
} from "@/app/lib/utils/evaluation";
import { formatScoreValue, getScoreByName } from "@/app/lib/utils";
import { InfoTooltip } from "@/app/components/ui";
import { GroupedResultsTable } from "@/app/components/evaluations";
import { MarkdownContent } from "@/app/components/chat";
import { ExternalLinkIcon } from "@/app/components/icons";

interface DetailedResultsTableProps {
job: EvalJob;
Expand All @@ -26,6 +28,7 @@ export default function DetailedResultsTable({
job,
}: DetailedResultsTableProps) {
const scoreObject = getScoreObject(job);
const isJudgeRun = job.is_judge_run;

if (!scoreObject || !hasSummaryScores(scoreObject)) {
return (
Expand All @@ -42,6 +45,7 @@ export default function DetailedResultsTable({
return (
<GroupedResultsTable
traces={scoreObject.traces as GroupedTraceItem[]}
isJudgeRun={isJudgeRun}
/>
);
}
Expand All @@ -61,12 +65,16 @@ export default function DetailedResultsTable({
}

// Get all unique score names from the first item
const scoreNames =
const allScoreNames =
individual_scores[0]?.trace_scores?.map((s) => s.name) || [];
const scoreNames = isJudgeRun
? allScoreNames.filter((name) => !isCosineScoreName(name))
: allScoreNames;

const hasAnyCategory = individual_scores.some(
(s) => (s.category ?? "").trim().length > 0,
);
const hasAnyTraceUrl = individual_scores.some((s) => s.score_trace_url);

const COLUMN_WIDTHS = {
index: 50,
Expand All @@ -75,14 +83,16 @@ export default function DetailedResultsTable({
groundTruth: 250,
answer: 250,
score: 160,
trace: 90,
};
const tableMinWidth =
COLUMN_WIDTHS.index +
(hasAnyCategory ? COLUMN_WIDTHS.category : 0) +
COLUMN_WIDTHS.question +
COLUMN_WIDTHS.groundTruth +
COLUMN_WIDTHS.answer +
scoreNames.length * COLUMN_WIDTHS.score;
scoreNames.length * COLUMN_WIDTHS.score +
(hasAnyTraceUrl ? COLUMN_WIDTHS.trace : 0);

return (
<div className="border rounded-lg overflow-hidden bg-white border-gray-200">
Expand Down Expand Up @@ -132,6 +142,14 @@ export default function DetailedResultsTable({
{scoreName}
</th>
))}
{hasAnyTraceUrl && (
<th
className="px-4 py-3 text-center text-xs font-semibold uppercase text-bg-primary"
style={{ width: `${COLUMN_WIDTHS.trace}px` }}
>
Trace
</th>
)}
</tr>
</thead>

Expand Down Expand Up @@ -209,6 +227,23 @@ export default function DetailedResultsTable({
</td>
);
})}

{hasAnyTraceUrl && (
<td className="px-4 py-3 text-center align-top">
{item.score_trace_url && (
<a
href={item.score_trace_url}
target="_blank"
rel="noopener noreferrer"
className="inline-flex items-center justify-center text-accent-primary hover:opacity-75 transition-opacity"
aria-label="View trace"
title="View trace"
>
<ExternalLinkIcon className="w-4 h-4" />
</a>
)}
</td>
)}
</tr>
);
})}
Expand Down
9 changes: 7 additions & 2 deletions app/components/evaluations/EvalRunCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default function EvalRunCard({
const isCompleted = job.status?.toLowerCase() === "completed";
const scoreObj = getScoreObject(job);
const statusColor = getStatusColor(job.status || "");
const isJudgeRun = job.is_judge_run;

return (
<div
Expand Down Expand Up @@ -59,7 +60,11 @@ export default function EvalRunCard({

{scoreObj && (
<div className="mt-3">
<ScoreDisplay score={scoreObj} errorMessage={job.error_message} />
<ScoreDisplay
score={scoreObj}
errorMessage={job.error_message}
isJudgeRun={isJudgeRun}
/>
</div>
)}

Expand Down Expand Up @@ -91,7 +96,7 @@ export default function EvalRunCard({
</span>
</>
)}
{job.cost.embedding && (
{job.cost.embedding && !isJudgeRun && (
<>
<span>Cosine similarity calculation</span>
<span className="text-left">
Expand Down
10 changes: 9 additions & 1 deletion app/components/evaluations/GroupedResultsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@

import { Fragment } from "react";
import { TraceScore, GroupedTraceItem } from "@/app/lib/types/evaluation";
import { isCosineScoreName } from "@/app/lib/utils/evaluation";
import { formatScoreValue } from "@/app/lib/utils";
import { InfoTooltip } from "@/app/components/ui";
export default function GroupedResultsTable({
traces,
isJudgeRun,
}: {
traces: GroupedTraceItem[];
isJudgeRun?: boolean;
}) {
if (!traces || traces.length === 0) {
return (
Expand Down Expand Up @@ -171,8 +174,13 @@ export default function GroupedResultsTable({
<td className="px-4 pt-1 pb-3 bg-accent-subtle/50" />

{Array.from({ length: maxAnswers }, (_, answerIndex) => {
const answerScores: TraceScore[] =
const rawAnswerScores: TraceScore[] =
group.scores?.[answerIndex] || [];
const answerScores = isJudgeRun
? rawAnswerScores.filter(
(s) => !isCosineScoreName(s.name),
)
: rawAnswerScores;
const answer = group.llm_answers[answerIndex];

return (
Expand Down
27 changes: 17 additions & 10 deletions app/components/evaluations/MetricsOverview.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use client";

import type { EvalJob, SummaryScore } from "@/app/lib/types/evaluation";
import { isCosineScoreName } from "@/app/lib/utils/evaluation";
import { Button } from "@/app/components/ui";
import { RefreshIcon, WarningTriangleIcon } from "@/app/components/icons";

Expand All @@ -14,11 +15,15 @@ interface MetricsOverviewProps {

export default function MetricsOverview({
job,
summaryScores,
summaryScores: allSummaryScores,
isJobInProgress,
isResyncing,
onResync,
}: MetricsOverviewProps) {
const isJudgeRun = job.is_judge_run;
const summaryScores = isJudgeRun
? allSummaryScores.filter((s) => !isCosineScoreName(s.name))
: allSummaryScores;
const showPartialNotice =
summaryScores.some(
(s) => job.total_items && s.total_pairs < job.total_items,
Expand All @@ -38,15 +43,17 @@ export default function MetricsOverview({
<h3 className="text-sm font-semibold text-text-secondary">
Metrics Overview
</h3>
<Button
variant="primary"
size="sm"
onClick={onResync}
disabled={isResyncing}
>
<RefreshIcon className={isResyncing ? "animate-spin" : ""} />
{isResyncing ? "Resyncing..." : "Resync"}
</Button>
{!isJudgeRun && (
<Button
variant="primary"
size="sm"
onClick={onResync}
disabled={isResyncing}
>
<RefreshIcon className={isResyncing ? "animate-spin" : ""} />
{isResyncing ? "Resyncing..." : "Resync"}
</Button>
)}
</div>
{summaryScores.length > 0 ? (
<div className="flex gap-4 flex-wrap">
Expand Down
11 changes: 9 additions & 2 deletions app/components/evaluations/ScoreDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@
"use client";

import type { ScoreObject } from "@/app/lib/types/evaluation";
import { hasSummaryScores } from "@/app/lib/utils/evaluation";
import {
hasSummaryScores,
isCosineScoreName,
} from "@/app/lib/utils/evaluation";

interface ScoreDisplayProps {
score: ScoreObject | null;
errorMessage?: string | null;
isJudgeRun?: boolean;
}

export default function ScoreDisplay({
score,
errorMessage,
isJudgeRun,
}: ScoreDisplayProps) {
if (!score) {
return (
Expand All @@ -31,7 +36,9 @@ export default function ScoreDisplay({

// Handle score format with summary_scores (V1, V2, or Basic)
if (hasSummaryScores(score)) {
const summaryScores = score.summary_scores || [];
const summaryScores = (score.summary_scores || []).filter(
(s) => !isJudgeRun || !isCosineScoreName(s.name),
);

if (summaryScores.length === 0) {
return (
Expand Down
21 changes: 21 additions & 0 deletions app/components/icons/evaluations/ExternalLinkIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
interface IconProps {
className?: string;
}

export default function ExternalLinkIcon({ className }: IconProps) {
return (
<svg
className={className}
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
strokeWidth={2}
strokeLinecap="round"
strokeLinejoin="round"
>
<path d="M18 13v6a2 2 0 01-2 2H5a2 2 0 01-2-2V8a2 2 0 012-2h6" />
<polyline points="15 3 21 3 21 9" />
<line x1="10" y1="14" x2="21" y2="3" />
</svg>
);
}
1 change: 1 addition & 0 deletions app/components/icons/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export { default as EditIcon } from "./evaluations/EditIcon";
export { default as MenuIcon } from "./evaluations/MenuIcon";
export { default as DatabaseIcon } from "./evaluations/DatabaseIcon";
export { default as GroupIcon } from "./evaluations/GroupIcon";
export { default as ExternalLinkIcon } from "./evaluations/ExternalLinkIcon";

// Document Icons
export { default as DocumentFileIcon } from "./document/DocumentFileIcon";
Expand Down
3 changes: 3 additions & 0 deletions app/lib/types/evaluation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface TraceItem {
question_id?: number;
category?: string;
scores: TraceScore[];
score_trace_url?: string;
}

export interface GroupedTraceItem {
Expand Down Expand Up @@ -42,6 +43,7 @@ export interface IndividualScore {
response_id?: string;
};
trace_scores: TraceScore[];
score_trace_url?: string;
}

export interface CategoryMetric {
Expand Down Expand Up @@ -129,6 +131,7 @@ export interface EvalJob {
id: number;
run_name: string;
run_mode?: RunMode;
is_judge_run?: boolean;
dataset_name: string;
dataset_id: number;
batch_job_id: number;
Expand Down
5 changes: 5 additions & 0 deletions app/lib/utils/evaluation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export function getScoreObject(job: EvalJob): ScoreObject | null {
return job.scores || job.score || null;
}

export function isCosineScoreName(name: string): boolean {
return /cosine/i.test(name);
}

export function isGroupedFormat(
traces: TraceItem[] | GroupedTraceItem[],
): traces is GroupedTraceItem[] {
Expand All @@ -47,6 +51,7 @@ export function normalizeToIndividualScores(
output: { answer: trace.llm_answer },
metadata: { ground_truth: trace.ground_truth_answer },
trace_scores: trace.scores,
score_trace_url: trace.score_trace_url,
};
}
return { trace_id: "", trace_scores: [] };
Expand Down
Loading