File tree Expand file tree Collapse file tree 5 files changed +57
-12
lines changed
orchestration/src/main/java/com/sap/ai/sdk/orchestration
sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/controllers Expand file tree Collapse file tree 5 files changed +57
-12
lines changed Original file line number Diff line number Diff line change 22
33import com .sap .ai .sdk .orchestration .client .model .ChatMessage ;
44import javax .annotation .Nonnull ;
5+ import lombok .Value ;
6+ import lombok .experimental .Accessors ;
57
6- public record AssistantMessage (@ Nonnull String content ) implements Message {
8+ /** Represents a chat message as 'assistant' to the orchestration service. */
9+ @ Value
10+ @ Accessors (fluent = true )
11+ public class AssistantMessage implements Message {
712
8- public static final String ROLE = "assistant" ;
13+ /** The role of the assistant. */
14+ @ Nonnull public static final String ROLE = "assistant" ;
915
16+ @ Nonnull String content ;
17+
18+ /**
19+ * Converts the message to a serializable ChatMessage object.
20+ *
21+ * @return the corresponding {@code ChatMessage} object.
22+ */
1023 @ Nonnull
1124 public ChatMessage toChatMessage () {
1225 return ChatMessage .create ().role (ROLE ).content (content );
Original file line number Diff line number Diff line change 11package com .sap .ai .sdk .orchestration ;
22
33import com .sap .ai .sdk .orchestration .client .model .ChatMessage ;
4+ import javax .annotation .Nonnull ;
45
6+ /** Represents a chat message to the orchestration service. */
57public sealed interface Message permits UserMessage , AssistantMessage , SystemMessage {
6- public ChatMessage toChatMessage ();
8+
9+ /**
10+ * Converts the message to a serializable ChatMessage object.
11+ *
12+ * @return the corresponding {@code ChatMessage} object.
13+ */
14+ @ Nonnull
15+ ChatMessage toChatMessage ();
716}
Original file line number Diff line number Diff line change 22
33import com .sap .ai .sdk .orchestration .client .model .ChatMessage ;
44import javax .annotation .Nonnull ;
5+ import lombok .Value ;
6+ import lombok .experimental .Accessors ;
57
6- public record SystemMessage (@ Nonnull String content ) implements Message {
8+ /** Represents a chat message as 'system' to the orchestration service. */
9+ @ Value
10+ @ Accessors (fluent = true )
11+ public class SystemMessage implements Message {
712
8- public static final String ROLE = "system" ;
13+ /** The role of the assistant. */
14+ @ Nonnull public static final String ROLE = "system" ;
915
16+ @ Nonnull String content ;
17+
18+ /**
19+ * Converts the message to a serializable ChatMessage object.
20+ *
21+ * @return the corresponding {@code ChatMessage} object.
22+ */
1023 @ Nonnull
1124 public ChatMessage toChatMessage () {
1225 return ChatMessage .create ().role (ROLE ).content (content );
Original file line number Diff line number Diff line change 22
33import com .sap .ai .sdk .orchestration .client .model .ChatMessage ;
44import javax .annotation .Nonnull ;
5+ import lombok .Value ;
6+ import lombok .experimental .Accessors ;
57
6- public record UserMessage (@ Nonnull String content ) implements Message {
8+ /** Represents a chat message as 'user' to the orchestration service. */
9+ @ Value
10+ @ Accessors (fluent = true )
11+ public class UserMessage implements Message {
712
8- public static final String ROLE = "user" ;
13+ /** The role of the assistant. */
14+ @ Nonnull public static final String ROLE = "user" ;
915
16+ @ Nonnull String content ;
17+
18+ /**
19+ * Converts the message to a serializable ChatMessage object.
20+ *
21+ * @return the corresponding {@code ChatMessage} object.
22+ */
1023 @ Nonnull
1124 public ChatMessage toChatMessage () {
1225 return ChatMessage .create ().role (ROLE ).content (content );
Original file line number Diff line number Diff line change 1313import com .sap .ai .sdk .orchestration .OrchestrationPrompt ;
1414import com .sap .ai .sdk .orchestration .SystemMessage ;
1515import com .sap .ai .sdk .orchestration .UserMessage ;
16- import com .sap .ai .sdk .orchestration .client .model .ChatMessage ;
1716import com .sap .ai .sdk .orchestration .client .model .DPIEntities ;
1817import com .sap .ai .sdk .orchestration .client .model .Template ;
1918import java .util .List ;
@@ -55,10 +54,8 @@ public OrchestrationChatResponse completion() {
5554 @ Nonnull
5655 public OrchestrationChatResponse template () {
5756 final var template =
58- ChatMessage .create ()
59- .role ("user" )
60- .content ("Reply with 'Orchestration Service is working!' in {{?language}}" );
61- final var templatingConfig = Template .create ().template (List .of (template ));
57+ new UserMessage ("Reply with 'Orchestration Service is working!' in {{?language}}" );
58+ final var templatingConfig = Template .create ().template (List .of (template .toChatMessage ()));
6259 final var configWithTemplate = config .withTemplateConfig (templatingConfig );
6360
6461 final var inputParams = Map .of ("language" , "German" );
You can’t perform that action at this time.
0 commit comments