Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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,15 @@ 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;
new SpringApplicationBuilder(Main.class)
.properties(SpringAIModelProperties.CHAT_MODEL + "=" + chatModel)
.run(args);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ spring:
web-application-type: none
banner-mode: "off"
ai:
# Right now, we cannot select azure or openai with a single property.
# See https://github.com/spring-projects/spring-ai/issues/2712
model:
embedding: ${spring.ai.model.chat}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so, for now, I'm re-using the chat value for the others that have auto-configuration depenedencies despite being used. At some point I think the word "model" shouldn't be used as these are inference providers, not models

audio:
transcription: ${spring.ai.model.chat}
image: ${spring.ai.model.chat}
openai:
base-url: ${OPENAI_BASE_URL:https://api.openai.com/v1}
api-key: ${OPENAI_API_KEY:enter-your-api-key}
Expand All @@ -30,11 +37,18 @@ management.observations.annotations.enabled: true
logging:
level:
root: WARN
io:
netty:
resolver:
dns:
# Hush warnings about native DNS on MacOS
DnsServerAddressStreamProviders: OFF
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