feat: add error logging for server responses in completion clients
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
package de.extio.lmlib.client.oai.completion;
|
package de.extio.lmlib.client.oai.completion;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
@@ -17,6 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
|
import org.springframework.http.HttpStatusCode;
|
||||||
import org.springframework.web.client.RestClient;
|
import org.springframework.web.client.RestClient;
|
||||||
import org.springframework.web.client.RestClientException;
|
import org.springframework.web.client.RestClientException;
|
||||||
import org.springframework.web.client.RestClientResponseException;
|
import org.springframework.web.client.RestClientResponseException;
|
||||||
@@ -168,6 +171,15 @@ public abstract class AbstractCompletionClient implements Client, DisposableBean
|
|||||||
return this.getModelNames(modelProfile, false).stream().findFirst().orElse("");
|
return this.getModelNames(modelProfile, false).stream().findFirst().orElse("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void logErrorResponse(final HttpStatusCode statusCode, final InputStream responseBody) {
|
||||||
|
try {
|
||||||
|
LOGGER.warn("Error response from server: {} {}", statusCode, new String(responseBody.readAllBytes(), java.nio.charset.StandardCharsets.UTF_8));
|
||||||
|
}
|
||||||
|
catch (final IOException e) {
|
||||||
|
LOGGER.warn("Error response from server: {} <failed to read response body: {}>", statusCode, e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private List<String> loadModelNames(final ModelProfile modelProfile) {
|
private List<String> loadModelNames(final ModelProfile modelProfile) {
|
||||||
try {
|
try {
|
||||||
final var restClient = this.restClientBuilder.baseUrl(modelProfile.url()).build();
|
final var restClient = this.restClientBuilder.baseUrl(modelProfile.url()).build();
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ public class ChatCompletionClient extends AbstractCompletionClient {
|
|||||||
.body(requestBody)
|
.body(requestBody)
|
||||||
.exchange((clientRequest, clientResponse) -> {
|
.exchange((clientRequest, clientResponse) -> {
|
||||||
if (clientResponse.getStatusCode().isError()) {
|
if (clientResponse.getStatusCode().isError()) {
|
||||||
|
this.logErrorResponse(clientResponse.getStatusCode(), clientResponse.getBody());
|
||||||
throw new IllegalStateException("Error response from server: " + clientResponse.getStatusCode());
|
throw new IllegalStateException("Error response from server: " + clientResponse.getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ public class TextCompletionClient extends AbstractCompletionClient {
|
|||||||
.body(requestBody)
|
.body(requestBody)
|
||||||
.exchange((clientRequest, clientResponse) -> {
|
.exchange((clientRequest, clientResponse) -> {
|
||||||
if (clientResponse.getStatusCode().isError()) {
|
if (clientResponse.getStatusCode().isError()) {
|
||||||
|
this.logErrorResponse(clientResponse.getStatusCode(), clientResponse.getBody());
|
||||||
throw new IllegalStateException("Error response from server: " + clientResponse.getStatusCode());
|
throw new IllegalStateException("Error response from server: " + clientResponse.getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user