# Model arena

> Blind side-by-side model comparison card with latency stats, voting buttons and identity reveal after voting.

- Kind: block · Category: AI · Interactivity: script
- Install: `npx shadcn@latest add @haze/model-arena`
- File: `src/components/haze/blocks/model-arena.astro`
- npm dependencies: @lucide/astro
- Registry dependencies: @haze/utils
- Docs page: https://hazeui.com/blocks/model-arena

## Use when
- Comparing two anonymous models on the same prompt before revealing which model wrote each answer
- Collecting human preference votes alongside first-token latency and throughput

## Avoid when
- Running automated regression test suites across many cases; use eval-suite instead

## Alternatives
- [comparison-plan-matrix](https://hazeui.com/blocks/comparison-plan-matrix.md)
- [model-picker](https://hazeui.com/blocks/model-picker.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| id | `string` | "haze-model-arena" | no | Unique prefix for form and heading IDs. |
| title | `string` | "Blind model arena" | no | Section heading for the arena card. |
| prompt | `string` | Postgres index prompt | no | Initial prompt shown in the comparison input. |
| modelAName | `string` | "Sonnet 4.5" | no | Hidden identity revealed for Model A. |
| modelBName | `string` | "Gemini 3.8 Pro" | no | Hidden identity revealed for Model B. |
| class | `string` |  | no | Extra classes on the outer section. |

## Accessibility
- Voting controls are grouped in a labelled role="group" and announce the revealed model names in a polite status region.
- Both anonymous response columns use semantic article headings that update cleanly on reveal.
- Key Tab: Move across the prompt input, Run battle button, voting buttons and Reveal button
- Key Enter / Space: Start a new comparison, cast a vote or reveal model identities

## Agent prompts

### Install and use

Install the Haze UI block "Model arena" with `npx shadcn@latest add @haze/model-arena`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "https://hazeui.com/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import ModelArena from "@/components/haze/blocks/model-arena.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: https://hazeui.com/blocks/model-arena.md

### Customize with real content

Adapt the Haze model-arena block for our product. Replace the demo values of these props with our real content: id, title, prompt, modelAName, modelBName, class. Keep the layout, the heading level rules and these accessibility details: Voting controls are grouped in a labelled role="group" and announce the revealed model names in a polite status region. Both anonymous response columns use semantic article headings that update cleanly on reveal. Do not add raw color classes; use the Haze tokens.

### Choose the right block

Before using model-arena, check it fits: use it when comparing two anonymous models on the same prompt before revealing which model wrote each answer; collecting human preference votes alongside first-token latency and throughput. Avoid it when running automated regression test suites across many cases; use eval-suite instead. Alternatives: @haze/comparison-plan-matrix, @haze/model-picker.

## Example requests that should lead here
- Build a blind side-by-side AI model arena with TTFT metrics, voting controls and model reveal

## Source

```astro
---
import { ArrowUp, Eye, Scale, Trophy, Zap } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";

interface Props {
  id?: string;
  title?: string;
  prompt?: string;
  modelAName?: string;
  modelBName?: string;
  class?: string;
}

const {
  id = "haze-model-arena",
  title = "Blind model arena",
  prompt = "Write a concise Postgres index strategy for a multi-tenant events table queried by tenant_id and created_at.",
  modelAName = "Sonnet 4.5",
  modelBName = "Gemini 3.8 Pro",
  class: className,
} = Astro.props;
---

<section aria-labelledby={`${id}-title`} data-haze-model-arena data-model-a={modelAName} data-model-b={modelBName} class={cn("bg-background px-4 py-10 sm:px-6 sm:py-14", className)}>
  <div class="mx-auto max-w-5xl rounded-2xl border border-border bg-card p-5 sm:p-6">
    <div class="flex flex-wrap items-center justify-between gap-3">
      <div class="flex items-center gap-2">
        <Scale class="size-4 text-muted-foreground" aria-hidden="true" />
        <h2 id={`${id}-title`} class="text-base/6 font-semibold tracking-tight text-foreground">{title}</h2>
      </div>
      <span class="rounded-full border border-frame bg-muted/40 px-2.5 py-0.5 text-xs/5 text-muted-foreground">Identities hidden until you vote</span>
    </div>

    <form data-arena-form class="mt-4 flex flex-col gap-2 sm:flex-row">
      <label for={`${id}-prompt`} class="sr-only">Arena prompt</label>
      <input
        id={`${id}-prompt`}
        data-arena-input
        type="text"
        value={prompt}
        class="h-10 min-w-0 flex-1 rounded-xl border border-frame-input bg-field px-3.5 text-sm text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/24 focus-visible:outline-hidden transition-[color,background-color,border-color,box-shadow] duration-150 hover:border-frame-foreground"
      />
      <button type="submit" class="inline-flex h-10 shrink-0 cursor-pointer items-center justify-center gap-1.5 rounded-xl bg-primary px-4 text-sm font-medium text-primary-foreground transition-opacity duration-150 hover:opacity-90 focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring active:scale-[0.97] active:duration-75">
        Run battle
        <ArrowUp class="size-4" aria-hidden="true" />
      </button>
    </form>

    <div class="mt-5 grid gap-4 md:grid-cols-2">
      <article data-arena-col="A" class="flex flex-col justify-between rounded-xl border border-border bg-muted/40 p-4 transition-colors duration-150 data-[winner=true]:border-success-border data-[winner=true]:bg-success/8">
        <div>
          <div class="flex items-center justify-between gap-2 border-b border-border pb-2.5">
            <h3 data-arena-label="A" class="text-sm/5 font-semibold text-foreground">Model A</h3>
            <span class="inline-flex items-center gap-1 font-mono text-[0.6875rem]/4 text-muted-foreground tabular-nums">
              <Zap class="size-3 text-muted-foreground" aria-hidden="true" />
              240ms TTFT · 86 tok/s
            </span>
          </div>
          <p data-arena-out="A" class="mt-3 text-sm/6 text-pretty text-foreground">
            Create a composite B-tree index on <code class="rounded-sm bg-muted px-1 font-mono text-xs">(tenant_id, created_at DESC)</code>. Equality on tenant_id narrows the scan immediately, and descending created_at serves newest-first pages without a sort node. Partition by month once rows pass 100M.
          </p>
        </div>
      </article>

      <article data-arena-col="B" class="flex flex-col justify-between rounded-xl border border-border bg-muted/40 p-4 transition-colors duration-150 data-[winner=true]:border-success-border data-[winner=true]:bg-success/8">
        <div>
          <div class="flex items-center justify-between gap-2 border-b border-border pb-2.5">
            <h3 data-arena-label="B" class="text-sm/5 font-semibold text-foreground">Model B</h3>
            <span class="inline-flex items-center gap-1 font-mono text-[0.6875rem]/4 text-muted-foreground tabular-nums">
              <Zap class="size-3 text-muted-foreground" aria-hidden="true" />
              190ms TTFT · 112 tok/s
            </span>
          </div>
          <p data-arena-out="B" class="mt-3 text-sm/6 text-pretty text-foreground">
            Use a covering index <code class="rounded-sm bg-muted px-1 font-mono text-xs">(tenant_id, created_at DESC) INCLUDE (event_type, status)</code> for index-only scans on dashboard feeds, paired with a BRIN index on <code class="rounded-sm bg-muted px-1 font-mono text-xs">created_at</code> for cold archive sweeps.
          </p>
        </div>
      </article>
    </div>

    <div class="mt-5 flex flex-wrap items-center justify-between gap-3 border-t border-border pt-4">
      <div role="group" aria-label="Vote for stronger response" class="flex flex-wrap gap-2">
        <button type="button" data-arena-vote="A" class="inline-flex h-9 cursor-pointer items-center gap-1.5 rounded-lg border border-frame bg-field px-3 text-xs font-medium text-foreground transition-colors duration-150 hover:border-frame-strong hover:bg-accent focus-visible:outline-2 focus-visible:outline-ring active:scale-[0.97] active:duration-75">
          <Trophy class="size-3.5 text-muted-foreground" aria-hidden="true" />
          A is better
        </button>
        <button type="button" data-arena-vote="tie" class="inline-flex h-9 cursor-pointer items-center rounded-lg border border-frame bg-field px-3 text-xs font-medium text-muted-foreground transition-colors duration-150 hover:border-frame-strong hover:text-foreground focus-visible:outline-2 focus-visible:outline-ring active:scale-[0.97] active:duration-75">
          Tie
        </button>
        <button type="button" data-arena-vote="B" class="inline-flex h-9 cursor-pointer items-center gap-1.5 rounded-lg border border-frame bg-field px-3 text-xs font-medium text-foreground transition-colors duration-150 hover:border-frame-strong hover:bg-accent focus-visible:outline-2 focus-visible:outline-ring active:scale-[0.97] active:duration-75">
          <Trophy class="size-3.5 text-muted-foreground" aria-hidden="true" />
          B is better
        </button>
      </div>
      <button type="button" data-arena-reveal class="inline-flex h-9 cursor-pointer items-center gap-1.5 rounded-lg px-3 text-xs font-medium text-muted-foreground transition-colors duration-150 hover:bg-accent hover:text-foreground focus-visible:outline-2 focus-visible:outline-ring active:scale-[0.97] active:duration-75">
        <Eye class="size-3.5" aria-hidden="true" />
        Reveal models
      </button>
    </div>

    <p data-arena-status role="status" class="mt-2 min-h-4 text-xs/4 text-muted-foreground"></p>
  </div>
</section>

<script>
  function initModelArenas() {
    document.querySelectorAll<HTMLElement>("[data-haze-model-arena]").forEach((root) => {
      if (root.hasAttribute("data-enhanced")) return;
      root.setAttribute("data-enhanced", "");
      const modelA = root.dataset.modelA ?? "Model A";
      const modelB = root.dataset.modelB ?? "Model B";
      const labelA = root.querySelector<HTMLElement>('[data-arena-label="A"]');
      const labelB = root.querySelector<HTMLElement>('[data-arena-label="B"]');
      const colA = root.querySelector<HTMLElement>('[data-arena-col="A"]');
      const colB = root.querySelector<HTMLElement>('[data-arena-col="B"]');
      const status = root.querySelector<HTMLElement>("[data-arena-status]");

      const reveal = (vote?: string) => {
        if (labelA) labelA.textContent = `Model A · ${modelA}`;
        if (labelB) labelB.textContent = `Model B · ${modelB}`;
        colA?.setAttribute("data-winner", String(vote === "A"));
        colB?.setAttribute("data-winner", String(vote === "B"));
        if (status) {
          status.textContent = vote === "A" ? `Voted for Model A (${modelA}).` : vote === "B" ? `Voted for Model B (${modelB}).` : vote === "tie" ? `Marked as a tie (${modelA} vs ${modelB}).` : `Revealed: Model A is ${modelA}, Model B is ${modelB}.`;
        }
      };

      root.querySelectorAll<HTMLButtonElement>("[data-arena-vote]").forEach((btn) => {
        btn.addEventListener("click", () => reveal(btn.dataset.arenaVote));
      });
      root.querySelector<HTMLButtonElement>("[data-arena-reveal]")?.addEventListener("click", () => reveal());
      root.querySelector<HTMLFormElement>("[data-arena-form]")?.addEventListener("submit", (ev) => {
        ev.preventDefault();
        if (labelA) labelA.textContent = "Model A";
        if (labelB) labelB.textContent = "Model B";
        colA?.removeAttribute("data-winner");
        colB?.removeAttribute("data-winner");
        if (status) status.textContent = "New blind comparison ready. Read both replies and cast a vote.";
      });
    });
  }
  initModelArenas();
  document.addEventListener("astro:page-load", initModelArenas);
</script>
```
