diff --git a/README.md b/README.md index 80c12dc..6a1b6ae 100644 --- a/README.md +++ b/README.md @@ -1,136 +1,99 @@ # eac (evals-as-code) -Define evals as code and run them with one CLI. Supports both offline and online evals. +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. -You write the runner that calls your system, the cases, and the judges that score what it returns. eac sets up fixtures, runs every case, scores the outputs and saves each run. +📚 [Full Documentation](https://eac.sentry.dev) -The full docs are at [eac.sentry.dev](https://eac.sentry.dev). +## Get started -## Quick start +### 1. Install -[Examples](examples/) contains basic examples covering a range of cases. +```sh +git clone https://github.com/getsentry/eac.git && cd eac +make install # needs Rust 1.87+ +pip install -e sdks/python # needs Python 3.11+ +``` -### Offline evals +### 2. Write an eval -1. Install the `eac` CLI and the SDK for your language. There are no packaged releases yet, so build the CLI from this repo. [`core/README.md`](core/README.md#build) lists what that needs. +Add a `dataset.yml` and the code it points to, anywhere in your repo. - ```sh - make install # puts eac on your PATH - pip install -e sdks/python # into the environment your evals run in - ``` +```yaml +# evals/chat/dataset.yml +name: chat +runtime: python +offline: + runner: ./dataset.py:ChatRunner + cases: ./dataset.py:CASES +``` -2. Add a dataset: a folder anywhere in your repo with a `dataset.yml` and its code. eac finds every `dataset.yml` under the repo's root, or under the nearest folder with an [`eac.yml`](core/README.md#eacyml) if you need shared settings. +```python +# evals/chat/dataset.py +from eac import Case, Judge, OfflineRunner, Score - ``` - evals/chat/ - dataset.yml - dataset.py - ``` - ```yaml - # evals/chat/dataset.yml - name: chat - runtime: python - offline: - runner: ./dataset.py:ChatRunner - cases: ./dataset.py:CASES - ``` +def reply(query: str) -> str: + return "hello there" if query == "hi" else "see you later" # call your AI agent here - ```python - # evals/chat/dataset.py - from eac import Case, Judge, OfflineRunner, Score +class ChatRunner(OfflineRunner): + def run_case(self, case, *, seeds, conversation_id): + return {"response": reply(case.input["query"])} - def reply(query: str) -> str: - return "hello there" # call your system here +class Greets(Judge): + name = "greets_judge" - class ChatRunner(OfflineRunner): - def run_case(self, case, *, seeds, conversation_id): - return {"response": reply(case.input["query"])} + def judge(self, case, *, seeds, agent_trace=None): + response = case.output.get("response", "") + if "hello" in response: + return Score(name=self.name, score=1.0) + return Score( + name=self.name, + score=0.0, + explanation=f"no greeting in {response!r}", + ) - class Greets(Judge): - name = "greets" - def judge(self, case, *, seeds, agent_trace=None): - ok = "hello" in case.output.get("response", "") - return Score(name=self.name, score=1.0 if ok else 0.0) +CASES = [ + Case(name="greeting", input={"query": "hi"}, judges=[Greets()]), + Case(name="goodbye", input={"query": "bye"}, judges=[Greets()]), +] +``` +### 3. Run it - CASES = [Case(name="greets", input={"query": "hi"}, judges=[Greets()])] - ``` +eac seeds fixtures, runs each case, judges the output and prints the results. -3. Run it from the repo's root: +```sh +eac offline run --dataset chat +``` - ```sh - eac list # the datasets and cases eac found - eac offline run --dataset chat # seed, execute and judge every case in the chat dataset +```text +RESULTS + +------------------+----------------+----------+ + | Case | Status / score | Duration | + +==================+================+==========+ + | chat/greeting | PASSED | 0.00s | + | └ greets_judge | 1 | | + | chat/goodbye | FAILED | 0.00s | + | └ greets_judge | 0 | | + +------------------+----------------+----------+ - # Alternatively, run each step separately - eac offline seed --dataset chat # seed (create fixtures) into a new run - eac offline execute # execute (run each case) for the latest run - eac offline judge # judge (judge output of execute) for the latest run - ``` + Below 1 + chat/goodbye › greets_judge: no greeting in 'see you later' -[`examples/basic-example-python`](examples/basic-example-python) is a fuller -project to start from. + 2 cases 1 passed 1 failed 0 errored +``` -### Online evals +`greeting` passes, `goodbye` fails. -Online evals judge what your system already did in production, so nothing is re-run and there are no seeds. You write the runner that collects production runs as cases, and the judges that score them. +## Learn more -1. Install the `eac` CLI and SDK as in step 1 above. +The [docs](https://eac.sentry.dev) cover judges, seeds, [online evals](https://eac.sentry.dev/online-evals) and the full CLI reference. [`examples/`](examples/) has complete projects to start from. -2. Add an `online` section to a dataset, with its runner and the judges `--judge` can pick from. A dataset can have both an `offline` and an `online` section: - - ```yaml - # evals/chat/dataset.yml - name: chat - runtime: python - online: - runner: ./dataset.py:ProdChats - judges: - - {name: greets, path: ./dataset.py:Greets} - ``` - - ```python - # evals/chat/dataset.py, next to the Greets judge above - from eac import Case, OnlineRunner - - - class ProdChats(OnlineRunner): - def collect_cases(self, window): - rows = [{"id": "trace-1", "query": "hi", "reply": "hello there"}] # query production here - return [ - Case(name=row["id"], input={"query": row["query"]}, output={"response": row["reply"]}) - for row in rows[: window.limit] - ] - ``` - -3. Run it from the repo's root: - - ```sh - eac online run --dataset chat --judge greets --since 24h # collect the last 24h of production runs and judge them - - # Alternatively, run each step separately - eac online execute --dataset chat --since 24h # execute (collect production runs as cases) into a new run - eac online judge --judge greets # judge the latest collected run - ``` - -The `assistant` dataset in [`examples/basic-example-python`](examples/basic-example-python) has an online section too. - -## SDKs - -Each SDK's README covers cases, runners, judges and seeds, including sharing seeds between machines and fetching agent traces. - -- Python: [`sdks/python`](sdks/python/README.md) - -## More - -- [eac.sentry.dev](https://eac.sentry.dev): the full docs. -- [`core/README.md`](core/README.md): Covers the CLI and core framework details. -- [`core/PROTOCOL.md`](core/PROTOCOL.md): how the CLI talks to an SDK, for creating a new SDK. +For contributors: [`core/README.md`](core/README.md) covers the CLI, [`core/PROTOCOL.md`](core/PROTOCOL.md) how it talks to an SDK, and [`CONTRIBUTING.md`](CONTRIBUTING.md) releasing. ## License diff --git a/docs/AGENTS.md b/docs/AGENTS.md new file mode 100644 index 0000000..af3b7c8 --- /dev/null +++ b/docs/AGENTS.md @@ -0,0 +1,9 @@ + + +## This is NOT the Next.js you know + +This version has breaking changes — APIs, conventions, and file structure may all differ from your training data. Read the relevant guide in `node_modules/next/dist/docs/` (resolved from this file's directory; in monorepos the `next` package may not be visible from the repo root) before writing any code. Heed deprecation notices. + +This block is written and re-added by `next dev` — verify at `node_modules/next/dist/server/lib/generate-agent-files.js`. Removing it from a diff only re-creates the uncommitted change; committing it with your work keeps the tree clean. + + diff --git a/docs/README.md b/docs/README.md index 3693fbe..b5e9394 100644 --- a/docs/README.md +++ b/docs/README.md @@ -13,6 +13,12 @@ pnpm typecheck # TypeScript CI runs `pnpm lint` and `pnpm typecheck` on pull requests that change `docs/` (`.github/workflows/docs.yml`). +## Landing page + +`/` is a full-width landing page (`app/page.tsx`, `components/landing.tsx`) with +a short quick start and links into the docs, which start at `/introduction`. +`components/docsShell.tsx` leaves out the sidebar on it. + ## Adding a page 1. Create `app//page.mdx`, starting with `export const metadata = {title: '...'}`. diff --git a/docs/app/globals.css b/docs/app/globals.css index 2f98395..7f05f08 100644 --- a/docs/app/globals.css +++ b/docs/app/globals.css @@ -1,3 +1,17 @@ +/* + * Roboto Mono has no box-drawing characters (│ └ ─ ...). next/font puts its + * generated "Roboto Mono Fallback" (a resized Arial) right after it, so that + * would draw them, too wide for the grid. This face covers only that range, + * from a system monospace font at the same width, and goes first in the mono + * stack. Everything else falls through to Roboto Mono. + */ +@font-face { + font-family: 'Mono Box Drawing'; + src: local('Menlo Regular'), local('Menlo-Regular'), local('Menlo'), local('Monaco'), + local('DejaVu Sans Mono'), local('Consolas'); + unicode-range: U+2500-257F; +} + *, *::before, *::after { @@ -18,5 +32,5 @@ body { pre, code, kbd { - font-family: var(--font-roboto-mono), Monaco, Consolas, monospace; + font-family: 'Mono Box Drawing', var(--font-roboto-mono), Monaco, Consolas, monospace; } diff --git a/docs/app/page.mdx b/docs/app/introduction/page.mdx similarity index 100% rename from docs/app/page.mdx rename to docs/app/introduction/page.mdx diff --git a/docs/app/page.tsx b/docs/app/page.tsx new file mode 100644 index 0000000..7b6f310 --- /dev/null +++ b/docs/app/page.tsx @@ -0,0 +1,11 @@ +import type {Metadata} from 'next'; + +import {Landing} from '@/components/landing'; + +export const metadata: Metadata = { + title: {absolute: 'eac: evals as code'}, +}; + +export default function Home() { + return ; +} diff --git a/docs/app/protocol/page.mdx b/docs/app/protocol/page.mdx index 6d1d24d..ab716a6 100644 --- a/docs/app/protocol/page.mdx +++ b/docs/app/protocol/page.mdx @@ -37,4 +37,4 @@ eac starts a worker process for your language and talks to it with JSON, one mes ]} /> -The full spec, with every param and result, is in [`core/PROTOCOL.md`](https://github.com/getsentry/eve/blob/main/core/PROTOCOL.md). +The full spec, with every param and result, is in [`core/PROTOCOL.md`](https://github.com/getsentry/eac/blob/main/core/PROTOCOL.md). diff --git a/docs/app/quick-start/page.mdx b/docs/app/quick-start/page.mdx index 6b38b39..35784b2 100644 --- a/docs/app/quick-start/page.mdx +++ b/docs/app/quick-start/page.mdx @@ -111,4 +111,4 @@ That's it. The results are saved in `.eac/runs//`. Changed a judge? Run `eac offline judge` to re-score the last run without running your system again. -For a bigger example with seeds and online evals, see [`examples/basic-example-python`](https://github.com/getsentry/eve/tree/main/examples/basic-example-python). +For a bigger example with seeds and online evals, see [`examples/basic-example-python`](https://github.com/getsentry/eac/tree/main/examples/basic-example-python). diff --git a/docs/app/run-directory/page.mdx b/docs/app/run-directory/page.mdx index 37d09e7..03089be 100644 --- a/docs/app/run-directory/page.mdx +++ b/docs/app/run-directory/page.mdx @@ -17,7 +17,7 @@ Every run is saved to its own folder: ## Uploading results -eac never sends results anywhere. If you want them in a dashboard, point a script at the run's `results/` folder. It's the one format meant for other tools: [`schemas/results.schema.json`](https://github.com/getsentry/eve/blob/main/schemas/results.schema.json) describes it, and its `schema_version` goes up whenever a change could break a reader. Commands that judge print the run id, so you can chain them: +eac never sends results anywhere. If you want them in a dashboard, point a script at the run's `results/` folder. It's the one format meant for other tools: [`schemas/results.schema.json`](https://github.com/getsentry/eac/blob/main/schemas/results.schema.json) describes it, and its `schema_version` goes up whenever a change could break a reader. Commands that judge print the run id, so you can chain them: ```sh id=$(eac offline run); ./upload.py ".eac/runs/$id" diff --git a/docs/components/docsShell.tsx b/docs/components/docsShell.tsx index 3f1e75c..df4c7bb 100644 --- a/docs/components/docsShell.tsx +++ b/docs/components/docsShell.tsx @@ -5,8 +5,8 @@ import {usePathname} from 'next/navigation'; import {IconGithub} from '@sentry/icons/github'; import {IconMoon} from '@sentry/icons/moon'; import {IconSun} from '@sentry/icons/sun'; +import {Badge} from '@sentry/scraps/badge'; import {Button, LinkButton} from '@sentry/scraps/button'; -import {InlineCode} from '@sentry/scraps/code'; import {Flex, Stack} from '@sentry/scraps/layout'; import {Link} from '@sentry/scraps/link'; import {Prose, Text} from '@sentry/scraps/text'; @@ -23,34 +23,19 @@ export function DocsShell({children}: {children: React.ReactNode}) { const prev = index > 0 ? PAGES[index - 1] : undefined; const next = index >= 0 && index < PAGES.length - 1 ? PAGES[index + 1] : undefined; + // The landing page is full width, without the sidebar or pager. + if (pathname === '/') { + return ( + + + {children} + + ); + } + return ( -
- - - - eac - - - - evals-as-code - - - v{process.env.EAC_VERSION} - - - - - } - aria-label="GitHub repository" - /> - -
+ @@ -111,6 +96,42 @@ export function DocsShell({children}: {children: React.ReactNode}) { ); } +function SiteHeader() { + return ( +
+ + + + + eac + + + evals as code + + + + + v{process.env.EAC_VERSION} + + + + + Docs + + } + aria-label="GitHub repository" + /> + + +
+ ); +} + function ThemeToggle() { const {mode, toggle} = useThemeMode(); const label = mode === 'dark' ? 'Switch to light theme' : 'Switch to dark theme'; diff --git a/docs/components/landing.tsx b/docs/components/landing.tsx new file mode 100644 index 0000000..16d1552 --- /dev/null +++ b/docs/components/landing.tsx @@ -0,0 +1,279 @@ +'use client'; + +import styled from '@emotion/styled'; +import {IconArrow} from '@sentry/icons/arrow'; +import {IconGithub} from '@sentry/icons/github'; +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 {Heading, Text} from '@sentry/scraps/text'; + +const REPO_URL = 'https://github.com/getsentry/eac'; + +const INSTALL = `git clone ${REPO_URL}.git && cd eac +make install # needs Rust 1.87+ +pip install -e sdks/python # needs Python 3.11+`; + +const DATASET_YML = `name: chat +runtime: python +offline: + runner: ./dataset.py:ChatRunner + cases: ./dataset.py:CASES`; + +const DATASET_PY = `from eac import Case, Judge, OfflineRunner, Score + + +def reply(query: str) -> str: + return "hello there" if query == "hi" else "see you later" # call your AI agent here + + +class ChatRunner(OfflineRunner): + def run_case(self, case, *, seeds, conversation_id): + return {"response": reply(case.input["query"])} + + +class Greets(Judge): + name = "greets_judge" + + def judge(self, case, *, seeds, agent_trace=None): + response = case.output.get("response", "") + if "hello" in response: + return Score(name=self.name, score=1.0) + + return Score( + name=self.name, + score=0.0, + explanation=f"no greeting in {response!r}", + ) + + +CASES = [ + Case(name="greeting", input={"query": "hi"}, judges=[Greets()]), + Case(name="goodbye", input={"query": "bye"}, judges=[Greets()]), +]`; + +const RUN = 'eac offline run --dataset chat'; + +const RUN_OUTPUT = `RESULTS + +------------------+----------------+----------+ + | Case | Status / score | Duration | + +==================+================+==========+ + | chat/greeting | PASSED | 0.00s | + | └ greets_judge | 1 | | + | chat/goodbye | FAILED | 0.00s | + | └ greets_judge | 0 | | + +------------------+----------------+----------+ + + Below 1 + chat/goodbye › greets_judge: no greeting in 'see you later' + + 2 cases 1 passed 1 failed 0 errored`; + +export function Landing() { + 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. + + + + } + > + Read the docs + + }> + GitHub + + + + + +
+ + Get started + + + + + {INSTALL} + + + Add a dataset.yml anywhere in your repo. + + } + > + + + {DATASET_YML} + + + {DATASET_PY} + + + + + + {RUN} + + {RUN_OUTPUT} + + + + greeting passes, goodbye fails. + + + +
+ +
+ + + + Learn more + + + Judges, seeds, online evals and the full CLI reference. + + } + > + Read the docs + + + +
+
+ ); +} + +function Step({ + children, + description, + number, + title, +}: { + children: React.ReactNode; + number: number; + title: string; + description?: React.ReactNode; +}) { + return ( + + {number} + + + + {title} + + {description && ( + + {description} + + )} + + {children} + + + ); +} + +const Wrapper = styled('main')` + max-width: 960px; + margin: 0 auto; + padding: 0 ${p => p.theme.space['2xl']} 96px; + + a[role='button'] { + text-decoration: none; + } + + @media (max-width: ${p => p.theme.breakpoints.sm}) { + padding: 0 ${p => p.theme.space.xl} 64px; + } +`; + +const Hero = styled('section')` + padding: 112px 0 72px; + text-align: center; + + p { + margin: 0; + } + + @media (max-width: ${p => p.theme.breakpoints.sm}) { + padding: 64px 0 40px; + } +`; + +const HeroTitle = styled(Heading)` + font-size: clamp(2.5rem, 7vw, 4rem); + line-height: 1.1; + letter-spacing: -0.02em; +`; + +const Section = styled('section')` + padding: 48px 0; +`; + +const Steps = styled('ol')` + display: flex; + flex-direction: column; + gap: ${p => p.theme.space['3xl']}; + margin: ${p => p.theme.space['3xl']} 0 0; + padding: 0; + list-style: none; +`; + +// Don't stretch the content to the row's height: a stretched (definite) height +// makes CodeBlock's \`height: 100%\` panels overflow under their filename header. +const StepRow = styled('li')` + display: flex; + align-items: flex-start; + gap: ${p => p.theme.space.xl}; +`; + +const StepNumber = styled('div')` + display: flex; + flex-shrink: 0; + align-items: center; + justify-content: center; + width: 32px; + height: 32px; + border-radius: 50%; + background: ${p => p.theme.tokens.background.transparent.accent.muted}; + color: ${p => p.theme.tokens.content.accent}; + font-weight: ${p => p.theme.font.weight.sans.medium}; +`; + +const CtaBand = styled('div')` + padding: 40px ${p => p.theme.space['2xl']}; + border: 1px solid ${p => p.theme.tokens.border.primary}; + border-radius: ${p => p.theme.radius.lg}; + background: ${p => p.theme.tokens.background.secondary}; + + p { + margin: 0; + } +`; diff --git a/docs/components/nav.ts b/docs/components/nav.ts index 7965786..e8ce757 100644 --- a/docs/components/nav.ts +++ b/docs/components/nav.ts @@ -12,7 +12,7 @@ export const NAV: NavSection[] = [ { title: 'Getting started', items: [ - {title: 'Introduction', href: '/'}, + {title: 'Introduction', href: '/introduction'}, {title: 'Quick start', href: '/quick-start'}, {title: 'How eac works', href: '/concepts'}, ], diff --git a/docs/components/providers.tsx b/docs/components/providers.tsx index 97f6dd3..8e26679 100644 --- a/docs/components/providers.tsx +++ b/docs/components/providers.tsx @@ -17,7 +17,8 @@ function RouterLink({ ...props }: LinkProps) { const href = typeof to === 'string' ? to : (to.pathname ?? '') + (to.hash ?? ''); - return ; + // Spread first: Scraps' passes `href: undefined` alongside `to`. + return ; } const linkBehavior = { diff --git a/docs/components/themeContext.tsx b/docs/components/themeContext.tsx index 3eac145..5ccd463 100644 --- a/docs/components/themeContext.tsx +++ b/docs/components/themeContext.tsx @@ -16,9 +16,9 @@ function withFonts(theme: typeof lightTheme): typeof lightTheme { ...theme.font, family: { sans: `var(--font-rubik), ${theme.font.family.sans}`, - // Menlo first among the fallbacks: it has the box-drawing glyphs - // Roboto Mono lacks, at the same width, so diagrams line up. - mono: `var(--font-roboto-mono), Menlo, ${theme.font.family.mono}`, + // 'Mono Box Drawing' (app/globals.css) supplies the box-drawing + // glyphs Roboto Mono lacks, at the same width, so diagrams line up. + mono: `'Mono Box Drawing', var(--font-roboto-mono), Menlo, ${theme.font.family.mono}`, }, }, } as unknown as typeof lightTheme;