generated from SAP/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 16
feat: Orchestration image support #294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
61 commits
Select commit
Hold shift + click to select a range
77b6637
Call Orchestration with image and multiString via executeRequestFromJ…
Jonas-Isr 026771b
Merge branch 'main' into orchestration-image-support
Jonas-Isr 09816d2
Work in Progress
Jonas-Isr 54a2c19
Align System- nad AssintantMessage with UserMessage
Jonas-Isr 98ba774
Improve exceptions
Jonas-Isr 75afed1
Improve tests
Jonas-Isr 38f3fd4
Prepare draft
Jonas-Isr f8ea4d0
- Restrict Multi- and ImageContent to appropriate classes;
Jonas-Isr cd20ca8
Rename addTextMessages() to addText()
Jonas-Isr a2fe90f
Remove or hide unneeded constructors, use Message.user() etc. instead
Jonas-Isr ec899a4
Add simple e2e tests
Jonas-Isr f173057
Prepare draft
Jonas-Isr c57bd1d
Small change
Jonas-Isr 0524fd7
Refactor newly introduced classes
Jonas-Isr 60e8120
WIP
Jonas-Isr 3754d9c
add test for base64 image
Jonas-Isr 8ab1514
Small cleanups, no more unnecessary Exceptions
Jonas-Isr e99d7b9
Small changes: ImageItem.DetailLevel is not mandatory by spec, refact…
Jonas-Isr 7c05d89
Delete MessageContent.toString()
Jonas-Isr 5a72a33
Bit of clean up
Jonas-Isr 6100502
Add/improve javadocs
Jonas-Isr 85d077f
Add/improve javadocs some more
Jonas-Isr 7113283
Add annotations
Jonas-Isr 60b97b0
Add explicit allArgs constructor to ImageItem
Jonas-Isr fa1add0
Fix codestyle etc.
Jonas-Isr 682794a
Fix order in add methods
Jonas-Isr b671bc7
Improve unit test
Jonas-Isr 3bd521c
Improve e2e test
Jonas-Isr a152c2f
Merge branch 'main' into orchestration-image-support
Jonas-Isr 0f928a8
Small fixes after merge
Jonas-Isr 6ee7290
Add unit test for message construction
Jonas-Isr 57330d4
Fix sample app after merge
Jonas-Isr 65d01c6
Simplify multiMessage unit test
Jonas-Isr 8a0c79d
Formatting
bot-sdk-js 13c0387
Add constructor for multiple strings for UserMessage and MessageContent
Jonas-Isr f95c4d3
Small changes
Jonas-Isr eaf2632
Merge remote-tracking branch 'origin/orchestration-image-support' int…
Jonas-Isr be70506
Add documentation and release notes
Jonas-Isr fb0a89f
Improve documentation
Jonas-Isr 8357b89
Update orchestration/src/main/java/com/sap/ai/sdk/orchestration/Messa…
Jonas-Isr 8d32086
Minor changes
Jonas-Isr dff4fb8
Make `.content()` @Beta
Jonas-Isr b0e6701
change method names from `addXYZ()` to `andXYZ()`
Jonas-Isr 29ceee1
Delete unnecessary @Nonnull from ImageItem constructor
Jonas-Isr d8fd060
Improve tests
Jonas-Isr bcf0d99
Merge branch 'main' into orchestration-image-support
Jonas-Isr 162cb6b
increase coverage
CharlesDuboisSAP adf81da
We hate Jacoco
CharlesDuboisSAP a099ee0
Update docs/release-notes/release_notes.md
Jonas-Isr 4899f36
Simplify logic
Jonas-Isr 837fd66
Small fixes
Jonas-Isr 3dd3085
Reduce and streamline amount of public API
Jonas-Isr d91ca3b
Rename convenience methods to `withXyz()`
Jonas-Isr e438330
Simplify code and adapt jacoco coverage
Jonas-Isr a87fa5d
Small change
Jonas-Isr 27a1033
Add release number to javadocs
Jonas-Isr b505272
Fit jacoco coverage
Jonas-Isr 72f66b5
Merge branch 'main' into orchestration-image-support
Jonas-Isr dc69ad1
Rename MessageContent.contentItemList to MessageContent.items
Jonas-Isr 3d8315e
Update docs
Jonas-Isr cd08312
Merge branch 'main' into orchestration-image-support
Jonas-Isr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -7,11 +7,7 @@ | |
| import com.sap.ai.sdk.orchestration.model.ImageContentImageUrl; | ||
| import com.sap.ai.sdk.orchestration.model.MultiChatMessage; | ||
| import com.sap.ai.sdk.orchestration.model.TextContent; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.stream.Stream; | ||
| import javax.annotation.Nonnull; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| /** Interface representing convenience wrappers of chat message to the orchestration service. */ | ||
| public sealed interface Message permits UserMessage, AssistantMessage, SystemMessage { | ||
|
|
@@ -27,6 +23,17 @@ static UserMessage user(@Nonnull final String msg) { | |
| return new UserMessage(msg); | ||
| } | ||
|
|
||
| /** | ||
| * A convenience method to create a user message. | ||
| * | ||
| * @param msg the message content. | ||
| * @return the user message. | ||
| */ | ||
| @Nonnull | ||
| static UserMessage user(@Nonnull final MessageContent msg) { | ||
| return new UserMessage(msg); | ||
| } | ||
|
|
||
| /** | ||
| * A convenience method to create an assistant message. | ||
| * | ||
|
|
@@ -49,16 +56,29 @@ static SystemMessage system(@Nonnull final String msg) { | |
| return new SystemMessage(msg); | ||
| } | ||
|
|
||
| /** | ||
| * A convenience method to create a system message. | ||
| * | ||
| * @param msg the message content. | ||
| * @return the system message. | ||
| */ | ||
| @Nonnull | ||
| static SystemMessage system(@Nonnull final MessageContent msg) { | ||
| return new SystemMessage(msg); | ||
| } | ||
|
|
||
| /** | ||
| * Converts the message to a serializable ChatMessage object. | ||
| * | ||
| * @return the corresponding {@code ChatMessage} object. | ||
| */ | ||
| @Nonnull | ||
| default ChatMessagesInner createChatMessage() { | ||
| if (this.getContent() instanceof MessageContentSingle) { | ||
| return ChatMessage.create().role(role()).content(content()); | ||
| } else if (this.getContent() instanceof MessageContentMulti mCMulti) { | ||
| if (this.content() instanceof MessageContentSingle) { | ||
|
||
| return ChatMessage.create() | ||
| .role(role()) | ||
| .content(((MessageContentSingle) content()).content()); | ||
| } else if (this.content() instanceof MessageContentMulti mCMulti) { | ||
| return MultiChatMessage.create() | ||
| .role(role()) | ||
| .content( | ||
|
|
@@ -85,66 +105,8 @@ default ChatMessagesInner createChatMessage() { | |
| }) | ||
| .toList()); | ||
| } else { | ||
| throw new IllegalArgumentException("Unknown content type: " + this.getContent().getClass()); | ||
| } | ||
| } | ||
|
|
||
| static Message addTextMessages( | ||
| @Nullable MessageContent oldContent, @Nonnull String role, @Nonnull String... messages) { | ||
| if (oldContent == null && messages.length == 1) { | ||
| return switch (role) { | ||
| case "user" -> new UserMessage(messages[0]); | ||
| case "assistant" -> new AssistantMessage(messages[0]); | ||
| case "system" -> new SystemMessage(messages[0]); | ||
| default -> throw new IllegalArgumentException("Unknown role: " + role); | ||
| }; | ||
| } | ||
| var messagesAsMultiMessageContents = | ||
| Stream.of(messages).map(MultiMessageTextContent::new).toList(); | ||
| return switch (role) { | ||
| case "user" -> | ||
| new UserMessage(createMultiContent(messagesAsMultiMessageContents, oldContent)); | ||
| case "assistant" -> | ||
| new AssistantMessage(createMultiContent(messagesAsMultiMessageContents, oldContent)); | ||
| case "system" -> | ||
| new SystemMessage(createMultiContent(messagesAsMultiMessageContents, oldContent)); | ||
| default -> throw new IllegalArgumentException("Unknown role: " + role); | ||
| }; | ||
| } | ||
|
|
||
| static Message addImage( | ||
| @Nullable MessageContent oldContent, | ||
| @Nonnull String role, | ||
| @Nonnull String imageUrl, | ||
| @Nonnull MultiMessageImageContent.DetailLevel detailLevel) { | ||
| return switch (role) { | ||
| case "user" -> | ||
| new UserMessage( | ||
| createMultiContent( | ||
| List.of(new MultiMessageImageContent(imageUrl, detailLevel)), oldContent)); | ||
| case "assistant" -> | ||
| new AssistantMessage( | ||
| createMultiContent( | ||
| List.of(new MultiMessageImageContent(imageUrl, detailLevel)), oldContent)); | ||
| case "system" -> | ||
| new SystemMessage( | ||
| createMultiContent( | ||
| List.of(new MultiMessageImageContent(imageUrl, detailLevel)), oldContent)); | ||
| default -> throw new IllegalArgumentException("Unknown role: " + role); | ||
| }; | ||
| } | ||
|
|
||
| private static MessageContentMulti createMultiContent( | ||
| @Nonnull List<? extends MultiMessageContent> newContent, | ||
| @Nullable MessageContent oldContent) { | ||
| var multiContentList = new ArrayList<MultiMessageContent>(); | ||
| if (oldContent instanceof MessageContentSingle mCSingle) { | ||
| multiContentList.add(new MultiMessageTextContent(mCSingle.content())); | ||
| } else if (oldContent != null) { | ||
| multiContentList.addAll(((MessageContentMulti) oldContent).multiContentList()); | ||
| throw new IllegalArgumentException("Unknown content type: " + this.content().getClass()); | ||
| } | ||
| multiContentList.addAll(newContent); | ||
| return new MessageContentMulti(multiContentList); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -162,17 +124,5 @@ private static MessageContentMulti createMultiContent( | |
| */ | ||
| @Nonnull | ||
| @Beta | ||
| String content(); | ||
|
|
||
| @Nonnull | ||
| @Beta | ||
| MessageContent getContent(); | ||
|
|
||
| @Nonnull | ||
| @Beta | ||
| Message addTextMessages(@Nonnull String... messages); | ||
|
|
||
| @Nonnull | ||
| @Beta | ||
| Message addImage(@Nonnull String imageUrl, MultiMessageImageContent.DetailLevel detailLevel); | ||
| Object content(); | ||
| } | ||
This file contains hidden or 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
2 changes: 1 addition & 1 deletion
2
orchestration/src/main/java/com/sap/ai/sdk/orchestration/MessageContentSingle.java
This file contains hidden or 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 |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| package com.sap.ai.sdk.orchestration; | ||
|
|
||
| public record MessageContentSingle(String content) implements MessageContent{} | ||
| public record MessageContentSingle(String content) implements MessageContent {} |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.