Skip to content

Commit c566482

Browse files
Removed isError
1 parent 21b2e20 commit c566482

File tree

6 files changed

+5
-36
lines changed

6 files changed

+5
-36
lines changed

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

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

33
import com.fasterxml.jackson.core.JsonProcessingException;
4+
import com.fasterxml.jackson.databind.JsonNode;
45
import com.fasterxml.jackson.databind.ObjectMapper;
56
import com.google.common.annotations.Beta;
67
import java.io.IOException;
@@ -78,12 +79,12 @@ public Stream<D> handleStreamingResponse(@Nonnull final ClassicHttpResponse resp
7879
line -> {
7980
final String data = line.substring(5); // remove "data: "
8081
try {
81-
final D delta = objectMapper.readValue(data, successType);
82-
if (delta.isError()) {
82+
final JsonNode jsonNode = objectMapper.readTree(data);
83+
if (jsonNode.has("error")) {
8384
throwErrorType(response, data);
8485
}
85-
return delta;
86-
} catch (final IOException e) { // exception message e gets lost
86+
return objectMapper.treeToValue(jsonNode, successType);
87+
} catch (final IOException e) {
8788
log.error("Failed to parse delta chunk to type {}", successType);
8889
final String message = "Failed to parse delta chunk";
8990
throw exceptionFactory.build(message, e).setHttpResponse(response);

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,4 @@ public interface StreamedDelta {
4242
*/
4343
@Nullable
4444
String getFinishReason();
45-
46-
/**
47-
* Indicates if the delta is an error of type {@link ClientError}
48-
*
49-
* @return true if the delta is an error, false otherwise.
50-
*/
51-
boolean isError();
5245
}

core/src/test/java/com/sap/ai/sdk/core/common/ClientStreamingHandlerTest.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@ public String getDeltaContent() {
4040
public String getFinishReason() {
4141
return finishReason;
4242
}
43-
44-
@Override
45-
public boolean isError() {
46-
return false;
47-
}
4843
}
4944

5045
@SneakyThrows

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,6 @@ public String getFinishReason() {
5151
return null;
5252
}
5353

54-
@Override
55-
public boolean isError() {
56-
return originalResponse.getCustomFieldNames().contains("error");
57-
}
58-
5954
/**
6055
* Retrieves the completion usage from the response, or null if it is not available.
6156
*

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ public class OpenAiChatCompletionDelta extends OpenAiCompletionOutput implements
2121
@Getter(onMethod_ = @Nonnull)
2222
private List<OpenAiDeltaChatCompletionChoice> choices;
2323

24-
/** error field in case of an error. */
25-
@JsonProperty("error")
26-
@Getter(onMethod_ = @Nullable)
27-
private Object error;
28-
2924
/**
3025
* Can be used in conjunction with the seed request parameter to understand when backend changes
3126
* have been made that might impact determinism.
@@ -64,9 +59,4 @@ && getChoices().get(0).getIndex() == 0) {
6459
}
6560
return null;
6661
}
67-
68-
@Override
69-
public boolean isError() {
70-
return error != null;
71-
}
7262
}

orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationChatCompletionDelta.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,4 @@ public String getDeltaContent() {
3131
public String getFinishReason() {
3232
return getFinalResult().getChoices().get(0).getFinishReason();
3333
}
34-
35-
@Override
36-
public boolean isError() {
37-
return getCustomFieldNames().contains("error");
38-
}
3934
}

0 commit comments

Comments
 (0)