No description
- Python 100%
| data | ||
| src | ||
| .gitignore | ||
| CLAUDE.md | ||
| pyproject.toml | ||
| README.md | ||
| test_run.py | ||
| TEXT2SQL_REFERENCE.md | ||
| uv.lock | ||
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
- ChromaDB retrieves relevant schema/examples as context
- llama3.2 generates SQL from that context
- SQL runs against
data/Chinook.sqlite - 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"],