Skip to content

Commit f2274eb

Browse files
ilayaperumalgspring-builds
authored andcommitted
Bedrock converse chat model to merge toolcalling chat options (#4314)
- When building the chat client request, if the ToolCallingChatOptions is passed via prompt, merge the options into Bedrock chat options. Previously, this was ignored. - Add test to verify function calling when ToolCallingChatOptions is passed Fixes: #4314 Signed-off-by: Ilayaperumal Gopinathan <[email protected]> (cherry picked from commit 26166a1)
1 parent 3e6e272 commit f2274eb

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

models/spring-ai-bedrock-converse/src/main/java/org/springframework/ai/bedrock/converse/BedrockProxyChatModel.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,10 @@ Prompt buildRequestPrompt(Prompt prompt) {
271271
if (prompt.getOptions() instanceof ToolCallingChatOptions toolCallingChatOptions) {
272272
runtimeOptions = toolCallingChatOptions.copy();
273273
}
274+
else if (prompt.getOptions() instanceof ToolCallingChatOptions toolCallingChatOptions) {
275+
runtimeOptions = ModelOptionsUtils.copyToTarget(toolCallingChatOptions, ToolCallingChatOptions.class,
276+
BedrockChatOptions.class);
277+
}
274278
else {
275279
runtimeOptions = from(prompt.getOptions());
276280
}

models/spring-ai-bedrock-converse/src/test/java/org/springframework/ai/bedrock/converse/BedrockProxyChatModelIT.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,29 @@ void functionCallTest() {
280280
assertThat(generation.getOutput().getText()).contains("30", "10", "15");
281281
}
282282

283+
@Test
284+
void functionCallTestWithToolCallingOptions() {
285+
286+
UserMessage userMessage = new UserMessage(
287+
"What's the weather like in San Francisco, Tokyo and Paris? Return the result in Celsius.");
288+
289+
List<Message> messages = new ArrayList<>(List.of(userMessage));
290+
291+
var promptOptions = ToolCallingChatOptions.builder()
292+
.toolCallbacks(List.of(FunctionToolCallback.builder("getCurrentWeather", new MockWeatherService())
293+
.description("Get the weather in location. Return in 36°C format")
294+
.inputType(MockWeatherService.Request.class)
295+
.build()))
296+
.build();
297+
298+
ChatResponse response = this.chatModel.call(new Prompt(messages, promptOptions));
299+
300+
logger.info("Response: {}", response);
301+
302+
Generation generation = response.getResult();
303+
assertThat(generation.getOutput().getText()).contains("30", "10", "15");
304+
}
305+
283306
@Test
284307
void streamFunctionCallTest() {
285308

0 commit comments

Comments
 (0)