Production-oriented procurement drift detection service built with FastAPI.
The backend now follows a modular structure:
src/api/: FastAPI app, routers, and route handlerssrc/services/: business logic (detection, simulation, ingestion, task orchestration)src/models/: Pydantic API contracts and task store primitivessrc/utils/: settings, database engine, logging, serialization helpers
Legacy paths (src/api/fastapi_app.py, src/agents/*) are kept as compatibility wrappers.
- Create a virtual environment and install dependencies:
python3.11 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt- Configure environment variables:
cp .env.example .env- Generate and ingest demo data:
python data_generator.py
python -c "from src.agents.ingestor import run; run()"- Start the API:
uvicorn src.api.main:app --reload --port 8000- (Optional) Start the frontend:
cd frontend
npm install
npm run devGET /api/health: health/version checkGET /api/leaks: current drift detectionsPOST /api/run-detection: start async detection taskGET /api/run-detection/{task_id}: poll task statusPOST /api/simulate-traffic: append synthetic traffic for demosPOST /api/vendors/rank: upload CSV and return weighted vendor rankingPOST /api/vendors/explain-ranking: upload ranked CSV and get short OpenAI business summary
Use weighted scoring to rank vendors from a CSV file.
CLI usage:
python scripts/rank_vendors.py input.csv -o ranked_vendors.csv --weights "unit_price:-0.5,on_time_rate:0.3,quality_score:0.2"Notes:
vendor_idis used by default as the vendor key (--vendor-columnto change).- Positive weight means higher metric is better.
- Negative weight means lower metric is better (for example cost/price/risk metrics).
Generate a short, business-focused summary from ranked vendor results:
python scripts/explain_vendor_ranking.py ranked_vendors.csv --top-n 3Required environment variable:
OPENAI_API_KEY
Run an interactive app to upload CSV, rank vendors, and generate a short explanation:
streamlit run streamlit_app.pyIn the app:
- Upload vendor metrics CSV
- Set optional weights and vendor column
- View ranked vendors and download ranked output CSV
- Generate a short business-focused explanation with OpenAI
docker build -t procurement-agent .
docker run -p 8000:8000 procurement-agentThe API is exposed at http://localhost:8000.