|
8 | 8 | import com.sap.ai.sdk.orchestration.model.ChatMessageContent; |
9 | 9 | import com.sap.ai.sdk.orchestration.model.MessageToolCall; |
10 | 10 | import com.sap.ai.sdk.orchestration.model.TextContent; |
| 11 | +import java.util.ArrayList; |
11 | 12 | import java.util.List; |
12 | 13 | import javax.annotation.Nonnull; |
13 | 14 | import javax.annotation.Nullable; |
@@ -57,23 +58,32 @@ public AssistantMessage(@Nonnull final String singleMessage) { |
57 | 58 | * Creates a new assistant message with the given tool calls. |
58 | 59 | * |
59 | 60 | * @param toolCalls list of tool call objects |
| 61 | + * @deprecated Please use {@link #withToolCalls(List)} instead. |
60 | 62 | */ |
| 63 | + @Deprecated |
61 | 64 | public AssistantMessage(@Nonnull final List<MessageToolCall> toolCalls) { |
62 | 65 | content = new MessageContent(List.of()); |
63 | 66 | this.toolCalls = toolCalls; |
64 | 67 | } |
65 | 68 |
|
| 69 | + private AssistantMessage( |
| 70 | + @Nonnull final MessageContent content, @Nullable final List<MessageToolCall> toolCalls) { |
| 71 | + this.content = content; |
| 72 | + this.toolCalls = toolCalls; |
| 73 | + } |
| 74 | + |
66 | 75 | /** |
67 | | - * Creates a new assistant message with the given message and tool calls. |
| 76 | + * Returns a new AssistantMessage instance with the provided tool calls added to the existing |
| 77 | + * ones. |
68 | 78 | * |
69 | | - * @param singleMessage the message content. |
70 | | - * @param toolCalls list of tool call objects |
71 | | - * @since 1.11.0 |
| 79 | + * @param toolCalls the list of tool calls to add. |
| 80 | + * @return a new AssistantMessage instance with the combined tool calls. |
72 | 81 | */ |
73 | | - public AssistantMessage( |
74 | | - @Nonnull final String singleMessage, @Nullable final List<MessageToolCall> toolCalls) { |
75 | | - this.content = new MessageContent(List.of(new TextItem(singleMessage))); |
76 | | - this.toolCalls = toolCalls; |
| 82 | + @Nonnull |
| 83 | + public AssistantMessage withToolCalls(@Nonnull final List<MessageToolCall> toolCalls) { |
| 84 | + val newToolcalls = new ArrayList<>(this.toolCalls != null ? this.toolCalls : List.of()); |
| 85 | + newToolcalls.addAll(toolCalls); |
| 86 | + return new AssistantMessage(this.content, newToolcalls); |
77 | 87 | } |
78 | 88 |
|
79 | 89 | @Nonnull |
|
0 commit comments