ghazaljohri/agentic-router-pro
0
Agentic Model Router โ Pro
This Space runs a FastAPI app with multiple models routed automatically through a Docker backend.
๐งฉ Features
- One endpoint (
/query) that auto-routes to the best model (or force a task) - API Key authentication (header
x-api-key) - Prometheus metrics at
/metrics(request count, latency, task labels) - Optional Redis response cache
- Minimal, pretty web UI
- Tests + Dockerfile
โ๏ธ Environment
- Python 3.11 recommended
- macOS Apple Silicon (M1/M2/M3/M4):
torchfrom PyPI supports CPU and Metal (MPS). Pip will choose the right wheel.
๐ Run (Local)
python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
export API_KEY=dev-secret-123 # change this
./run_local.sh
# open http://localhost:8000UI calls require the key; enter it in the top-right field (the UI includes it on requests).
๐ API Usage
curl -X POST http://localhost:8000/query -H 'Content-Type: application/json' -H 'x-api-key: dev-secret-123' -d '{"text":"Translate this to Hindi: I am learning AI.","task":"auto"}'๐ Metrics
Visit http://localhost:8000/metrics for Prometheus exposition format. Add to Grafana via Prometheus data source.
๐ณ Docker
docker build -t agentic-router-pro .
docker run -p 8000:8000 -e API_KEY=dev-secret-123 agentic-router-proโ๏ธ Deploy
- Render: Docker Web Service โ set
API_KEY, (optional)ENABLE_REDIS=true,REDIS_URL=.... - Hugging Face Spaces: Space (Docker) โ expose port
8000โ setAPI_KEYsecret.
๐งช Tests
pytest -qNotes
- For Apple Silicon, PyTorch will use CPU by default. To try Metal (MPS), set
PYTORCH_ENABLE_MPS_FALLBACK=1; pipelines will still run even if ops fall back to CPU. - You can swap the heuristic router with a learned classifier for extra credit.
