Skip to content

Commit f16f752

Browse files
committed
Merge remote-tracking branch 'origin/main' into feat/orchestration/embedding-conv
2 parents 2b6f8fe + 7751699 commit f16f752

File tree

6 files changed

+49
-21
lines changed

6 files changed

+49
-21
lines changed

docs/release_notes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@
2222

2323
### 🐛 Fixed Issues
2424

25-
-
25+
- [Orchestration] Tool calling works on all models

orchestration/src/main/java/com/sap/ai/sdk/orchestration/AssistantMessage.java

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.sap.ai.sdk.orchestration.model.ChatMessageContent;
99
import com.sap.ai.sdk.orchestration.model.MessageToolCall;
1010
import com.sap.ai.sdk.orchestration.model.TextContent;
11+
import java.util.ArrayList;
1112
import java.util.List;
1213
import javax.annotation.Nonnull;
1314
import javax.annotation.Nullable;
@@ -57,30 +58,55 @@ public AssistantMessage(@Nonnull final String singleMessage) {
5758
* Creates a new assistant message with the given tool calls.
5859
*
5960
* @param toolCalls list of tool call objects
61+
* @deprecated Please use {@link #withToolCalls(List)} instead.
6062
*/
63+
@Deprecated
6164
public AssistantMessage(@Nonnull final List<MessageToolCall> toolCalls) {
6265
content = new MessageContent(List.of());
6366
this.toolCalls = toolCalls;
6467
}
6568

69+
private AssistantMessage(
70+
@Nonnull final MessageContent content, @Nullable final List<MessageToolCall> toolCalls) {
71+
this.content = content;
72+
this.toolCalls = toolCalls;
73+
}
74+
75+
/**
76+
* Returns a new AssistantMessage instance with the provided tool calls added to the existing
77+
* ones.
78+
*
79+
* @param toolCalls the list of tool calls to add.
80+
* @return a new AssistantMessage instance with the combined tool calls.
81+
*/
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);
87+
}
88+
6689
@Nonnull
6790
@Override
6891
public ChatMessage createChatMessage() {
92+
val assistantChatMessage = AssistantChatMessage.create().role(ASSISTANT);
93+
6994
if (toolCalls != null) {
70-
return AssistantChatMessage.create().role(ASSISTANT).toolCalls(toolCalls);
95+
assistantChatMessage.setToolCalls(toolCalls);
7196
}
97+
98+
ChatMessageContent text;
7299
if (content.items().size() == 1 && content.items().get(0) instanceof TextItem textItem) {
73-
return AssistantChatMessage.create()
74-
.role(ASSISTANT)
75-
.content(ChatMessageContent.create(textItem.text()));
100+
text = ChatMessageContent.create(textItem.text());
101+
} else {
102+
val texts =
103+
content.items().stream()
104+
.filter(item -> item instanceof TextItem)
105+
.map(item -> (TextItem) item)
106+
.map(item -> TextContent.create().type(TextContent.TypeEnum.TEXT).text(item.text()))
107+
.toList();
108+
text = ChatMessageContent.create(texts);
76109
}
77-
val texts =
78-
content.items().stream()
79-
.filter(item -> item instanceof TextItem)
80-
.map(item -> (TextItem) item)
81-
.map(item -> TextContent.create().type(TextContent.TypeEnum.TEXT).text(item.text()))
82-
.toList();
83-
84-
return AssistantChatMessage.create().role(ASSISTANT).content(ChatMessageContent.create(texts));
110+
return assistantChatMessage.content(text);
85111
}
86112
}

