Skip to content

Commit 4908718

Browse files
committed
Update Tests, add Llama Guard Test
1 parent d60505e commit 4908718

File tree

6 files changed

+38
-13
lines changed

6 files changed

+38
-13
lines changed

orchestration/src/test/java/com/sap/ai/sdk/orchestration/OrchestrationUnitTest.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import com.github.tomakehurst.wiremock.junit5.WireMockTest;
3838
import com.github.tomakehurst.wiremock.stubbing.Scenario;
3939
import com.sap.ai.sdk.orchestration.model.ChatMessage;
40-
import com.sap.ai.sdk.orchestration.model.ChatMessagesInner;
4140
import com.sap.ai.sdk.orchestration.model.CompletionPostRequest;
4241
import com.sap.ai.sdk.orchestration.model.CompletionPostResponse;
4342
import com.sap.ai.sdk.orchestration.model.DPIEntities;
@@ -47,9 +46,12 @@
4746
import com.sap.ai.sdk.orchestration.model.LLMModuleConfig;
4847
import com.sap.ai.sdk.orchestration.model.LLMModuleResult;
4948
import com.sap.ai.sdk.orchestration.model.LLMModuleResultSynchronous;
49+
import com.sap.ai.sdk.orchestration.model.LlamaGuard38b;
50+
import com.sap.ai.sdk.orchestration.model.LlamaGuard38bFilterConfig;
5051
import com.sap.ai.sdk.orchestration.model.ModuleConfigs;
5152
import com.sap.ai.sdk.orchestration.model.MultiChatMessage;
5253
import com.sap.ai.sdk.orchestration.model.OrchestrationConfig;
54+
import com.sap.ai.sdk.orchestration.model.SingleChatMessage;
5355
import com.sap.ai.sdk.orchestration.model.Template;
5456
import com.sap.ai.sdk.orchestration.model.TextContent;
5557
import com.sap.cloud.sdk.cloudplatform.connectivity.ApacheHttpClient5Accessor;
@@ -147,7 +149,7 @@ void testGrounding() {
147149
assertThat(groundingData.get("grounding_result").toString())
148150
.startsWith("Joule is the AI copilot that truly understands your business.");
149151
assertThat(result.getModuleResults().getGrounding().getMessage()).isEqualTo("grounding result");
150-
assertThat(((ChatMessage) result.getModuleResults().getTemplating().get(0)).getContent())
152+
assertThat(((SingleChatMessage) result.getModuleResults().getTemplating().get(0)).getContent())
151153
.startsWith(
152154
"What does Joule do? Use the following information as additional context: Joule is the AI copilot that truly understands your business.");
153155
assertThat(llmChoice.getMessage().getContent())
@@ -258,14 +260,22 @@ void filteringLoose() throws IOException {
258260
.withBodyFile("filteringLooseResponse.json")
259261
.withHeader("Content-Type", "application/json")));
260262

261-
final var filter =
263+
final var azureFilter =
262264
new AzureContentFilter()
263265
.hate(ALLOW_SAFE_LOW_MEDIUM)
264266
.selfHarm(ALLOW_SAFE_LOW_MEDIUM)
265267
.sexual(ALLOW_SAFE_LOW_MEDIUM)
266268
.violence(ALLOW_SAFE_LOW_MEDIUM);
267269

268-
client.chatCompletion(prompt, config.withInputFiltering(filter).withOutputFiltering(filter));
270+
ContentFilter llamaFilter =
271+
() ->
272+
LlamaGuard38bFilterConfig.create()
273+
.type(LlamaGuard38bFilterConfig.TypeEnum.LLAMA_GUARD_3_8B)
274+
.config(LlamaGuard38b.create().selfHarm(true));
275+
276+
client.chatCompletion(
277+
prompt,
278+
config.withInputFiltering(azureFilter, llamaFilter).withOutputFiltering(azureFilter));
269279
// the result is asserted in the verify step below
270280

271281
// verify that null fields are absent from the sent request
@@ -603,7 +613,7 @@ void streamChatCompletionDeltas() throws IOException {
603613
final var templating = deltaList.get(0).getModuleResults().getTemplating();
604614
assertThat(templating).hasSize(1);
605615

606-
final var templateItem = (ChatMessage) templating.get(0);
616+
final var templateItem = (SingleChatMessage) templating.get(0);
607617
assertThat(templateItem.getRole()).isEqualTo("user");
608618
assertThat(templateItem.getContent())
609619
.isEqualTo("Hello world! Why is this phrase so famous?");
@@ -755,10 +765,9 @@ void testOrchestrationChatResponseWithMultiChatMessage() {
755765
module.addDeserializer(
756766
LLMModuleResult.class,
757767
PolymorphicFallbackDeserializer.fromJsonSubTypes(LLMModuleResult.class));
758-
module.setMixInAnnotation(ChatMessagesInner.class, JacksonMixins.NoneTypeInfoMixin.class);
768+
module.setMixInAnnotation(ChatMessage.class, JacksonMixins.NoneTypeInfoMixin.class);
759769
module.addDeserializer(
760-
ChatMessagesInner.class,
761-
PolymorphicFallbackDeserializer.fromJsonSubTypes(ChatMessagesInner.class));
770+
ChatMessage.class, PolymorphicFallbackDeserializer.fromJsonSubTypes(ChatMessage.class));
762771

763772
var orchestrationChatResponse =
764773
new OrchestrationChatResponse(

orchestration/src/test/resources/filteringLooseRequest.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
"role": "user",
2020
"content": "Hello World! Why is this phrase so famous?"
2121
}
22-
]
22+
],
23+
"defaults" : { },
24+
"tools" : [ ]
2325
},
2426
"filtering_module_config": {
2527
"input": {
@@ -32,6 +34,12 @@
3234
"Sexual": 4,
3335
"Violence": 4
3436
}
37+
},
38+
{
39+
"type": "llama_guard_3_8b",
40+
"config": {
41+
"self_harm": true
42+
}
3543
}
3644
]
3745
},

orchestration/src/test/resources/maskingRequest.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
"role": "user",
2020
"content": "Hello World! Why is this phrase so famous?"
2121
}
22-
]
22+
],
23+
"defaults" : { },
24+
"tools" : [ ]
2325
},
2426
"masking_module_config": {
2527
"masking_providers": [

orchestration/src/test/resources/messagesHistoryRequest.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
"role": "user",
2020
"content": "What is the typical food there?"
2121
}
22-
]
22+
],
23+
"defaults" : { },
24+
"tools" : [ ]
2325
}
2426
},
2527
"stream": false

orchestration/src/test/resources/multiChatMessageRequest.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
}
2525
]
2626
}
27-
]
27+
],
28+
"defaults" : { },
29+
"tools" : [ ]
2830
}
2931
},
3032
"stream": false

orchestration/src/test/resources/templatingRequest.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
"role": "user",
88
"content": "{{?input}}"
99
}
10-
]
10+
],
11+
"defaults" : { },
12+
"tools" : [ ]
1113
},
1214
"llm_module_config": {
1315
"model_name": "gpt-35-turbo-16k",

0 commit comments

Comments
 (0)