Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions genai-function-calling/spring-ai/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ FROM eclipse-temurin:21-jdk-alpine AS build

WORKDIR /build

# Copy the local code to the container
COPY mvnw pom.xml ./
COPY src ./src
# Install dependencies (verify resolves more than dependency:go-offline)
COPY mvnw ./
COPY .mvn ./.mvn
COPY pom.xml ./
RUN ./mvnw verify -DskipTests

# Copy source code and build the application
COPY src ./src
RUN ./mvnw package

FROM eclipse-temurin:21-jre-alpine
Expand Down
10 changes: 5 additions & 5 deletions genai-function-calling/spring-ai/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<name>genai-function-calling</name>
<description>Function Calling with Spring AI</description>
<properties>
<java.version>17</java.version>
<spring-ai.version>1.0.0-M6</spring-ai.version>
<java.version>21</java.version>
<spring-ai.version>1.0.0-M7</spring-ai.version>
</properties>
<dependencies>
<dependency>
Expand All @@ -24,11 +24,11 @@
</dependency>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-azure-openai-spring-boot-starter</artifactId>
<artifactId>spring-ai-starter-model-azure-openai</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-openai-spring-boot-starter</artifactId>
<artifactId>spring-ai-starter-model-openai</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -93,7 +93,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.4.1</version>
<version>3.5.0</version>
<executions>
<execution>
<goals>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,25 @@

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.model.SpringAIModelProperties;
import org.springframework.ai.model.SpringAIModels;
import org.springframework.ai.model.tool.DefaultToolCallingChatOptions;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@SpringBootApplication
public class Main {

@Component
static class VersionAgent implements CommandLineRunner {
static class VersionAgent implements CommandLineRunner {

private final ChatClient chat;
private final ElasticsearchTools tools;

VersionAgent(ChatModel chat, ElasticsearchTools tools) {
VersionAgent(ChatModel chat, ElasticsearchTools tools) {
this.chat = ChatClient.builder(chat).build();
this.tools = tools;
}
Expand Down Expand Up @@ -51,7 +53,21 @@ OpenTelemetry openTelemetry() {
}

public static void main(String[] args) {
SpringApplication.run(Main.class, args);
// Choose between Azure OpenAI and OpenAI based on the presence of the official SDK
// environment variable AZURE_OPENAI_API_KEY. Otherwise, we'd create two beans.
String azureApiKey = System.getenv("AZURE_OPENAI_API_KEY");
String chatModel = azureApiKey != null && !azureApiKey.trim().isEmpty()
? SpringAIModels.AZURE_OPENAI
: SpringAIModels.OPENAI;
// Right now, we cannot select azure or openai with a single property, so set all of them.
// See https://github.com/spring-projects/spring-ai/issues/2712
new SpringApplicationBuilder(Main.class)
.properties(
SpringAIModelProperties.AUDIO_TRANSCRIPTION_MODEL + "=" + chatModel,
SpringAIModelProperties.CHAT_MODEL + "=" + chatModel,
SpringAIModelProperties.EMBEDDING_MODEL + "=" + chatModel,
SpringAIModelProperties.IMAGE_MODEL + "=" + chatModel
).run(args);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ logging:
org:
springframework:
ai:
autoconfigure:
model:
chat:
observation:
# Hush warnings about prompt and completion logging
ChatObservationAutoConfiguration: OFF
autoconfigure:
# Hush warnings about prompt and completion logging
ChatObservationAutoConfiguration: OFF