-
Notifications
You must be signed in to change notification settings - Fork 25
feat(appkit): managed eval datasets + turn semantics (stack 3/5) #479
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
+598
−27
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7c8d1d0
feat(appkit): read managed eval datasets + explicit turn semantics
MarioCadenas 7eeca0b
chore(playground): point example dataset eval at main.mario.appkit_ev…
MarioCadenas 67982a4
feat(appkit): judges gate eval results by default
MarioCadenas cb930bd
refactor(appkit): unify eval CLI to a single --warehouse-id flag
MarioCadenas 98582c1
fix(appkit): surface empty-dataset evals as errors; guard dataset LIMIT
MarioCadenas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
apps/dev-playground/server/agents/query/evals/dataset.eval.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import { defineEval, isJudgeConfigured } from "@databricks/appkit/beta"; | ||
|
|
||
| /** | ||
| * Dataset-driven eval: runs once per row of a Databricks managed evaluation | ||
| * dataset (a Unity Catalog table with `inputs`/`expectations` columns). The | ||
| * runner binds each row to `t.input`/`t.expected`. | ||
| * | ||
| * Run it (reading the dataset needs a workspace client + warehouse; judging the | ||
| * guidelines needs a judge model): | ||
| * appkit agent eval dataset --root apps/dev-playground --url http://localhost:8000 \ | ||
| * --profile <profile> --warehouse <warehouse-id> --judge-model <endpoint> | ||
| * | ||
| * Row shape produced by the MLflow managed-dataset UI: | ||
| * inputs {"messages":[{"role":"user","content":"..."}]} | ||
| * expectations {"guidelines":{"value":["...","..."]}} (optional) | ||
| */ | ||
|
|
||
| /** Pull the last user message out of an MLflow `{messages:[...]}` input. */ | ||
| function userMessage(input: Record<string, unknown>): string { | ||
| const messages = Array.isArray(input.messages) | ||
| ? (input.messages as Array<{ role?: string; content?: string }>) | ||
| : []; | ||
| const last = [...messages].reverse().find((m) => m.role === "user"); | ||
| return last?.content ?? ""; | ||
| } | ||
|
|
||
| /** Read `expectations.guidelines` — the UI wraps the array as `{value: [...]}`. */ | ||
| function guidelines(expected: Record<string, unknown> | undefined): string[] { | ||
| const g = (expected?.guidelines as { value?: unknown } | undefined)?.value; | ||
| return Array.isArray(g) ? g.map(String) : []; | ||
| } | ||
|
|
||
| export default defineEval({ | ||
| description: "Query agent satisfies each dataset row's guidelines", | ||
| // Point at your own managed evaluation dataset (catalog.schema.table). | ||
| dataset: { table: "main.mario.appkit_eval_dataset" }, | ||
| async test(t) { | ||
| // One turn per row. For a multi-turn conversation, call `t.send` again | ||
| // (same thread); to start an independent turn in the same test, `t.reset()`. | ||
| await t.send(userMessage(t.input)); | ||
| t.succeeded(); | ||
|
|
||
| // Each guideline is judged against the reply — gate by default, so a miss | ||
| // fails the eval (chain `.soft()` to only track it). Skipped cleanly when no | ||
| // judge model is configured, so the eval still exercises the dataset read + | ||
| // drive path without one. | ||
| if (isJudgeConfigured()) { | ||
| for (const guideline of guidelines(t.expected)) { | ||
| (await t.judge.closedQA(guideline)).atLeast(0.5); | ||
| } | ||
| } | ||
| }, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import { SQLWarehouseConnector } from "../connectors"; | ||
| import type { WorkspaceClient } from "../workspace-client"; | ||
|
|
||
| /** | ||
| * One row of a managed evaluation dataset. `inputs` are the kwargs passed to the | ||
| * agent for the turn; `expectations` (when present) is the row's ground truth / | ||
| * guidelines. Mirrors the `{inputs, expectations}` shape of `mlflow.genai` | ||
| * datasets and of the Unity Catalog table backing a managed eval dataset. | ||
| */ | ||
| export interface DatasetRow { | ||
| inputs: Record<string, unknown>; | ||
| expectations?: Record<string, unknown>; | ||
| } | ||
|
|
||
| export interface ReadEvalDatasetOptions { | ||
| /** Fully-qualified UC table: `catalog.schema.table`. */ | ||
| table: string; | ||
| /** SQL warehouse id to run the read against. */ | ||
| warehouseId: string; | ||
| /** Optional row cap. */ | ||
| limit?: number; | ||
| } | ||
|
|
||
| /** A managed eval dataset is a UC table; only 3-level names are valid. */ | ||
| const UC_TABLE = /^[A-Za-z0-9_]+\.[A-Za-z0-9_]+\.[A-Za-z0-9_]+$/; | ||
|
|
||
| /** Coerce a cell (already JSON-parsed by the connector for JSON columns) to a record. */ | ||
| function toRecord(value: unknown): Record<string, unknown> | undefined { | ||
| if (value && typeof value === "object" && !Array.isArray(value)) { | ||
| return value as Record<string, unknown>; | ||
| } | ||
| return undefined; | ||
| } | ||
|
|
||
| /** | ||
| * Read a Databricks managed evaluation dataset (a Unity Catalog table with | ||
| * `inputs`/`expectations` columns) into rows, over the public SQL Statement | ||
| * Execution API. Reuses {@link SQLWarehouseConnector} for submit/poll/transform | ||
| * — its result transform already JSON-parses string columns into objects, so | ||
| * `inputs`/`expectations` come back as records whether the table stores them as | ||
| * JSON strings or structs. | ||
| * | ||
| * The Python `mlflow.genai.datasets` API needs a Spark session (no TS | ||
| * equivalent), so we read the backing table directly. | ||
| */ | ||
| export async function readEvalDataset( | ||
| client: WorkspaceClient, | ||
| options: ReadEvalDatasetOptions, | ||
| ): Promise<DatasetRow[]> { | ||
| if (!UC_TABLE.test(options.table)) { | ||
| throw new Error( | ||
| `Invalid dataset table "${options.table}" — expected catalog.schema.table`, | ||
| ); | ||
| } | ||
|
|
||
| const limit = | ||
| typeof options.limit === "number" && options.limit > 0 | ||
| ? ` LIMIT ${Math.floor(options.limit)}` | ||
| : ""; | ||
| const connector = new SQLWarehouseConnector({}); | ||
| const response = await connector.executeStatement(client, { | ||
| warehouse_id: options.warehouseId, | ||
| statement: `SELECT inputs, expectations FROM ${options.table}${limit}`, | ||
| }); | ||
|
|
||
| const rows = | ||
| (response.result as { data?: Array<Record<string, unknown>> } | undefined) | ||
| ?.data ?? []; | ||
|
|
||
| return rows.map((row) => ({ | ||
| inputs: toRecord(row.inputs) ?? {}, | ||
| expectations: toRecord(row.expectations), | ||
| })); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.