Skip to content

Commit 6cba520

Browse files
Renamed package to common
1 parent e1ca568 commit 6cba520

File tree

15 files changed

+31
-29
lines changed

15 files changed

+31
-29
lines changed

core/src/main/java/com/sap/ai/sdk/core/commons/ClientError.java renamed to core/src/main/java/com/sap/ai/sdk/core/common/ClientError.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.sap.ai.sdk.core.commons;
1+
package com.sap.ai.sdk.core.common;
22

33
import com.google.common.annotations.Beta;
44
import javax.annotation.Nullable;

core/src/main/java/com/sap/ai/sdk/core/commons/ClientException.java renamed to core/src/main/java/com/sap/ai/sdk/core/common/ClientException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.sap.ai.sdk.core.commons;
1+
package com.sap.ai.sdk.core.common;
22

33
import com.google.common.annotations.Beta;
44
import lombok.experimental.StandardException;

core/src/main/java/com/sap/ai/sdk/core/commons/ClientResponseHandler.java renamed to core/src/main/java/com/sap/ai/sdk/core/common/ClientResponseHandler.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.sap.ai.sdk.core.commons;
1+
package com.sap.ai.sdk.core.common;
22

33
import static com.sap.ai.sdk.core.JacksonConfiguration.getDefaultObjectMapper;
44

