|
17 | 17 |
|
18 | 18 | import java.util.List; |
19 | 19 | import java.util.Map; |
20 | | - |
21 | | -import com.fasterxml.jackson.annotation.JsonInclude; |
22 | | -import com.fasterxml.jackson.annotation.JsonInclude.Include; |
23 | | -import com.fasterxml.jackson.annotation.JsonProperty; |
| 20 | +import java.util.function.Consumer; |
24 | 21 |
|
25 | 22 | import org.springframework.ai.openai.api.common.OpenAiApiConstants; |
26 | 23 | import org.springframework.ai.retry.RetryUtils; |
27 | | -import org.springframework.ai.util.api.ApiUtils; |
28 | 24 | import org.springframework.core.io.ByteArrayResource; |
29 | 25 | import org.springframework.http.HttpHeaders; |
30 | 26 | import org.springframework.http.MediaType; |
|
36 | 32 | import org.springframework.web.client.ResponseErrorHandler; |
37 | 33 | import org.springframework.web.client.RestClient; |
38 | 34 | import org.springframework.web.reactive.function.client.WebClient; |
| 35 | + |
| 36 | +import com.fasterxml.jackson.annotation.JsonInclude; |
| 37 | +import com.fasterxml.jackson.annotation.JsonInclude.Include; |
| 38 | +import com.fasterxml.jackson.annotation.JsonProperty; |
| 39 | + |
39 | 40 | import reactor.core.publisher.Flux; |
40 | 41 | import reactor.core.publisher.Mono; |
41 | 42 |
|
@@ -71,13 +72,14 @@ public OpenAiAudioApi(String openAiToken) { |
71 | 72 | public OpenAiAudioApi(String baseUrl, String openAiToken, RestClient.Builder restClientBuilder, |
72 | 73 | ResponseErrorHandler responseErrorHandler) { |
73 | 74 |
|
74 | | - this.restClient = restClientBuilder.baseUrl(baseUrl).defaultHeaders(headers -> { |
75 | | - headers.setBearerAuth(openAiToken); |
76 | | - }).defaultStatusHandler(responseErrorHandler).build(); |
| 75 | + Consumer<HttpHeaders> authHeaders = h -> h.setBearerAuth(openAiToken); |
77 | 76 |
|
78 | | - this.webClient = WebClient.builder().baseUrl(baseUrl).defaultHeaders(headers -> { |
79 | | - headers.setBearerAuth(openAiToken); |
80 | | - }).defaultHeaders(ApiUtils.getJsonContentHeaders(openAiToken)).build(); |
| 77 | + this.restClient = restClientBuilder.baseUrl(baseUrl) |
| 78 | + .defaultHeaders(authHeaders) |
| 79 | + .defaultStatusHandler(responseErrorHandler) |
| 80 | + .build(); |
| 81 | + |
| 82 | + this.webClient = WebClient.builder().baseUrl(baseUrl).defaultHeaders(authHeaders).build(); |
81 | 83 | } |
82 | 84 |
|
83 | 85 | /** |
@@ -108,23 +110,18 @@ public OpenAiAudioApi(String baseUrl, String apiKey, MultiValueMap<String, Strin |
108 | 110 | RestClient.Builder restClientBuilder, WebClient.Builder webClientBuilder, |
109 | 111 | ResponseErrorHandler responseErrorHandler) { |
110 | 112 |
|
111 | | - // @formatter:off |
112 | | - this.restClient = restClientBuilder |
113 | | - .baseUrl(baseUrl) |
114 | | - .defaultHeaders(h -> { |
115 | | - h.setBearerAuth(apiKey); |
116 | | - h.addAll(headers); |
117 | | - }) |
118 | | - .defaultStatusHandler(responseErrorHandler).build(); |
119 | | - |
120 | | - this.webClient = webClientBuilder |
121 | | - .baseUrl(baseUrl) |
122 | | - .defaultHeaders(h -> { |
123 | | - h.setBearerAuth(apiKey); |
124 | | - h.addAll(headers); |
125 | | - }) |
126 | | - .defaultHeaders(ApiUtils.getJsonContentHeaders(apiKey)).build(); |
127 | | - // @formatter:on |
| 113 | + Consumer<HttpHeaders> authHeaders = h -> { |
| 114 | + h.setBearerAuth(apiKey); |
| 115 | + h.addAll(headers); |
| 116 | + // h.setContentType(MediaType.APPLICATION_JSON); |
| 117 | + }; |
| 118 | + |
| 119 | + this.restClient = restClientBuilder.baseUrl(baseUrl) |
| 120 | + .defaultHeaders(authHeaders) |
| 121 | + .defaultStatusHandler(responseErrorHandler) |
| 122 | + .build(); |
| 123 | + |
| 124 | + this.webClient = webClientBuilder.baseUrl(baseUrl).defaultHeaders(authHeaders).build(); |
128 | 125 | } |
129 | 126 |
|
130 | 127 | /** |
|
0 commit comments