Skip to content

Commit 3cab5bd

Browse files
habumamarkpollack
authored andcommitted
Autowire WebClient.Builder into OllamaApi
1 parent bf8dabf commit 3cab5bd

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

models/spring-ai-ollama/src/main/java/org/springframework/ai/ollama/api/OllamaApi.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public OllamaApi() {
100100
* @param baseUrl The base url of the Ollama server.
101101
*/
102102
public OllamaApi(String baseUrl) {
103-
this(baseUrl, RestClient.builder());
103+
this(baseUrl, RestClient.builder(), WebClient.builder());
104104
}
105105

106106
/**
@@ -109,7 +109,7 @@ public OllamaApi(String baseUrl) {
109109
* @param baseUrl The base url of the Ollama server.
110110
* @param restClientBuilder The {@link RestClient.Builder} to use.
111111
*/
112-
public OllamaApi(String baseUrl, RestClient.Builder restClientBuilder) {
112+
public OllamaApi(String baseUrl, RestClient.Builder restClientBuilder, WebClient.Builder webClientBuilder) {
113113

114114
this.responseErrorHandler = new OllamaResponseErrorHandler();
115115

@@ -120,7 +120,7 @@ public OllamaApi(String baseUrl, RestClient.Builder restClientBuilder) {
120120

121121
this.restClient = restClientBuilder.baseUrl(baseUrl).defaultHeaders(defaultHeaders).build();
122122

123-
this.webClient = WebClient.builder().baseUrl(baseUrl).defaultHeaders(defaultHeaders).build();
123+
this.webClient = webClientBuilder.baseUrl(baseUrl).defaultHeaders(defaultHeaders).build();
124124
}
125125

126126
// --------------------------------------------------------------------------

spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/ollama/OllamaAutoConfiguration.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.springframework.context.ApplicationContext;
3838
import org.springframework.context.annotation.Bean;
3939
import org.springframework.web.client.RestClient;
40+
import org.springframework.web.reactive.function.client.WebClient;
4041

4142
/**
4243
* {@link AutoConfiguration Auto-configuration} for Ollama Chat Client.
@@ -61,8 +62,9 @@ public PropertiesOllamaConnectionDetails ollamaConnectionDetails(OllamaConnectio
6162

6263
@Bean
6364
@ConditionalOnMissingBean
64-
public OllamaApi ollamaApi(OllamaConnectionDetails connectionDetails, RestClient.Builder restClientBuilder) {
65-
return new OllamaApi(connectionDetails.getBaseUrl(), restClientBuilder);
65+
public OllamaApi ollamaApi(OllamaConnectionDetails connectionDetails, RestClient.Builder restClientBuilder,
66+
WebClient.Builder webClientBuilder) {
67+
return new OllamaApi(connectionDetails.getBaseUrl(), restClientBuilder, webClientBuilder);
6668
}
6769

6870
@Bean

0 commit comments

Comments
 (0)