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
7 changes: 7 additions & 0 deletions models/spring-ai-azure-openai/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@
<artifactId>micrometer-observation-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-http-okhttp</artifactId>
<version>1.12.11</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

/*
* Copyright 2023-2024 the original author or authors.
*
Expand All @@ -16,9 +17,13 @@

package org.springframework.ai.azure.openai;

import java.util.concurrent.TimeUnit;

import com.azure.ai.openai.OpenAIClient;
import com.azure.ai.openai.OpenAIClientBuilder;
import com.azure.core.credential.AzureKeyCredential;
import com.azure.core.http.okhttp.OkHttpAsyncHttpClientBuilder;
import okhttp3.OkHttpClient;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariables;
Expand Down Expand Up @@ -91,8 +96,16 @@ public OpenAIClient openAIClient() {

// System.out.println("API Key: " + apiKey);
// System.out.println("Endpoint: " + endpoint);
int readTimeout = 120;
int writeTimeout = 120;

// OkHttp client with long timeouts
OkHttpClient okHttpClient = new OkHttpClient.Builder().readTimeout(readTimeout, TimeUnit.SECONDS)
.callTimeout(writeTimeout, TimeUnit.SECONDS)
.build();

return new OpenAIClientBuilder().credential(new AzureKeyCredential(apiKey))
return new OpenAIClientBuilder().httpClient(new OkHttpAsyncHttpClientBuilder(okHttpClient).build())
.credential(new AzureKeyCredential(apiKey))
.endpoint(endpoint)
// .serviceVersion(OpenAIServiceVersion.V2024_02_15_PREVIEW)
.buildClient();
Expand Down