From 4f919bdc5f2f91e655ebc5a853b28ee3c0dc1b24 Mon Sep 17 00:00:00 2001 From: mukunda katta Date: Sun, 19 Apr 2026 16:08:35 -0700 Subject: [PATCH] fix(frontend): keep instance metrics readable --- .../src/components/Predictions.test.tsx | 75 +++++++++++++++++++ helm-frontend/src/components/Predictions.tsx | 25 ++++--- 2 files changed, 91 insertions(+), 9 deletions(-) create mode 100644 helm-frontend/src/components/Predictions.test.tsx diff --git a/helm-frontend/src/components/Predictions.test.tsx b/helm-frontend/src/components/Predictions.test.tsx new file mode 100644 index 00000000000..81b00401d0d --- /dev/null +++ b/helm-frontend/src/components/Predictions.test.tsx @@ -0,0 +1,75 @@ +import { render, screen } from "@testing-library/react"; +import "@testing-library/jest-dom"; +import type DisplayPrediction from "@/types/DisplayPrediction"; +import type DisplayRequest from "@/types/DisplayRequest"; +import type MetricFieldMap from "@/types/MetricFieldMap"; +import Predictions from "./Predictions"; + +it("renders instance metrics in a compact two-column list", () => { + const predictions: DisplayPrediction[] = [ + { + instance_id: "instance-1", + predicted_text: "hello world", + train_trial_index: 0, + stats: { + very_long_metric_name_for_layout_regression: 0.75, + exact_match: 1, + }, + mapped_output: undefined, + }, + ]; + const requests: DisplayRequest[] = [ + { + instance_id: "instance-1", + train_trial_index: 0, + request: { + echo_prompt: false, + embedding: false, + frequency_penalty: 0, + max_tokens: 16, + model: "example/model", + num_completions: 1, + presence_penalty: 0, + prompt: "Prompt text", + stop_sequences: [], + temperature: 0, + top_k_per_token: 1, + top_p: 1, + multimodal_prompt: undefined, + messages: undefined, + }, + }, + ]; + const metricFieldMap: MetricFieldMap = { + very_long_metric_name_for_layout_regression: { + name: "very_long_metric_name_for_layout_regression", + display_name: "Very long metric name for layout regression", + short_display_name: "Very long metric", + description: "Long label used to verify compact metric layout rendering.", + lower_is_better: false, + }, + exact_match: { + name: "exact_match", + display_name: "Exact match", + short_display_name: "EM", + description: "Exact match metric", + lower_is_better: false, + }, + }; + + render( + , + ); + + const metricsContainer = screen.getByTestId("prediction-metrics"); + expect(metricsContainer).toHaveClass("max-w-3xl"); + expect( + screen.getByText("Very long metric name for layout regression"), + ).toBeInTheDocument(); + expect(screen.getByText("0.75")).toBeInTheDocument(); + expect(screen.getByText("Exact match")).toBeInTheDocument(); +}); diff --git a/helm-frontend/src/components/Predictions.tsx b/helm-frontend/src/components/Predictions.tsx index a49dbd7edfc..73c93744075 100644 --- a/helm-frontend/src/components/Predictions.tsx +++ b/helm-frontend/src/components/Predictions.tsx @@ -4,7 +4,6 @@ import type MetricFieldMap from "@/types/MetricFieldMap"; import Indicator from "@/components/Indicator"; import Request from "@/components/Request"; import Preview from "@/components/Preview"; -import { List, ListItem } from "@tremor/react"; import AnnotationsDisplay from "./AnnotationsDisplay"; type Props = { @@ -72,22 +71,30 @@ export default function Predictions({ -
+

Metrics

- +
    {Object.keys(prediction.stats).map((statKey, idx) => ( - +
  • {metricFieldMap[statKey] ? ( - + {metricFieldMap[statKey].display_name} ) : ( - {statKey} + {statKey} )} - {String(prediction.stats[statKey])} - + + {String(prediction.stats[statKey])} + +
  • ))} - +
Request details