Skip to content

sifinell/NLP2SQL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NLP2SQL: Chat with Your SQL Database 🔍

Welcome to NLP2SQL, a Streamlit-based application that allows users to interact with a SQL database using natural language. Powered by Azure OpenAI, LangChain, and Vector Search, this tool simplifies database exploration with an intuitive chat interface.

Features

  • Natural Language to SQL: Convert plain language queries into SQL commands.
  • Embedded Knowledge Base: Retrieve proper nouns like artist names or album titles using FAISS for more precise filtering.
  • Interactive Chat Interface: Engage with the database through a user-friendly Streamlit chat interface.

Files in the Repository

  • .env: Contains environment variables for the Azure OpenAI configuration.
  • requirements.txt: Lists required Python libraries.
  • Chinook.db: A sample SQLite database.
  • app.py: The main application file that connects LangChain, Azure OpenAI, and the Chinook database.

Installation and Setup

  1. Clone the repository:

    git clone https://github.com/sifinell/NLP2SQL.git
    cd NLP2SQL
  2. Install dependencies:

    pip install -r requirements.txt
  3. Set up the environment variables:

    • Create a .env file in the project root with the following content:
    AZURE_OPENAI_ENDPOINT="your-azure-openai-endpoint"
    AZURE_OPENAI_API_KEY="your-azure-openai-api-key"
    AZURE_OPENAI_DEPLOYMENT_NAME="gpt-4o"
    AZURE_OPENAI_EMBEDDING_NAME="text-embedding-ada-002 model"
    AZURE_OPENAI_API_VERSION="2024-05-01-preview"
    
    • Replace your-azure-openai-endpoint and your-azure-openai-api-key with your Azure OpenAI deployment details.
  4. Run the application:

    streamlit run app.py

Sample Questions

Here are some examples of queries you can ask the application:

  1. List all artists:

    Input: List all artists.
    Query: SELECT * FROM Artist;
    
  2. Find all albums for the artist 'AC/DC':

    Input: Find all albums for the artist 'AC/DC'.
    Query: SELECT * FROM Album WHERE ArtistId = (SELECT ArtistId FROM Artist WHERE Name = 'AC/DC');
    
  3. List all tracks in the 'Rock' genre:

    Input: List all tracks in the 'Rock' genre.
    Query: SELECT * FROM Track WHERE GenreId = (SELECT GenreId FROM Genre WHERE Name = 'Rock');
    
  4. Find the total duration of all tracks:

    Input: Find the total duration of all tracks.
    Query: SELECT SUM(Milliseconds) FROM Track;
    
  5. List all customers from Canada:

    Input: List all customers from Canada.
    Query: SELECT * FROM Customer WHERE Country = 'Canada';
    
  6. How many employees are there?:

    Input: How many employees are there?
    Query: SELECT COUNT(*) FROM "Employee";
    

References

For more details about the LangChain SQL capabilities used in this project, visit the LangChain SQL Quickstart documentation.

Contributing

Feel free to submit issues or pull requests for new features and improvements!

About

NLP2SQL is a Streamlit app that turns natural language queries into SQL commands, powered by Azure OpenAI and LangChain for intuitive database exploration.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages