AI powered expert system || Flight Booking Service by using SpringAI


Spring AI to build an AI-powered system that:

  • Has access to terms and conditions (retrieval augmented generation, RAG)
  • Can access tools (Java methods) to perform actions (Function Calling)
  • Uses an LLM to interact with the user



Requirements

  • Java 17+
  • OpenAI API key in OPENAI_API_KEY environment variable

Running

Run the app by running Application.java in your IDE or mvn in the command line.

With OpenAI Chat

Add to the POM the Spring AI Open AI boot starter:

<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-openai-spring-boot-starter</artifactId>
</dependency>


Add the OpenAI configuraiton to the applicaiton.properties:

spring.ai.openai.api-key=${OPENAI_API_KEY}
spring.ai.openai.chat.options.model=gpt-4o                                     

WIth VertexAI Geminie Chat

Add to the POM the Spring AI VertexAI Gemeni and Onnx Transfomer Embedding boot starters:

<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-vertex-ai-gemini-spring-boot-starter</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-transformers-spring-boot-starter</artifactId>
</dependency>

Add the VertexAI Gemini configuraiton to the applicaiton.properties:                                                                                                                                                                                                           

spring.ai.vertex.ai.gemini.project-id=${VERTEX_AI_GEMINI_PROJECT_ID}
spring.ai.vertex.ai.gemini.location=${VERTEX_AI_GEMINI_LOCATION}
spring.ai.vertex.ai.gemini.chat.options.model=gemini-1.5-pro-001
# spring.ai.vertex.ai.gemini.chat.options.model=gemini-1.5-flash-001  

Build Jar

./mvnw clean install -Pproduction
java -jar ./target/playground-flight-booking-0.0.1-SNAPSHOT.jar
docker run -it --rm --name postgres -p 5432:5432 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres ankane/pgvector


Post a Comment

Previous Post Next Post