Metadata-Version: 2.4
Name: ai-eval-platform
Version: 1.0.0
Summary: Python SDK and `ai-eval` CI quality-gate CLI for the AI Evaluation Platform
Author: AssertThat
License-Expression: Apache-2.0
Project-URL: Homepage, https://ai-evaluation-platform.com
Project-URL: Documentation, https://ai-evaluation-platform.com/docs#ci
Project-URL: AWS Marketplace, https://aws.amazon.com/marketplace/pp/prodview-qejr2yng5xgc6
Project-URL: GitHub Action, https://github.com/marketplace/actions/ai-evaluation-platform-quality-gate
Keywords: llm,evaluation,llm-as-a-judge,quality-gate,ci,ragas,opentelemetry,tracing
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Quality Assurance
Classifier: Topic :: Software Development :: Testing
Classifier: Typing :: Typed
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# ai-eval-platform (Python SDK + CLI)

Standard-library-only client for the AI Evaluation Platform API, plus an `ai-eval` command
that runs an evaluation and fails your CI build when quality drops.

```bash
pip install ai-eval-platform
export AI_EVAL_API_KEY=...            # Settings > API keys in the app
export AI_EVAL_API_URL=https://api.ai-evaluation-platform.com
```

## Quality gate in CI

```bash
# 1. Your pipeline runs your app over the dataset's prompts and writes outputs.json:
#    {"case-1": "the app's answer", "case-2": "..."}
# 2. Evaluate and gate:
ai-eval run --project <project_id> --dataset <dataset_id> --outputs outputs.json \
    --fail-under pass_rate=0.9 --metric factual_accuracy=0.8 --version-label "$GIT_SHA"
```

- `--fail-under NAME=VALUE` (repeatable or comma-separated): `pass_rate` (share of cases
  where every metric meets its pass mark), `good_rate` (share labelled Good), or a run
  average: `overall`, `safety`, `truth`, `quality`.
- `--metric KEY=VALUE`: the run average of metric `KEY` must be at least `VALUE`; `VALUE`
  is also that metric's pass mark for `pass_rate`. Other metrics use the project's
  thresholds, else 0.70.
- Instead of a dataset: `--file cases.jsonl` (cases with `prompt`, `llm_output`, ...) or
  `--file results.csv` (uploaded with the same column mapping as the app), or
  `--job <job_id>` to gate a run that already exists.
- Exit code 0 = passed, 1 = gate failed, 2 = error (bad arguments, API error, timeout).
  `--report-json gate.json` writes the numbers for later steps.

The run shows up in the app with its version label, so you can compare it with the
previous build's run on the same dataset version.

### GitHub Actions

The [AI Evaluation Platform quality gate](https://github.com/marketplace/actions/ai-evaluation-platform-quality-gate)
action wraps the CLI:

```yaml
- run: python scripts/generate_outputs.py > outputs.json   # your app
- uses: assertthat/ai-eval-action@v1
  with:
    api-key: ${{ secrets.AI_EVAL_API_KEY }}
    project: ${{ vars.AI_EVAL_PROJECT }}
    dataset: ${{ vars.AI_EVAL_DATASET }}
    outputs: outputs.json
    fail-under: pass_rate=0.9
    metric-thresholds: factual_accuracy=0.8
```

### Bitbucket Pipelines

With the pipe:

```yaml
- step:
    name: LLM quality gate
    script:
      - python scripts/generate_outputs.py > outputs.json   # your app
      - pipe: docker://assertthat/ai-eval-pipe:1.0.0
        variables:
          AI_EVAL_API_KEY: $AI_EVAL_API_KEY
          PROJECT: $AI_EVAL_PROJECT
          DATASET: $AI_EVAL_DATASET
          OUTPUTS: outputs.json
          FAIL_UNDER: pass_rate=0.9
```

Or with the CLI directly:

```yaml
- step:
    name: LLM quality gate
    image: python:3.12-slim
    script:
      - pip install ai-eval-platform
      - python scripts/generate_outputs.py > outputs.json
      - ai-eval run --project $AI_EVAL_PROJECT --dataset $AI_EVAL_DATASET --outputs outputs.json
          --fail-under pass_rate=0.9 --version-label $BITBUCKET_COMMIT --run-name "$BITBUCKET_BRANCH"
```

(Set `AI_EVAL_API_KEY` as a secured repository variable.)

## Tracing agents

```python
from ai_eval import Client
from ai_eval.tracing import Tracer

tracer = Tracer(Client(), project_id="...")
with tracer.trace("support-agent", session_id=conversation_id, input=question) as t:
    with tracer.span("lookup_order", kind="tool", input={"id": 42}) as s:
        s.output = lookup_order(42)
    t.output = answer
```

Or point any OpenTelemetry OTLP/HTTP exporter at `<api>/v1/traces` with the header
`X-API-Key` - see the [tracing docs](https://ai-evaluation-platform.com/docs#traces).

## Production monitoring

```python
from ai_eval.monitor import Monitor

monitor = Monitor(Client(), project_id="...")          # sends in the background
monitor.log(prompt=question, llm_output=answer, id=request_id, latency_ms=812)
```

Turn monitoring on and set the sample rate per project in the app (Monitoring > Setup); only
sampled records are evaluated.

## Library use

```python
from ai_eval import Client, evaluate_gate

c = Client()
job = c.evaluate_batch(dataset_id="...", outputs={"case-1": "..."}, project_id="...",
                       version={"label": "v2", "model": "claude-sonnet", "prompt": open("system.txt").read()})
results = c.wait_for_results(job["job_id"])
gate = evaluate_gate(results, {"pass_rate": 0.9}, {"factual_accuracy": 0.8})
print(gate.passed, gate.stats["pass_rate"])
```

## Links

- Docs: https://ai-evaluation-platform.com/docs
- Buy on AWS Marketplace: https://aws.amazon.com/marketplace/pp/prodview-qejr2yng5xgc6
- Support: hello@ai-evaluation-platform.com
