Skip to main content

Provider-agnostic A/B testing for LLM systems

Project description

modelab

Provider-agnostic A/B testing for LLM systems in production.

Two components:

  1. Python SDK — zero-dependency library for assignment, tracking, and evaluation
  2. Server + Dashboard — self-hosted FastAPI + React app for visualization (Docker Compose)

Quick Start

SDK (local development)

pip install modelab
import modelab
from modelab import Flag, Variant, EvalContext

# Initialize — point to the modelab server
modelab.init(
    server="http://localhost:8100",
    flags=[
        Flag(
            name="summarizer_v2",
            variants=[
                Variant("control", weight=50, config={"model": "gpt-3.5-turbo", "prompt": "Summarize: {input}"}),
                Variant("treatment", weight=50, config={"model": "gpt-4", "prompt": "Concisely summarize: {input}"}),
            ],
            rollout_pct=100,
        ),
    ],
)

# Assign a variant
ctx = EvalContext(user_id="user_123", session_id="abc")
assignment = modelab.assign("summarizer_v2", ctx)

if assignment is None:
    # Outside rollout — use default behavior
    response = call_llm(model="gpt-3.5-turbo", prompt=text)
else:
    # In experiment — use assigned variant config
    response = call_llm(
        model=assignment.config["model"],
        prompt=assignment.config["prompt"].format(input=text),
    )
    assignment.record(response, cost=0.013)
    assignment.mark_success()

# Evaluate results
results = modelab.evaluate("summarizer_v2")
print(results)

Self-Hosted Server + Dashboard

docker compose up

This starts:

  • PostgreSQL on port 5432
  • modelab server + dashboard on port 8100

Concepts

Flags

An experiment with one or more variants and a rollout percentage (0-100%).

Variants

Each variant has a name, weight (for traffic splitting), and a config dict you use to parameterize your LLM calls.

Assignment

Deterministic — the same (flag_name, user_id) always maps to the same variant. Uses MD5 hashing into 10,000 buckets for 0.01% rollout granularity.

Recording

Use assignment.record(response) to capture execution metrics. Token counts are automatically extracted from the response object via duck-typing (supports OpenAI and Anthropic response formats). Cost, latency, error, and arbitrary metadata can be passed as keyword arguments:

assignment.record(response, cost=0.013, latency_ms=250.0, model="gpt-4o")

You can also record without a response object:

assignment.record(input_tokens=50, output_tokens=100, cost=0.01)

Events

Mark assignments as success/failure or record custom events (e.g., "copied", "thumbs_up").

Evaluation

modelab.evaluate(flag_name) returns per-variant metrics: success rate, avg latency, avg cost, token usage, and custom event counts.

Server API

Ingestion (from SDK)

POST /api/v1/ingest/assignments    (batch)
POST /api/v1/ingest/executions     (batch)
POST /api/v1/ingest/events         (batch)

Dashboard API

GET /api/v1/flags                  — list flags with summary stats
GET /api/v1/flags/{name}           — detailed per-variant evaluation
GET /api/v1/flags/{name}/timeline  — time-series metrics

Development

# Install in dev mode
pip install -e ".[dev]"

# Run tests
pytest

# Run dashboard dev server
cd dashboard && npm install && npm run dev

# Run API server (requires Postgres)
uvicorn server.app:app --reload --port 8100

Architecture

Developer's App
│
├── modelab SDK (pip install modelab)
│   └── ServerStorage ──HTTP POST──▶ modelab-server
│
modelab-server (docker compose up)
├── FastAPI backend
├── React dashboard (served as static files)
└── PostgreSQL

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

modelab-0.1.0.tar.gz (55.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

modelab-0.1.0-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file modelab-0.1.0.tar.gz.

File metadata

  • Download URL: modelab-0.1.0.tar.gz
  • Upload date:
  • Size: 55.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for modelab-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d3551d9ff1564ea5ff3969c6fd7413cd9b1519acb78c828e4a903c5f34ad5199
MD5 527353b1d80ef7daa2e7f1e7286f1e4e
BLAKE2b-256 af428d8808385d9f2f6cf27bb7b64879f32e7693e3e0d8167deed213b42d6ea0

See more details on using hashes here.

Provenance

The following attestation bundles were made for modelab-0.1.0.tar.gz:

Publisher: publish.yml on elliot736/modelab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file modelab-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: modelab-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for modelab-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1c0e0eae069afdb078276a1198d71e152bc47fff2beb49735c569b5b13af2f24
MD5 e0188e99cf7e087c696c6b2621f1febc
BLAKE2b-256 ba326e944adf4faa4a119583170759599fad7947530dd1b883fea8514cb66377

See more details on using hashes here.

Provenance

The following attestation bundles were made for modelab-0.1.0-py3-none-any.whl:

Publisher: publish.yml on elliot736/modelab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page