|
| 1 | + |
1 | 2 | /* |
2 | 3 | * Copyright 2023-2024 the original author or authors. |
3 | 4 | * |
|
16 | 17 |
|
17 | 18 | package org.springframework.ai.azure.openai; |
18 | 19 |
|
| 20 | +import java.util.concurrent.TimeUnit; |
| 21 | + |
19 | 22 | import com.azure.ai.openai.OpenAIClient; |
20 | 23 | import com.azure.ai.openai.OpenAIClientBuilder; |
21 | 24 | import com.azure.core.credential.AzureKeyCredential; |
| 25 | +import com.azure.core.http.okhttp.OkHttpAsyncHttpClientBuilder; |
| 26 | +import okhttp3.OkHttpClient; |
22 | 27 | import org.junit.jupiter.api.Test; |
23 | 28 | import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; |
24 | 29 | import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariables; |
@@ -91,8 +96,17 @@ public OpenAIClient openAIClient() { |
91 | 96 |
|
92 | 97 | // System.out.println("API Key: " + apiKey); |
93 | 98 | // 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(); |
94 | 106 |
|
95 | | - return new OpenAIClientBuilder().credential(new AzureKeyCredential(apiKey)) |
| 107 | + return new OpenAIClientBuilder() |
| 108 | + .httpClient(new OkHttpAsyncHttpClientBuilder(okHttpClient).build()) |
| 109 | + .credential(new AzureKeyCredential(apiKey)) |
96 | 110 | .endpoint(endpoint) |
97 | 111 | // .serviceVersion(OpenAIServiceVersion.V2024_02_15_PREVIEW) |
98 | 112 | .buildClient(); |
|
0 commit comments