Skip to content

A conversational SQL query chatbot built with Streamlit and LangChain, using Groq's Llama3-8b-8192 model to query SQLite (`student.db`) or MySQL databases with natural language, supporting chat history and real-time feedback.

License

Notifications You must be signed in to change notification settings

Monish-Nallagondalla/LLM_Text_To_SQL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LLM Text to SQL Chatbot

A powerful conversational chatbot that enables users to query SQL databases using natural language, built with Streamlit, LangChain, and Groq's advanced LLM models. This application translates everyday language into SQL queries, making database interaction intuitive and accessible.

🚀 Features

  • Natural Language Processing: Convert plain English queries into SQL statements using Groq's Llama3-8b-8192 model
  • Multi-Database Support: Seamlessly connect to SQLite or MySQL databases
  • Interactive Chat Interface: Streamlit-powered UI with persistent chat history
  • Real-time Query Execution: Live feedback and results display
  • Pre-populated Database: Includes a sample SQLite database with student records for immediate testing
  • Secure API Key Management: Password-protected input for Groq API credentials
  • Extensible Architecture: Easily adaptable to other database types and LLM providers

📁 Project Structure

LLM_Text_To_SQL/
├── app.py                 # Main Streamlit application
├── sqlite.py              # Database setup script for SQLite
├── student.db             # Pre-populated SQLite database
├── requirements.txt       # Python dependencies
├── README.md              # Project documentation
├── LICENSE                # MIT License
├── .gitignore             # Git ignore rules
└── TODO.md                # Development tasks (generated)

🛠️ Installation

Prerequisites

Step-by-Step Setup

  1. Clone the Repository

    git clone https://github.com/Monish-Nallagondalla/LLM_Text_To_SQL.git
    cd LLM_Text_To_SQL
  2. Create Virtual Environment (Recommended)

    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
  3. Install Dependencies

    pip install -r requirements.txt
  4. Set Up Environment Variables Create a .env file in the project root:

    GROQ_API_KEY=your_actual_groq_api_key_here
  5. Prepare the Database The project includes a pre-populated SQLite database. To recreate it:

    python sqlite.py

🚀 Usage

Running the Application

streamlit run app.py

Using the Chatbot

  1. Select Database Type

    • Choose between SQLite (local) or MySQL (remote) in the sidebar
  2. Configure Database Connection

    • SQLite: Automatically uses the included student.db
    • MySQL: Enter host, username, password, and database name
  3. Enter API Key

    • Input your Groq API key in the secure text field
  4. Start Chatting

    • Type natural language queries like:
      • "Show me all students in Data Science class"
      • "Who has the highest marks?"
      • "List students with marks above 80 in section A"
  5. View Results

    • The chatbot will display the generated SQL query and results
    • Chat history is maintained for context

Sample Queries

  • "How many students are in the DEVOPS class?"
  • "What is the average marks for Data Science students?"
  • "Show me students with marks between 50 and 90"

📊 Database Schema

The included SQLite database (student.db) contains a STUDENT table:

Column Type Description
NAME VARCHAR(25) Student name
CLASS VARCHAR(25) Class/Subject
SECTION VARCHAR(25) Section/Grade
MARKS INT Academic marks

Sample data includes students from Data Science and DEVOPS classes.

🔧 Configuration

Environment Variables

  • GROQ_API_KEY: Your Groq API key (required)

Database Configuration

  • SQLite: No additional configuration needed
  • MySQL: Provide connection details in the app sidebar

📋 Dependencies

Key packages (see requirements.txt for full list):

  • streamlit: Web app framework
  • langchain: LLM orchestration
  • langchain-groq: Groq integration
  • sqlalchemy: Database ORM
  • python-dotenv: Environment variable management

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

🐛 Troubleshooting

Common Issues

  • API Key Errors: Ensure your Groq API key is valid and correctly entered
  • Database Connection: Verify MySQL credentials and network access
  • Dependencies: Run pip install -r requirements.txt to ensure all packages are installed
  • Python Version: Confirm you're using Python 3.8+

Debug Mode

Run with verbose logging:

streamlit run app.py --logger.level=debug

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • LangChain for the powerful SQL agent framework
  • Groq for providing fast and efficient LLM inference
  • Streamlit for the intuitive web app interface

📞 Support

If you encounter any issues or have questions:

  1. Check the Troubleshooting section
  2. Open an issue on GitHub
  3. Review the LangChain and Groq documentation

Happy querying! 🦜

About

A conversational SQL query chatbot built with Streamlit and LangChain, using Groq's Llama3-8b-8192 model to query SQLite (`student.db`) or MySQL databases with natural language, supporting chat history and real-time feedback.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages