Skip to documentation content

Eval Compare

Compare the same prompt's outputs from several models or prompt versions side by side, with a word diff, a scorecard, and a preference vote.

eval-compare-demo

Overview

Eval Compare puts two to four answers to the same prompt next to each other: different models, prompt versions, or settings. It can show what changed word by word against a baseline, score each answer on the metrics you measured, list the checks each one passed, and collect a person's preference.

It shows the results you pass. Running the models and scoring them is your application's work.

Anatomy

Eval Compare
  • HeaderThe prompt, the expected answer, the case switcher, and the Differences toggle
  • ColumnOne per candidate: its label, note, output, checks, and Prefer
  • ScorecardA table with a row per metric and a column per candidate
  • FooterTie, and the announcement of the vote, when you collect votes

Installing eval-compare brings Button and Toggle along as registry dependencies.

Behavior

Differences

Differences compares every column with the baseline, word by word. Added words are tinted and removed words are struck through, and each column counts both. The first candidate is the baseline until a person chooses another with its "Compare against" link. diffWords is exported if you need the same comparison elsewhere.

Very long outputs fall back to marking the whole text as changed instead of blocking the page.

Scorecard

Each metric names the direction that wins with better. The best value in a row gets a dot and medium weight. A row where every candidate ties, or with fewer than two values, has no best. A missing value shows as a dash. Pass format to show units such as seconds or dollars.

Checks and votes

Passed checks keep a neutral mark and failed ones are red. Passing onVote shows Prefer under each column and Tie in the footer. Pressing the current choice again clears it, and onVote receives null.

Cases

With caseIndex, caseCount, and onCaseChange, the header shows a switcher such as "Case 2 of 12". Pass the new case's prompt and candidates when it changes.

Layout

Columns sit side by side when the component is wide enough and stack when it is narrow. Rows line up across columns, so outputs of different lengths still start their checks at the same height.

Accessibility

The comparison is a group named Comparison, not a landmark, so several on one page stay distinct. Each candidate is an article named by its label. Added and removed words use ins and del. The scorecard is a table with row and column headers, and the best value is announced as best. Prefer and Differences are toggle buttons that report whether they are pressed, and a vote is announced.

KeyAction
TabMove across the switcher, Differences, the baseline links, and the votes
Enter or SpacePress the focused control

Installation

npx honestui@latest add eval-compare

Usage

import { EvalCompare, type EvalMetric } from "@/components/ai/eval-compare"

const metrics: EvalMetric[] = [
  { key: "correctness", label: "Correctness", better: "higher" },
  { key: "latency", label: "Latency", better: "lower", format: (ms) => `${ms} ms` },
]

<EvalCompare
  prompt={run.prompt}
  candidates={run.outputs.map((output) => ({
    id: output.model,
    label: output.model,
    output: output.text,
    metrics: output.scores,
  }))}
  metrics={metrics}
  vote={vote}
  onVote={setVote}
/>

Examples

Two prompt versions

Differences starts on, so the change between versions is the first thing a reviewer sees.

eval-compare-diff

API reference

EvalCompare

Accepts native div props beyond those listed.

PropTypeDefaultDescription
candidatesEvalCandidate[]RequiredTwo to four outputs, in column order.
promptReactNodeNoneThe input every candidate answered.
expectedReactNodeNoneA reference answer, shown under the prompt.
metricsEvalMetric[]NoneThe scorecard rows. Without it, no scorecard is shown.
diffbooleanNoneControls whether Differences is on.
defaultDiffbooleanfalseWhether Differences starts on.
onDiffChange(diff: boolean) => voidNoneCalled when Differences is toggled.
baselineIdstringFirst candidateControls the column the others are compared against.
defaultBaselineIdstringNoneThe starting baseline.
onBaselineChange(id: string) => voidNoneCalled when a person picks another baseline.
votestring | "tie" | nullNoneThe current preference.
onVote(vote: EvalVote) => voidNonePassing it shows Prefer and Tie.
caseIndexnumberNoneThe current case, from zero.
caseCountnumberNoneHow many cases there are.
onCaseChange(index: number) => voidNonePassing it with the two above shows the case switcher.
renderOutput(candidate: EvalCandidate) => ReactNodeNoneDraws an output, such as Markdown, while Differences is off.
labelsPartial<EvalCompareLabels>EnglishEvery visible and announced string.

Types

ExportShape
EvalCandidateid, label, output, and optional meta, metrics, and assertions
EvalMetrickey, label, and optional better ("higher" or "lower") and format
EvalAssertionlabel, passed, and an optional detail
WordDiffParttype ("equal", "added", or "removed") and text
diffWords(before: string, after: string) => WordDiffPart[]