Skip to content

Remove FunctionCallback deprecations #2534

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

Closed
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
Expand Up @@ -66,14 +66,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),
AnthropicChatOptions.builder().function("weatherFunction").build()));
AnthropicChatOptions.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),
AnthropicChatOptions.builder().function("weatherFunction3").build()));
AnthropicChatOptions.builder().toolNames("weatherFunction3").build()));

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void functionCallTest() {
"What's the weather like in San Francisco, in Paris and in Tokyo? Return the temperature in Celsius.");

var promptOptions = AnthropicChatOptions.builder()
.functionCallbacks(
.toolCallbacks(
List.of(FunctionToolCallback.builder("CurrentWeatherService", new MockWeatherService())
.description("Get the weather in location. Return temperature in 36°F or 36°C format.")
.inputType(MockWeatherService.Request.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ void functionCallTest() {
"What's the weather like in San Francisco, Paris and in Tokyo? Use Multi-turn function calling.");

ChatResponse response = chatModel.call(new Prompt(List.of(userMessage),
AzureOpenAiChatOptions.builder().function("weatherFunction").build()));
AzureOpenAiChatOptions.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),
AzureOpenAiChatOptions.builder().function("weatherFunction3").build()));
AzureOpenAiChatOptions.builder().toolNames("weatherFunction3").build()));

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void functionCallTest() {
"What's the weather like in San Francisco, Paris and in Tokyo?");

ChatResponse response = chatModel.call(new Prompt(List.of(userMessage),
AzureOpenAiChatOptions.builder().function("WeatherInfo").build()));
AzureOpenAiChatOptions.builder().toolNames("WeatherInfo").build()));

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void functionCallTest() {
"What's the weather like in San Francisco, in Paris and in Tokyo? Use Multi-turn function calling.");

