Please do a quick search on GitHub issues first, the feature you are about to request might have already been requested.
Expected Behavior
It should be possible to use a custom WebClient.Builder in the Spring configuration. Currently only a RestClient.Builder is supported.
/**
* Create a new chat completion api.
*
* @param baseUrl api base URL.
* @param openAiToken OpenAI apiKey.
* @param restClientBuilder RestClient builder.
* @param webClientBuilder RestClient builder.
* @param responseErrorHandler Response error handler.
*/
public OpenAiApi(String baseUrl, String openAiToken, RestClient.Builder restClientBuilder, WebClient.Builder webClientBuilder, ResponseErrorHandler responseErrorHandler) {
this.restClient = restClientBuilder
.baseUrl(baseUrl)
.defaultHeaders(ApiUtils.getJsonContentHeaders(openAiToken))
.defaultStatusHandler(responseErrorHandler)
.build();
this.webClient = webClientBuilder
.baseUrl(baseUrl)
.defaultHeaders(ApiUtils.getJsonContentHeaders(openAiToken))
.build();
}
The class org.springframework.ai.autoconfigure.openai.OpenAiAutoConfiguration needs to be updated as well to accept the WebClient.Builder.
@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(prefix = OpenAiEmbeddingProperties.CONFIG_PREFIX, name = "enabled", havingValue = "true",
matchIfMissing = true)
public OpenAiEmbeddingClient openAiEmbeddingClient(OpenAiConnectionProperties commonProperties,
OpenAiEmbeddingProperties embeddingProperties, RestClient.Builder restClientBuilder,
WebClient.Builder webClientBuilder, RetryTemplate retryTemplate, ResponseErrorHandler responseErrorHandler) {
var openAiApi = openAiApi(embeddingProperties.getBaseUrl(), commonProperties.getBaseUrl(),
embeddingProperties.getApiKey(), commonProperties.getApiKey(), restClientBuilder, webClientBuilder, responseErrorHandler);
return new OpenAiEmbeddingClient(openAiApi, embeddingProperties.getMetadataMode(),
embeddingProperties.getOptions(), retryTemplate);
}
Current Behavior
Currently it is not possible to inject a custom WebClient.Builder into the constructor.
Context
Can not use the pre configured WebClient.Builder.
Comment From: tha2015
This is a duplicate of https://github.com/spring-projects/spring-ai/issues/609 which was fixed recently. See commit https://github.com/spring-projects/spring-ai/commit/377b5ffa61427ce94f49793b00f4617edfcc59bc
Comment From: Adakole2020
This is a duplicate of #609 which was fixed recently. See commit 377b5ff
This problem seems to continue to persist even in the recent release. It doesn't expect the rest-client builder to be nullable and as such operates on the assumption that both configurations and builders are available.
Comment From: markpollack
Thanks for the feedback @Adakole2020 Will investigate.