SQLchat / readme.md
Invicto69's picture
Synced repo using 'sync_with_huggingface' Github Action
d3bfe40 verified
# 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
1. Clone the repository:
```bash
git clone https://github.com/arthiondaena/SQLchat.git
cd SQLchat
```
2. Set up a virtual environment:
```bash
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
```
3. Install dependencies:
```bash
pip install -r requirements.txt
```
## Usage
Run the application using Streamlit:
```bash
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
1. **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.
2. **Table Schemas**:
- The chatbot extracts table structures and schemas from the database for generating SQL queries. Make sure the database contains valid schema definitions.
3. **API Key Configuration**:
- Provide your Groq API key for LLM integration within the script.
4. **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
1. **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.
2. **Database Schema Utilization**:
- Extracts table information (columns, types, relationships) from the connected database.
- Leverages this knowledge to produce highly precise SQL queries.
3. **Customizable Model Prompts**:
- Custom system prompts and instructions can be added to suit diverse database use cases.
## Example Workflow
1. Connect the chatbot to your database by specifying the database URI.
2. Provide the chatbot with your SQL query requirement in plain language (e.g., "Fetch the top 10 customers by revenue").
3. The chatbot generates and returns an accurate SQL query based on the schema.