From 21d2a78aa700c82dd8eebb577463e22b28c93694 Mon Sep 17 00:00:00 2001 From: Ryan Brooks Date: Wed, 25 Nov 2026 11:48:38 -0800 Subject: [PATCH] Cooler landing --- core/src/eac/phases/judge.rs | 4 +- core/tests/cli.rs | 2 +- docs/README.md | 5 + docs/components/landing.tsx | 276 +++++++++++++++++++++++++------ docs/components/terminal.tsx | 192 +++++++++++++++++++++ docs/components/themeContext.tsx | 2 +- 6 files changed, 425 insertions(+), 56 deletions(-) create mode 100644 docs/components/terminal.tsx diff --git a/core/src/eac/phases/judge.rs b/core/src/eac/phases/judge.rs index 7e6b7d5..85d2f63 100644 --- a/core/src/eac/phases/judge.rs +++ b/core/src/eac/phases/judge.rs @@ -95,9 +95,7 @@ impl Judging<'_> { Err(e) if scored.error.is_empty() => scored.error = format!("judge failed: {e:#}"), Err(_) => {} } - if !self.online { - detail!("{}/{} judged", d.name, c.name); - } + detail!("{}/{} judged", d.name, c.name); let case = case_result(c, &out, &scored, trace.and_then(|t| t.metrics)); Ok((scored, case)) } diff --git a/core/tests/cli.rs b/core/tests/cli.rs index baac919..4d8b8be 100644 --- a/core/tests/cli.rs +++ b/core/tests/cli.rs @@ -410,7 +410,7 @@ fn online_cases_are_judged_at_once_with_concurrency() { let p = Project::new(&base()); p.write("rendezvous", "2"); let args = ["online", "run", "--judge", "nonempty", "--concurrency", "2"]; - p.eac(&args).code(0); + p.eac(&args).code(0).says("chat/trace_0 judged").says("chat/trace_1 judged"); let calls = p.events("online_judge"); assert_eq!(calls.len(), 2); assert!(calls.iter().all(|c| c["together"] == true), "{calls:?}"); diff --git a/docs/README.md b/docs/README.md index e3b925c..b717cfa 100644 --- a/docs/README.md +++ b/docs/README.md @@ -16,6 +16,11 @@ pnpm typecheck # TypeScript a short quick start and links into the docs, which start at `/introduction`. `components/docsShell.tsx` leaves out the sidebar on it. +A toggle switches it between offline and online evals, each with its own +example, steps and terminal (`components/terminal.tsx`). The terminal plays +what the example prints, ANSI colors included. When the CLI's output changes, +run each example and update its `output` in `EXAMPLES` to match. + ## Adding a page 1. Create `app//page.mdx`, starting with `export const metadata = {title: '...'}`. diff --git a/docs/components/landing.tsx b/docs/components/landing.tsx index aaf5a9a..9a88891 100644 --- a/docs/components/landing.tsx +++ b/docs/components/landing.tsx @@ -1,5 +1,6 @@ 'use client'; +import {useState} from 'react'; import styled from '@emotion/styled'; import {IconArrow} from '@sentry/icons/arrow'; import {IconGithub} from '@sentry/icons/github'; @@ -7,8 +8,11 @@ import {LinkButton} from '@sentry/scraps/button'; import {InlineCode} from '@sentry/scraps/code'; import {CodeBlock} from '@sentry/scraps/codeBlock'; import {Flex, Stack} from '@sentry/scraps/layout'; +import {SegmentedControl} from '@sentry/scraps/segmentedControl'; import {Heading, Text} from '@sentry/scraps/text'; +import {Terminal} from './terminal'; + const REPO_URL = 'https://github.com/getsentry/eac'; const INSTALL = `brew tap getsentry/tap @@ -16,13 +20,30 @@ brew install getsentry/tap/eac pip install -e sdks/python # needs Python 3.11+`; -const DATASET_YML = `name: chat +// eac's colors (core/src/report/mod.rs), for the outputs below. +const [B, D, R, G, Y, X] = ['1', '2', '31', '32', '33', '0'].map(c => `\x1b[${c}m`); + +const EXAMPLES = { + offline: { + summary: 'Offline evals run your AI system on cases you write, and judge what it does.', + write: { + title: 'Write an eval', + description: ( + <> + Add a dataset.yml anywhere in your repo, with an{' '} + offline section: the runner that calls your system, and + the cases to run it on. + + ), + }, + datasetYml: `name: chat runtime: python offline: runner: ./dataset.py:ChatRunner - cases: ./dataset.py:CASES`; + cases: ./dataset.py:CASES`, + datasetPy: `from typing import Any -const DATASET_PY = `from eac import Case, Judge, OfflineRunner, Score +from eac import Case, Judge, OfflineRunner, Score def reply(query: str) -> str: @@ -52,42 +73,163 @@ class GreetsJudge(Judge): CASES = [ Case(name="greeting", input={"query": "hi"}, judges=[GreetsJudge()]), Case(name="goodbye", input={"query": "bye"}, judges=[GreetsJudge()]), -]`; - -const RUN = 'eac offline run --dataset chat'; - -const RUN_OUTPUT = `RESULTS +]`, + run: { + description: + 'eac seeds fixtures, runs each case, judges the output and prints the results.', + result: ( + <> + It prints the run at the top of this page: greeting{' '} + passes, goodbye fails. + + ), + }, + command: 'eac offline run --dataset chat', + output: ` +${B}DISCOVER${X} + chat 2/2 cases evals/chat/dataset.yml + +${B}SEED${X} + ${D}no seeds${X} + +${B}EXECUTE${X} + ${D}chat/greeting ran in 0.00s${X} + ${D}chat/goodbye ran in 0.00s${X} + +${B}JUDGE${X} + ${D}chat/greeting judged${X} + ${D}chat/goodbye judged${X} + +${B}RESULTS${X} +------------------+----------------+----------+ | Case | Status / score | Duration | +==================+================+==========+ - | chat/greeting | PASSED | 0.00s | + | chat/greeting | ${G}PASSED ${X} | 0.00s | | └ greets_judge | 1 | | - | chat/goodbye | FAILED | 0.00s | + | chat/goodbye | ${R}FAILED ${X} | 0.00s | | └ greets_judge | 0 | | +------------------+----------------+----------+ - Below 1 - chat/goodbye › greets_judge: no greeting in 'see you later' + ${B}Below 1${X} + ${D}chat/goodbye › greets_judge: no greeting in 'see you later'${X} + + ${B}2 cases${X} ${G}1 passed${X} ${R}1 failed${X} ${Y}0 errored${X}`, + }, + online: { + summary: + 'Online evals judge what your AI system already did in production. Nothing is re-run.', + write: { + title: 'Collect production runs', + description: ( + <> + Add a dataset.yml with an online{' '} + section: the runner that collects what your system did in production, and the + judges that score it. + + ), + }, + datasetYml: `name: chat +runtime: python +online: + runner: ./dataset.py:ChatRunner + judges: + - name: greets_judge + path: ./dataset.py:GreetsJudge`, + datasetPy: `from datetime import datetime +from typing import Any + +from eac import Case, Judge, OnlineRunner, Score, Window + + +def recent_conversations(since: datetime, until: datetime) -> list[dict[str, Any]]: + return [ # query your production logs or traces here + {"id": "conv-1", "query": "hi", "response": "hello there"}, + {"id": "conv-2", "query": "hey", "response": "hello!"}, + {"id": "conv-3", "query": "bye", "response": "see you later"}, + ] + + +class ChatRunner(OnlineRunner): + def collect_cases(self, window: Window) -> list[Case]: + conversations = recent_conversations(window.since, window.until) + return [ + Case( + name=c["id"], + input={"query": c["query"]}, + run_results={"response": c["response"]}, + conversation_id=c["id"], + ) + for c in conversations[: window.limit] + if window.samples(c["id"]) + ] + + +class GreetsJudge(Judge): + name = "greets_judge" + + def judge(self, case: Case, *, seed_results: dict[str, dict[str, Any]], agent_trace: Any = None) -> Score | None: + response = case.run_results.get("response", "") + if "hello" in response: + return Score(name=self.name, score=1.0) - 2 cases 1 passed 1 failed 0 errored`; + return Score( + name=self.name, + score=0.0, + explanation=f"no greeting in {response!r}", + )`, + run: { + description: + 'eac collects the last day of production runs, judges each one and prints the average scores. Online runs never fail.', + result: ( + <> + It prints the run at the top of this page: greets_judge{' '} + averages 0.667, as one of the three conversations doesn't greet. + + ), + }, + command: 'eac online run --judge greets_judge --since 24h', + output: ` +${B}EXECUTE${X} + chat 3 cases + +${B}JUDGE${X} + ${D}chat/conv-1 judged${X} + ${D}chat/conv-2 judged${X} + ${D}chat/conv-3 judged${X} + +${B}RESULTS${X} + +--------------+------------+-------+ + | Judge | Mean score | Cases | + +==============+============+=======+ + | greets_judge | 0.667 | 3 | + +--------------+------------+-------+ + + ${B}3 cases${X} ${D}1 below 1 or errored${X}`, + }, +}; + +type Mode = keyof typeof EXAMPLES; export function Landing() { + const [mode, setMode] = useState('offline'); + const example = EXAMPLES[mode]; + return ( - + Evals-as-Code (eac) - - + + EAC is a command line tool & SDKs to write evals for AI systems. - + It handles fixtures, running and judging your AI system, all configurable through code. - + }> GitHub - + + + + + + + {/* Keyed, so switching plays the new run from the start. */} +
- - Get started - + + + + Get started + + + + + {example.summary} + + {INSTALL} - - Add a dataset.yml anywhere in your repo. - - } - > + - {DATASET_YML} + {example.datasetYml} - {DATASET_PY} + {example.datasetPy} - - - {RUN} - - {RUN_OUTPUT} - - + + {example.command} - greeting passes, goodbye fails. + {example.run.result} @@ -170,6 +310,15 @@ export function Landing() { ); } +function ModeToggle({mode, onChange}: {mode: Mode; onChange: (mode: Mode) => void}) { + return ( + + Offline evals + Online evals + + ); +} + function Step({ children, description, @@ -202,7 +351,7 @@ function Step({ } const Wrapper = styled('main')` - max-width: 960px; + max-width: 1100px; margin: 0 auto; padding: 0 ${p => p.theme.space['2xl']} 96px; @@ -216,20 +365,45 @@ const Wrapper = styled('main')` `; const Hero = styled('section')` - padding: 84px 0 24px; - text-align: center; + display: grid; + grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); + gap: 56px; + align-items: center; + padding: 72px 0 24px; p { margin: 0; } - @media (max-width: ${p => p.theme.breakpoints.sm}) { - padding: 64px 0 40px; + @media (max-width: ${p => p.theme.breakpoints.md}) { + grid-template-columns: minmax(0, 1fr); + gap: 40px; + padding: 56px 0 24px; + } +`; + +const HeroCopy = styled('div')` + display: flex; + flex-direction: column; + gap: ${p => p.theme.space.xl}; + + @media (max-width: ${p => p.theme.breakpoints.md}) { + text-align: center; + } +`; + +const HeroRow = styled('div')` + display: flex; + flex-wrap: wrap; + gap: ${p => p.theme.space.md}; + + @media (max-width: ${p => p.theme.breakpoints.md}) { + justify-content: center; } `; const HeroTitle = styled(Heading)` - font-size: clamp(2.5rem, 7vw, 4rem); + font-size: clamp(2.5rem, 5vw, 3.5rem); line-height: 1.1; letter-spacing: -0.02em; `; diff --git a/docs/components/terminal.tsx b/docs/components/terminal.tsx new file mode 100644 index 0000000..c79934e --- /dev/null +++ b/docs/components/terminal.tsx @@ -0,0 +1,192 @@ +'use client'; + +import {Fragment, useEffect, useMemo, useRef, useState} from 'react'; +import {ThemeProvider} from '@emotion/react'; +import styled from '@emotion/styled'; + +import {THEMES} from './themeContext'; + +export function Terminal({command, output}: {command: string; output: string}) { + const lines = useMemo(() => output.split('\n'), [output]); + // The characters of the command typed, then the lines of output printed. + const [step, setStep] = useState(0); + const total = command.length + lines.length; + const done = step >= total; + const body = useRef(null); + + useEffect(() => { + if (done) { + return undefined; + } + const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches; + const timeout = setTimeout( + () => setStep(reduceMotion ? total : step + 1), + reduceMotion ? 0 : delayBefore(step, command, lines) + ); + return () => clearTimeout(timeout); + }, [command, done, lines, step, total]); + + useEffect(() => { + body.current?.scrollTo({top: body.current.scrollHeight}); + }, [step]); + + return ( + // Terminals are dark, whichever theme the page is in. + + + + + + + + + ~/my-app + + + + $ + {command.slice(0, step)} + {lines.slice(0, Math.max(0, step - command.length)).map((line, i) => ( + + {'\n'} + {colored(line)} + + ))} + {step > command.length && '\n'} + {done && $ } + {/* Solid while it types or prints, blinking while it waits. */} + + + + + + ); +} + +/** How long to wait before taking `step`, in milliseconds. */ +function delayBefore(step: number, command: string, lines: string[]): number { + if (step === 0) { + return 800; + } + // A keystroke, at an uneven pace. + if (step < command.length) { + return 30 + Math.random() * 70; + } + // Enter. + if (step === command.length) { + return 500; + } + // A blank line starts the next phase; the rest of a phase follows quickly. + return lines[step - command.length] ? 40 : 300; +} + +/** A line, with each `ESC[m…ESC[0m` span colored. */ +function colored(line: string) { + // Alternates text, a span's code, the span's text, text, ... + const parts = line.split(/\x1b\[(\d+)m(.*?)\x1b\[0m/); + return parts.map((part, i) => { + if (i % 3 === 0) { + return part; + } + if (i % 3 === 2) { + return ( + + {part} + + ); + } + return null; + }); +} + +const COLORS = {1: 'headings', 2: 'secondary', 31: 'danger', 32: 'success', 33: 'warning'} as const; + +const Ansi = styled('span')<{code: number}>` + color: ${p => p.theme.tokens.content[COLORS[p.code as keyof typeof COLORS]]}; + font-weight: ${p => (p.code === 1 ? p.theme.font.weight.mono.medium : 'inherit')}; +`; + +const Window = styled('figure')` + margin: 0; + overflow: hidden; + border: 1px solid ${p => p.theme.tokens.border.primary}; + border-radius: ${p => p.theme.radius.lg}; + background: ${p => p.theme.tokens.background.tertiary}; + color: ${p => p.theme.tokens.content.primary}; + box-shadow: + 0 1px 2px rgb(0 0 0 / 0.12), + 0 16px 40px -12px rgb(0 0 0 / 0.45); +`; + +const TitleBar = styled('div')` + display: grid; + grid-template-columns: 1fr auto 1fr; + align-items: center; + padding: ${p => p.theme.space.md}; + border-bottom: 1px solid ${p => p.theme.tokens.border.primary}; + background: ${p => p.theme.tokens.background.secondary}; +`; + +const Lights = styled('div')` + display: flex; + gap: 8px; + + span { + width: 12px; + height: 12px; + border-radius: 50%; + background: #ff5f57; + } + span:nth-of-type(2) { + background: #febc2e; + } + span:nth-of-type(3) { + background: #28c840; + } +`; + +const Title = styled('figcaption')` + color: ${p => p.theme.tokens.content.secondary}; + font-family: ${p => p.theme.font.family.mono}; + font-size: ${p => p.theme.font.size.sm}; +`; + +// A fixed height, so the page doesn't move as it prints: it scrolls instead. +const Body = styled('pre')` + height: calc(22lh + 2 * ${p => p.theme.space.xl}); + margin: 0; + padding: ${p => p.theme.space.xl}; + overflow: auto; + font-size: 13px; + line-height: 1.5; + scrollbar-width: thin; + scrollbar-color: ${p => p.theme.tokens.border.primary} transparent; +`; + +const Prompt = styled('span')` + color: ${p => p.theme.tokens.content.accent}; + user-select: none; +`; + +const Command = styled('span')` + color: ${p => p.theme.tokens.content.headings}; +`; + +const Cursor = styled('span')<{blink: boolean}>` + display: inline-block; + width: 0.6em; + height: 1.2em; + vertical-align: text-bottom; + background: ${p => p.theme.tokens.content.secondary}; + animation: ${p => (p.blink ? 'blink 1.1s steps(1) infinite' : 'none')}; + + @keyframes blink { + 50% { + opacity: 0; + } + } + + @media (prefers-reduced-motion: reduce) { + animation: none; + } +`; diff --git a/docs/components/themeContext.tsx b/docs/components/themeContext.tsx index 5ccd463..11216fd 100644 --- a/docs/components/themeContext.tsx +++ b/docs/components/themeContext.tsx @@ -24,7 +24,7 @@ function withFonts(theme: typeof lightTheme): typeof lightTheme { } as unknown as typeof lightTheme; } -const THEMES = { +export const THEMES = { light: withFonts(lightTheme), dark: withFonts(darkTheme as unknown as typeof lightTheme), };