Skip to content

Commit cf59964

Browse files
committed
Review suggestion
1 parent c1b6440 commit cf59964

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ public class ClientResponseHandler<T, R extends ClientError, E extends ClientExc
3636
@Nonnull final Class<T> successType;
3737

3838
/** The HTTP error response type */
39-
@Nonnull protected final Class<R> errorType;
39+
@Nonnull final Class<R> errorType;
4040

4141
/** The factory to create exceptions for Http 4xx/5xx responses. */
42-
@Nonnull protected final ClientExceptionFactory<E, R> exceptionFactory;
42+
@Nonnull final ClientExceptionFactory<E, R> exceptionFactory;
4343

4444
/** The parses for JSON responses, will be private once we can remove mixins */
4545
@Nonnull ObjectMapper objectMapper = getDefaultObjectMapper();

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public String getFinishReason() {
4444

4545
@SneakyThrows
4646
@Test
47-
void testHandleStreamingResponse_variousScenarios() {
47+
void testHandleStreamingResponse() {
4848
var sut =
4949
new ClientStreamingHandler<>(
5050
MyStreamedDelta.class, MyError.class, new MyExceptionFactory());
@@ -97,12 +97,12 @@ void testHandleStreamingResponse_variousScenarios() {
9797
assertThat(stream2).isEmpty();
9898

9999
var stream3 = sut.handleStreamingResponse(response);
100-
assertThatThrownBy(() -> stream3.toList())
100+
assertThatThrownBy(stream3::toList)
101101
.isInstanceOf(MyException.class)
102102
.hasMessageContaining("Failed to parse response");
103103

104104
var stream4 = sut.handleStreamingResponse(response);
105-
assertThatThrownBy(() -> stream4.toList())
105+
assertThatThrownBy(stream4::toList)
106106
.isInstanceOf(MyException.class)
107107
.hasMessageContaining("Failed to parse delta chunk")
108108
.hasCauseInstanceOf(JsonParseException.class);

sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/controllers/OrchestrationController.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,13 @@ Object inputFiltering(
131131
} catch (OrchestrationInputFilterException e) {
132132
final var msg =
133133
new StringBuilder(
134-
"Failed to obtain a response as the content was flagged by input filter. Error %d"
134+
"[Http %d] Failed to obtain a response as the content was flagged by input filter. "
135135
.formatted(e.getStatusCode()));
136136

137137
Optional.ofNullable(e.getAzureContentSafetyInput())
138-
.map(AzureContentSafetyInput::getHate)
138+
.map(AzureContentSafetyInput::getViolence)
139139
.filter(rating -> rating.compareTo(policy.getAzureThreshold()) > 0)
140-
.ifPresent(rating -> msg.append("Hate score %d".formatted(rating.getValue())));
140+
.ifPresent(rating -> msg.append("Violence score %d".formatted(rating.getValue())));
141141

142142
log.debug(msg.toString(), e);
143143
return ResponseEntity.internalServerError().body(msg.toString());
@@ -163,12 +163,12 @@ Object outputFiltering(
163163
} catch (OrchestrationOutputFilterException e) {
164164
final var msg =
165165
new StringBuilder(
166-
"Failed to obtain a response as the content was flagged by output filter.");
166+
"Failed to obtain a response as the content was flagged by output filter. ");
167167

168168
Optional.ofNullable(e.getAzureContentSafetyOutput())
169-
.map(AzureContentSafetyOutput::getHate)
169+
.map(AzureContentSafetyOutput::getViolence)
170170
.filter(rating -> rating.compareTo(policy.getAzureThreshold()) > 0)
171-
.ifPresent(rating -> msg.append("Hate score %d ".formatted(rating.getValue())));
171+
.ifPresent(rating -> msg.append("Violence score %d ".formatted(rating.getValue())));
172172

173173
log.debug(msg.toString(), e);
174174
return ResponseEntity.internalServerError().body(msg.toString());
@@ -190,9 +190,12 @@ Object llamaGuardInputFiltering(
190190
try {
191191
response = service.llamaGuardInputFilter(enabled);
192192
} catch (OrchestrationInputFilterException e) {
193-
final var msg =
194-
"Failed to obtain a response as the content was flagged by input filter. Error %d"
193+
var msg =
194+
"[Http %d] Failed to obtain a response as the content was flagged by input filter. "
195195
.formatted(e.getStatusCode());
196+
if(e.getLlamaGuard38b() != null){
197+
msg += " Violent crimes are %s".formatted(e.getLlamaGuard38b().isViolentCrimes());
198+
}
196199
log.debug(msg, e);
197200
return ResponseEntity.internalServerError().body(msg);
198201
}

0 commit comments

Comments
 (0)