Project 2 — Card-spending analysis with OpenAI (cloud)
Audience: students who finished Project 1 or want the fastest version of the spending analyzer. ~95% of the code is identical; only
llm.pydiffers.
Why a cloud variant
Section titled “Why a cloud variant”| You want | You pick |
|---|---|
| Privacy, no API key, no recurring cost | Project 1 — Ollama |
| Sub-second answers, max accuracy, OK with cloud | This project (OpenAI) |
The OpenAI variant is built specifically to answer the question: “How would the same app look if I replaced ollama.chat() with openai.chat.completions.create()?”
Spoiler: the diff is ~40 lines. Everything else (ingestion, normalization, SQLite, dashboards, the query_sql tool spec, the system prompt) is byte-for-byte identical.
Architecture (same as Project 1, different LLM)
Section titled “Architecture (same as Project 1, different LLM)” bank CSV (data1-anonymized.csv, 734 rows) │ ▼ ┌─────────────────────────┐ │ csv-llm-shared/ │ ← shared Python module (Project 3) └────────────┬────────────┘ │ ▼ csv-llm-openai/ port 8505 ← (Project 1 was 8504) gpt-4o-mini app.py + llm.py ← only llm.py differs from Project 1The two apps can even run side-by-side on the same machine: csv-llm-ollama on 127.0.0.1:8504, csv-llm-openai on 127.0.0.1:8505. Same SQLite schema, separate .cache/ databases.
What you’ll have at the end
Section titled “What you’ll have at the end”-
A Streamlit app on
http://127.0.0.1:8505that:- loads
csv-llm-openai/data/data1-anonymized.csv; - shows the same 4 dashboards as Project 1;
- answers your 4 canonical questions in ~2 seconds instead of ~10.
- loads
-
A clear understanding of:
- the 4 ways
openai.chat.completions.create()differs fromollama.chat(), - the cost per question (spoiler: under $0.001),
- the privacy trade-off and how to mitigate it,
- the
.env+.gitignorepattern to never leak an API key.
- the 4 ways
The 7 chapters
Section titled “The 7 chapters”| # | Chapter | Duration | Type |
|---|---|---|---|
| 01 | Overview and goals | 8 min | Theory |
| 02 | Setting up the environment + API key | 10 min | Hands-on |
| 03 | llm.py side-by-side: Ollama vs OpenAI | 15 min | Code |
| 04 | The OpenAI agent loop with SQL tool | 20 min | Code |
| 05 | Running the app step-by-step | 12 min | Guided |
| 06 | Cost, latency, accuracy comparison | 10 min | Analysis |
| 07 | API key security and going further | 10 min | Theory |
Prerequisites checklist
Section titled “Prerequisites checklist”Before starting:
- ✅ You’ve read at least chapters 04–08 of Project 1, or you’re comfortable with
ingest.py/db.safe_query()/ theSQL_TOOLspec. - ✅ You have an OpenAI account with at least $1 of credit (one cent is enough for the whole course; $1 is the minimum payment).
- ✅ Python 3.9+, pip, and the
csv-llm-shared/repo already cloned.
How to read this course
Section titled “How to read this course”- Linear: 01 → 07. About 1.5 hours.
- Already finished Project 1: skip 01, jump to 03. About 1 hour.
- Just run the app: 02 → 05. 25 min.
← Coming from Project 1 — Ollama? You’ll feel right at home. → Want to deep-dive the shared library powering both apps? Head to Project 3 — csv-llm-shared.