Metadata-Version: 2.4
Name: bidradar
Version: 0.1.0
Summary: Local-first AI bid intelligence on Australian Government procurement data (AusTender).
Author: Deep Mehta
License-Expression: MIT
Keywords: austender,procurement,tenders,rag,text-to-sql,langgraph,ollama,pgvector,australia
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Operating System :: MacOS
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: httpx>=0.27
Requires-Dist: psycopg[binary]>=3.2
Requires-Dist: openai>=1.50
Requires-Dist: fastapi>=0.115
Requires-Dist: uvicorn[standard]>=0.30
Requires-Dist: langgraph>=0.2
Requires-Dist: langchain-core>=0.3
Requires-Dist: langchain-openai>=0.2
Requires-Dist: opentelemetry-sdk>=1.27
Requires-Dist: opentelemetry-exporter-otlp-proto-http>=1.27
Requires-Dist: openinference-instrumentation-langchain>=0.1
Provides-Extra: eval
Requires-Dist: inspect-ai>=0.3; extra == "eval"
Requires-Dist: deepeval>=2.0; extra == "eval"
Requires-Dist: pytest>=8.0; extra == "eval"
Provides-Extra: mlx
Requires-Dist: mlx-lm>=0.20; (sys_platform == "darwin" and platform_machine == "arm64") and extra == "mlx"
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == "dev"
Requires-Dist: ruff>=0.6; extra == "dev"
Requires-Dist: build>=1.2; extra == "dev"
Requires-Dist: twine>=5; extra == "dev"
Provides-Extra: all
Requires-Dist: bidradar[eval,mlx]; extra == "all"
Dynamic: license-file

# BidRadar 🇦🇺: AI bid intelligence on Australian Government contracts

Ask questions about **Australian Government contracts** in plain English, and get a **re-tender radar**:
contracts like yours that are about to expire, who holds them now, and what they're worth.

It runs **locally on a Mac (Apple Silicon)** using open-source models and free public data
(the AusTender OCDS API, which needs no key). No data leaves your machine.

> *"Which agencies spent the most on IT services this financial year, and who won?"*
> *"We're a Canberra data analytics firm. Which contracts like ours expire in the next 9 months?"*
> *"What market share does Accenture have in each UNSPSC family?"*

## Install

```bash
pip install bidradar                 # core: pipeline, agent, API, CLI
pip install "bidradar[eval]"         # + Inspect AI and DeepEval evaluations
pip install "bidradar[mlx]"          # + MLX fine-tuning and serving (Apple Silicon)
pip install "bidradar[all]"
```

You also need [Ollama](https://ollama.com) and Docker (OrbStack or Docker Desktop). Python 3.11 or later.

## Quickstart

```bash
bidradar init ~/bidradar && cd ~/bidradar   # creates docker-compose.yml, LiteLLM config, SQL schema, .env
bidradar models                             # pull qwen2.5-coder:7b + nomic-embed-text into Ollama
bidradar up                                 # Postgres+pgvector, LiteLLM, Phoenix, Open WebUI

bidradar ingest --days 180                  # contracts published in the last 180 days
bidradar expiring --months 12               # contracts ending in the next 12 months
bidradar embed                              # vectors for semantic search and the radar

bidradar ask "Top 5 agencies by total contract value this financial year"
bidradar serve                              # agent API (keep running), then open http://localhost:3000
bidradar health                             # check every service, the data and the models
```

In Open WebUI choose the model **bidradar**. Traces are at http://localhost:6006, in the **bidradar** project.

## Commands

| Command | What it does |
|---|---|
| `init [dir]` | Create a workspace (Docker Compose, LiteLLM config, SQL schema, `.env`) |
| `up` / `down` | Start and stop the Docker services |
| `models` | Pull the local models into Ollama |
| `ingest --days N` | Load contracts published in the last N days (4 days fetched in parallel) |
| `expiring --months N` | Load contracts ending in the next N months |
| `incremental` | Load new and amended notices since the last run |
| `embed` | Embed contracts that don't have a vector yet (resumable) |
| `daily` / `schedule` / `unschedule` | Daily refresh, and run it every morning via launchd |
| `ask "…"` | Ask the agent a question in the terminal, with a step-by-step log |
| `serve` | OpenAI-compatible API for the agent (model id `bidradar`) |
| `health` | Check Ollama, LiteLLM, Phoenix, Open WebUI, the API, Postgres and the models |
| `eval sql --model sql-base` | Inspect AI: text-to-SQL execution accuracy on 20 held-out questions |
| `eval agent` | DeepEval: answer groundedness and relevance, judged by a local model |
| `finetune data \| train \| serve` | Synthetic NL→SQL data from your warehouse, MLX LoRA training, serving on :8081 |
| `bench --models sql-base sql-ft` | Serving benchmark (latency and throughput) through the gateway |

## Architecture

```
 AusTender OCDS API (CC BY 3.0 AU) ──▶ pipeline: bronze (raw JSON) → silver (contracts) → gold (FY views)
                                                                  │ embeddings → pgvector (HNSW)
                                                                  ▼
 LangGraph agent: route → write SQL → guard → read-only run (repair ×2) │ vector search / radar → grounded answer
        │ OpenAI-compatible API (bidradar serve)                         traces → Phoenix
        ▼
 Open WebUI ── LiteLLM gateway ── Ollama (Qwen) · mlx_lm.server (fine-tuned) · vllm-metal (optional)
```

- **Safe SQL in three layers:** a guard (single read-only SELECT/WITH, blocked keywords and schemas, forced LIMIT),
  a read-only Postgres role, and a read-only transaction with a timeout.
- **Grounded answers:** answers come only from the rows retrieved, show the SQL that ran, cite contract IDs,
  and state the date range the data covers.
- **Local-first:** every model runs on your Mac through LiteLLM aliases, so engines can be swapped without code changes.

## Configuration

Settings are read from `.env` in the current directory (the workspace created by `bidradar init`):
database DSNs, the LiteLLM URL and key, the model aliases (`CHAT_MODEL`, `SQL_MODEL`, `EMBED_MODEL`), the embedding
dimension and the tracing endpoint. Model aliases map to engines in `litellm/config.yaml`.

## Development

```bash
git clone <repo> && cd bidradar
pip install -e ".[dev]"
pytest -q && ruff check .
python -m build && twine check dist/*
```

## Data and licence

AusTender material is from the Department of Finance, licensed under CC BY 3.0 AU. BidRadar is not affiliated with
or endorsed by the Department of Finance. Verify all details at www.tenders.gov.au. The code is MIT-licensed.
