Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;

/**
* {@link AutoConfiguration Auto-configuration} for Azure OpenAI.
Expand All @@ -42,7 +43,7 @@
@EnableConfigurationProperties(AzureOpenAiAudioTranscriptionProperties.class)
@ConditionalOnProperty(name = SpringAIModelProperties.AUDIO_TRANSCRIPTION_MODEL,
havingValue = SpringAIModels.AZURE_OPENAI, matchIfMissing = true)
@ImportAutoConfiguration(classes = AzureOpenAiClientBuilderAutoConfiguration.class)
@Import(AzureOpenAiClientBuilderConfiguration.class)
public class AzureOpenAiAudioTranscriptionAutoConfiguration {

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;

/**
* {@link AutoConfiguration Auto-configuration} for Azure OpenAI.
Expand All @@ -52,8 +53,8 @@
@EnableConfigurationProperties({ AzureOpenAiChatProperties.class })
@ConditionalOnProperty(name = SpringAIModelProperties.CHAT_MODEL, havingValue = SpringAIModels.AZURE_OPENAI,
matchIfMissing = true)
@ImportAutoConfiguration(
classes = { AzureOpenAiClientBuilderAutoConfiguration.class, ToolCallingAutoConfiguration.class })
@ImportAutoConfiguration(classes = { ToolCallingAutoConfiguration.class })
@Import(AzureOpenAiClientBuilderConfiguration.class)
public class AzureOpenAiChatAutoConfiguration {

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,16 @@
import org.springframework.util.StringUtils;

/**
* {@link AutoConfiguration Auto-configuration} for Azure OpenAI.
* Azure OpenAI Client Builder configuration.
*
* @author Piotr Olaszewski
* @author Soby Chacko
* @author Manuel Andreo Garcia
* @author Ilayaperumal Gopinathan
*/
@AutoConfiguration
@ConditionalOnClass({ OpenAIClientBuilder.class })
@EnableConfigurationProperties(AzureOpenAiConnectionProperties.class)
public class AzureOpenAiClientBuilderAutoConfiguration {
public class AzureOpenAiClientBuilderConfiguration {

private static final String APPLICATION_ID = "spring-ai";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;

/**
* {@link AutoConfiguration Auto-configuration} for Azure OpenAI.
Expand All @@ -45,7 +46,7 @@
@EnableConfigurationProperties({ AzureOpenAiEmbeddingProperties.class })
@ConditionalOnProperty(name = SpringAIModelProperties.EMBEDDING_MODEL, havingValue = SpringAIModels.AZURE_OPENAI,
matchIfMissing = true)
@ImportAutoConfiguration(classes = AzureOpenAiClientBuilderAutoConfiguration.class)
@Import(AzureOpenAiClientBuilderConfiguration.class)
public class AzureOpenAiEmbeddingAutoConfiguration {

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;

/**
* {@link AutoConfiguration Auto-configuration} for Azure OpenAI.
Expand All @@ -42,7 +43,7 @@
@ConditionalOnProperty(name = SpringAIModelProperties.IMAGE_MODEL, havingValue = SpringAIModels.AZURE_OPENAI,
matchIfMissing = true)
@EnableConfigurationProperties(AzureOpenAiImageOptionsProperties.class)
@ImportAutoConfiguration(classes = AzureOpenAiClientBuilderAutoConfiguration.class)
@Import(AzureOpenAiClientBuilderConfiguration.class)
public class AzureOpenAiImageAutoConfiguration {

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.springframework.ai.model.azure.openai.autoconfigure;

import com.azure.ai.openai.OpenAIClientBuilder;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;

Expand Down Expand Up @@ -45,6 +46,7 @@ void chatModelActivation() {
this.contextRunner.withConfiguration(AutoConfigurations.of(AzureOpenAiChatAutoConfiguration.class))
.run(context -> {
assertThat(context.getBeansOfType(AzureOpenAiChatModel.class)).isNotEmpty();
assertThat(context.getBeansOfType(OpenAIClientBuilder.class)).isNotEmpty();
assertThat(context.getBeansOfType(AzureOpenAiEmbeddingModel.class)).isEmpty();
assertThat(context.getBeansOfType(AzureOpenAiImageModel.class)).isEmpty();
assertThat(context.getBeansOfType(AzureOpenAiAudioTranscriptionModel.class)).isEmpty();
Expand All @@ -55,6 +57,7 @@ void chatModelActivation() {
.run(context -> {
assertThat(context.getBeansOfType(AzureOpenAiChatProperties.class)).isEmpty();
assertThat(context.getBeansOfType(AzureOpenAiChatModel.class)).isEmpty();
assertThat(context.getBeansOfType(OpenAIClientBuilder.class)).isEmpty();
});

this.contextRunner.withConfiguration(AutoConfigurations.of(AzureOpenAiChatAutoConfiguration.class))
Expand All @@ -70,6 +73,7 @@ void chatModelActivation() {
"spring.ai.model.audio.transcription=none", "spring.ai.model.moderation=none")
.run(context -> {
assertThat(context.getBeansOfType(AzureOpenAiChatModel.class)).isNotEmpty();
assertThat(context.getBeansOfType(OpenAIClientBuilder.class)).isNotEmpty();
assertThat(context.getBeansOfType(AzureOpenAiEmbeddingModel.class)).isEmpty();
assertThat(context.getBeansOfType(AzureOpenAiImageModel.class)).isEmpty();
assertThat(context.getBeansOfType(AzureOpenAiAudioTranscriptionModel.class)).isEmpty();
Expand All @@ -84,20 +88,23 @@ void embeddingModelActivation() {
assertThat(context.getBeansOfType(AzureOpenAiEmbeddingModel.class)).isNotEmpty();
assertThat(context.getBeansOfType(AzureOpenAiImageModel.class)).isEmpty();
assertThat(context.getBeansOfType(AzureOpenAiAudioTranscriptionModel.class)).isEmpty();
assertThat(context.getBeansOfType(OpenAIClientBuilder.class)).isNotEmpty();
});

this.contextRunner.withConfiguration(AutoConfigurations.of(AzureOpenAiEmbeddingAutoConfiguration.class))
.withPropertyValues("spring.ai.model.embedding=none")
.run(context -> {
assertThat(context.getBeansOfType(AzureOpenAiEmbeddingProperties.class)).isEmpty();
assertThat(context.getBeansOfType(AzureOpenAiEmbeddingModel.class)).isEmpty();
assertThat(context.getBeansOfType(OpenAIClientBuilder.class)).isEmpty();
});

this.contextRunner.withConfiguration(AutoConfigurations.of(AzureOpenAiEmbeddingAutoConfiguration.class))
.withPropertyValues("spring.ai.model.embedding=azure-openai")
.run(context -> {
assertThat(context.getBeansOfType(AzureOpenAiEmbeddingProperties.class)).isNotEmpty();
assertThat(context.getBeansOfType(AzureOpenAiEmbeddingModel.class)).isNotEmpty();
assertThat(context.getBeansOfType(OpenAIClientBuilder.class)).isNotEmpty();
});

this.contextRunner.withConfiguration(AutoConfigurations.of(AzureOpenAiEmbeddingAutoConfiguration.class))
Expand All @@ -107,6 +114,7 @@ void embeddingModelActivation() {
.run(context -> {
assertThat(context.getBeansOfType(AzureOpenAiChatModel.class)).isEmpty();
assertThat(context.getBeansOfType(AzureOpenAiEmbeddingModel.class)).isNotEmpty();
assertThat(context.getBeansOfType(OpenAIClientBuilder.class)).isNotEmpty();
assertThat(context.getBeansOfType(AzureOpenAiImageModel.class)).isEmpty();
assertThat(context.getBeansOfType(AzureOpenAiAudioTranscriptionModel.class)).isEmpty();
});
Expand All @@ -119,6 +127,7 @@ void imageModelActivation() {
assertThat(context.getBeansOfType(AzureOpenAiChatModel.class)).isEmpty();
assertThat(context.getBeansOfType(AzureOpenAiEmbeddingModel.class)).isEmpty();
assertThat(context.getBeansOfType(AzureOpenAiImageModel.class)).isNotEmpty();
assertThat(context.getBeansOfType(OpenAIClientBuilder.class)).isNotEmpty();
assertThat(context.getBeansOfType(AzureOpenAiAudioTranscriptionModel.class)).isEmpty();
});

Expand All @@ -127,13 +136,15 @@ void imageModelActivation() {
.run(context -> {
assertThat(context.getBeansOfType(AzureOpenAiImageOptionsProperties.class)).isEmpty();
assertThat(context.getBeansOfType(AzureOpenAiImageModel.class)).isEmpty();
assertThat(context.getBeansOfType(OpenAIClientBuilder.class)).isEmpty();
});

this.contextRunner.withConfiguration(AutoConfigurations.of(AzureOpenAiImageAutoConfiguration.class))
.withPropertyValues("spring.ai.model.image=azure-openai")
.run(context -> {
assertThat(context.getBeansOfType(AzureOpenAiImageOptionsProperties.class)).isNotEmpty();
assertThat(context.getBeansOfType(AzureOpenAiImageModel.class)).isNotEmpty();
assertThat(context.getBeansOfType(OpenAIClientBuilder.class)).isNotEmpty();
});

this.contextRunner.withConfiguration(AutoConfigurations.of(AzureOpenAiImageAutoConfiguration.class))
Expand All @@ -144,6 +155,7 @@ void imageModelActivation() {
assertThat(context.getBeansOfType(AzureOpenAiChatModel.class)).isEmpty();
assertThat(context.getBeansOfType(AzureOpenAiEmbeddingModel.class)).isEmpty();
assertThat(context.getBeansOfType(AzureOpenAiImageModel.class)).isNotEmpty();
assertThat(context.getBeansOfType(OpenAIClientBuilder.class)).isNotEmpty();
assertThat(context.getBeansOfType(AzureOpenAiAudioTranscriptionModel.class)).isEmpty();
});
}
Expand All @@ -157,6 +169,7 @@ void audioTranscriptionModelActivation() {
assertThat(context.getBeansOfType(AzureOpenAiEmbeddingModel.class)).isEmpty();
assertThat(context.getBeansOfType(AzureOpenAiImageModel.class)).isEmpty();
assertThat(context.getBeansOfType(AzureOpenAiAudioTranscriptionModel.class)).isNotEmpty();
assertThat(context.getBeansOfType(OpenAIClientBuilder.class)).isNotEmpty();
});

this.contextRunner
Expand All @@ -165,6 +178,7 @@ void audioTranscriptionModelActivation() {
.run(context -> {
assertThat(context.getBeansOfType(AzureOpenAiAudioTranscriptionProperties.class)).isEmpty();
assertThat(context.getBeansOfType(AzureOpenAiAudioTranscriptionModel.class)).isEmpty();
assertThat(context.getBeansOfType(OpenAIClientBuilder.class)).isEmpty();
});

this.contextRunner
Expand All @@ -173,6 +187,7 @@ void audioTranscriptionModelActivation() {
.run(context -> {
assertThat(context.getBeansOfType(AzureOpenAiAudioTranscriptionProperties.class)).isNotEmpty();
assertThat(context.getBeansOfType(AzureOpenAiAudioTranscriptionModel.class)).isNotEmpty();
assertThat(context.getBeansOfType(OpenAIClientBuilder.class)).isNotEmpty();
});

this.contextRunner
Expand All @@ -185,6 +200,7 @@ void audioTranscriptionModelActivation() {
assertThat(context.getBeansOfType(AzureOpenAiEmbeddingModel.class)).isEmpty();
assertThat(context.getBeansOfType(AzureOpenAiImageModel.class)).isEmpty();
assertThat(context.getBeansOfType(AzureOpenAiAudioTranscriptionModel.class)).isNotEmpty();
assertThat(context.getBeansOfType(OpenAIClientBuilder.class)).isNotEmpty();
});
}

Expand Down