Skip to content

murcoder14/ai-workout

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AI Workout using Spring AI

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.

Prerequisites

  1. Java 21, Spring Boot 3.4.4, Spring AI Milestone Release M6

  2. Maven 3.9 or higher

  3. OpenAI API Key

  4. Docker Desktop

  5. Redis

Setup

  1. Obtain the OPENAI_API_KEY

  2. 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
  3. Install Docker Desktop.

  4. 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
  5. Clone this github repository.

    git clone https://github.com/murcoder14/ai-workout
  6. 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

Running the application

  • Run the Sprint Boot Application using maven.

        mvn spring-boot:run

Testing the application

  • 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.

Reference Documentation

For further reference, please consider the following:

License

MIT

Free Software, Hell Yeah!

About

Contains examples of Generative AI and Agentic AI using Spring AI

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published