Your friendly personal assistant powered by OpenAI
Here’s a detailed README file template for your project. This template covers the main aspects of your project, including an overview, installation steps, usage instructions, and more. You can customize it further according to your project’s specifics.
This project is a full-stack web application built with Spring Boot, Spring AI, React, and Docker. It serves as a learning tool for developers who want to get hands-on experience with Spring AI, leveraging the OpenAI API to create an intelligent chatbot. The chatbot can assist users in learning more about Spring AI by answering questions and providing information based on user queries.
- Interactive Chatbot: Engage with a chatbot to learn more about Spring AI and how to integrate it with your Spring Boot applications.
- Spring Boot Backend: A robust backend powered by Spring Boot, utilizing Spring AI for processing and generating responses using the OpenAI API.
- React Frontend: A user-friendly and responsive frontend built with React, providing an intuitive interface to interact with the chatbot.
- Dockerized Setup: Both the frontend and backend are containerized using Docker, allowing easy setup and deployment.
Here’s a quick demo of how the project works:
Watch the demo video:
- Backend:
- Java 17
- Spring Boot
- Spring AI
- OpenAI API
- Frontend:
- React
- HTML5 & CSS3
- Axios
- Nginx (for serving the React app)
- DevOps:
- Docker
- Docker Compose
Before you begin, ensure you have the following installed on your machine:
- Docker
- Docker Compose
- Java 17 (if running the Spring Boot app locally)
- Node.js and npm (if running the React app locally)
git clone https://github.com/vikasrajputin/spring-ai-chatbot.git
cd spring-ai-chatbot
The project is organized into two main directories:
- spring-boot-ai-chatbot/: Contains the Spring Boot application with Spring AI integration.
- chatbot-ui/: Contains the React application that serves as the chatbot interface.
Before running the application, make sure to set up the environment variables for accessing the OpenAI API.
-
Create a
.env
file in thespring-boot-ai-chatbot
directory:OPENAI_API_KEY=your_openai_api_key
-
(Optional) Create a
.env
file in thechatbot-ui
directory if needed.
The project is fully dockerized, making it easy to run both the frontend and backend together.
-
Build and run the containers:
docker-compose up --build
-
Access the application:
- The Spring Boot application (backend) will be available at:
http://localhost:8080
- The React application (frontend) will be available at:
http://localhost:3000
- The Spring Boot application (backend) will be available at:
-
Navigate to the
spring-boot-ai-chatbot/
directory:cd spring-boot-ai-chatbot/
-
Build and run the Spring Boot application:
./mvnw clean install spring-boot:run
-
Access the backend API:
http://localhost:8080
-
Navigate to the
chatbot-ui/
directory:cd chatbot-ui
-
Install the dependencies:
npm install
-
Start the React application:
npm start
-
Access the frontend:
http://localhost:3000
The backend provides the following key API endpoints:
-
GET /ai/chat/string
: Accepts amessage
query parameter and returns a response generated by the AI model.- Example:
http://localhost:8080/ai/chat/string?message=Tell me about Spring AI
- Example:
-
POST /ai/chat
: Accepts a JSON body with amessage
field and returns a response generated by the AI model.- Example:
POST http://localhost:8080/ai/chat Content-Type: application/json { "message": "Explain how to use OpenAI with Spring Boot" }
- Example:
- The React frontend is located in the
chatbot-ui/
directory. - You can customize the UI by editing the components in the
src/
directory. - Update the styling by modifying the
Chatbot.css
file.
- The Spring Boot backend is located in the
spring-boot-ai-chatbot/
directory. - You can customize the AI responses by modifying the services and controllers in the
src/main/java
directory. - Update the Spring AI configuration in the
application.yml
file.
To deploy the application to a local environment, you can use the Docker images built with the provided Dockerfiles.
-
Build the Docker images:
docker-compose build
- Backend: Deploy the Spring Boot jar to a server or cloud service (e.g., AWS EC2, Heroku).
- Frontend: Build the React app (
npm run build
) and serve it using a web server (e.g., Nginx, Apache).
This project is licensed under the MIT License. See the LICENSE file for more information.