Skip to content

refactor: GH-3620 Add BedrockChatOptions to Bedrock #3770

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024-2024 the original author or authors.
* Copyright 2024-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,7 +16,7 @@

package org.springframework.ai.model.bedrock.converse.autoconfigure;

import org.springframework.ai.model.tool.ToolCallingChatOptions;
import org.springframework.ai.bedrock.converse.BedrockChatOptions;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.util.Assert;
Expand All @@ -33,14 +33,14 @@ public class BedrockConverseProxyChatProperties {
public static final String CONFIG_PREFIX = "spring.ai.bedrock.converse.chat";

@NestedConfigurationProperty
private ToolCallingChatOptions options = ToolCallingChatOptions.builder().temperature(0.7).maxTokens(300).build();
private BedrockChatOptions options = BedrockChatOptions.builder().temperature(0.7).maxTokens(300).build();

public ToolCallingChatOptions getOptions() {
public BedrockChatOptions getOptions() {
return this.options;
}

public void setOptions(ToolCallingChatOptions options) {
Assert.notNull(options, "ToolCallingChatOptions must not be null");
public void setOptions(BedrockChatOptions options) {
Assert.notNull(options, "BedrockChatOptions must not be null");
this.options = options;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.bedrock.converse.BedrockChatOptions;
import reactor.core.publisher.Flux;

import org.springframework.ai.bedrock.converse.BedrockProxyChatModel;
Expand All @@ -32,7 +33,6 @@
import org.springframework.ai.model.bedrock.autoconfigure.BedrockTestUtils;
import org.springframework.ai.model.bedrock.autoconfigure.RequiresAwsCredentials;
import org.springframework.ai.model.bedrock.converse.autoconfigure.BedrockConverseProxyChatAutoConfiguration;
import org.springframework.ai.model.tool.ToolCallingChatOptions;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean;
Expand Down Expand Up @@ -64,14 +64,14 @@ void functionCallTest() {
"What's the weather like in San Francisco, in Paris, France and in Tokyo, Japan? Return the temperature in Celsius.");

ChatResponse response = chatModel.call(new Prompt(List.of(userMessage),
ToolCallingChatOptions.builder().toolNames("weatherFunction").build()));
BedrockChatOptions.builder().toolNames("weatherFunction").build()));

logger.info("Response: {}", response);

assertThat(response.getResult().getOutput().getText()).contains("30", "10", "15");

response = chatModel.call(new Prompt(List.of(userMessage),
ToolCallingChatOptions.builder().toolNames("weatherFunction3").build()));
BedrockChatOptions.builder().toolNames("weatherFunction3").build()));

logger.info("Response: {}", response);

Expand All @@ -93,7 +93,7 @@ void functionStreamTest() {
"What's the weather like in San Francisco, in Paris, France and in Tokyo, Japan? Return the temperature in Celsius.");

Flux<ChatResponse> responses = chatModel.stream(new Prompt(List.of(userMessage),
ToolCallingChatOptions.builder().toolNames("weatherFunction").build()));
BedrockChatOptions.builder().toolNames("weatherFunction").build()));

String content = responses.collectList()
.block()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 the original author or authors.
* Copyright 2023-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,14 +22,14 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.ai.bedrock.converse.BedrockChatOptions;
import org.springframework.ai.bedrock.converse.BedrockProxyChatModel;
import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.model.bedrock.autoconfigure.BedrockTestUtils;
import org.springframework.ai.model.bedrock.autoconfigure.RequiresAwsCredentials;
import org.springframework.ai.model.bedrock.converse.autoconfigure.BedrockConverseProxyChatAutoConfiguration;
import org.springframework.ai.model.tool.ToolCallingChatOptions;
import org.springframework.ai.tool.function.FunctionToolCallback;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
Expand All @@ -56,7 +56,7 @@ void functionCallTest() {
UserMessage userMessage = new UserMessage(
"What's the weather like in San Francisco, in Paris and in Tokyo? Return the temperature in Celsius.");

var promptOptions = ToolCallingChatOptions.builder()
var promptOptions = BedrockChatOptions.builder()
.toolCallbacks(
List.of(FunctionToolCallback.builder("CurrentWeatherService", new MockWeatherService())
.description("Get the weather in location. Return temperature in 36°F or 36°C format.")
Expand Down
Loading