Skip to content

Commit 769532e

Browse files
fixed test
1 parent 469e436 commit 769532e

File tree

4 files changed

+42
-27
lines changed

4 files changed

+42
-27
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,18 @@ interface NoneTypeInfoMixin {}
4040
name = "text")
4141
})
4242
interface ResponseFormatSubTypesMixin {}
43+
44+
@JsonTypeInfo(
45+
use = JsonTypeInfo.Id.NAME,
46+
include = JsonTypeInfo.As.PROPERTY,
47+
property = "role",
48+
visible = true)
49+
@JsonSubTypes({
50+
@JsonSubTypes.Type(value = com.sap.ai.sdk.orchestration.model.AssistantChatMessage.class, name = "assistant"),
51+
@JsonSubTypes.Type(value = com.sap.ai.sdk.orchestration.model.DeveloperChatMessage.class, name = "developer"),
52+
@JsonSubTypes.Type(value = com.sap.ai.sdk.orchestration.model.SystemChatMessage.class, name = "system"),
53+
@JsonSubTypes.Type(value = com.sap.ai.sdk.orchestration.model.ToolChatMessage.class, name = "tool"),
54+
@JsonSubTypes.Type(value = com.sap.ai.sdk.orchestration.model.UserChatMessage.class, name = "user")
55+
})
56+
interface ChatMessageMixin {}
4357
}

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,13 @@ public static ObjectMapper getOrchestrationObjectMapper() {
4242
jackson.addMixIn(
4343
ModuleResultsOutputUnmaskingInner.class,
4444
JacksonMixins.ModuleResultsOutputUnmaskingInnerMixIn.class);
45+
jackson.addMixIn(ChatMessage.class, JacksonMixins.ChatMessageMixin.class);
4546

4647
final var module =
4748
new SimpleModule()
48-
.addDeserializer(
49-
ChatMessage.class,
50-
PolymorphicFallbackDeserializer.fromJsonSubTypes(ChatMessage.class))
5149
.addDeserializer(
5250
TemplateResponseFormat.class,
5351
PolymorphicFallbackDeserializer.fromJsonSubTypes(TemplateResponseFormat.class))
54-
.setMixInAnnotation(ChatMessage.class, JacksonMixins.NoneTypeInfoMixin.class)
5552
.setMixInAnnotation(
5653
TemplateResponseFormat.class, JacksonMixins.ResponseFormatSubTypesMixin.class);
5754
jackson.registerModule(module);

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import static com.sap.ai.sdk.orchestration.OrchestrationAiModel.GPT_4O;
2020
import static com.sap.ai.sdk.orchestration.OrchestrationAiModel.GPT_4O_MINI;
2121
import static com.sap.ai.sdk.orchestration.OrchestrationAiModel.Parameter.*;
22+
import static com.sap.ai.sdk.orchestration.model.ResponseChatMessage.RoleEnum.ASSISTANT;
23+
import static com.sap.ai.sdk.orchestration.model.UserChatMessage.RoleEnum.USER;
2224
import static org.apache.hc.core5.http.HttpStatus.SC_BAD_REQUEST;
2325
import static org.apache.hc.core5.http.HttpStatus.SC_OK;
2426
import static org.assertj.core.api.Assertions.assertThat;
@@ -35,8 +37,6 @@
3537
import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo;
3638
import com.github.tomakehurst.wiremock.junit5.WireMockTest;
3739
import com.github.tomakehurst.wiremock.stubbing.Scenario;
38-
import com.sap.ai.sdk.orchestration.model.AssistantChatMessage;
39-
import com.sap.ai.sdk.orchestration.model.ChatMessageContent;
4040
import com.sap.ai.sdk.orchestration.model.DPIEntities;
4141
import com.sap.ai.sdk.orchestration.model.DataRepositoryType;
4242
import com.sap.ai.sdk.orchestration.model.DocumentGroundingFilter;
@@ -51,6 +51,8 @@
5151
import com.sap.ai.sdk.orchestration.model.SearchDocumentKeyValueListPair;
5252
import com.sap.ai.sdk.orchestration.model.SearchSelectOptionEnum;
5353
import com.sap.ai.sdk.orchestration.model.Template;
54+
import com.sap.ai.sdk.orchestration.model.UserChatMessage;
55+
import com.sap.ai.sdk.orchestration.model.UserChatMessageContent;
5456
import com.sap.cloud.sdk.cloudplatform.connectivity.ApacheHttpClient5Accessor;
5557
import com.sap.cloud.sdk.cloudplatform.connectivity.ApacheHttpClient5Cache;
5658
import com.sap.cloud.sdk.cloudplatform.connectivity.DefaultHttpDestination;
@@ -277,10 +279,10 @@ void testTemplating() throws IOException {
277279

278280
assertThat(((TextItem) messageList.get(0).content().items().get(0)).text())
279281
.isEqualTo("You are a multi language translator");
280-
assertThat(messageList.get(0).role()).isEqualTo("assistant"); // JONAS: why is the change needed here?
282+
assertThat(messageList.get(0).role()).isEqualTo("system");
281283
assertThat(((TextItem) messageList.get(1).content().items().get(0)).text())
282284
.isEqualTo("Reply with 'Orchestration Service is working!' in German");
283-
assertThat(messageList.get(1).role()).isEqualTo("assistant");
285+
assertThat(messageList.get(1).role()).isEqualTo("user");
284286
assertThat(((TextItem) messageList.get(2).content().items().get(0)).text())
285287
.isEqualTo("Orchestration Service funktioniert!");
286288
assertThat(messageList.get(2).role()).isEqualTo("assistant");
@@ -295,7 +297,7 @@ void testTemplating() throws IOException {
295297
assertThat(choices.get(0).getIndex()).isZero();
296298
assertThat(choices.get(0).getMessage().getContent())
297299
.isEqualTo("Le service d'orchestration fonctionne!");
298-
assertThat(choices.get(0).getMessage().getRole().toString()).isEqualTo("assistant");
300+
assertThat(choices.get(0).getMessage().getRole()).isEqualTo(ASSISTANT);
299301
assertThat(choices.get(0).getFinishReason()).isEqualTo("stop");
300302
var usage = result.getTokenUsage();
301303
assertThat(usage.getCompletionTokens()).isEqualTo(7);
@@ -310,7 +312,7 @@ void testTemplating() throws IOException {
310312
assertThat(choices.get(0).getIndex()).isZero();
311313
assertThat(choices.get(0).getMessage().getContent())
312314
.isEqualTo("Le service d'orchestration fonctionne!");
313-
assertThat(choices.get(0).getMessage().getRole().toString()).isEqualTo("assistant");
315+
assertThat(choices.get(0).getMessage().getRole()).isEqualTo(ASSISTANT);
314316
assertThat(choices.get(0).getFinishReason()).isEqualTo("stop");
315317
usage = result.getTokenUsage();
316318
assertThat(usage.getCompletionTokens()).isEqualTo(7);
@@ -708,9 +710,9 @@ void streamChatCompletionDeltas() throws IOException {
708710
final var templating = deltaList.get(0).getModuleResults().getTemplating();
709711
assertThat(templating).hasSize(1);
710712

711-
final var templateItem = templating.get(0); // JONAS: why?
712-
assertThat(templateItem).isInstanceOf(AssistantChatMessage.class);
713-
assertThat(((ChatMessageContent.InnerString) ((AssistantChatMessage) templateItem).getContent()).value())
713+
final var templateItem = (UserChatMessage) templating.get(0);
714+
assertThat(templateItem.getRole()).isEqualTo(USER);
715+
assertThat(((UserChatMessageContent.InnerString) templateItem.getContent()).value())
714716
.isEqualTo("Hello world! Why is this phrase so famous?");
715717

716718
assertThat(result1.getSystemFingerprint()).isEqualTo("fp_808245b034");
@@ -775,7 +777,7 @@ void testMultiMessage() throws IOException {
775777
.isEqualTo(
776778
"Well, this image features the logo of SAP, a software company, set against a gradient blue background transitioning from light to dark. The main color in the image is blue.");
777779
assertThat(result.getAllMessages()).hasSize(3);
778-
var systemMessage = result.getAllMessages().get(0); // JONAS: why?
780+
var systemMessage = result.getAllMessages().get(0);
779781
assertThat(systemMessage.role()).isEqualTo("system");
780782
assertThat(systemMessage.content().items()).hasSize(2);
781783
assertThat(systemMessage.content().items().get(0)).isInstanceOf(TextItem.class);
@@ -813,15 +815,14 @@ void testMultiMessage() throws IOException {
813815
.isEqualTo(
814816
"Well, this image features the logo of SAP, a software company, set against a gradient blue background transitioning from light to dark. The main color in the image is blue.");
815817
assertThat(llmResults.getChoices().get(0).getFinishReason()).isEqualTo("stop");
816-
assertThat(llmResults.getChoices().get(0).getMessage().getRole()).isEqualTo("assistant");
818+
assertThat(llmResults.getChoices().get(0).getMessage().getRole()).isEqualTo(ASSISTANT);
817819
var orchestrationResult = (LLMModuleResultSynchronous) response.getOrchestrationResult();
818820
assertThat(orchestrationResult.getChoices()).hasSize(1);
819821
assertThat(orchestrationResult.getChoices().get(0).getMessage().getContent())
820822
.isEqualTo(
821823
"Well, this image features the logo of SAP, a software company, set against a gradient blue background transitioning from light to dark. The main color in the image is blue.");
822824
assertThat(orchestrationResult.getChoices().get(0).getFinishReason()).isEqualTo("stop");
823-
assertThat(orchestrationResult.getChoices().get(0).getMessage().getRole())
824-
.isEqualTo("assistant");
825+
assertThat(orchestrationResult.getChoices().get(0).getMessage().getRole()).isEqualTo(ASSISTANT);
825826

826827
try (var requestInputStream = fileLoader.apply("multiMessageRequest.json")) {
827828
final String requestBody = new String(requestInputStream.readAllBytes());

orchestration/src/test/resources/templatingRequest.json

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
11
{
22
"orchestration_config": {
33
"module_configurations": {
4-
"templating_module_config": {
5-
"template": [
6-
{
7-
"role": "user",
8-
"content": "{{?input}}"
9-
}
10-
],
11-
"defaults" : { },
12-
"tools" : [ ]
13-
},
144
"llm_module_config": {
155
"model_name": "gpt-4o",
166
"model_params": {
@@ -22,6 +12,19 @@
2212
"n" : 1
2313
},
2414
"model_version": "latest"
15+
},
16+
"templating_module_config": {
17+
"template": [
18+
{
19+
"role": "user",
20+
"content": [ {
21+
"type" : "text",
22+
"text" : "{{?input}}"
23+
} ]
24+
}
25+
],
26+
"defaults" : { },
27+
"tools" : [ ]
2528
}
2629
},
2730
"stream": false

0 commit comments

Comments
 (0)