orchestration/src/main/java/com/sap/ai/sdk/orchestration/spring/OrchestrationChatModel.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,17 @@ private static com.sap.ai.sdk.orchestration.Message[] toOrchestrationMessages(
126126
case USER:
127127
yield List.of(new UserMessage(msg.getText()));
128128
case ASSISTANT:
129+
val assistantMessage = new AssistantMessage(msg.getText());
129130
val springToolCalls =
130131
((org.springframework.ai.chat.messages.AssistantMessage) msg).getToolCalls();
131132
if (springToolCalls != null && !springToolCalls.isEmpty()) {
132133
final List<MessageToolCall> sdkToolCalls =
133134
springToolCalls.stream()
134135
.map(OrchestrationChatModel::toOrchestrationToolCall)
135136
.toList();
136-
yield List.of(new AssistantMessage(sdkToolCalls));
137+
yield List.of(assistantMessage.withToolCalls(sdkToolCalls));
137138
}
138-
yield List.of(new AssistantMessage(msg.getText()));
139+
yield List.of(assistantMessage);
139140
case TOOL:
140141
val toolResponses = ((ToolResponseMessage) msg).getResponses();
141142
yield toolResponses.stream()

orchestration/src/test/resources/toolCallsRequest2.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
},
1818
{
1919
"role": "assistant",
20+
"content" : "",
2021
"tool_calls": [
2122
{
2223
"id": "call_LOyP7EVdeqFlGEmVzmPdCVey",

pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
<cloud-sdk.version>5.22.0</cloud-sdk.version>
5959
<junit-jupiter.version>5.13.4</junit-jupiter.version>
6060
<wiremock.version>3.13.1</wiremock.version>
61-
<assertj-core.version>3.27.4</assertj-core.version>
61+
<assertj-core.version>3.27.5</assertj-core.version>
6262
<slf4j.version>2.0.17</slf4j.version>
6363
<checkstyle.version>11.0.1</checkstyle.version>
6464
<system-stubs.version>2.1.3</system-stubs.version>
@@ -67,7 +67,7 @@
6767
<spring-ai.version>1.0.2</spring-ai.version>
6868
<reactor-core.version>3.7.11</reactor-core.version>
6969
<dotenv-java.version>3.2.0</dotenv-java.version>
70-
<mockito.version>5.19.0</mockito.version>
70+
<mockito.version>5.20.0</mockito.version>
7171
<javaparser.version>3.27.0</javaparser.version>
7272
<jsonschema-generator.version>4.38.0</jsonschema-generator.version>
7373
<jackson.version>2.20.0</jackson.version>
@@ -749,7 +749,7 @@ https://gitbox.apache.org/repos/asf?p=maven-pmd-plugin.git;a=blob_plain;f=src/ma
749749
<plugin>
750750
<groupId>com.github.spotbugs</groupId>
751751
<artifactId>spotbugs-maven-plugin</artifactId>
752-
<version>4.9.4.2</version>
752+
<version>4.9.6.0</version>
753753
<configuration>
754754
<includeFilterFile>${project.rootdir}/.pipeline/spotbugs.xml</includeFilterFile>
755755
<!-- Exclude generated clients -->
@@ -832,7 +832,7 @@ https://gitbox.apache.org/repos/asf?p=maven-pmd-plugin.git;a=blob_plain;f=src/ma
832832
<dependency>
833833
<groupId>org.projectlombok</groupId>
834834
<artifactId>lombok</artifactId>
835-
<version>1.18.40</version>
835+
<version>1.18.42</version>
836836
</dependency>
837837
</dependencies>
838838
<executions>
@@ -852,7 +852,7 @@ https://gitbox.apache.org/repos/asf?p=maven-pmd-plugin.git;a=blob_plain;f=src/ma
852852
<plugin>
853853
<groupId>org.apache.maven.plugins</groupId>
854854
<artifactId>maven-javadoc-plugin</artifactId>
855-
<version>3.11.3</version>
855+
<version>3.12.0</version>
856856
<configuration>
857857
<quiet>true</quiet>
858858
<additionalOptions>-Xdoclint:none</additionalOptions>

sample-code/spring-app/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
</developers>
3434
<properties>
3535
<project.rootdir>${project.basedir}/../../</project.rootdir>
36-
<spring-boot.version>3.5.5</spring-boot.version>
36+
<spring-boot.version>3.5.6</spring-boot.version>
3737
<logback.version>1.5.18</logback.version>
3838
<cf-logging.version>3.8.6</cf-logging.version>
3939
<apache-tomcat-embed.version>11.0.11</apache-tomcat-embed.version>

0 commit comments

Comments
 (0)