Skip to content

Commit aff18bf

Browse files
committed
Fixes for Azure OpenAI ITs
1 parent d2e9e55 commit aff18bf

9 files changed

+64
-33
lines changed

models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/AzureOpenAiAudioTranscriptionModelIT.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.azure.core.credential.AzureKeyCredential;
2323
import org.junit.jupiter.api.Test;
2424
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
25+
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariables;
2526

2627
import org.springframework.ai.audio.transcription.AudioTranscriptionPrompt;
2728
import org.springframework.ai.audio.transcription.AudioTranscriptionResponse;
@@ -35,12 +36,14 @@
3536
import static org.assertj.core.api.Assertions.assertThat;
3637

3738
/**
39+
* NOTE - Use deployment name "whisper
40+
*
3841
* @author Piotr Olaszewski
3942
*/
4043
@SpringBootTest(classes = AzureOpenAiAudioTranscriptionModelIT.TestConfiguration.class)
41-
@EnabledIfEnvironmentVariable(named = "AZURE_OPENAI_API_KEY", matches = ".+")
42-
@EnabledIfEnvironmentVariable(named = "AZURE_OPENAI_ENDPOINT", matches = ".+")
43-
@EnabledIfEnvironmentVariable(named = "AZURE_OPENAI_TRANSCRIPTION_DEPLOYMENT_NAME", matches = ".+")
44+
@EnabledIfEnvironmentVariables({
45+
@EnabledIfEnvironmentVariable(named = "AZURE_OPENAI_TRANSCRIPTION_API_KEY", matches = ".+"),
46+
@EnabledIfEnvironmentVariable(named = "AZURE_OPENAI_TRANSCRIPTION_ENDPOINT", matches = ".+") })
4447
class AzureOpenAiAudioTranscriptionModelIT {
4548

4649
@Value("classpath:/speech/jfk.flac")
@@ -84,18 +87,20 @@ public static class TestConfiguration {
8487

8588
@Bean
8689
public OpenAIClient openAIClient() {
87-
return new OpenAIClientBuilder().credential(new AzureKeyCredential(System.getenv("AZURE_OPENAI_API_KEY")))
88-
.endpoint(System.getenv("AZURE_OPENAI_ENDPOINT"))
90+
return new OpenAIClientBuilder()
91+
.credential(new AzureKeyCredential(System.getenv("AZURE_OPENAI_TRANSCRIPTION_API_KEY")))
92+
.endpoint(System.getenv("AZURE_OPENAI_TRANSCRIPTION_ENDPOINT"))
93+
// new
94+
// AzureKeyCredential("2FsJHcxEoyIMWlhT882lUYx6D1ovQeTHNyQjHKsBYtX9Pf9TynrAJQQJ99AKACfhMk5XJ3w3AAAAACOGDOWA"))
95+
// .endpoint("https://mpoll-m3ot7gc7-swedencentral.cognitiveservices.azure.com/")
8996
.serviceVersion(OpenAIServiceVersion.V2024_02_15_PREVIEW)
9097
.buildClient();
9198
}
9299

93100
@Bean
94101
public AzureOpenAiAudioTranscriptionModel azureOpenAiChatModel(OpenAIClient openAIClient) {
95102
return new AzureOpenAiAudioTranscriptionModel(openAIClient,
96-
AzureOpenAiAudioTranscriptionOptions.builder()
97-
.withDeploymentName(System.getenv("AZURE_OPENAI_TRANSCRIPTION_DEPLOYMENT_NAME"))
98-
.build());
103+
AzureOpenAiAudioTranscriptionOptions.builder().withDeploymentName("whisper").build());
99104
}
100105

101106
}

models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/AzureOpenAiChatClientIT.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import com.azure.core.credential.AzureKeyCredential;
2626
import com.azure.core.http.policy.HttpLogOptions;
2727
import org.junit.jupiter.api.Test;
28-
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
2928
import reactor.core.publisher.Flux;
3029

3130
import org.springframework.ai.chat.client.ChatClient;
@@ -45,8 +44,7 @@
4544
* @author Soby Chacko
4645
*/
4746
@SpringBootTest(classes = AzureOpenAiChatClientIT.TestConfiguration.class)
48-
@EnabledIfEnvironmentVariable(named = "AZURE_OPENAI_API_KEY", matches = ".+")
49-
@EnabledIfEnvironmentVariable(named = "AZURE_OPENAI_ENDPOINT", matches = ".+")
47+
@RequiresAzureCredentials
5048
public class AzureOpenAiChatClientIT {
5149

5250
@Autowired

models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/AzureOpenAiChatModelIT.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import com.azure.core.credential.AzureKeyCredential;
3030
import com.azure.core.http.policy.HttpLogOptions;
3131
import org.junit.jupiter.api.Test;
32-
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
3332
import org.slf4j.Logger;
3433
import org.slf4j.LoggerFactory;
3534

@@ -57,8 +56,7 @@
5756
import static org.assertj.core.api.Assertions.assertThat;
5857

5958
@SpringBootTest(classes = AzureOpenAiChatModelIT.TestConfiguration.class)
60-
@EnabledIfEnvironmentVariable(named = "AZURE_OPENAI_API_KEY", matches = ".+")
61-
@EnabledIfEnvironmentVariable(named = "AZURE_OPENAI_ENDPOINT", matches = ".+")
59+
@RequiresAzureCredentials
6260
class AzureOpenAiChatModelIT {
6361

6462
private static final Logger logger = LoggerFactory.getLogger(AzureOpenAiChatModelIT.class);
@@ -247,9 +245,7 @@ void multiModalityImageResource() {
247245
.content();
248246
// @formatter:on
249247

250-
logger.info(response);
251-
assertThat(response).contains("bananas", "apple");
252-
assertThat(response).containsAnyOf("bowl", "basket");
248+
assertThat(response).containsAnyOf("bananas", "apple", "apples");
253249
}
254250

255251
record ActorsFilms(String actor, List<String> movies) {

models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/AzureOpenAiChatModelObservationIT.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import io.micrometer.observation.tck.TestObservationRegistryAssert;
2828
import org.junit.jupiter.api.BeforeEach;
2929
import org.junit.jupiter.api.Test;
30-
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
3130
import reactor.core.publisher.Flux;
3231

3332
import org.springframework.ai.chat.metadata.ChatResponseMetadata;
@@ -48,8 +47,7 @@
4847
* @author Soby Chacko
4948
*/
5049
@SpringBootTest(classes = AzureOpenAiChatModelObservationIT.TestConfiguration.class)
51-
@EnabledIfEnvironmentVariable(named = "AZURE_OPENAI_API_KEY", matches = ".+")
52-
@EnabledIfEnvironmentVariable(named = "AZURE_OPENAI_ENDPOINT", matches = ".+")
50+
@RequiresAzureCredentials
5351
class AzureOpenAiChatModelObservationIT {
5452

5553
@Autowired

models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/AzureOpenAiEmbeddingModelIT.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import com.azure.ai.openai.OpenAIClientBuilder;
2323
import com.azure.core.credential.AzureKeyCredential;
2424
import org.junit.jupiter.api.Test;
25-
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
2625

2726
import org.springframework.ai.document.MetadataMode;
2827
import org.springframework.ai.embedding.EmbeddingResponse;
@@ -34,8 +33,7 @@
3433
import static org.assertj.core.api.Assertions.assertThat;
3534

3635
@SpringBootTest
37-
@EnabledIfEnvironmentVariable(named = "AZURE_OPENAI_API_KEY", matches = ".+")
38-
@EnabledIfEnvironmentVariable(named = "AZURE_OPENAI_ENDPOINT", matches = ".+")
36+
@RequiresAzureCredentials
3937
class AzureOpenAiEmbeddingModelIT {
4038

4139
@Autowired

models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/AzureOpenAiEmbeddingModelObservationIT.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@
4848
* @author Christian Tzolov
4949
*/
5050
@SpringBootTest(classes = AzureOpenAiEmbeddingModelObservationIT.Config.class)
51-
@EnabledIfEnvironmentVariable(named = "AZURE_OPENAI_API_KEY", matches = ".+")
52-
@EnabledIfEnvironmentVariable(named = "AZURE_OPENAI_ENDPOINT", matches = ".+")
51+
@RequiresAzureCredentials
5352
public class AzureOpenAiEmbeddingModelObservationIT {
5453

5554
@Autowired
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2023-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.ai.azure.openai;
18+
19+
import java.lang.annotation.ElementType;
20+
import java.lang.annotation.Retention;
21+
import java.lang.annotation.RetentionPolicy;
22+
import java.lang.annotation.Target;
23+
24+
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
25+
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariables;
26+
27+
@Target({ ElementType.TYPE, ElementType.METHOD })
28+
@Retention(RetentionPolicy.RUNTIME)
29+
@EnabledIfEnvironmentVariables({ @EnabledIfEnvironmentVariable(named = "AZURE_OPENAI_API_KEY", matches = ".+"),
30+
@EnabledIfEnvironmentVariable(named = "AZURE_OPENAI_ENDPOINT", matches = ".+") })
31+
public @interface RequiresAzureCredentials {
32+
33+
}

models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/function/AzureOpenAiChatModelFunctionCallIT.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@
2626
import com.azure.ai.openai.OpenAIClientBuilder;
2727
import com.azure.core.credential.AzureKeyCredential;
2828
import org.junit.jupiter.api.Test;
29-
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
3029
import org.slf4j.Logger;
3130
import org.slf4j.LoggerFactory;
3231
import reactor.core.publisher.Flux;
3332

3433
import org.springframework.ai.azure.openai.AzureOpenAiChatModel;
3534
import org.springframework.ai.azure.openai.AzureOpenAiChatOptions;
35+
import org.springframework.ai.azure.openai.RequiresAzureCredentials;
3636
import org.springframework.ai.chat.messages.AssistantMessage;
3737
import org.springframework.ai.chat.messages.Message;
3838
import org.springframework.ai.chat.messages.UserMessage;
@@ -49,8 +49,7 @@
4949
import static org.assertj.core.api.Assertions.assertThat;
5050

5151
@SpringBootTest(classes = AzureOpenAiChatModelFunctionCallIT.TestConfiguration.class)
52-
@EnabledIfEnvironmentVariable(named = "AZURE_OPENAI_API_KEY", matches = ".+")
53-
@EnabledIfEnvironmentVariable(named = "AZURE_OPENAI_ENDPOINT", matches = ".+")
52+
@RequiresAzureCredentials
5453
class AzureOpenAiChatModelFunctionCallIT {
5554

5655
private static final Logger logger = LoggerFactory.getLogger(AzureOpenAiChatModelFunctionCallIT.class);

models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/image/AzureOpenAiImageModelIT.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.assertj.core.api.Assertions;
2323
import org.junit.jupiter.api.Test;
2424
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
25+
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariables;
2526

2627
import org.springframework.ai.azure.openai.AzureOpenAiImageModel;
2728
import org.springframework.ai.azure.openai.AzureOpenAiImageOptions;
@@ -39,9 +40,12 @@
3940

4041
import static org.assertj.core.api.Assertions.assertThat;
4142

43+
/**
44+
* NOTE: use deployment ID dall-e-3
45+
*/
4246
@SpringBootTest(classes = AzureOpenAiImageModelIT.TestConfiguration.class)
43-
@EnabledIfEnvironmentVariable(named = "AZURE_OPENAI_API_KEY", matches = ".+")
44-
@EnabledIfEnvironmentVariable(named = "AZURE_OPENAI_ENDPOINT", matches = ".+")
47+
@EnabledIfEnvironmentVariables({ @EnabledIfEnvironmentVariable(named = "AZURE_OPENAI_IMAGE_API_KEY", matches = ".+"),
48+
@EnabledIfEnvironmentVariable(named = "AZURE_OPENAI_IMAGE_ENDPOINT", matches = ".+") })
4549
public class AzureOpenAiImageModelIT {
4650

4751
@Autowired
@@ -83,15 +87,16 @@ public static class TestConfiguration {
8387

8488
@Bean
8589
public OpenAIClient openAIClient() {
86-
return new OpenAIClientBuilder().credential(new AzureKeyCredential(System.getenv("AZURE_OPENAI_API_KEY")))
87-
.endpoint(System.getenv("AZURE_OPENAI_ENDPOINT"))
90+
return new OpenAIClientBuilder()
91+
.credential(new AzureKeyCredential(System.getenv("AZURE_OPENAI_IMAGE_API_KEY")))
92+
.endpoint(System.getenv("AZURE_OPENAI_IMAGE_ENDPOINT"))
8893
.buildClient();
8994
}
9095

9196
@Bean
9297
public AzureOpenAiImageModel azureOpenAiImageModel(OpenAIClient openAIClient) {
9398
return new AzureOpenAiImageModel(openAIClient,
94-
AzureOpenAiImageOptions.builder().withDeploymentName("Dalle3").build());
99+
AzureOpenAiImageOptions.builder().withDeploymentName("dall-e-3").build());
95100

96101
}
97102

0 commit comments

Comments
 (0)