This project provides an API that leverages AI to interact with a SQL database. It allows users to perform database operations using natural language queries, which are translated into SQL by an AI model.
The primary purpose of this project is to simplify database interactions for users who may not be proficient in SQL. It bridges the gap between natural language and structured query language, enabling more intuitive data access and manipulation.
- Natural Language to SQL: Translates user queries in plain English into executable SQL commands.
- FastAPI Backend: Built with FastAPI for high performance and ease of development.
- OpenAI Integration: Utilizes OpenAI's powerful language models for translation.
- PostgreSQL Support: Connects to a PostgreSQL database for data storage and retrieval.
- Asynchronous Operations: Leverages async capabilities for efficient handling of requests.
- Python 3.8+
- pip (Python package installer)
- PostgreSQL Database (local or cloud-hosted)
- OpenAI API Key
Python Packages:
fastapi
uvicorn[standard]
openai
databases[postgresql]
sqlalchemy
psycopg2-binary
python-dotenv
(A brief overview of the project's directory structure can be added here once finalized)
sql-ai-api-main/
βββ .env # Environment variables (OPENAI_API_KEY, DATABASE_URL)
βββ requirements.txt # Project dependencies
βββ setup.md # Detailed setup instructions
βββ tutorial_full.py # Example FastAPI application
βββ README.md # This file
-
Clone the Repository:
git clone <your-repo-url> cd sql-ai-api-main
-
Set up a Virtual Environment (Recommended):
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install Dependencies:
pip install -r requirements.txt
-
Configure Environment Variables: Create a
.envfile in the project root and add your credentials:OPENAI_API_KEY=your_openai_api_key DATABASE_URL=postgresql://user:password@host:port/database_name
Remember to add
.envto your.gitignorefile. -
Run the Application: (Refer to
setup.mdor specific run instructions for the main application file, e.g.,tutorial_full.py)uvicorn tutorial_full:app --reload
Contributions are welcome! Please feel free to submit pull requests or open issues to improve the project.
(Add specific contribution guidelines if applicable)
(Specify the project's license here, e.g., MIT, Apache 2.0. If no license is chosen, state that.)
This project is currently unlicensed.
Syed Abdullah Shah
- π Connect on LinkedIn: http://www.linkedin.com/in/syed-abdullah-shah-4018a5176
- π© Email: sa.abdullahshah.2001@gmail.com