@@ -35,7 +35,7 @@ public class ClientResponseHandler<T, E extends ClientException>
3535
implements HttpClientResponseHandler<T> {
3636
@Nonnull final Class<T> responseType;
3737
@Nonnull private final Class<? extends ClientError> errorType;
38-
@Nonnull final BiFunction<String, Throwable, E> exceptionType;
38+
@Nonnull final BiFunction<String, Throwable, E> exceptionConstructor;
3939

4040
/** The parses for JSON responses, will be private once we can remove mixins */
4141
@Nonnull ObjectMapper objectMapper = getDefaultObjectMapper();
@@ -74,15 +74,15 @@ public T handleResponse(@Nonnull final ClassicHttpResponse response) throws E {
7474
private T parseResponse(@Nonnull final ClassicHttpResponse response) throws E {
7575
final HttpEntity responseEntity = response.getEntity();
7676
if (responseEntity == null) {
77-
throw exceptionType.apply("Response was empty.", null);
77+
throw exceptionConstructor.apply("Response was empty.", null);
7878
}
7979
val content = getContent(responseEntity);
8080
log.debug("Parsing response from JSON response: {}", content);
8181
try {
8282
return objectMapper.readValue(content, responseType);
8383
} catch (final JsonProcessingException e) {
8484
log.error("Failed to parse the following response: {}", content);
85-
throw exceptionType.apply("Failed to parse response", e);
85+
throw exceptionConstructor.apply("Failed to parse response", e);
8686
}
8787
}
8888

@@ -91,7 +91,7 @@ private String getContent(@Nonnull final HttpEntity entity) {
9191
try {
9292
return EntityUtils.toString(entity, StandardCharsets.UTF_8);
9393
} catch (IOException | ParseException e) {
94-
throw exceptionType.apply("Failed to read response content.", e);
94+
throw exceptionConstructor.apply("Failed to read response content.", e);
9595
}
9696
}
9797

@@ -103,7 +103,7 @@ private String getContent(@Nonnull final HttpEntity entity) {
103103
@SuppressWarnings("PMD.CloseResource")
104104
public void buildExceptionAndThrow(@Nonnull final ClassicHttpResponse response) throws E {
105105
val exception =
106-
exceptionType.apply(
106+
exceptionConstructor.apply(
107107
"Request failed with status %s %s"
108108
.formatted(response.getCode(), response.getReasonPhrase()),
109109
null);
@@ -146,6 +146,6 @@ public void parseErrorAndThrow(
146146

147147
val error = Objects.requireNonNullElse(maybeError.get().getMessage(), "");
148148
val message = "%s and error message: '%s'".formatted(baseException.getMessage(), error);
149-
throw exceptionType.apply(message, baseException);
149+
throw exceptionConstructor.apply(message, baseException);
150150
}
151151
}

core/src/main/java/com/sap/ai/sdk/core/commons/ClientStreamingHandler.java renamed to core/src/main/java/com/sap/ai/sdk/core/common/ClientStreamingHandler.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
package com.sap.ai.sdk.core.commons;
1+
package com.sap.ai.sdk.core.common;
22

33
import com.fasterxml.jackson.databind.ObjectMapper;
4+
import com.google.common.annotations.Beta;
45
import java.io.IOException;
56
import java.util.function.BiFunction;
67
import java.util.stream.Stream;
@@ -13,8 +14,9 @@
1314
*
1415
* @param <D> The type of the response.
1516
* @param <E> The type of the exception to throw.
16-
* @since 1.1.0
17+
* @since 1.2.0
1718
*/
19+
@Beta
1820
@Slf4j
1921
public class ClientStreamingHandler<D extends StreamedDelta, E extends ClientException>
2022
extends ClientResponseHandler<D, E> {
@@ -58,14 +60,14 @@ public Stream<D> handleStreamingResponse(@Nonnull final ClassicHttpResponse resp
5860
if (response.getCode() >= 300) {
5961
super.buildExceptionAndThrow(response);
6062
}
61-
return IterableStreamConverter.lines(response.getEntity(), exceptionType)
63+
return IterableStreamConverter.lines(response.getEntity(), exceptionConstructor)
6264
// half of the lines are empty newlines, the last line is "data: [DONE]"
6365
.filter(line -> !line.isEmpty() && !"data: [DONE]".equals(line.trim()))
6466
.peek(
6567
line -> {
6668
if (!line.startsWith("data: ")) {
6769
final String msg = "Failed to parse response";
68-
super.parseErrorAndThrow(line, exceptionType.apply(msg, null));
70+
super.parseErrorAndThrow(line, exceptionConstructor.apply(msg, null));
6971
}
7072
})
7173
.map(
@@ -75,7 +77,7 @@ public Stream<D> handleStreamingResponse(@Nonnull final ClassicHttpResponse resp
7577
return objectMapper.readValue(data, responseType);
7678
} catch (final IOException e) { // exception message e gets lost
7779
log.error("Failed to parse the following response: {}", line);
78-
throw exceptionType.apply("Failed to parse delta message: " + line, e);
80+
throw exceptionConstructor.apply("Failed to parse delta message: " + line, e);
7981
}
8082
});
8183
}

core/src/main/java/com/sap/ai/sdk/core/commons/IterableStreamConverter.java renamed to core/src/main/java/com/sap/ai/sdk/core/common/IterableStreamConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.sap.ai.sdk.core.commons;
1+
package com.sap.ai.sdk.core.common;
22

33
import static java.nio.charset.StandardCharsets.UTF_8;
44
import static java.util.Spliterator.NONNULL;

core/src/main/java/com/sap/ai/sdk/core/commons/StreamedDelta.java renamed to core/src/main/java/com/sap/ai/sdk/core/common/StreamedDelta.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.sap.ai.sdk.core.commons;
1+
package com.sap.ai.sdk.core.common;
22

33
import javax.annotation.Nonnull;
44
import javax.annotation.Nullable;

core/src/test/java/com/sap/ai/sdk/core/commons/IterableStreamConverterTest.java renamed to core/src/test/java/com/sap/ai/sdk/core/common/IterableStreamConverterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.sap.ai.sdk.core.commons;
1+
package com.sap.ai.sdk.core.common;
22

33
import static org.assertj.core.api.Assertions.assertThat;
44
import static org.assertj.core.api.Assertions.assertThatThrownBy;

foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiClient.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
import com.google.common.annotations.Beta;
88
import com.sap.ai.sdk.core.AiCoreService;
99
import com.sap.ai.sdk.core.DeploymentResolutionException;
10-
import com.sap.ai.sdk.core.commons.ClientResponseHandler;
11-
import com.sap.ai.sdk.core.commons.ClientStreamingHandler;
12-
import com.sap.ai.sdk.core.commons.StreamedDelta;
10+
import com.sap.ai.sdk.core.common.ClientResponseHandler;
11+
import com.sap.ai.sdk.core.common.ClientStreamingHandler;
12+
import com.sap.ai.sdk.core.common.StreamedDelta;
1313
import com.sap.ai.sdk.foundationmodels.openai.model.OpenAiChatCompletionDelta;
1414
import com.sap.ai.sdk.foundationmodels.openai.model.OpenAiChatCompletionOutput;
1515
import com.sap.ai.sdk.foundationmodels.openai.model.OpenAiChatCompletionParameters;

foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiClientException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.sap.ai.sdk.foundationmodels.openai;
22

3-
import com.sap.ai.sdk.core.commons.ClientException;
3+
import com.sap.ai.sdk.core.common.ClientException;
44
import lombok.experimental.StandardException;
55

66
/** Generic exception for errors occurring when using OpenAI foundation models. */

foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model/OpenAiChatCompletionDelta.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import com.fasterxml.jackson.annotation.JsonProperty;
44
import com.google.common.annotations.Beta;
5-
import com.sap.ai.sdk.core.commons.StreamedDelta;
5+
import com.sap.ai.sdk.core.common.StreamedDelta;
66
import java.util.List;
77
import javax.annotation.Nonnull;
88
import javax.annotation.Nullable;

0 commit comments

Comments
 (0)