Skip to main content

Internal Django SSE eval runner

Project description

dj-evals

Internal Django helper for running one eval function with multiple argument sets in parallel, so you can visually compare output, tool calls, usage, cost, and completion behavior as the runs happen.

Django setup

Add dj_evals to INSTALLED_APPS and mount your eval view:

INSTALLED_APPS = [
    "dj_evals",
]
from django.urls import path

urlpatterns = [
    path("evals/run/", eval_run),
]

Protect the eval view with your app's normal authorization checks before using it in production.

Usage

from dj_evals import handle_eval_request

async def eval_run(request):
    return await handle_eval_request(
        request,
        allowed_paths={"myapp.evals.echo_eval"},
    )

Generate a URL for the view with one or more eval argument dictionaries:

from dj_evals import generate_eval_url

url = "/evals/run/" + generate_eval_url(
    "myapp.evals.echo_eval",
    {"model": "gpt-4.1", "text": "hello"},
    {"model": "gemini-3-flash-preview", "text": "hello"},
)

The GET request renders the comparison page. The page starts one POST request per argument set. Each POST response is a direct SSE stream from the eval run, and the browser renders those events into the comparison panels.

Eval function contract

The eval function must be importable by dotted path and whitelisted in allowed_paths. It can be a sync or async function that returns one event, or an async generator that yields events.

def echo_eval(text="hello", model=""):
    return {"type": "response.output_text.delta", "delta": text}


async def async_eval(text="hello", model=""):
    return {"type": "response.output_text.delta", "delta": text}


async def streaming_eval(text="hello"):
    yield {"type": "response.output_text.delta", "delta": text}
    yield {"type": "response.completed", "response": {"cost": 0}}

Eval argument dictionaries are passed to the eval function as keyword arguments.

Helper utilities

You can yield EvalEvent for custom progress messages in the output panel:

from dj_evals import EvalEvent


async def streaming_eval():
    event: EvalEvent = {
        "type": "dj_evals.event",
        "message": "Fetched documents",
    }
    yield event

Developers

Run a local demo server to try the library in a browser:

uv run --with daphne daphne -p 8003 examples.local_server:application
# or, if you have just installed:
just run

Then open http://127.0.0.1:8003/. The demo redirects to an eval URL that starts three argument sets side by side and streams their events over SSE.

Run checks from this repo:

uv run --with ruff ruff check .
uv run --with pytest --with pytest-asyncio pytest -q
# or, if you have just installed:
just test

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

dj_evals-0.5.1.tar.gz (91.5 kB view details)

Uploaded Source

Built Distribution

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

dj_evals-0.5.1-py3-none-any.whl (89.4 kB view details)

Uploaded Python 3

File details

Details for the file dj_evals-0.5.1.tar.gz.

File metadata

  • Download URL: dj_evals-0.5.1.tar.gz
  • Upload date:
  • Size: 91.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for dj_evals-0.5.1.tar.gz
Algorithm Hash digest
SHA256 360fc1acee57d920b60b539010efec7ef0110e6b35be13597f9ed31a26425234
MD5 fd0f01679466c4d91327a0eabe4cbe96
BLAKE2b-256 1a0c72369b4b4f6ddb5721fa95ad85506db3880d75ea8699892c3e2370ca2e09

See more details on using hashes here.

File details

Details for the file dj_evals-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: dj_evals-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 89.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for dj_evals-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fcb0f7075f49a9ff6c22cb4c3fd0e35e1302693b4d8bc5fa6d6e94173576289c
MD5 7fa3eec9a7be0af9a4ff0481a5e0d800
BLAKE2b-256 a996f323f8d9544c7b989ea49b529238e7cf2698caec7b22fe99d82debdd120b

See more details on using hashes here.

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