|
1 | | -# Spring AI SQL Assistant |
2 | | - |
3 | | -Ask a question in natural language, and AI will generate and execute a SQL query. The application is connected to PostgreSQL, where the `ai_service` table containing the parameters of 18 AI models (prices, SQL support, providers, etc.) is stored. |
| 1 | +# SpringAI SQL Assistant 🚀 |
4 | 2 |
|
5 | | -## 💡 Tech Stack |
| 3 | +   |
6 | 4 |
|
7 | | -- Java |
8 | | -- Spring Boot 3.4.5 |
9 | | -- Spring AI 1.0.0-M8 |
10 | | -- PostgreSQL |
11 | | -- OpenAI GPT (gpt-3.5-turbo) |
12 | | -- 🐳 Docker + Docker Compose |
| 5 | +Welcome to the **SpringAI SQL Assistant** repository! This project harnesses the power of GPT to transform how you interact with your databases. With natural language processing capabilities, this assistant allows you to query your database using everyday language, making database interactions easier and more intuitive. |
13 | 6 |
|
14 | | -## Project Showcase |
| 7 | +## Table of Contents |
15 | 8 |
|
16 | | - |
17 | | -- [UI walkthrough video](./media_examples/app_video.mp4) _(short demo, downloadable if not previewable)_ |
18 | | -- 📂 Example screenshots and results are located in the `media_example/` folder |
| 9 | +1. [Features](#features) |
| 10 | +2. [Getting Started](#getting-started) |
| 11 | + - [Prerequisites](#prerequisites) |
| 12 | + - [Installation](#installation) |
| 13 | +3. [Usage](#usage) |
| 14 | +4. [Technologies Used](#technologies-used) |
| 15 | +5. [Contributing](#contributing) |
| 16 | +6. [License](#license) |
| 17 | +7. [Contact](#contact) |
| 18 | +8. [Releases](#releases) |
19 | 19 |
|
20 | | -## ⚙️ Key Engineering Challenges |
| 20 | +## Features |
21 | 21 |
|
22 | | -- **Natural language to SQL translation using LLMs** |
23 | | - Integrated Spring AI with OpenAI (GPT-3.5) to translate user questions into SQL queries based on the structure of the `ai_services` table. |
| 22 | +- **Natural Language Queries**: Ask questions in plain English and get accurate SQL queries in return. |
| 23 | +- **Multi-Database Support**: Works with various databases, including PostgreSQL. |
| 24 | +- **Easy Integration**: Set up with Docker and Docker Compose for a smooth deployment experience. |
| 25 | +- **Extensible**: Built on a modular architecture, allowing easy updates and feature additions. |
| 26 | +- **OpenAI Integration**: Utilizes the ChatGPT API for enhanced conversational capabilities. |
24 | 27 |
|
25 | | -- **Safe dynamic SQL execution** |
26 | | - Designed a secure way to execute dynamically generated SQL without injection risks, using validation and controlled execution via `JdbcTemplate`. |
| 28 | +## Getting Started |
27 | 29 |
|
28 | | -- **Database bootstrapping with production-ready data** |
29 | | - On first startup, the PostgreSQL container automatically initializes the `ai_services` table with 18 real AI model entries via `spring_ai_init.sql`. |
| 30 | +### Prerequisites |
30 | 31 |
|
31 | | -- **Dockerized multi-container setup with persistent storage** |
32 | | - Used Docker Compose to orchestrate the Spring Boot app and PostgreSQL with named volumes and health checks to ensure reliable startup and data persistence. |
| 32 | +Before you begin, ensure you have the following installed: |
33 | 33 |
|
34 | | -- **Flexible, language-agnostic prompting pipeline** |
35 | | - The LLM prompting system is designed to handle both SQL and natural questions with domain-specific context, and can be extended to other database schemas. |
| 34 | +- [Java 11](https://www.oracle.com/java/technologies/javase-jdk11-downloads.html) |
| 35 | +- [Docker](https://www.docker.com/get-started) |
| 36 | +- [Docker Compose](https://docs.docker.com/compose/install/) |
36 | 37 |
|
| 38 | +### Installation |
37 | 39 |
|
38 | | -## ✅ Testing |
| 40 | +1. Clone the repository: |
39 | 41 |
|
40 | | -The Java backend is covered with both unit and integration-style tests for core logic components: |
| 42 | + ```bash |
| 43 | + git clone https://github.com/PrimeTheKid/SpringAI-SQL-Assistant.git |
| 44 | + cd SpringAI-SQL-Assistant |
| 45 | + ``` |
41 | 46 |
|
42 | | -- Text-to-SQL conversion logic: Validates that natural language questions are correctly translated into SQL using mocked ChatClient (LLM). |
43 | | -- SQL execution layer: Verifies safety of query execution, correct result formatting, null-handling, column ordering, and exception handling using JdbcTemplate. |
44 | | -- Safety filters: Prevent unsafe queries (DELETE, DROP, etc.) from being executed — covered by negative test cases. |
| 47 | +2. Build the Docker image: |
45 | 48 |
|
46 | | -## 🐳 How to Run |
| 49 | + ```bash |
| 50 | + docker-compose build |
| 51 | + ``` |
47 | 52 |
|
48 | | -1. Open docker-compose.yml and update these environment variables: |
49 | | -- POSTGRES_PASSWORD=your_password |
50 | | -- SPRING_AI_OPENAI_API-KEY=your_openai_api_key |
51 | | -- |
52 | | -2. Run everything with Docker Compose: |
| 53 | +3. Start the application: |
53 | 54 |
|
54 | | -```bash |
55 | | -docker-compose up --build |
56 | | -``` |
| 55 | + ```bash |
| 56 | + docker-compose up |
| 57 | + ``` |
57 | 58 |
|
58 | | -3. Access service: |
59 | | - - `http://localhost:8080/ask` |
| 59 | +4. Access the application at `http://localhost:8080`. |
60 | 60 |
|
61 | | -## ⚠️ Tech Notes |
| 61 | +## Usage |
62 | 62 |
|
63 | | -- This project uses the OpenAI API, but the architecture allows for easy integration with other LLM providers (e.g. Anthropic, Google, Cohere, Mistral) depending on business needs and cost model. |
| 63 | +Once the application is running, you can start interacting with it. Simply type your question in the provided interface. For example: |
64 | 64 |
|
65 | | -## 🤝 Thanks for your interest! |
| 65 | +- "Show me all users." |
| 66 | +- "What are the sales figures for last month?" |
66 | 67 |
|
67 | | -- I'm always open to feedback, collaboration, or professional connections. |
68 | | -- Feel free to reach out! |
| 68 | +The assistant will convert your request into SQL and execute it against your database. |
| 69 | + |
| 70 | +## Technologies Used |
| 71 | + |
| 72 | +- **Java**: The core language for backend development. |
| 73 | +- **Spring Framework**: For building the application. |
| 74 | +- **Docker**: For containerization. |
| 75 | +- **PostgreSQL**: The database used for data storage. |
| 76 | +- **OpenAI GPT**: For natural language processing. |
| 77 | + |
| 78 | +## Contributing |
| 79 | + |
| 80 | +We welcome contributions! To contribute: |
| 81 | + |
| 82 | +1. Fork the repository. |
| 83 | +2. Create a new branch (`git checkout -b feature/YourFeature`). |
| 84 | +3. Make your changes and commit them (`git commit -m 'Add some feature'`). |
| 85 | +4. Push to the branch (`git push origin feature/YourFeature`). |
| 86 | +5. Open a pull request. |
| 87 | + |
| 88 | +## License |
| 89 | + |
| 90 | +This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. |
| 91 | + |
| 92 | +## Contact |
| 93 | + |
| 94 | +For questions or feedback, feel free to reach out: |
| 95 | + |
| 96 | +- Email: support@example.com |
| 97 | +- Twitter: [@YourHandle](https://twitter.com/YourHandle) |
| 98 | + |
| 99 | +## Releases |
| 100 | + |
| 101 | +To download the latest release, visit our [Releases](https://github.com/PrimeTheKid/SpringAI-SQL-Assistant/releases) section. Here, you can find all available versions and their respective changelogs. |
| 102 | + |
| 103 | +--- |
| 104 | + |
| 105 | +Feel free to explore, test, and enhance the **SpringAI SQL Assistant**. Your feedback and contributions will help us improve and expand its capabilities! |
0 commit comments