Skip to content

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.py differs.

Level · IntermediateDuration · ~1.5 hoursChapters · 7Stack · Streamlit + Python + SQLite + OpenAI API + Plotly
You wantYou pick
Privacy, no API key, no recurring costProject 1 — Ollama
Sub-second answers, max accuracy, OK with cloudThis 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 1

The 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.

  • A Streamlit app on http://127.0.0.1:8505 that:

    • 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.
  • A clear understanding of:

    • the 4 ways openai.chat.completions.create() differs from ollama.chat(),
    • the cost per question (spoiler: under $0.001),
    • the privacy trade-off and how to mitigate it,
    • the .env + .gitignore pattern to never leak an API key.
#ChapterDurationType
01Overview and goals8 minTheory
02Setting up the environment + API key10 minHands-on
03llm.py side-by-side: Ollama vs OpenAI15 minCode
04The OpenAI agent loop with SQL tool20 minCode
05Running the app step-by-step12 minGuided
06Cost, latency, accuracy comparison10 minAnalysis
07API key security and going further10 minTheory

Before starting:

  • ✅ You’ve read at least chapters 04–08 of Project 1, or you’re comfortable with ingest.py / db.safe_query() / the SQL_TOOL spec.
  • ✅ 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.
  • 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.

Start with chapter 01 →