Skip to content

Meet MySQL Assistant: Access database info seamlessly with natural language. No SQL expertise required. Simply ask questions, receive clear responses.

Notifications You must be signed in to change notification settings

Gaurav-Van/Chat-With-MySQL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chat-With-MySQL

Meet MySQL Assistant: Access database info seamlessly with natural language. No SQL expertise required. Simply ask questions, receive clear responses.

YouTube Link of the Demo of the App: https://www.youtube.com/watch?v=HZ6WFniL8W8


Table of Contents

  1. What it Does
  2. How I Built it
  3. Design
  4. How to Run it Locally

What it Does

The MySQL Assistant revolutionizes data interaction by providing information in a user-friendly, natural language format. It accepts queries in everyday language, eliminating the need for SQL knowledge. For instance, if you ask, “How many countries have Spanish as an official language?”, the Assistant responds in plain English with the precise count. Additionally, it offers the corresponding SQL query as a reference. This innovative approach simplifies data extraction, making it accessible to all, regardless of their technical expertise. No more gatekeeping - just straightforward, effective data interaction.

Chat_with_MySQL.mp4

How I built it

Langchain: The mysql-connector plays a crucial role in Langchain by establishing a connection with the MySQL database, extracting the database schema, and executing database queries. The features of AI and Human Messages contribute to the creation of the app's chat-like interface.

Streamlit: Streamlit is a user-friendly tool that facilitates the creation of web apps and the showcasing of our work. It's a time-saver and was employed to construct the entire web app for this project.

Gemini and Gemini API: The seamless conversion from user-query to SQL-query and back from SQL-query response to natural language is made possible by the freeflow prompt functionality of Gemini and Gemini API.

  1. get_sql Function: This function takes in the Database schema, chat history, and user query. It utilizes a well-curated template to convert the user query into an SQL query.

  2. get_response Function: This function takes in the Database schema, chat history, user query, and the generated SQL query from the get_sql function. It runs the generated SQL query on the database and feeds the result into a well-curated prompt which also takes in the schema, chat history, and user query.

The process can be summarized as follows: User query + Data Schema -> LLM -> SQL query -> Run Query -> LLM -> Natural Language Answer. This flow represents the core functionality of Langchain.

Design

Chat-with-SQL-Design

How to Run it Locally

Windows

Folder
├── src
│   └── app.py
├── design
│   └── Chat-with-SQL-Design.png
├── requirements.txt
├── .env
└── README.md
create virtual env: python -m venv env
activate it: env\Scripts\activate

[inside the virtual env]
[Important installations]

pip install streamlit langchain mysql-connector-python python-dotenv google.generativeai

or

pip install -r requirements.txt

[Store your gemini api key inside the .env file]
[from command prompt or terminal run the following command to run the app]

streamlit run src/app.py

About

Meet MySQL Assistant: Access database info seamlessly with natural language. No SQL expertise required. Simply ask questions, receive clear responses.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages