Skip to content

Commit a9fc130

Browse files
Use OkHttpClient for AzureOpenAiAudioTranscriptionModelIT (#3665)
- To fix the race condition with the default HTTP client used by the Azure OpenAIClient, switch to use OkHttpClient. More discussion on this here: Azure/azure-sdk-for-java#43583 - Thanks to @Allamss for his suggestion here: Azure/azure-sdk-for-java#43583 (comment) Auto-cherry-pick to 1.0.x Fixes #3665 Signed-off-by: Ilayaperumal Gopinathan <[email protected]>
1 parent d92a2ea commit a9fc130

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

models/spring-ai-azure-openai/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@
8383
<artifactId>micrometer-observation-test</artifactId>
8484
<scope>test</scope>
8585
</dependency>
86+
87+
<dependency>
88+
<groupId>com.azure</groupId>
89+
<artifactId>azure-core-http-okhttp</artifactId>
90+
<version>1.12.11</version>
91+
<scope>test</scope>
92+
</dependency>
8693
</dependencies>
8794

8895
</project>

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
/*
23
* Copyright 2023-2024 the original author or authors.
34
*
@@ -16,9 +17,13 @@
1617

1718
package org.springframework.ai.azure.openai;
1819

20+
import java.util.concurrent.TimeUnit;
21+
1922
import com.azure.ai.openai.OpenAIClient;
2023
import com.azure.ai.openai.OpenAIClientBuilder;
2124
import com.azure.core.credential.AzureKeyCredential;
25+
import com.azure.core.http.okhttp.OkHttpAsyncHttpClientBuilder;
26+
import okhttp3.OkHttpClient;
2227
import org.junit.jupiter.api.Test;
2328
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
2429
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariables;
@@ -91,8 +96,16 @@ public OpenAIClient openAIClient() {
9196

9297
// System.out.println("API Key: " + apiKey);
9398
// System.out.println("Endpoint: " + endpoint);
99+
int readTimeout = 120;
100+
int writeTimeout = 120;
101+
102+
// OkHttp client with long timeouts
103+
OkHttpClient okHttpClient = new OkHttpClient.Builder().readTimeout(readTimeout, TimeUnit.SECONDS)
104+
.callTimeout(writeTimeout, TimeUnit.SECONDS)
105+
.build();
94106

95-
return new OpenAIClientBuilder().credential(new AzureKeyCredential(apiKey))
107+
return new OpenAIClientBuilder().httpClient(new OkHttpAsyncHttpClientBuilder(okHttpClient).build())
108+
.credential(new AzureKeyCredential(apiKey))
96109
.endpoint(endpoint)
97110
// .serviceVersion(OpenAIServiceVersion.V2024_02_15_PREVIEW)
98111
.buildClient();

0 commit comments

Comments
 (0)