No description
Find a file
2026-03-24 16:22:58 +01:00
data Add src/ for functional adaption. 2026-03-24 14:58:48 +01:00
src Add src/ for functional adaption. 2026-03-24 14:58:48 +01:00
.gitignore Add src/ for functional adaption. 2026-03-24 14:58:48 +01:00
CLAUDE.md Add src/ for functional adaption. 2026-03-24 14:58:48 +01:00
pyproject.toml Add src/ for functional adaption. 2026-03-24 14:58:48 +01:00
README.md Update README.md content 2026-03-24 16:22:58 +01:00
test_run.py Add src/ for functional adaption. 2026-03-24 14:58:48 +01:00
TEXT2SQL_REFERENCE.md Add src/ for functional adaption. 2026-03-24 14:58:48 +01:00
uv.lock Add src/ for functional adaption. 2026-03-24 14:58:48 +01:00

demo-t2sql

A text-to-SQL workflow package. Accepts a natural language question, generates SQL via an LLM (Ollama/llama3.2), runs it against a SQLite database (Chinook), and streams back the SQL, result rows, and a plain-English summary.

Designed to be called by an external platform.


How it works

question → ChromaDB (RAG context) → Ollama (SQL generation) → SQLite (execution) → summary
  1. ChromaDB retrieves relevant schema/examples as context
  2. llama3.2 generates SQL from that context
  3. SQL runs against data/Chinook.sqlite
  4. llama3.2 summarises the results in plain English

Setup

uv sync
ollama pull llama3.2

The ChromaDB knowledge base is pre-populated. If you need to rebuild it, run data/setup_knowledge.py once.


Entry points

File Style Use when
src/default.py Linear, simple Standard use
src/workflow.py pydantic_graph nodes Need branching/conditional logic

Both expose the same signature:

async def run_workflow(request: QueryRequestModel, llm_id: str = "default", **kwargs)
    -> AsyncGenerator[ResponseEventToken | ResponseEventNode | ResponseEventProgress, None]

Key files to edit

What you want to change File
Switch LLM (Ollama ↔ OpenAI) src/tools/vanna_client.py
Customise the summary prompt src/tools/vanna_client.py — uncomment generate_summary override
Add/change pipeline steps src/default.py
Add graph nodes / branching src/nodes/ + src/workflow.py
Retrain the knowledge base data/setup_knowledge.py

Switching to OpenAI

In src/tools/vanna_client.py, uncomment the OpenAI import and class, comment out the Ollama ones, and set your key:

# "model": "gpt-4o",
# "api_key": os.environ["OPENAI_API_KEY"],