Evalite Documentation

repository·main·Indexed 23 days ago

https://github.com/mattpocock/evalite

A TypeScript-native, local-first tool for testing LLM-powered applications. Built on top of Vitest, Evalite provides a terminal UI for prototyping, supports tracing and custom scorers, and includes a UI server for viewing evaluation results. Key features include watch mode for automatic re-runs, threshold-based failure for CI/CD, and integration with Vercel AI SDK via traceAISDKModel.

Tokens
18.6K
Snippets
51
Records
96
Agent score
81%

What's inside Evalite

  1. What is Evalite?

    main

    Evalite is a TypeScript-native, local-first tool designed for testing LLM-powered applications. It is built on top of Vitest and provides a terminal UI for quick prototyping. Key features include:

    • Open Source: No API keys are required for the core tool.
    • Local-first: Runs entirely on your machine to ensure data privacy.
    • Extensible: Supports tracing and custom scorers.
    • Vitest-based: Leverages the Vitest TypeScript test runner.
  2. Overview of Evalite features

    main

    Evalite is a TypeScript-native tool designed to simplify testing AI-powered applications. Key features include:

    • TypeScript-native testing: Use .eval.ts files with an API that is familiar to TypeScript developers.
    • Local Interactive UI: Run a local dev server to explore outputs, traces, and logs in an interactive interface.
    • Vitest Integration: Built on top of Vitest, allowing you to use existing mocks, fixtures, and testing patterns.
    • LLM Agnostic: No vendor lock-in; you can work with any LLM and compare outputs from different models.
    • CI/CD Ready: Export evaluations as static HTML bundles and use score thresholds to determine build success or failure.
  3. Key features of Evalite

    main

    Evalite is a local-first, TypeScript-native tool designed for testing LLM-powered apps. Key features include:

    • Local Execution: Runs entirely on your machine with a local server on localhost and live reload, ensuring data privacy and no vendor lock-in.
    • Standard Tooling: Based on Vitest, allowing the use of familiar mocks and lifecycle hooks.
    • Observability: Supports capturing traces and building custom scorers.
    • File Format: Uses .eval.ts files for defining evaluation logic.
  4. Understand the Starlight project structure

    main

    A standard Starlight project follows this directory structure:

    • src/content/docs/: The primary location for documentation. Starlight automatically exposes .md or .mdx files in this directory as routes based on their filenames.
    • src/assets/: Place images here to embed them in Markdown using relative links.
    • public/: Place static assets like favicons here.
    • astro.config.mjs: The Astro configuration file.
    • package.json: Project dependencies and scripts.
    • tsconfig.json: TypeScript configuration.
    .
    ├── public/
    ├── src/
    │   ├── assets/
    │   ├── content/
    │   │   ├── docs/
    │   │   └── config.ts
    │   └── env.d.ts
    ├── astro.config.mjs
    ├── package.json
    └── tsconfig.json
  5. Measure variance using trialCount

    main

    To measure variance in non-deterministic evaluations, you can run each test case multiple times using trialCount.

    • Global configuration: Set trialCount in evalite.config.ts to apply it to all evals.
    • Per-eval override: Pass trialCount directly into the evalite() function call. Per-eval settings take precedence over the global config.
    // Global configuration
    import { defineConfig } from "evalite/config";
    
    export default defineConfig({
      trialCount: 3, // Run each test case 3 times
    });
    
    // OR Per-eval override
    
    evalite("Non-deterministic eval", {
      data: () => [{ input: "Alice", expected: "Alice" }],
      task: async (input) => {
        // Non-deterministic task
        return getRandomGreeting(input);
      },
      scorers: [
        /* ... */
      ],
      trialCount: 5, // Override config: run 5 times
    });
  6. Configure Evalite run modes

    main

    The mode option determines how the runner behaves:

    • run-once-and-exit: Runs all evaluations once and then terminates. This is the recommended mode for CI/CD pipelines.
    • watch-for-file-changes: Watches for file changes and automatically re-runs evaluations. This mode also starts the Evalite UI server.

    Note: When using watch-for-file-changes, it is strongly recommended to implement a caching layer for your LLM calls to avoid excessive API costs during rapid re-runs.

  7. Quickstart: Set up Evalite in an existing project

    main

    Follow these steps to integrate Evalite into your project for testing LLM-powered applications.

    1. Install dependencies: Install evalite, vitest, and a scoring library (e.g., autoevals).

      pnpm add -D evalite vitest autoevals
    2. Configure dev script: Add an eval:dev script to your package.json to enable the watch mode.

      {
        "scripts": {
          "eval:dev": "evalite watch"
        }
      }
    3. Create an eval file: Create a file with the .eval.ts extension. This extension is required for Evalite to scan and discover your evals.

    4. Run the dev environment: Execute pnpm run eval:dev. This command:

      • Runs the data array/function to retrieve test data.
      • Executes the task function for each data point.
      • Scores the results using the provided scorers.
      • Persists results to a SQLite database located in node_modules/.evalite.
      • Starts a UI at http://localhost:3006 to view traces, scores, inputs, and outputs.
    5. View results: Open http://localhost:3006 in your browser.

    pnpm add -D evalite vitest autoevals
    
    # Add to package.json
    "eval:dev": "evalite watch"
    
    # Run it
    pnpm run eval:dev