CoolFace
Apppublic

ghazaljohri/agentic-router-pro

sourceHugging Faceupdated 10mo agoView on Hugging Face
0likes
App README

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): torch from PyPI supports CPU and Metal (MPS). Pip will choose the right wheel.

๐Ÿš€ Run (Local)

bash
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:8000

UI calls require the key; enter it in the top-right field (the UI includes it on requests).

๐Ÿ” API Usage

bash
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

bash
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 โ†’ set API_KEY secret.

๐Ÿงช Tests

bash
pytest -q

Notes

  • โ€”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.