This project is a full-stack application that converts natural language input into SQL queries using React for the front end, Node.js and Express for the backend, and integrating the ChatGPT API. The goal is to provide users with an intuitive tool to generate SQL queries without any prior coding knowledge.
The SQL Query Generator project aims to simplify the process of writing SQL queries by allowing users to input natural language descriptions. The application translates these descriptions into SQL queries using the OpenAI ChatGPT API.
- Convert natural language descriptions into SQL queries.
- User-friendly interface built with React.
- Backend API built with Node.js and Express.
- Integration with the OpenAI ChatGPT API for query generation.
- Real-time query generation and display.
- Frontend: React
- Backend: Node.js, Express
- API: OpenAI ChatGPT API
- Styling: CSS (using a stylesheet for simplicity)
- Node.js (v18 or later)
- npm (v7 or later)
- Clone the repository:
git clone https://github.com/roma2023/openai-api-sql.git cd openai-api-sql
- Install dependencies for both client and server:
cd client npm install cd ../server npm install
Create a .env
file in the server
directory with your OpenAI API key: OPENAI_API_KEY=your_openai_api_key
```
openai-api-sql/
│
├── client/
│ ├── public/
│ ├── src/
│ │ ├── components/
│ │ ├── App.jsx
│ │ ├── index.js
│ │ └── styles.module.css
│ ├── .gitignore
│ ├── package.json
│ └── README.md
│
├── server/
│ ├── api.js
│ ├── generate.js
│ ├── index.js
│ ├── .env.example
│ ├── .gitignore
│ └── package.json
│
└── README.md
```
- Start the backend server:
cd server npm start
- Start the frontend development server:
cd client npm run dev
- Open your browser and navigate to
http://localhost:3000
.
To generate an SQL query, enter a natural language description such as "Select the first 10 elements from the table users where the column age is greater than 18" and click "Generate Query". The generated SQL query will be displayed below the input field.