var promptOptions = AzureOpenAiChatOptions.builder()
.functionCallbacks(
.toolCallbacks(
List.of(FunctionToolCallback.builder("CurrentWeatherService", new MockWeatherService())
.description("Get the weather in location")
.inputType(MockWeatherService.Request.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ void functionCallTest() {
ChatResponse response = chatModel
.call(new Prompt(List.of(new UserMessage("What's the status of my transaction with id T1001?")),
MistralAiChatOptions.builder()
.function("retrievePaymentStatus")
.function("retrievePaymentDate")
.toolNames("retrievePaymentStatus")
.toolNames("retrievePaymentDate")
.build()));

logger.info("Response: {}", response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ void functionCallTest() {
ChatResponse response = chatModel
.call(new Prompt(List.of(new UserMessage("What's the status of my transaction with id T1001?")),
OpenAiChatOptions.builder()
.function("retrievePaymentStatus")
.function("retrievePaymentDate")
.toolNames("retrievePaymentStatus")
.toolNames("retrievePaymentDate")
.build()));

logger.info("Response: {}", response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void functionCallTest() {
UserMessage userMessage = new UserMessage("What's the status of my transaction with id T1001?");

var promptOptions = MistralAiChatOptions.builder()
.functionCallbacks(List.of(FunctionToolCallback
.toolCallbacks(List.of(FunctionToolCallback
.builder("retrievePaymentStatus",
(Transaction transaction) -> new Status(DATA.get(transaction).status()))
.description("Get payment status of a transaction")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,10 @@ void promptFunctionCall() {

var promptOptions = MistralAiChatOptions.builder()
.toolChoice(ToolChoice.AUTO)
.functionCallbacks(
List.of(FunctionToolCallback.builder("CurrentWeatherService", new MyWeatherService())
.description("Get the current weather in requested location")
.inputType(MyWeatherService.Request.class)
.build()))
.toolCallbacks(List.of(FunctionToolCallback.builder("CurrentWeatherService", new MyWeatherService())
.description("Get the current weather in requested location")
.inputType(MyWeatherService.Request.class)
.build()))
.build();

ChatResponse response = chatModel.call(new Prompt(List.of(userMessage), promptOptions));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ void functionCallTest() {
"What are the weather conditions in San Francisco, Tokyo, and Paris? Find the temperature in Celsius for each of the three locations.");

var promptOptions = OllamaOptions.builder()
.functionCallbacks(List.of(FunctionToolCallback
.builder("CurrentWeatherService", new MockWeatherService())
.toolCallbacks(List.of(FunctionToolCallback.builder("CurrentWeatherService", new MockWeatherService())
.description(
"Find the weather conditions, forecasts, and temperatures for a location, like a city or state.")
.inputType(MockWeatherService.Request.class)
Expand All @@ -96,8 +95,7 @@ void streamingFunctionCallTest() {
"What are the weather conditions in San Francisco, Tokyo, and Paris? Find the temperature in Celsius for each of the three locations.");

var promptOptions = OllamaOptions.builder()
.functionCallbacks(List.of(FunctionToolCallback
.builder("CurrentWeatherService", new MockWeatherService())
.toolCallbacks(List.of(FunctionToolCallback.builder("CurrentWeatherService", new MockWeatherService())
.description(
"Find the weather conditions, forecasts, and temperatures for a location, like a city or state.")
.inputType(MockWeatherService.Request.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void functionCallTest() {
"What are the weather conditions in San Francisco, Tokyo, and Paris? Find the temperature in Celsius for each of the three locations.");

ChatResponse response = chatModel
.call(new Prompt(List.of(userMessage), OllamaOptions.builder().function("WeatherInfo").build()));
.call(new Prompt(List.of(userMessage), OllamaOptions.builder().toolNames("WeatherInfo").build()));

logger.info("Response: " + response);

Expand All @@ -93,7 +93,7 @@ void streamFunctionCallTest() {
"What are the weather conditions in San Francisco, Tokyo, and Paris? Find the temperature in Celsius for each of the three locations.");

Flux<ChatResponse> response = chatModel
.stream(new Prompt(List.of(userMessage), OllamaOptions.builder().function("WeatherInfo").build()));
.stream(new Prompt(List.of(userMessage), OllamaOptions.builder().toolNames("WeatherInfo").build()));

String content = response.collectList()
.block()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void streamFunctionCallTest() {
"What are the weather conditions in San Francisco, Tokyo, and Paris? Find the temperature in Celsius for each of the three locations.");

Flux<ChatResponse> response = chatModel
.stream(new Prompt(List.of(userMessage), OllamaOptions.builder().function("weatherInfo").build()));
.stream(new Prompt(List.of(userMessage), OllamaOptions.builder().toolNames("weatherInfo").build()));

String content = response.collectList()
.block()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class FunctionCallbackResolverKotlinIT : BaseOllamaIT() {
"What are the weather conditions in San Francisco, Tokyo, and Paris? Find the temperature in Celsius for each of the three locations.")

val response = chatModel
.call(Prompt(listOf(userMessage), OllamaOptions.builder().function("weatherInfo").build()))
.call(Prompt(listOf(userMessage), OllamaOptions.builder().toolNames("weatherInfo").build()))

logger.info("Response: $response")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void functionCallTest() {

String content = ChatClient.builder(chatModel).build().prompt()
.user("What's the weather like in San Francisco, Tokyo, and Paris?")
.functions(FunctionToolCallback
.tools(FunctionToolCallback
.builder("CurrentWeatherService", new MockWeatherService())
.description("Get the weather in location")
.inputType(MockWeatherService.Request.class)
Expand Down Expand Up @@ -88,7 +88,7 @@ record LightInfo(String roomName, boolean isOn) {
// @formatter:off
String content = ChatClient.builder(chatModel).build().prompt()
.user("Turn the light on in the kitchen and in the living room!")
.functions(FunctionToolCallback
.tools(FunctionToolCallback
.builder("turnLight", (LightInfo lightInfo) -> {
logger.info("Turning light to [" + lightInfo.isOn + "] in " + lightInfo.roomName());
state.put(lightInfo.roomName(), lightInfo.isOn());
Expand All @@ -114,7 +114,7 @@ void functionCallTest2() {
// @formatter:off
String content = ChatClient.builder(chatModel).build().prompt()
.user("What's the weather like in Amsterdam?")
.functions(FunctionToolCallback
.tools(FunctionToolCallback
.builder("CurrentWeatherService", input -> "18 degrees Celsius")
.description("Get the weather in location")
.inputType(MockWeatherService.Request.class)
Expand All @@ -138,7 +138,7 @@ void streamingFunctionCallTest() {
// @formatter:off
String content = ChatClient.builder(chatModel).build().prompt()
.user("What's the weather like in San Francisco, Tokyo, and Paris?")
.functions(FunctionToolCallback
.tools(FunctionToolCallback
.builder("CurrentWeatherService", new MockWeatherService())
.description("Get the weather in location")
.inputType(MockWeatherService.Request.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void functionCallTest() {
"What's the weather like in San Francisco, Tokyo, and Paris?");

var promptOptions = OpenAiChatOptions.builder()
.functionCallbacks(
.toolCallbacks(
List.of(FunctionToolCallback.builder("CurrentWeatherService", new MockWeatherService())
.description("Get the weather in location")
.inputType(MockWeatherService.Request.class)
Expand Down Expand Up @@ -91,7 +91,7 @@ void streamingFunctionCallTest() {
"What's the weather like in San Francisco, Tokyo, and Paris?");

var promptOptions = OpenAiChatOptions.builder()
.functionCallbacks(
.toolCallbacks(
List.of(FunctionToolCallback.builder("CurrentWeatherService", new MockWeatherService())
.description("Get the weather in location")
.inputType(MockWeatherService.Request.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void functionCallingVoidInput() {
UserMessage userMessage = new UserMessage("Turn the light on in the living room");

ChatResponse response = chatModel.call(new Prompt(List.of(userMessage),
OpenAiChatOptions.builder().function("turnLivingRoomLightOn").build()));
OpenAiChatOptions.builder().toolNames("turnLivingRoomLightOn").build()));

logger.info("Response: {}", response);
assertThat(feedback).hasSize(1);
Expand All @@ -98,7 +98,7 @@ void functionCallingSupplier() {
UserMessage userMessage = new UserMessage("Turn the light on in the living room");

ChatResponse response = chatModel.call(new Prompt(List.of(userMessage),
OpenAiChatOptions.builder().function("turnLivingRoomLightOnSupplier").build()));
OpenAiChatOptions.builder().toolNames("turnLivingRoomLightOnSupplier").build()));

logger.info("Response: {}", response);
assertThat(feedback).hasSize(1);
Expand All @@ -116,7 +116,7 @@ void functionCallingVoidOutput() {
UserMessage userMessage = new UserMessage("Turn the light on in the kitchen and in the living room");

ChatResponse response = chatModel
.call(new Prompt(List.of(userMessage), OpenAiChatOptions.builder().function("turnLight").build()));
.call(new Prompt(List.of(userMessage), OpenAiChatOptions.builder().toolNames("turnLight").build()));

logger.info("Response: {}", response);
assertThat(feedback).hasSize(2);
Expand All @@ -135,7 +135,7 @@ void functionCallingConsumer() {
UserMessage userMessage = new UserMessage("Turn the light on in the kitchen and in the living room");

ChatResponse response = chatModel.call(new Prompt(List.of(userMessage),
OpenAiChatOptions.builder().function("turnLightConsumer").build()));
OpenAiChatOptions.builder().toolNames("turnLightConsumer").build()));

logger.info("Response: {}", response);
assertThat(feedback).hasSize(2);
Expand Down Expand Up @@ -174,7 +174,7 @@ void functionCallWithDirectBiFunction() {
ChatClient chatClient = ChatClient.builder(chatModel).build();

String content = chatClient.prompt("What's the weather like in San Francisco, Tokyo, and Paris?")
.functions("weatherFunctionWithContext")
.tools("weatherFunctionWithContext")
.toolContext(Map.of("sessionId", "123"))
.call()
.content();
Expand All @@ -186,7 +186,7 @@ void functionCallWithDirectBiFunction() {

ChatResponse response = chatModel.call(new Prompt(List.of(userMessage),
OpenAiChatOptions.builder()
.function("weatherFunctionWithContext")
.toolNames("weatherFunctionWithContext")
.toolContext(Map.of("sessionId", "123"))
.build()));

Expand All @@ -206,7 +206,7 @@ void functionCallWithBiFunctionClass() {
ChatClient chatClient = ChatClient.builder(chatModel).build();

String content = chatClient.prompt("What's the weather like in San Francisco, Tokyo, and Paris?")
.functions("weatherFunctionWithClassBiFunction")
.tools("weatherFunctionWithClassBiFunction")
.toolContext(Map.of("sessionId", "123"))
.call()
.content();
Expand All @@ -218,7 +218,7 @@ void functionCallWithBiFunctionClass() {

ChatResponse response = chatModel.call(new Prompt(List.of(userMessage),
OpenAiChatOptions.builder()
.function("weatherFunctionWithClassBiFunction")
.toolNames("weatherFunctionWithClassBiFunction")
.toolContext(Map.of("sessionId", "123"))
.build()));

Expand All @@ -240,15 +240,15 @@ void functionCallTest() {
"What's the weather like in San Francisco, Tokyo, and Paris? You can call the following functions 'weatherFunction'");

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

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

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

// Test weatherFunctionTwo
response = chatModel.call(new Prompt(List.of(userMessage),
OpenAiChatOptions.builder().function("weatherFunctionTwo").build()));
OpenAiChatOptions.builder().toolNames("weatherFunctionTwo").build()));

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

Expand Down Expand Up @@ -289,7 +289,7 @@ void streamFunctionCallTest() {
"What's the weather like in San Francisco, Tokyo, and Paris? You can call the following functions 'weatherFunction'");

Flux<ChatResponse> response = chatModel.stream(
new Prompt(List.of(userMessage), OpenAiChatOptions.builder().function("weatherFunction").build()));
new Prompt(List.of(userMessage), OpenAiChatOptions.builder().toolNames("weatherFunction").build()));

String content = response.collectList()
.block()
Expand All @@ -305,7 +305,7 @@ void streamFunctionCallTest() {

// Test weatherFunctionTwo
response = chatModel.stream(new Prompt(List.of(userMessage),
OpenAiChatOptions.builder().function("weatherFunctionTwo").build()));
OpenAiChatOptions.builder().toolNames("weatherFunctionTwo").build()));

content = response.collectList()
.block()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void functionCallTest() {

// @formatter:off
ChatClient chatClient = ChatClient.builder(chatModel)
.defaultFunctions("WeatherInfo")
.defaultTools("WeatherInfo")
.defaultUser(u -> u.text("What's the weather like in {cities}?"))
.build();

Expand All @@ -78,7 +78,7 @@ void streamFunctionCallTest() {

// @formatter:off
String content = ChatClient.builder(chatModel).build().prompt()
.functions("WeatherInfo")
.tools("WeatherInfo")
.user("What's the weather like in San Francisco, Tokyo, and Paris?")
.stream().content()
.collectList().block().stream().collect(Collectors.joining());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void functionCallTest() {
UserMessage userMessage = new UserMessage("What's the weather like in San Francisco, Tokyo, and Paris?");

ChatResponse response = chatModel
.call(new Prompt(List.of(userMessage), OpenAiChatOptions.builder().function("WeatherInfo").build()));
.call(new Prompt(List.of(userMessage), OpenAiChatOptions.builder().toolNames("WeatherInfo").build()));

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

Expand All @@ -82,7 +82,7 @@ void streamFunctionCallTest() {
"What's the weather like in San Francisco, Tokyo, and Paris? You can call the following functions 'WeatherInfo'");

Flux<ChatResponse> response = chatModel
.stream(new Prompt(List.of(userMessage), OpenAiChatOptions.builder().function("WeatherInfo").build()));
.stream(new Prompt(List.of(userMessage), OpenAiChatOptions.builder().toolNames("WeatherInfo").build()));

String content = response.collectList()
.block()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import io.micrometer.observation.ObservationRegistry;

import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.model.function.FunctionCallback;
import org.springframework.ai.model.tool.ToolCallingManager;
import org.springframework.ai.tool.ToolCallback;
import org.springframework.ai.tool.ToolCallbackProvider;
import org.springframework.ai.tool.execution.DefaultToolExecutionExceptionProcessor;
import org.springframework.ai.tool.execution.ToolExecutionExceptionProcessor;
Expand Down Expand Up @@ -52,9 +52,9 @@ public class ToolCallingAutoConfiguration {
@Bean
@ConditionalOnMissingBean
ToolCallbackResolver toolCallbackResolver(GenericApplicationContext applicationContext,
List<FunctionCallback> functionCallbacks, List<ToolCallbackProvider> tcbProviders) {
List<ToolCallback> toolCallbacks, List<ToolCallbackProvider> tcbProviders) {

List<FunctionCallback> allFunctionAndToolCallbacks = new ArrayList<>(functionCallbacks);
List<ToolCallback> allFunctionAndToolCallbacks = new ArrayList<>(toolCallbacks);
tcbProviders.stream().map(pr -> List.of(pr.getToolCallbacks())).forEach(allFunctionAndToolCallbacks::addAll);

var staticToolCallbackResolver = new StaticToolCallbackResolver(allFunctionAndToolCallbacks);
Expand Down
Loading