From adf56533e4ede009a1690ebe01caf2a327283c9b Mon Sep 17 00:00:00 2001 From: Ryan Brooks Date: Fri, 27 Nov 2026 16:57:16 -0800 Subject: [PATCH] Add install script and docs tweaks --- .github/workflows/docs.yml | 4 + CONTRIBUTING.md | 3 +- README.md | 26 +- docs/README.md | 10 + docs/app/cases-and-runners/page.mdx | 8 +- docs/app/introduction/page.mdx | 29 ++- docs/app/judges/page.mdx | 21 +- docs/app/online-evals/page.mdx | 1 + docs/app/seeds/page.mdx | 1 + docs/components/docsShell.tsx | 2 +- docs/components/landing.tsx | 225 +++++++++++------- docs/components/languageContext.tsx | 11 +- docs/next.config.ts | 5 + docs/public/install | 62 +++++ .../evals/triage/judges/found_cause_judge.py | 8 +- .../evals/triage/judges/found_issue_judge.py | 8 +- .../evals/triage/judges/triage_llm_judge.py | 13 +- .../evals/triage/runners/offline.py | 8 +- sdks/python/README.md | 45 +++- 19 files changed, 374 insertions(+), 116 deletions(-) create mode 100755 docs/public/install diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index f3edaca..6b7ac0b 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -39,3 +39,7 @@ jobs: - name: Typecheck run: pnpm typecheck + + # The runner image has ShellCheck. + - name: Check the installer + run: shellcheck public/install diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d768bba..7114b09 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -56,8 +56,7 @@ uv add --editable path/to/eac/sdks/python # the SDK, in your project Install the CLI and the SDK from a GitHub release, here `0.0.1`: ```sh -gh release download 0.0.1 -R getsentry/eac -p eac-Darwin-universal -O ~/.local/bin/eac -chmod +x ~/.local/bin/eac +EAC_VERSION=0.0.1 bash docs/public/install # the installer at eac.sentry.dev/install gh release download 0.0.1 -R getsentry/eac -p 'eac_sdk-*.whl' -D /tmp/eac uv pip install /tmp/eac/eac_sdk-0.0.1-py3-none-any.whl # in your project ``` diff --git a/README.md b/README.md index 49906c9..40cf97f 100644 --- a/README.md +++ b/README.md @@ -9,11 +9,14 @@ EAC is a command line tool & SDKs to write evals for AI systems. It handles fixt ### 1. Install ```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+ +curl -fsSL https://eac.sentry.dev/install | bash # the CLI, on macOS or Linux + +git clone https://github.com/getsentry/eac.git +pip install -e eac/sdks/python # the SDK, needs Python 3.11+ ``` +To build the CLI from source instead, run `make install` in the repo (needs Rust 1.87+). + ### 2. Write an eval Add a `dataset.yml` and the code it points to, anywhere in your repo. @@ -37,14 +40,27 @@ def reply(query: str) -> str: class ChatRunner(OfflineRunner): - def run_case(self, case: Case, *, seed_results: dict[str, dict[str, Any]], conversation_id: str) -> dict[str, Any]: + + def run_case( + self, + case: Case, + *, + seed_results: dict[str, dict[str, Any]], + conversation_id: str, + ) -> dict[str, Any]: return {"response": reply(case.input["query"])} class Greets(Judge): name = "greets_judge" - def judge(self, case: Case, *, seed_results: dict[str, dict[str, Any]], agent_trace: Any = None) -> Score | None: + 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) diff --git a/docs/README.md b/docs/README.md index b717cfa..f9211e9 100644 --- a/docs/README.md +++ b/docs/README.md @@ -21,6 +21,16 @@ 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. +A language dropdown, the same setting as the sidebar's, picks the SDK whose +install command and eval code the steps show, from `SDKS`. When you add a +language, give it an entry there. + +## Installer + +`public/install` is the CLI's install script, served at `/install` for +`curl -fsSL https://eac.sentry.dev/install | bash`. It downloads the binaries +`.craft.yml` attaches to each GitHub release, by name. CI runs ShellCheck on it. + ## Adding a page 1. Create `app//page.mdx`, starting with `export const metadata = {title: '...'}`. diff --git a/docs/app/cases-and-runners/page.mdx b/docs/app/cases-and-runners/page.mdx index 837e4e8..501b46a 100644 --- a/docs/app/cases-and-runners/page.mdx +++ b/docs/app/cases-and-runners/page.mdx @@ -66,7 +66,13 @@ from eac import Case, OfflineRunner class OfflineTriageRunner(OfflineRunner): credentials = [OpenRouterKey(), SentryLogin()] - def run_case(self, case: Case, *, seed_results: dict[str, dict[str, Any]], conversation_id: str) -> dict[str, Any]: + def run_case( + self, + case: Case, + *, + seed_results: dict[str, dict[str, Any]], + conversation_id: str, + ) -> dict[str, Any]: alert = case.input["alert"].format(release=seed_results["incident"]["release"]) model = self.args.get("model", DEFAULT_MODEL) return triage(alert, conversation_id=conversation_id, model=model) diff --git a/docs/app/introduction/page.mdx b/docs/app/introduction/page.mdx index ca19e53..9309619 100644 --- a/docs/app/introduction/page.mdx +++ b/docs/app/introduction/page.mdx @@ -35,12 +35,20 @@ Set up a project and run a first eval. It takes about five minutes. ### Install -eac doesn't have packaged releases yet, so build the CLI from the repo. You'll need Rust 1.87+. +Install the CLI on macOS or Linux: ```sh -make install # puts eac on your PATH +curl -fsSL https://eac.sentry.dev/install | bash ``` +It puts `eac` in `~/.local/bin`. To pick another directory or a specific release: + +```sh +curl -fsSL https://eac.sentry.dev/install | EAC_INSTALL_DIR=/usr/local/bin EAC_VERSION=0.1.0 bash +``` + +To build from source instead, run `make install` in the repo (needs Rust 1.87+). + Then install the SDK into the environment your evals run in: @@ -106,14 +114,27 @@ def reply(query: str) -> str: class ChatRunner(OfflineRunner): - def run_case(self, case: Case, *, seed_results: dict[str, dict[str, Any]], conversation_id: str) -> dict[str, Any]: + + def run_case( + self, + case: Case, + *, + seed_results: dict[str, dict[str, Any]], + conversation_id: str, + ) -> dict[str, Any]: return {"response": reply(case.input["query"])} class Greets(Judge): name = "greets" - def judge(self, case: Case, *, seed_results: dict[str, dict[str, Any]], agent_trace: Any = None) -> Score | None: + def judge( + self, + case: Case, + *, + seed_results: dict[str, dict[str, Any]], + agent_trace: Any = None, + ) -> Score | None: ok = "hello" in case.run_results.get("response", "") return Score(name=self.name, score=1.0 if ok else 0.0) diff --git a/docs/app/judges/page.mdx b/docs/app/judges/page.mdx index ef13d2e..017783c 100644 --- a/docs/app/judges/page.mdx +++ b/docs/app/judges/page.mdx @@ -18,7 +18,13 @@ class FoundIssueJudge(Judge): name = "found_issue" - def judge(self, case: Case, *, seed_results: dict[str, dict[str, Any]], agent_trace: Any = None) -> Score | None: + def judge( + self, + case: Case, + *, + seed_results: dict[str, dict[str, Any]], + agent_trace: Any = None, + ) -> Score | None: error = case.expected_output["error"] expected = seed_results["incident"]["issues"][error] if error else None actual = case.run_results.get("issue") @@ -55,7 +61,10 @@ class TriageLLMJudge(Judge): conversation = load_conversation(run.conversation_id) if conversation is None: return None - return AgentTrace(trace=conversation["messages"], metrics=LLMMetrics(**conversation["usage"])) + return AgentTrace( + trace=conversation["messages"], + metrics=LLMMetrics(**conversation["usage"]), + ) ``` @@ -73,7 +82,13 @@ An LLM judge asks a model to grade the trace. This one asks two true-or-false qu ```python - def judge(self, case: Case, *, seed_results: dict[str, dict[str, Any]], agent_trace: Any = None) -> Score | None: + def judge( + self, + case: Case, + *, + seed_results: dict[str, dict[str, Any]], + agent_trace: Any = None, + ) -> Score | None: if agent_trace is None: return None with client() as openrouter: diff --git a/docs/app/online-evals/page.mdx b/docs/app/online-evals/page.mdx index a988b93..f336c75 100644 --- a/docs/app/online-evals/page.mdx +++ b/docs/app/online-evals/page.mdx @@ -37,6 +37,7 @@ from eac import Case, OnlineRunner, Window class OnlineTriageRunner(OnlineRunner): + def collect_cases(self, window: Window) -> list[Case]: conversations = recent_conversations(window.since, window.until) sampled = [c for c in conversations if window.samples(c["conversation_id"])] diff --git a/docs/app/seeds/page.mdx b/docs/app/seeds/page.mdx index b025df3..e462cdd 100644 --- a/docs/app/seeds/page.mdx +++ b/docs/app/seeds/page.mdx @@ -77,6 +77,7 @@ The cache lives on your machine by default. To share fixtures across CI jobs, st ```python class SharedSeed(Seed): + def load_cached(self, key: str) -> dict[str, Any] | None: return bucket.get(f"seeds/{self.name}/{key}") diff --git a/docs/components/docsShell.tsx b/docs/components/docsShell.tsx index 1a24828..3cd64cb 100644 --- a/docs/components/docsShell.tsx +++ b/docs/components/docsShell.tsx @@ -41,7 +41,7 @@ export function DocsShell({children}: {children: React.ReactNode}) { Language - + {NAV.map(section => ( diff --git a/docs/components/landing.tsx b/docs/components/landing.tsx index 9a88891..7a8e239 100644 --- a/docs/components/landing.tsx +++ b/docs/components/landing.tsx @@ -11,14 +11,13 @@ import {Flex, Stack} from '@sentry/scraps/layout'; import {SegmentedControl} from '@sentry/scraps/segmentedControl'; import {Heading, Text} from '@sentry/scraps/text'; +import {LanguageSelect, useLanguage} from './languageContext'; +import type {LanguageId} from './languages'; import {Terminal} from './terminal'; const REPO_URL = 'https://github.com/getsentry/eac'; -const INSTALL = `brew tap getsentry/tap -brew install getsentry/tap/eac - -pip install -e sdks/python # needs Python 3.11+`; +const INSTALL_CLI = 'curl -fsSL https://eac.sentry.dev/install | bash'; // 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`); @@ -36,44 +35,6 @@ const EXAMPLES = { ), }, - datasetYml: `name: chat -runtime: python -offline: - runner: ./dataset.py:ChatRunner - cases: ./dataset.py:CASES`, - datasetPy: `from typing import Any - -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: Case, *, seed_results: dict[str, dict[str, Any]], conversation_id: str) -> dict[str, Any]: - return {"response": reply(case.input["query"])} - - -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) - - return Score( - name=self.name, - score=0.0, - explanation=f"no greeting in {response!r}", - ) - - -CASES = [ - Case(name="greeting", input={"query": "hi"}, judges=[GreetsJudge()]), - Case(name="goodbye", input={"query": "bye"}, judges=[GreetsJudge()]), -]`, run: { description: 'eac seeds fixtures, runs each case, judges the output and prints the results.', @@ -93,8 +54,8 @@ ${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} + ${D}chat/greeting ran in 0.84s${X} + ${D}chat/goodbye ran in 0.61s${X} ${B}JUDGE${X} ${D}chat/greeting judged${X} @@ -104,14 +65,14 @@ ${B}RESULTS${X} +------------------+----------------+----------+ | Case | Status / score | Duration | +==================+================+==========+ - | chat/greeting | ${G}PASSED ${X} | 0.00s | + | chat/greeting | ${G}PASSED ${X} | 0.84s | | └ greets_judge | 1 | | - | chat/goodbye | ${R}FAILED ${X} | 0.00s | + | chat/goodbye | ${R}FAILED ${X} | 0.61s | | └ greets_judge | 0 | | +------------------+----------------+----------+ ${B}Below 1${X} - ${D}chat/goodbye › greets_judge: no greeting in 'see you later'${X} + ${D}chat/goodbye › greets_judge: no greeting in 'Goodbye! Take care.'${X} ${B}2 cases${X} ${G}1 passed${X} ${R}1 failed${X} ${Y}0 errored${X}`, }, @@ -128,14 +89,116 @@ ${B}RESULTS${X} ), }, - datasetYml: `name: chat + 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}`, + }, +}; + +// What each SDK's steps show, for the language picked on the page (the same +// setting as the docs' sidebar). +const SDKS: Record< + LanguageId, + { + install: string; + file: string; + offline: {datasetYml: string; code: string}; + online: {datasetYml: string; code: string}; + } +> = { + python: { + install: `# needs Python 3.11+ +pip install "eac-sdk @ git+${REPO_URL}#subdirectory=sdks/python"`, + file: 'dataset.py', + offline: { + datasetYml: `name: chat +runtime: python +offline: + runner: ./dataset.py:ChatRunner + cases: ./dataset.py:CASES`, + code: `from typing import Any + +from eac import Case, Judge, OfflineRunner, Score +from openai import OpenAI + + +class ChatRunner(OfflineRunner): + + def run_case( + self, + case: Case, + *, + seed_results: dict[str, dict[str, Any]], + conversation_id: str, + ) -> dict[str, Any]: + response = OpenAI().responses.create( + model="gpt-6-luna", + instructions="You're a friendly assistant. Reply in one short sentence.", + input=case.input["query"], + ) + return {"response": response.output_text} + + +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 response.lower().startswith(("hello", "hi", "hey")): + 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=[GreetsJudge()]), + Case(name="goodbye", input={"query": "bye"}, judges=[GreetsJudge()]), +]`, + }, + online: { + datasetYml: `name: chat runtime: python online: runner: ./dataset.py:ChatRunner judges: - name: greets_judge path: ./dataset.py:GreetsJudge`, - datasetPy: `from datetime import datetime + code: `from datetime import datetime from typing import Any from eac import Case, Judge, OnlineRunner, Score, Window @@ -150,6 +213,7 @@ def recent_conversations(since: datetime, until: datetime) -> list[dict[str, Any class ChatRunner(OnlineRunner): + def collect_cases(self, window: Window) -> list[Case]: conversations = recent_conversations(window.since, window.until) return [ @@ -167,7 +231,13 @@ class ChatRunner(OnlineRunner): class GreetsJudge(Judge): name = "greets_judge" - def judge(self, case: Case, *, seed_results: dict[str, dict[str, Any]], agent_trace: Any = None) -> Score | None: + 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) @@ -177,34 +247,7 @@ class GreetsJudge(Judge): 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}`, }, }; @@ -212,7 +255,9 @@ type Mode = keyof typeof EXAMPLES; export function Landing() { const [mode, setMode] = useState('offline'); + const {language} = useLanguage(); const example = EXAMPLES[mode]; + const sdk = SDKS[language.id]; return ( @@ -257,7 +302,10 @@ export function Landing() { Get started - + + + + {example.summary} @@ -265,20 +313,27 @@ export function Landing() { - - {INSTALL} + + {INSTALL_CLI} + + + {sdk.install} - + - {example.datasetYml} + {sdk[mode].datasetYml} - - {example.datasetPy} + + {sdk[mode].code} - + {example.command} {example.run.result} diff --git a/docs/components/languageContext.tsx b/docs/components/languageContext.tsx index 55b6b50..3d5439d 100644 --- a/docs/components/languageContext.tsx +++ b/docs/components/languageContext.tsx @@ -40,10 +40,13 @@ export function LanguageProvider({ return {children}; } -export function LanguageSelect() { +/** Picks the site's language. `fullWidth` fills the sidebar. */ +export function LanguageSelect({fullWidth = false}: {fullWidth?: boolean}) { const {language, setLanguage} = useLanguage(); + const Select = fullWidth ? FullWidthSelect : CompactSelect; + const Trigger = fullWidth ? FullWidthTrigger : OverlayTrigger.Button; return ( - ( - + {language.label} - + )} /> ); diff --git a/docs/next.config.ts b/docs/next.config.ts index 8033753..dc0354b 100644 --- a/docs/next.config.ts +++ b/docs/next.config.ts @@ -17,6 +17,11 @@ const nextConfig: NextConfig = { redirects: async () => [ {source: '/quick-start', destination: '/introduction#quick-start', permanent: true}, ], + // The installer (public/install) has no extension, so say it's text: browsers + // show it instead of downloading it. + headers: async () => [ + {source: '/install', headers: [{key: 'Content-Type', value: 'text/plain; charset=utf-8'}]}, + ], }; const withMDX = createMDX(); diff --git a/docs/public/install b/docs/public/install new file mode 100755 index 0000000..aac7304 --- /dev/null +++ b/docs/public/install @@ -0,0 +1,62 @@ +#!/bin/bash +# eac installer, served at https://eac.sentry.dev/install. +# +# curl -fsSL https://eac.sentry.dev/install | bash +# +# Installs this machine's eac binary from the latest GitHub release, or the one +# in EAC_VERSION, into ~/.local/bin, or EAC_INSTALL_DIR. +# +# main runs on the last line, so if this script's download is cut off, bash +# runs nothing instead of half an installer. +set -euo pipefail + +main() { + local repo="getsentry/eac" + local version="${EAC_VERSION:-}" + local dir="${EAC_INSTALL_DIR:-${HOME}/.local/bin}" + + # The releases have one universal binary for macOS and static ones for Linux. + local os arch + os="$(uname -s)" + arch="$(uname -m)" + if [[ "$os" == Darwin ]]; then arch=universal; fi + local asset="eac-${os}-${arch}" + case "$asset" in + eac-Darwin-universal|eac-Linux-x86_64|eac-Linux-aarch64) ;; + *) die "No eac build for ${os} ${arch}. Build it from source: https://github.com/${repo}" ;; + esac + + local url="https://github.com/${repo}/releases/latest/download/${asset}" + if [[ -n "$version" ]]; then + url="https://github.com/${repo}/releases/download/${version}/${asset}" + fi + + # Downloads next to the final path, so installing it is a rename. Global, so + # the EXIT trap can still see it after main returns. + mkdir -p "$dir" + download="${dir}/.eac-download-$$" + trap 'rm -f "$download"' EXIT + + echo "Downloading ${asset} ${version:-(latest)}..." + # While the repo is private, curl gets a 404, so try the GitHub CLI's login. + curl -fsL --retry 3 -o "$download" "$url" \ + || gh release download ${version:+"$version"} -R "$repo" -p "$asset" -O "$download" --clobber 2>/dev/null \ + || die "Couldn't download ${url}" + + chmod +x "$download" + "$download" --version >/dev/null || die "The downloaded ${asset} doesn't run on this machine." + mv -f "$download" "${dir}/eac" + echo "Installed $("${dir}/eac" --version) to ${dir}/eac" + + case ":${PATH}:" in + *":${dir}:"*) ;; + *) echo "Add it to your PATH, for example in ~/.zshrc or ~/.bashrc: export PATH=\"${dir}:\$PATH\"" ;; + esac +} + +die() { + echo "$1" >&2 + exit 1 +} + +main diff --git a/examples/sentry-assistant-python/evals/triage/judges/found_cause_judge.py b/examples/sentry-assistant-python/evals/triage/judges/found_cause_judge.py index d19786e..5b57abb 100644 --- a/examples/sentry-assistant-python/evals/triage/judges/found_cause_judge.py +++ b/examples/sentry-assistant-python/evals/triage/judges/found_cause_judge.py @@ -8,7 +8,13 @@ class FoundCauseJudge(Judge): name = "found_cause" - def judge(self, case: Case, *, seed_results: dict[str, dict[str, Any]], agent_trace: Any = None) -> Score | None: + def judge( + self, + case: Case, + *, + seed_results: dict[str, dict[str, Any]], + agent_trace: Any = None, + ) -> Score | None: expected = case.expected_output["function"] actual = case.run_results.get("function") diff --git a/examples/sentry-assistant-python/evals/triage/judges/found_issue_judge.py b/examples/sentry-assistant-python/evals/triage/judges/found_issue_judge.py index 8b3833d..f172dc2 100644 --- a/examples/sentry-assistant-python/evals/triage/judges/found_issue_judge.py +++ b/examples/sentry-assistant-python/evals/triage/judges/found_issue_judge.py @@ -9,7 +9,13 @@ class FoundIssueJudge(Judge): name = "found_issue" - def judge(self, case: Case, *, seed_results: dict[str, dict[str, Any]], agent_trace: Any = None) -> Score | None: + def judge( + self, + case: Case, + *, + seed_results: dict[str, dict[str, Any]], + agent_trace: Any = None, + ) -> Score | None: error = case.expected_output["error"] expected = seed_results["incident"]["issues"][error] if error else None diff --git a/examples/sentry-assistant-python/evals/triage/judges/triage_llm_judge.py b/examples/sentry-assistant-python/evals/triage/judges/triage_llm_judge.py index 4ea8253..363ec45 100644 --- a/examples/sentry-assistant-python/evals/triage/judges/triage_llm_judge.py +++ b/examples/sentry-assistant-python/evals/triage/judges/triage_llm_judge.py @@ -33,9 +33,18 @@ def get_agent_trace(self, run: AgentRun) -> AgentTrace | None: conversation = load_conversation(run.conversation_id) if conversation is None: return None - return AgentTrace(trace=conversation["messages"], metrics=LLMMetrics(**conversation["usage"])) + return AgentTrace( + trace=conversation["messages"], + metrics=LLMMetrics(**conversation["usage"]), + ) - def judge(self, case: Case, *, seed_results: dict[str, dict[str, Any]], agent_trace: Any = None) -> Score | None: + def judge( + self, + case: Case, + *, + seed_results: dict[str, dict[str, Any]], + agent_trace: Any = None, + ) -> Score | None: if agent_trace is None: return None with client() as openrouter: diff --git a/examples/sentry-assistant-python/evals/triage/runners/offline.py b/examples/sentry-assistant-python/evals/triage/runners/offline.py index 9b9398d..02f84c7 100644 --- a/examples/sentry-assistant-python/evals/triage/runners/offline.py +++ b/examples/sentry-assistant-python/evals/triage/runners/offline.py @@ -12,6 +12,12 @@ class OfflineTriageRunner(OfflineRunner): credentials = [OpenRouterKey(), SentryLogin()] - def run_case(self, case: Case, *, seed_results: dict[str, dict[str, Any]], conversation_id: str) -> dict[str, Any]: + def run_case( + self, + case: Case, + *, + seed_results: dict[str, dict[str, Any]], + conversation_id: str, + ) -> dict[str, Any]: alert = case.input["alert"].format(release=seed_results["incident"]["release"]) return triage(alert, conversation_id=conversation_id, model=self.args.get("model", DEFAULT_MODEL)) diff --git a/sdks/python/README.md b/sdks/python/README.md index 0fa9430..b3760c3 100644 --- a/sdks/python/README.md +++ b/sdks/python/README.md @@ -117,7 +117,14 @@ left to the judges. from eac import Case, OfflineRunner class ChatRunner(OfflineRunner): - def run_case(self, case: Case, *, seed_results: dict[str, dict[str, Any]], conversation_id: str) -> dict[str, Any]: + + def run_case( + self, + case: Case, + *, + seed_results: dict[str, dict[str, Any]], + conversation_id: str, + ) -> dict[str, Any]: model = self.args.get("model", "small") reply = my_chatbot(case.input["query"], model=model, tag=conversation_id) return {"response": reply} @@ -145,7 +152,13 @@ from eac import Case, Judge, Score class Matches(Judge): name = "matches" # what its scores are called - def judge(self, case: Case, *, seed_results: dict[str, dict[str, Any]], agent_trace: Any = None) -> Score | None: + def judge( + self, + case: Case, + *, + seed_results: dict[str, dict[str, Any]], + agent_trace: Any = None, + ) -> Score | None: expected = case.expected_output.get("response") if expected is None: return None # doesn't apply, e.g. online @@ -159,7 +172,13 @@ class CalledTool(Judge): def __init__(self, tool: str): self.tool = tool - def judge(self, case: Case, *, seed_results: dict[str, dict[str, Any]], agent_trace: Any = None) -> Score | None: + def judge( + self, + case: Case, + *, + seed_results: dict[str, dict[str, Any]], + agent_trace: Any = None, + ) -> Score | None: ok = self.tool in (case.run_results.get("tool_calls") or []) return Score(name=self.name, score=1.0 if ok else 0.0) ``` @@ -200,12 +219,21 @@ class SentryJudge(Judge): trace = fetch_trace(run.conversation_id, since=run.started_at) if trace is None: return None - return AgentTrace(trace=trace.spans, metrics=LLMMetrics(total_tokens=trace.tokens)) + return AgentTrace( + trace=trace.spans, + metrics=LLMMetrics(total_tokens=trace.tokens), + ) class UsedTheRightTool(SentryJudge): name = "used_the_right_tool" - def judge(self, case: Case, *, seed_results: dict[str, dict[str, Any]], agent_trace: Any = None) -> Score | None: + def judge( + self, + case: Case, + *, + seed_results: dict[str, dict[str, Any]], + agent_trace: Any = None, + ) -> Score | None: ... ``` @@ -294,6 +322,7 @@ re-run. from eac import Case, OnlineRunner, Window class ProdChats(OnlineRunner): + def collect_cases(self, window: Window) -> list[Case]: return [ Case( @@ -352,7 +381,11 @@ class GitHub(Credential): def authenticate(self) -> dict[str, str]: subprocess.run(["gh", "auth", "login"], check=True) - token = subprocess.run(["gh", "auth", "token"], capture_output=True, text=True).stdout.strip() + token = subprocess.run( + ["gh", "auth", "token"], + capture_output=True, + text=True, + ).stdout.strip() return {"GITHUB_TOKEN": token} # saved for later commands ```