|
31 | 31 | import static org.mockito.Mockito.when; |
32 | 32 |
|
33 | 33 | import com.fasterxml.jackson.core.JsonParseException; |
| 34 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 35 | +import com.fasterxml.jackson.databind.module.SimpleModule; |
34 | 36 | import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; |
35 | 37 | import com.github.tomakehurst.wiremock.junit5.WireMockTest; |
36 | 38 | import com.github.tomakehurst.wiremock.stubbing.Scenario; |
37 | 39 | import com.sap.ai.sdk.orchestration.model.ChatMessage; |
| 40 | +import com.sap.ai.sdk.orchestration.model.ChatMessagesInner; |
38 | 41 | import com.sap.ai.sdk.orchestration.model.CompletionPostRequest; |
| 42 | +import com.sap.ai.sdk.orchestration.model.CompletionPostResponse; |
39 | 43 | import com.sap.ai.sdk.orchestration.model.DPIEntities; |
40 | 44 | import com.sap.ai.sdk.orchestration.model.GenericModuleResult; |
41 | 45 | import com.sap.ai.sdk.orchestration.model.ImageContent; |
42 | 46 | import com.sap.ai.sdk.orchestration.model.ImageContentImageUrl; |
43 | 47 | import com.sap.ai.sdk.orchestration.model.LLMModuleConfig; |
| 48 | +import com.sap.ai.sdk.orchestration.model.LLMModuleResult; |
44 | 49 | import com.sap.ai.sdk.orchestration.model.LLMModuleResultSynchronous; |
45 | 50 | import com.sap.ai.sdk.orchestration.model.ModuleConfigs; |
46 | 51 | import com.sap.ai.sdk.orchestration.model.MultiChatMessage; |
|
58 | 63 | import java.util.function.Function; |
59 | 64 | import java.util.stream.Stream; |
60 | 65 | import javax.annotation.Nonnull; |
| 66 | +import lombok.SneakyThrows; |
61 | 67 | import org.apache.hc.client5.http.classic.HttpClient; |
62 | 68 | import org.apache.hc.core5.http.ContentType; |
63 | 69 | import org.apache.hc.core5.http.io.entity.InputStreamEntity; |
@@ -638,7 +644,7 @@ void streamChatCompletionDeltas() throws IOException { |
638 | 644 | } |
639 | 645 |
|
640 | 646 | @Test |
641 | | - void testMultiChatMessageRequest() throws IOException { |
| 647 | + void testRequestWithMultiChatMessage() throws IOException { |
642 | 648 |
|
643 | 649 | stubFor( |
644 | 650 | post("/completion") |
@@ -743,4 +749,29 @@ void testMultiChatMessageRequest() throws IOException { |
743 | 749 | .withRequestBody(equalToJson(requestBody))); |
744 | 750 | } |
745 | 751 | } |
| 752 | + |
| 753 | + @SneakyThrows |
| 754 | + @Test |
| 755 | + void testOrchestrationChatResponseWithImage() { |
| 756 | + var module = new SimpleModule(); |
| 757 | + module.setMixInAnnotation(LLMModuleResult.class, JacksonMixins.NoneTypeInfoMixin.class); |
| 758 | + module.addDeserializer( |
| 759 | + LLMModuleResult.class, new PolymorphicFallbackDeserializer<>(LLMModuleResult.class)); |
| 760 | + module.setMixInAnnotation(ChatMessagesInner.class, JacksonMixins.NoneTypeInfoMixin.class); |
| 761 | + module.addDeserializer( |
| 762 | + ChatMessagesInner.class, new PolymorphicFallbackDeserializer<>(ChatMessagesInner.class)); |
| 763 | + |
| 764 | + var orchestrationChatResponse = |
| 765 | + new OrchestrationChatResponse( |
| 766 | + new ObjectMapper() |
| 767 | + .registerModule(module) |
| 768 | + .readValue( |
| 769 | + new String( |
| 770 | + fileLoader.apply("__files/multiChatMessageResponse.json").readAllBytes()), |
| 771 | + CompletionPostResponse.class)); |
| 772 | + |
| 773 | + assertThatThrownBy(orchestrationChatResponse::getAllMessages) |
| 774 | + .isInstanceOf(UnsupportedOperationException.class) |
| 775 | + .hasMessage("Messages of MultiChatMessage type not supported by convenience API"); |
| 776 | + } |
746 | 777 | } |
0 commit comments