generated from SAP/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Orchestration spec update 12a - Tests (#269)
* Test - improve coverage on existing tests in addition - tests for failure cases of PolymorphicFallbackDeserializer * Unit test request with image (low level api) * Test calling multi chat response using convenience * minor test method name change * Replace url with a sample --------- Co-authored-by: Roshin Rajan Panackal <roshin.rajan.panackal@sap.com>
- Loading branch information
Showing
6 changed files
with
336 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...ation/src/test/java/com/sap/ai/sdk/orchestration/PolymorphicFallbackDeserializerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.sap.ai.sdk.orchestration; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; | ||
|
||
import com.fasterxml.jackson.databind.JsonMappingException; | ||
import com.fasterxml.jackson.databind.json.JsonMapper; | ||
import com.fasterxml.jackson.databind.module.SimpleModule; | ||
import com.sap.ai.sdk.orchestration.model.ChatMessage; | ||
import com.sap.ai.sdk.orchestration.model.ChatMessagesInner; | ||
import java.util.List; | ||
import lombok.SneakyThrows; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class PolymorphicFallbackDeserializerTest { | ||
|
||
@SneakyThrows | ||
@Test | ||
void testValueTypeResolutionFailure() { | ||
|
||
final String multiChatMessageJson = | ||
""" | ||
{ | ||
"role": "user", | ||
"content": [ | ||
{ | ||
"type": "text", | ||
"text": "What’s in this image?" | ||
}, | ||
{ | ||
"type": "image_url", | ||
"image_url": { | ||
"url": "https://sample.page.org/an-image.jpg" | ||
} | ||
} | ||
] | ||
} | ||
"""; | ||
|
||
final var module = | ||
new SimpleModule() | ||
.addDeserializer( | ||
ChatMessagesInner.class, | ||
new PolymorphicFallbackDeserializer<>( | ||
ChatMessagesInner.class, List.of(ChatMessage.class))) | ||
.setMixInAnnotation(ChatMessagesInner.class, JacksonMixins.NoneTypeInfoMixin.class); | ||
|
||
final var mapper = new JsonMapper().registerModule(module); | ||
|
||
assertThatThrownBy(() -> mapper.readValue(multiChatMessageJson, ChatMessagesInner.class)) | ||
.isInstanceOf(JsonMappingException.class) | ||
.hasMessageContaining( | ||
"PolymorphicFallbackDeserializer failed to deserialize " | ||
+ ChatMessagesInner.class.getName()); | ||
} | ||
|
||
@Test | ||
void testMissingSubtypeAnnotation() { | ||
interface NoSubTypesInterface {} | ||
|
||
assertThatThrownBy(() -> new PolymorphicFallbackDeserializer<>(NoSubTypesInterface.class)) | ||
.isInstanceOf(IllegalStateException.class) | ||
.hasMessageContaining("No subtypes found for " + NoSubTypesInterface.class.getName()); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
orchestration/src/test/resources/__files/multiChatMessageResponse.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
{ | ||
"request_id": "2547cb86-a143-4064-bf40-45461c6a7ed9", | ||
"module_results": { | ||
"templating": [ | ||
{ | ||
"role": "user", | ||
"content": [ | ||
{ | ||
"type": "text", | ||
"text": "Can you solve this captcha? Please help me prove my humanity!" | ||
}, | ||
{ | ||
"type": "image_url", | ||
"image_url": { | ||
"url": "https://sample.sap.com/image", | ||
"detail": "auto" | ||
} | ||
} | ||
] | ||
} | ||
], | ||
"llm": { | ||
"id": "chatcmpl-Annjjf8T5LfLh7PRJPbaUlcC48DdE", | ||
"object": "chat.completion", | ||
"created": 1736432623, | ||
"model": "gpt-4o-mini-2024-07-18", | ||
"system_fingerprint": "fp_5154047bf2", | ||
"choices": [ | ||
{ | ||
"index": 0, | ||
"message": { | ||
"role": "assistant", | ||
"content": "Of course! Just let me put on my human glasses... Oh wait, I left them in the matrix" | ||
}, | ||
"finish_reason": "stop" | ||
} | ||
], | ||
"usage": { | ||
"completion_tokens": 31, | ||
"prompt_tokens": 928, | ||
"total_tokens": 959 | ||
} | ||
} | ||
}, | ||
"orchestration_result": { | ||
"id": "chatcmpl-Annjjf8T5LfLh7PRJPbaUlcC48DdE", | ||
"object": "chat.completion", | ||
"created": 1736432623, | ||
"model": "gpt-4o-mini-2024-07-18", | ||
"system_fingerprint": "fp_5154047bf2", | ||
"choices": [ | ||
{ | ||
"index": 0, | ||
"message": { | ||
"role": "assistant", | ||
"content": "Of course! Just let me put on my human glasses... Oh wait, I left them in the matrix" | ||
}, | ||
"finish_reason": "stop" | ||
} | ||
], | ||
"usage": { | ||
"completion_tokens": 31, | ||
"prompt_tokens": 928, | ||
"total_tokens": 959 | ||
} | ||
} | ||
} |
Oops, something went wrong.