A newer version of the Streamlit SDK is available:
1.48.0
SQLchat
This project is a SQL Chatbot built with LangChain and Streamlit, designed to generate SQL queries and execute queries based on database table schemas and structure. The chatbot can interact with users to understand their requirements and translate them into SQL queries, leveraging relational database information provided via URI and schema definitions.
Features
- SQL Query Generator: Automatically generates SQL queries based on user inputs and database structure.
- SQL Query Execution: Automatically executes SQL queries generated by chatbot.
- Interactive Chat Interface: Built with Streamlit for a user-friendly conversational experience.
- Database Schema Integration: Parses table schemas from a database URI to provide accurate SQL generation capabilities.
- Customizable LLM Configuration: Supports various large language models (LLMs) for generating responses.
Installation
Clone the repository:
git clone https://github.com/arthiondaena/SQLchat.git cd SQLchat
Set up a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
Install dependencies:
pip install -r requirements.txt
Usage
Run the application using Streamlit:
streamlit run app.py
This will launch the chatbot interface in your default web browser. The chatbot can then process user inputs and generate SQL queries based on the database schema.
Setup
Configure Database Connection:
- Set up the
URI
configuration in the streamlit app to connect to your relational database. - Ensure the database has the necessary permissions to allow schema queries.
- Set up the
Table Schemas:
- The chatbot extracts table structures and schemas from the database for generating SQL queries. Make sure the database contains valid schema definitions.
API Key Configuration:
- Provide your Groq API key for LLM integration within the script.
System Prompt Customization:
- Adjust the instructions as per your specific SQL generation use case.
- The chatbot can remember upto last 4 conversations.
Features in Detail
SQL Query Generation:
- The chatbot uses relational database schemas to intelligently generate SQL queries.
- Supports basic and complex queries tailored to the provided database structure.
Database Schema Utilization:
- Extracts table information (columns, types, relationships) from the connected database.
- Leverages this knowledge to produce highly precise SQL queries.
Customizable Model Prompts:
- Custom system prompts and instructions can be added to suit diverse database use cases.
Example Workflow
- Connect the chatbot to your database by specifying the database URI.
- Provide the chatbot with your SQL query requirement in plain language (e.g., "Fetch the top 10 customers by revenue").
- The chatbot generates and returns an accurate SQL query based on the schema.