| title | summary |
|---|---|
Text2SQL Example |
Convert natural language queries into SQL statements using AI models. |
This demo shows how to build an AI-powered interface that converts natural-language questions into SQL queries and executes them against TiDB. Built with pytidb (the official Python SDK for TiDB), OpenAI GPT, and Streamlit, it lets you query your database using plain English.
Before you begin, ensure you have the following:
- Python (>=3.10): Install Python 3.10 or a later version.
- A TiDB Cloud Starter cluster: You can create a free TiDB cluster on TiDB Cloud.
- OpenAI API key: Get an OpenAI API key from OpenAI.
git clone https://github.com/pingcap/pytidb.git
cd pytidb/examples/text2sql/python -m venv .venv
source .venv/bin/activate
pip install -r reqs.txtstreamlit run app.pyOpen your browser and visit http://localhost:8501.
- Enter your OpenAI API key in the left sidebar
- Enter the TiDB connection string in the left sidebar, for example:
mysql+pymysql://root@localhost:4000/test
- Source Code: View on GitHub