A clean, minimal implementation of a dynamic PostgreSQL Text-to-SQL converter using OpenAI's GPT-4o-mini model.
- 🔍 Dynamic PostgreSQL: Connect to any PostgreSQL database
- 🤖 GPT-4o-mini: AI-powered natural language to SQL conversion
- 📊 Schema Analysis: Automatic table and column detection
- ⚡ Token Optimized: Efficient for large databases
- 🎨 Clean UI: Simple, focused interface with schema info page
langchain-example/
├── app_clean.py # Main application (342 lines)
├── config.env # Environment configuration
├── requirements.txt # Python dependencies
└── README.md # This file
-
Install Dependencies:
pip install -r requirements.txt
-
Configure Environment:
- Copy your OpenAI API key to
config.env
- Format:
OPENAI_API_KEY=sk-your-actual-api-key-here
- Copy your OpenAI API key to
-
Run the App:
streamlit run app_clean.py
-
Connect to PostgreSQL:
- Enter your database credentials in the sidebar
- Click "Connect" to establish connection
- Enter natural language queries
- Generate SQL using GPT-4o-mini
- Execute queries and view results
- View database metrics
- Explore table structures
- See sample data
- Python 3.8+
- PostgreSQL database
- OpenAI API key
- Valid database credentials
streamlit
- Web interfacepandas
- Data handlingsqlalchemy
- Database ORMpsycopg2-binary
- PostgreSQL adapterlangchain-openai
- OpenAI integrationpython-dotenv
- Environment management
- Minimal Code: Only essential functionality
- Fast Loading: No unnecessary imports
- Clean UI: Simple, focused interface
- Token Efficient: Optimized for large databases
- Modern Code: Latest LangChain syntax
- Error Free: No deprecation warnings
✅ Text-to-SQL Converter using OpenAI
✅ GPT-4o-mini model
✅ Fully dynamic PostgreSQL approach
✅ Schema Info Page for database exploration
✅ Clean, minimal code
✅ Token-optimized
✅ Modern LangChain syntax