The Spring AI framework enables AI integration by connecting enterprise Data and APIs with Large Language Models. Generative AI typically works on tasks that are narrow and well-defined, such as generating a paragraph of text or a digital picture. Agentic AI, on the other hand, often tackles broader, multi-step goals that require continuous decision-making and adaptation. This project demonstrates only the Generative AI techniques using Spring AI.
-
Java 21, Spring Boot 3.4.4, Spring AI Milestone Release M6
-
Maven 3.9 or higher
-
OpenAI API Key
-
Docker Desktop
-
Redis
-
Obtain the OPENAI_API_KEY
-
Set the environment variable,OPENAI_API_KEY as follows. The value of this key is used in the application.properties and allows the Spring AI code to connect to the LLM hosted by OPEN AI. (Note that the value used below does not represent an actual key and is shown only for illustration).
export OPENAI_API_KEY=sk-proj-58yArLp3BndDJtxp_V2fU-TA3hQnkGKk1FdTXIWVJgf04bpG6tgaVBzr_8sJWNPlQ
-
Install Docker Desktop.
-
Run Redis inside Docker. Redis shall be used as a Vector database for our use cases involving RAG.
docker run -d --name redis-stack -p 6379:6379 -p 8001:8001 redis/redis-stack:latest
-
Clone this github repository.
git clone https://github.com/murcoder14/ai-workout
-
Build the application (Note the build will fail if either the OPENAI_API_KEY is not set or if Redis is not running inside Docker).
cd ai-workout mvn clean package
-
Run the Sprint Boot Application using maven.
mvn spring-boot:run
- Use a HTTP Client such as cURL or Postman. The example below uses cURL to submit a HTTP GET request to find the winner of the Wimbledon Tennis Championship in 2024. The model was trained only with data upto 2023. Hence, the model is enhances with data using a technique called prompt-stuffing.
tmurali@fedora:~/tools$ curl "http://localhost:9090/ai-workout/content/askme?query=Who%20won%20the%20Wimbledon%20in%202024?&stuffit=true" Carlos Alcaraz won Wimbledon in 2024.
Every controller method is documented with comments on what Generative AI technique it is demonstrating and how to invoke it using cURL. So feel free to download the code and test it.
For further reference, please consider the following:
- Official Spring AI documentation
- OpenAI's Playground
- DeepLearning.AI
- User, System and Assistant Roles in LLMs
- AWS Prompt Engineering Guidelines
- Prompt Engineering Guide
- AWS Prompt Templates in Bedrock
MIT
Free Software, Hell Yeah!