Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autowire WebClient.Builder into OllamaApi #1296

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public OllamaApi() {
* @param baseUrl The base url of the Ollama server.
*/
public OllamaApi(String baseUrl) {
this(baseUrl, RestClient.builder());
this(baseUrl, RestClient.builder(), WebClient.builder());
}

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

this.responseErrorHandler = new OllamaResponseErrorHandler();

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

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

this.webClient = WebClient.builder().baseUrl(baseUrl).defaultHeaders(defaultHeaders).build();
this.webClient = webClientBuilder.baseUrl(baseUrl).defaultHeaders(defaultHeaders).build();
}

// --------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestClient;
import org.springframework.web.reactive.function.client.WebClient;

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

@Bean
@ConditionalOnMissingBean
public OllamaApi ollamaApi(OllamaConnectionDetails connectionDetails, RestClient.Builder restClientBuilder) {
return new OllamaApi(connectionDetails.getBaseUrl(), restClientBuilder);
public OllamaApi ollamaApi(OllamaConnectionDetails connectionDetails, RestClient.Builder restClientBuilder,
WebClient.Builder webClientBuilder) {
return new OllamaApi(connectionDetails.getBaseUrl(), restClientBuilder, webClientBuilder);
}

@Bean
Expand Down