Spaces:
Sleeping
Sleeping
File size: 5,169 Bytes
007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 5f7588b 1065f91 5f7588b 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd 1065f91 007fbdd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | # Deployment Guide
This guide explains how to run LedgerShield locally, in Docker, or as a Docker-backed Hugging Face Space, and documents the runtime environment variables that control benchmark behavior.
## Deployment Modes
### Local Python process
Best for development and testing.
```bash
python -m venv .venv
source .venv/bin/activate
pip install -e .
pip install -r requirements.txt
python -m server.app
```
Default bind:
- host: `0.0.0.0`
- port: `8000`
Health check:
```bash
curl http://127.0.0.1:8000/health
```
### Docker
The repo ships with a ready-to-build [`../Dockerfile`](../Dockerfile).
Build:
```bash
docker build -t ledgershield:latest .
```
Run:
```bash
docker run --rm -p 8000:8000 ledgershield:latest
```
Smoke test:
```bash
curl http://127.0.0.1:8000/health
```
### Hugging Face Spaces
The root `README.md` includes Docker Space front matter, and `openenv.yaml` describes the benchmark metadata. For a Docker Space deployment:
1. create a new Hugging Face Space using the Docker SDK
2. push this repo contents to the Space
3. ensure the Space exposes port `8000`
4. verify `/health`, `/reset`, and `/step`
### CI-backed validation
GitHub Actions already validates:
- Python test runs
- Docker build and container smoke test
- `openenv.yaml` integrity
See [`../.github/workflows/ci.yml`](../.github/workflows/ci.yml).
## Runtime Environment Variables
### Server bind settings
| Variable | Default | Meaning |
|---|---|---|
| `HOST` | `0.0.0.0` | bind host used by `server.app:main` |
| `PORT` | `8000` | bind port used by `server.app:main` |
### Case-loader controls
These are read by [`../server/data_loader.py`](../server/data_loader.py).
| Variable | Default | Meaning |
|---|---|---|
| `LEDGERSHIELD_INCLUDE_CHALLENGE` | `true` | include generated challenge variants in the loaded case pool |
| `LEDGERSHIELD_CHALLENGE_VARIANTS` | `2` | number of generated challenge variants per hard case |
| `LEDGERSHIELD_CHALLENGE_SEED` | `2026` | RNG seed for challenge generation |
| `LEDGERSHIELD_INCLUDE_HOLDOUT` | `false` | include generated holdout cases in the loaded case pool |
| `LEDGERSHIELD_HOLDOUT_VARIANTS` | `1` | holdout variants per hard case |
| `LEDGERSHIELD_HOLDOUT_SEED` | `31415` | RNG seed for holdout generation |
| `LEDGERSHIELD_INCLUDE_TWINS` | `false` | include benign contrastive twins in the loaded case pool |
### Agent-side variables
Common variables used by `inference.py` and related scripts:
| Variable | Typical use |
|---|---|
| `API_BASE_URL` | OpenAI-compatible API endpoint |
| `MODEL_NAME` | model name for inference (determines `ModelCapabilityProfile` tier) |
| `HF_TOKEN` | token used by the submission-safe agent |
| `OPENAI_API_KEY` | credential for live comparison scripts |
| `ENV_URL` | environment server base URL |
| `LOCAL_IMAGE_NAME` | optional Docker image name for local environment use |
| `LEDGERSHIELD_DEBUG` | set to `1` to enable stderr output from the inference agent (default: stderr suppressed) |
## Operational Checks
### Basic API checks
```bash
curl http://127.0.0.1:8000/health
curl http://127.0.0.1:8000/
```
### Reset a known case
```bash
curl -X POST http://127.0.0.1:8000/reset \
-H 'Content-Type: application/json' \
-d '{"case_id":"CASE-A-001"}'
```
### Run benchmark report generation locally
```bash
python benchmark_report.py --format markdown
```
Generated artifacts land under `artifacts/` when written.
## Recommended Deployment Profiles
### Minimal benchmark server
Use this when you only need the curated benchmark and generated challenge variants:
```bash
HOST=0.0.0.0 PORT=8000 python -m server.app
```
### Public benchmark only
Disable generated challenge variants:
```bash
LEDGERSHIELD_INCLUDE_CHALLENGE=0 python -m server.app
```
### Holdout-enabled evaluation server
```bash
LEDGERSHIELD_INCLUDE_HOLDOUT=1 \
LEDGERSHIELD_HOLDOUT_VARIANTS=1 \
python -m server.app
```
### Calibration-heavy server with twins
```bash
LEDGERSHIELD_INCLUDE_TWINS=1 python -m server.app
```
## Production Notes
LedgerShield is still a benchmark, not a payment system. For production-like hosting:
- terminate TLS outside the app
- health-check `/health`
- treat the service as stateless and restartable
- version-control `openenv.yaml` and benchmark artifacts
- avoid mixing benchmark servers with live finance systems
## Troubleshooting
### Server starts but endpoints fail
Check:
- port `8000` is not already in use
- dependencies from `requirements.txt` are installed
- you are running from the repo root so fixture paths resolve correctly
### Docker container builds but health check fails
Check:
- `curl http://localhost:8000/health`
- container logs for import/path issues
- whether your host already has something bound to `8000`
### Unexpected case counts
Remember that the loader includes challenge variants by default. If you expect only the curated 21-case benchmark, set:
```bash
LEDGERSHIELD_INCLUDE_CHALLENGE=0
```
### Missing benchmark report endpoint data
`/benchmark-report` and `/leaderboard` only return rich artifacts after report generation. Run:
```bash
python benchmark_report.py --format json
```
|