Skip to content
Open
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
19 changes: 19 additions & 0 deletions .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,22 @@ jobs:
- name: Run tests
run: |
./mvnw --batch-mode test
spring_7:
name: Compile with Spring 7
runs-on: ubuntu-latest
if: ${{ github.repository_owner == 'spring-projects' }}
steps:
- name: Checkout source code
uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: 'maven'

- name: Run tests
run: |
./mvnw --batch-mode -Dspring-framework.version=7.0.0-RC2 -Dkotlin.version=2.2.0 compile

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.springframework.ai.retry.autoconfigure;

import java.io.IOException;
import java.net.URI;
import java.nio.charset.StandardCharsets;

import org.slf4j.Logger;
Expand All @@ -30,6 +31,7 @@
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpMethod;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.lang.NonNull;
import org.springframework.retry.RetryCallback;
Expand Down Expand Up @@ -87,6 +89,14 @@ public boolean hasError(@NonNull ClientHttpResponse response) throws IOException
}

@Override
public void handleError(URI url, HttpMethod method, ClientHttpResponse response) throws IOException {
handleError(response);
}

// On purposes commented out so that the code can compile both with Spring 6
// and Spring 7
// @Override
@SuppressWarnings("removal")
public void handleError(@NonNull ClientHttpResponse response) throws IOException {
if (!response.getStatusCode().isError()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public ResponseEntity<ChatCompletionResponse> chatCompletionEntity(ChatCompletio
return this.restClient.post()
.uri(this.completionsPath)
.headers(headers -> {
headers.addAll(additionalHttpHeader);
additionalHttpHeader.forEach(headers::addAll);
addDefaultHeadersIfMissing(headers);
})
.body(chatRequest)
Expand Down Expand Up @@ -217,7 +217,7 @@ public Flux<ChatCompletionResponse> chatCompletionStream(ChatCompletionRequest c
return this.webClient.post()
.uri(this.completionsPath)
.headers(headers -> {
headers.addAll(additionalHttpHeader);
additionalHttpHeader.forEach(headers::addAll);
addDefaultHeadersIfMissing(headers);
}) // @formatter:off
.body(Mono.just(chatRequest), ChatCompletionRequest.class)
Expand Down Expand Up @@ -256,7 +256,8 @@ public Flux<ChatCompletionResponse> chatCompletionStream(ChatCompletionRequest c
}

private void addDefaultHeadersIfMissing(HttpHeaders headers) {
if (!headers.containsKey(HEADER_X_API_KEY)) {
List<String> apiKeyHeaders = headers.get(HEADER_X_API_KEY);
if (apiKeyHeaders == null) {
String apiKeyValue = this.apiKey.getValue();
if (StringUtils.hasText(apiKeyValue)) {
headers.add(HEADER_X_API_KEY, apiKeyValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public DeepSeekApi(String baseUrl, ApiKey apiKey, MultiValueMap<String, String>
Consumer<HttpHeaders> finalHeaders = h -> {
h.setBearerAuth(apiKey.getValue());
h.setContentType(MediaType.APPLICATION_JSON);
h.addAll(headers);
headers.forEach(h::addAll);
};
this.restClient = restClientBuilder.baseUrl(baseUrl)
.defaultHeaders(finalHeaders)
Expand Down Expand Up @@ -153,7 +153,7 @@ public Flux<ChatCompletionChunk> chatCompletionStream(ChatCompletionRequest chat

return this.webClient.post()
.uri(this.getEndpoint(chatRequest))
.headers(headers -> headers.addAll(additionalHttpHeader))
.headers(headers -> additionalHttpHeader.forEach(headers::addAll))
.body(Mono.just(chatRequest), ChatCompletionRequest.class)
.retrieve()
.bodyToFlux(String.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private ElevenLabsApi(String baseUrl, ApiKey apiKey, MultiValueMap<String, Strin
if (!(apiKey instanceof NoopApiKey)) {
h.set("xi-api-key", apiKey.getValue());
}
h.addAll(headers);
headers.forEach(h::addAll);
h.setContentType(MediaType.APPLICATION_JSON);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public ElevenLabsVoicesApi(String baseUrl, ApiKey apiKey, MultiValueMap<String,
if (!(apiKey instanceof NoopApiKey)) {
h.set("xi-api-key", apiKey.getValue());
}
h.addAll(headers);
headers.forEach(h::addAll);
h.setContentType(MediaType.APPLICATION_JSON);
};

Expand Down
Loading