How nodero-group-project/ade-chat-assistant-backend works
This is a FastAPI backend for answering questions with Stats NZ data and managing the dataset catalogue. In the report workflow, the API classifies a question, rejects low-confidence matches, loads the chosen dataset, asks a routed Groq model to form a Stats NZ URL, retrieves data, and returns results with token usage. Dataset CRUD is a separate API capability backed by PostgreSQL. The excerpts show the main calls and integrations; unsampled modules and undocumented wiring are omitted.
Main entry points: main.py FastAPI endpoints · intent_classification.py Dataset selection · llm_query.py StatsNZ URL generation · db.py Dataset repository
Components 13
API
- FastAPI endpoints
app/main.py
Dataset catalogue
- Dataset schema
app/models/Dataset.py - Catalogue access
app/datasets.py - Dataset repository
app/db.py
Question processing
- Dataset selection
app/intent_classification.py - Model tier routing
app/heuristic_router.py - StatsNZ URL generation
app/llm_query.py - Token accounting
app/llm_usage.py
External services
- PostgreSQL
- Groq
- Stats NZ API
- Stats NZ client
app/services/stat_nz.py
Other components
- Client
Connections 16
- Client → FastAPI endpoints: submits requests
app/main.py - FastAPI endpoints → Dataset selection: classifies question
app/main.py - Dataset selection → Catalogue access: loads candidates
app/intent_classification.py - Catalogue access → Dataset repository: reads datasets
app/datasets.py - Dataset repository → PostgreSQL: reads and writes
app/db.py - FastAPI endpoints → Dataset repository: manages datasets
app/main.py - FastAPI endpoints → Dataset schema: validates dataset input
app/main.py - FastAPI endpoints → StatsNZ URL generation: requests URL
app/main.py - StatsNZ URL generation → Model tier routing: selects tier
app/llm_query.py - Dataset selection → Groq: requests classification
app/intent_classification.py - StatsNZ URL generation → Groq: requests URL
app/llm_query.py - StatsNZ URL generation → Token accounting: logs tokens
app/llm_query.py - Dataset selection → Token accounting: logs tokens
app/intent_classification.py - FastAPI endpoints → Token accounting: combines usage
app/main.py - FastAPI endpoints → Stats NZ client: fetches results
app/main.py - Stats NZ client → Stats NZ API: sends GET request
app/services/stat_nz.py