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

Add support for custom WebClientBuilder #739

Open
fmunch opened this issue May 20, 2024 · 0 comments
Open

Add support for custom WebClientBuilder #739

fmunch opened this issue May 20, 2024 · 0 comments

Comments

@fmunch
Copy link

fmunch commented May 20, 2024

This might be related to #512 and #609.

Expected Behavior

The *Api client classes should offer a way to customize the WebClient used. For example to add an Authorization header for custom Ollama setups, or to add some logging.

Current Behavior

Most *Api clients offer a constructor with a RestClient.Builder parameter, but also create a hardcoded WebClient.Builder:

public OllamaApi(String baseUrl, RestClient.Builder restClientBuilder) {
    // ...
    this.restClient = restClientBuilder.baseUrl(baseUrl).defaultHeaders(defaultHeaders).build();
    this.webClient = WebClient.builder().baseUrl(baseUrl).defaultHeaders(defaultHeaders).build();
}

public MistralAiApi(String baseUrl, String mistralAiApiKey, RestClient.Builder restClientBuilder,
        ResponseErrorHandler responseErrorHandler) {
    // ...
    this.restClient = restClientBuilder.baseUrl(baseUrl)
	    .defaultHeaders(jsonContentHeaders)
	    .defaultStatusHandler(responseErrorHandler)
	    .build();
    this.webClient = WebClient.builder().baseUrl(baseUrl).defaultHeaders(jsonContentHeaders).build();
}

public OpenAiApi(String baseUrl, String openAiToken, RestClient.Builder restClientBuilder,
        ResponseErrorHandler responseErrorHandler) {
    this.restClient = restClientBuilder
		    .baseUrl(baseUrl)
		    .defaultHeaders(ApiUtils.getJsonContentHeaders(openAiToken))
		    .defaultStatusHandler(responseErrorHandler)
		    .build();
    this.webClient = WebClient.builder()
		    .baseUrl(baseUrl)
		    .defaultHeaders(ApiUtils.getJsonContentHeaders(openAiToken))
		    .build();
}

This does not allow to customize the WebClient used in streaming methods.

Context

We want to deploy a Spring AI cluster that calls an Ollama instance, ideally with some sort of authentication.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant