|
37 | 37 | import com.github.tomakehurst.wiremock.junit5.WireMockTest; |
38 | 38 | import com.github.tomakehurst.wiremock.stubbing.Scenario; |
39 | 39 | import com.sap.ai.sdk.orchestration.model.ChatMessage; |
40 | | -import com.sap.ai.sdk.orchestration.model.ChatMessagesInner; |
41 | 40 | import com.sap.ai.sdk.orchestration.model.CompletionPostRequest; |
42 | 41 | import com.sap.ai.sdk.orchestration.model.CompletionPostResponse; |
43 | 42 | import com.sap.ai.sdk.orchestration.model.DPIEntities; |
|
47 | 46 | import com.sap.ai.sdk.orchestration.model.LLMModuleConfig; |
48 | 47 | import com.sap.ai.sdk.orchestration.model.LLMModuleResult; |
49 | 48 | 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; |
50 | 51 | import com.sap.ai.sdk.orchestration.model.ModuleConfigs; |
51 | 52 | import com.sap.ai.sdk.orchestration.model.MultiChatMessage; |
52 | 53 | import com.sap.ai.sdk.orchestration.model.OrchestrationConfig; |
| 54 | +import com.sap.ai.sdk.orchestration.model.SingleChatMessage; |
53 | 55 | import com.sap.ai.sdk.orchestration.model.Template; |
54 | 56 | import com.sap.ai.sdk.orchestration.model.TextContent; |
55 | 57 | import com.sap.cloud.sdk.cloudplatform.connectivity.ApacheHttpClient5Accessor; |
@@ -147,7 +149,7 @@ void testGrounding() { |
147 | 149 | assertThat(groundingData.get("grounding_result").toString()) |
148 | 150 | .startsWith("Joule is the AI copilot that truly understands your business."); |
149 | 151 | 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()) |
151 | 153 | .startsWith( |
152 | 154 | "What does Joule do? Use the following information as additional context: Joule is the AI copilot that truly understands your business."); |
153 | 155 | assertThat(llmChoice.getMessage().getContent()) |
@@ -258,14 +260,22 @@ void filteringLoose() throws IOException { |
258 | 260 | .withBodyFile("filteringLooseResponse.json") |
259 | 261 | .withHeader("Content-Type", "application/json"))); |
260 | 262 |
|
261 | | - final var filter = |
| 263 | + final var azureFilter = |
262 | 264 | new AzureContentFilter() |
263 | 265 | .hate(ALLOW_SAFE_LOW_MEDIUM) |
264 | 266 | .selfHarm(ALLOW_SAFE_LOW_MEDIUM) |
265 | 267 | .sexual(ALLOW_SAFE_LOW_MEDIUM) |
266 | 268 | .violence(ALLOW_SAFE_LOW_MEDIUM); |
267 | 269 |
|
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)); |
269 | 279 | // the result is asserted in the verify step below |
270 | 280 |
|
271 | 281 | // verify that null fields are absent from the sent request |
@@ -603,7 +613,7 @@ void streamChatCompletionDeltas() throws IOException { |
603 | 613 | final var templating = deltaList.get(0).getModuleResults().getTemplating(); |
604 | 614 | assertThat(templating).hasSize(1); |
605 | 615 |
|
606 | | - final var templateItem = (ChatMessage) templating.get(0); |
| 616 | + final var templateItem = (SingleChatMessage) templating.get(0); |
607 | 617 | assertThat(templateItem.getRole()).isEqualTo("user"); |
608 | 618 | assertThat(templateItem.getContent()) |
609 | 619 | .isEqualTo("Hello world! Why is this phrase so famous?"); |
@@ -755,10 +765,9 @@ void testOrchestrationChatResponseWithMultiChatMessage() { |
755 | 765 | module.addDeserializer( |
756 | 766 | LLMModuleResult.class, |
757 | 767 | PolymorphicFallbackDeserializer.fromJsonSubTypes(LLMModuleResult.class)); |
758 | | - module.setMixInAnnotation(ChatMessagesInner.class, JacksonMixins.NoneTypeInfoMixin.class); |
| 768 | + module.setMixInAnnotation(ChatMessage.class, JacksonMixins.NoneTypeInfoMixin.class); |
759 | 769 | module.addDeserializer( |
760 | | - ChatMessagesInner.class, |
761 | | - PolymorphicFallbackDeserializer.fromJsonSubTypes(ChatMessagesInner.class)); |
| 770 | + ChatMessage.class, PolymorphicFallbackDeserializer.fromJsonSubTypes(ChatMessage.class)); |
762 | 771 |
|
763 | 772 | var orchestrationChatResponse = |
764 | 773 | new OrchestrationChatResponse( |
|
0 commit comments