Skip to content

Commit 4dd439a

Browse files
committed
Update all existing code and tests to use the new FunctionCallback.Builder instead of FunctionCallbackWrapper.Builder
1 parent a12293b commit 4dd439a

File tree

45 files changed

+472
-440
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+472
-440
lines changed

models/spring-ai-anthropic/src/test/java/org/springframework/ai/anthropic/AnthropicChatModelIT.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
import org.springframework.ai.converter.ListOutputConverter;
4949
import org.springframework.ai.converter.MapOutputConverter;
5050
import org.springframework.ai.model.Media;
51-
import org.springframework.ai.model.function.FunctionCallbackWrapper;
51+
import org.springframework.ai.model.function.FunctionCallback;
5252
import org.springframework.beans.factory.annotation.Autowired;
5353
import org.springframework.beans.factory.annotation.Value;
5454
import org.springframework.boot.SpringBootConfiguration;
@@ -256,10 +256,11 @@ void functionCallTest() {
256256

257257
var promptOptions = AnthropicChatOptions.builder()
258258
.withModel(AnthropicApi.ChatModel.CLAUDE_3_OPUS.getName())
259-
.withFunctionCallbacks(List.of(FunctionCallbackWrapper.builder(new MockWeatherService())
260-
.withName("getCurrentWeather")
261-
.withDescription(
259+
.withFunctionCallbacks(List.of(FunctionCallback.builder(new MockWeatherService())
260+
.name("getCurrentWeather")
261+
.description(
262262
"Get the weather in location. Return temperature in 36°F or 36°C format. Use multi-turn if needed.")
263+
.inputType(MockWeatherService.Request.class)
263264
.build()))
264265
.build();
265266

@@ -283,10 +284,11 @@ void streamFunctionCallTest() {
283284

284285
var promptOptions = AnthropicChatOptions.builder()
285286
.withModel(AnthropicApi.ChatModel.CLAUDE_3_5_SONNET.getName())
286-
.withFunctionCallbacks(List.of(FunctionCallbackWrapper.builder(new MockWeatherService())
287-
.withName("getCurrentWeather")
288-
.withDescription(
287+
.withFunctionCallbacks(List.of(FunctionCallback.builder(new MockWeatherService())
288+
.name("getCurrentWeather")
289+
.description(
289290
"Get the weather in location. Return temperature in 36°F or 36°C format. Use multi-turn if needed.")
291+
.inputType(MockWeatherService.Request.class)
290292
.build()))
291293
.build();
292294

models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/function/AzureOpenAiChatModelFunctionCallIT.java

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
import org.springframework.ai.chat.model.ChatResponse;
4040
import org.springframework.ai.chat.model.Generation;
4141
import org.springframework.ai.chat.prompt.Prompt;
42-
import org.springframework.ai.model.function.FunctionCallbackWrapper;
42+
import org.springframework.ai.model.function.FunctionCallback;
4343
import org.springframework.beans.factory.annotation.Autowired;
4444
import org.springframework.boot.SpringBootConfiguration;
4545
import org.springframework.boot.test.context.SpringBootTest;
@@ -70,10 +70,11 @@ void functionCallTest() {
7070

7171
var promptOptions = AzureOpenAiChatOptions.builder()
7272
.withDeploymentName(this.selectedModel)
73-
.withFunctionCallbacks(List.of(FunctionCallbackWrapper.builder(new MockWeatherService())
74-
.withName("getCurrentWeather")
75-
.withDescription("Get the current weather in a given location")
76-
.withResponseConverter(response -> "" + response.temp() + response.unit())
73+
.withFunctionCallbacks(List.of(FunctionCallback.builder(new MockWeatherService())
74+
.name("getCurrentWeather")
75+
.description("Get the current weather in a given location")
76+
.inputType(MockWeatherService.Request.class)
77+
.responseConverter(response -> "" + response.temp() + response.unit())
7778
.build()))
7879
.build();
7980

@@ -94,10 +95,11 @@ void functionCallSequentialTest() {
9495

9596
var promptOptions = AzureOpenAiChatOptions.builder()
9697
.withDeploymentName(this.selectedModel)
97-
.withFunctionCallbacks(List.of(FunctionCallbackWrapper.builder(new MockWeatherService())
98-
.withName("getCurrentWeather")
99-
.withDescription("Get the current weather in a given location")
100-
.withResponseConverter(response -> "" + response.temp() + response.unit())
98+
.withFunctionCallbacks(List.of(FunctionCallback.builder(new MockWeatherService())
99+
.name("getCurrentWeather")
100+
.description("Get the current weather in a given location")
101+
.inputType(MockWeatherService.Request.class)
102+
.responseConverter(response -> "" + response.temp() + response.unit())
101103
.build()))
102104
.build();
103105

@@ -116,10 +118,11 @@ void streamFunctionCallTest() {
116118

117119
var promptOptions = AzureOpenAiChatOptions.builder()
118120
.withDeploymentName(this.selectedModel)
119-
.withFunctionCallbacks(List.of(FunctionCallbackWrapper.builder(new MockWeatherService())
120-
.withName("getCurrentWeather")
121-
.withDescription("Get the current weather in a given location")
122-
.withResponseConverter(response -> "" + response.temp() + response.unit())
121+
.withFunctionCallbacks(List.of(FunctionCallback.builder(new MockWeatherService())
122+
.name("getCurrentWeather")
123+
.description("Get the current weather in a given location")
124+
.inputType(MockWeatherService.Request.class)
125+
.responseConverter(response -> "" + response.temp() + response.unit())
123126
.build()))
124127
.build();
125128

@@ -153,10 +156,11 @@ void functionCallSequentialAndStreamTest() {
153156

154157
var promptOptions = AzureOpenAiChatOptions.builder()
155158
.withDeploymentName(this.selectedModel)
156-
.withFunctionCallbacks(List.of(FunctionCallbackWrapper.builder(new MockWeatherService())
157-
.withName("getCurrentWeather")
158-
.withDescription("Get the current weather in a given location")
159-
.withResponseConverter(response -> "" + response.temp() + response.unit())
159+
.withFunctionCallbacks(List.of(FunctionCallback.builder(new MockWeatherService())
160+
.name("getCurrentWeather")
161+
.description("Get the current weather in a given location")
162+
.inputType(MockWeatherService.Request.class)
163+
.responseConverter(response -> "" + response.temp() + response.unit())
160164
.build()))
161165
.build();
162166

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
import org.springframework.ai.converter.ListOutputConverter;
4848
import org.springframework.ai.converter.MapOutputConverter;
4949
import org.springframework.ai.model.Media;
50-
import org.springframework.ai.model.function.FunctionCallbackWrapper;
50+
import org.springframework.ai.model.function.FunctionCallback;
5151
import org.springframework.ai.model.function.FunctionCallingOptions;
5252
import org.springframework.beans.factory.annotation.Autowired;
5353
import org.springframework.beans.factory.annotation.Value;
@@ -254,10 +254,11 @@ void functionCallTest() {
254254
List<Message> messages = new ArrayList<>(List.of(userMessage));
255255

256256
var promptOptions = FunctionCallingOptions.builder()
257-
.withFunctionCallbacks(List.of(FunctionCallbackWrapper.builder(new MockWeatherService())
258-
.withName("getCurrentWeather")
259-
.withDescription(
257+
.withFunctionCallbacks(List.of(FunctionCallback.builder(new MockWeatherService())
258+
.name("getCurrentWeather")
259+
.description(
260260
"Get the weather in location. Return temperature in 36°F or 36°C format. Use multi-turn if needed.")
261+
.inputType(MockWeatherService.Request.class)
261262
.build()))
262263
.build();
263264

@@ -281,10 +282,11 @@ void streamFunctionCallTest() {
281282

282283
var promptOptions = FunctionCallingOptions.builder()
283284
.withModel("anthropic.claude-3-5-sonnet-20240620-v1:0")
284-
.withFunctionCallbacks(List.of(FunctionCallbackWrapper.builder(new MockWeatherService())
285-
.withName("getCurrentWeather")
286-
.withDescription(
285+
.withFunctionCallbacks(List.of(FunctionCallback.builder(new MockWeatherService())
286+
.name("getCurrentWeather")
287+
.description(
287288
"Get the weather in location. Return temperature in 36°F or 36°C format. Use multi-turn if needed.")
289+
.inputType(MockWeatherService.Request.class)
288290
.build()))
289291
.build();
290292

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import org.springframework.ai.bedrock.converse.BedrockProxyChatModel;
2727
import org.springframework.ai.bedrock.converse.MockWeatherService;
2828
import org.springframework.ai.chat.prompt.Prompt;
29-
import org.springframework.ai.model.function.FunctionCallbackWrapper;
29+
import org.springframework.ai.model.function.FunctionCallback;
3030
import org.springframework.ai.model.function.FunctionCallingOptionsBuilder.PortableFunctionCallingOptions;
3131

3232
/**
@@ -52,9 +52,10 @@ public static void main(String[] args) {
5252
"What's the weather like in Paris? Return the temperature in Celsius.",
5353
PortableFunctionCallingOptions.builder()
5454
.withModel(modelId)
55-
.withFunctionCallbacks(List.of(FunctionCallbackWrapper.builder(new MockWeatherService())
56-
.withName("getCurrentWeather")
57-
.withDescription("Get the weather in location")
55+
.withFunctionCallbacks(List.of(FunctionCallback.builder(new MockWeatherService())
56+
.name("getCurrentWeather")
57+
.description("Get the weather in location")
58+
.inputType(MockWeatherService.Request.class)
5859
.build()))
5960
.build());
6061

@@ -68,11 +69,6 @@ public static void main(String[] args) {
6869
Flux<ConverseStreamOutput> responses = chatModel.converseStream(streamRequest);
6970
List<ConverseStreamOutput> responseList = responses.collectList().block();
7071
System.out.println(responseList);
71-
72-
// Flux<ChatResponse> responses2 = ConverseApiUtils.toChatResponse(responses);
73-
// List<ChatResponse> responseList2 = responses2.collectList().block();
74-
// System.out.println(responseList2);
75-
7672
}
7773

7874
}

models/spring-ai-minimax/src/test/java/org/springframework/ai/minimax/ChatCompletionRequestTests.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import org.springframework.ai.chat.prompt.Prompt;
2424
import org.springframework.ai.minimax.api.MiniMaxApi;
2525
import org.springframework.ai.minimax.api.MockWeatherService;
26-
import org.springframework.ai.model.function.FunctionCallbackWrapper;
26+
import org.springframework.ai.model.function.FunctionCallback;
2727

2828
import static org.assertj.core.api.Assertions.assertThat;
2929

@@ -67,10 +67,11 @@ public void promptOptionsTools() {
6767
var request = client.createRequest(new Prompt("Test message content",
6868
MiniMaxChatOptions.builder()
6969
.withModel("PROMPT_MODEL")
70-
.withFunctionCallbacks(List.of(FunctionCallbackWrapper.builder(new MockWeatherService())
71-
.withName(TOOL_FUNCTION_NAME)
72-
.withDescription("Get the weather in location")
73-
.withResponseConverter(response -> "" + response.temp() + response.unit())
70+
.withFunctionCallbacks(List.of(FunctionCallback.builder(new MockWeatherService())
71+
.name(TOOL_FUNCTION_NAME)
72+
.description("Get the weather in location")
73+
.inputType(MockWeatherService.Request.class)
74+
.responseConverter(response -> "" + response.temp() + response.unit())
7475
.build()))
7576
.build()),
7677
false);
@@ -94,10 +95,11 @@ public void defaultOptionsTools() {
9495
var client = new MiniMaxChatModel(new MiniMaxApi("TEST"),
9596
MiniMaxChatOptions.builder()
9697
.withModel("DEFAULT_MODEL")
97-
.withFunctionCallbacks(List.of(FunctionCallbackWrapper.builder(new MockWeatherService())
98-
.withName(TOOL_FUNCTION_NAME)
99-
.withDescription("Get the weather in location")
100-
.withResponseConverter(response -> "" + response.temp() + response.unit())
98+
.withFunctionCallbacks(List.of(FunctionCallback.builder(new MockWeatherService())
99+
.name(TOOL_FUNCTION_NAME)
100+
.description("Get the weather in location")
101+
.inputType(MockWeatherService.Request.class)
102+
.responseConverter(response -> "" + response.temp() + response.unit())
101103
.build()))
102104
.build());
103105

@@ -126,9 +128,10 @@ public void defaultOptionsTools() {
126128
// Override the default options function with one from the prompt
127129
request = client.createRequest(new Prompt("Test message content",
128130
MiniMaxChatOptions.builder()
129-
.withFunctionCallbacks(List.of(FunctionCallbackWrapper.builder(new MockWeatherService())
130-
.withName(TOOL_FUNCTION_NAME)
131-
.withDescription("Overridden function description")
131+
.withFunctionCallbacks(List.of(FunctionCallback.builder(new MockWeatherService())
132+
.name(TOOL_FUNCTION_NAME)
133+
.description("Overridden function description")
134+
.inputType(MockWeatherService.Request.class)
132135
.build()))
133136
.build()),
134137
false);

models/spring-ai-mistral-ai/src/test/java/org/springframework/ai/mistralai/MistralAiChatModelIT.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
import org.springframework.ai.converter.ListOutputConverter;
4343
import org.springframework.ai.converter.MapOutputConverter;
4444
import org.springframework.ai.mistralai.api.MistralAiApi;
45-
import org.springframework.ai.model.function.FunctionCallbackWrapper;
45+
import org.springframework.ai.model.function.FunctionCallback;
4646
import org.springframework.beans.factory.annotation.Autowired;
4747
import org.springframework.beans.factory.annotation.Value;
4848
import org.springframework.boot.test.context.SpringBootTest;
@@ -193,10 +193,11 @@ void functionCallTest() {
193193

194194
var promptOptions = MistralAiChatOptions.builder()
195195
.withModel(MistralAiApi.ChatModel.SMALL.getValue())
196-
.withFunctionCallbacks(List.of(FunctionCallbackWrapper.builder(new MockWeatherService())
197-
.withName("getCurrentWeather")
198-
.withDescription("Get the weather in location")
199-
.withResponseConverter(response -> "" + response.temp() + response.unit())
196+
.withFunctionCallbacks(List.of(FunctionCallback.builder(new MockWeatherService())
197+
.name("getCurrentWeather")
198+
.description("Get the weather in location")
199+
.inputType(MockWeatherService.Request.class)
200+
.responseConverter(response -> "" + response.temp() + response.unit())
200201
.build()))
201202
.build();
202203

@@ -216,10 +217,11 @@ void streamFunctionCallTest() {
216217

217218
var promptOptions = MistralAiChatOptions.builder()
218219
.withModel(MistralAiApi.ChatModel.SMALL.getValue())
219-
.withFunctionCallbacks(List.of(FunctionCallbackWrapper.builder(new MockWeatherService())
220-
.withName("getCurrentWeather")
221-
.withDescription("Get the weather in location")
222-
.withResponseConverter(response -> "" + response.temp() + response.unit())
220+
.withFunctionCallbacks(List.of(FunctionCallback.builder(new MockWeatherService())
221+
.name("getCurrentWeather")
222+
.description("Get the weather in location")
223+
.inputType(MockWeatherService.Request.class)
224+
.responseConverter(response -> "" + response.temp() + response.unit())
223225
.build()))
224226
.build();
225227

models/spring-ai-moonshot/src/test/java/org/springframework/ai/moonshot/chat/MoonshotChatModelFunctionCallingIT.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import org.springframework.ai.chat.model.ChatResponse;
3535
import org.springframework.ai.chat.model.Generation;
3636
import org.springframework.ai.chat.prompt.Prompt;
37-
import org.springframework.ai.model.function.FunctionCallbackWrapper;
37+
import org.springframework.ai.model.function.FunctionCallback;
3838
import org.springframework.ai.moonshot.MoonshotChatOptions;
3939
import org.springframework.ai.moonshot.MoonshotTestConfiguration;
4040
import org.springframework.ai.moonshot.api.MockWeatherService;
@@ -63,10 +63,11 @@ void functionCallTest() {
6363

6464
var promptOptions = MoonshotChatOptions.builder()
6565
.withModel(MoonshotApi.ChatModel.MOONSHOT_V1_8K.getValue())
66-
.withFunctionCallbacks(List.of(FunctionCallbackWrapper.builder(new MockWeatherService())
67-
.withName("getCurrentWeather")
68-
.withDescription("Get the weather in location")
69-
.withResponseConverter(response -> "" + response.temp() + response.unit())
66+
.withFunctionCallbacks(List.of(FunctionCallback.builder(new MockWeatherService())
67+
.name("getCurrentWeather")
68+
.description("Get the weather in location")
69+
.inputType(MockWeatherService.Request.class)
70+
.responseConverter(response -> "" + response.temp() + response.unit())
7071
.build()))
7172
.build();
7273

@@ -86,11 +87,10 @@ void streamFunctionCallTest() {
8687
List<Message> messages = new ArrayList<>(List.of(userMessage));
8788

8889
var promptOptions = MoonshotChatOptions.builder()
89-
// .withModel(OpenAiApi.ChatModel.GPT_4_TURBO_PREVIEW.getValue())
90-
.withFunctionCallbacks(List.of(FunctionCallbackWrapper.builder(new MockWeatherService())
91-
.withName("getCurrentWeather")
92-
.withDescription("Get the weather in location")
93-
.withResponseConverter(response -> "" + response.temp() + response.unit())
90+
.withFunctionCallbacks(List.of(FunctionCallback.builder(new MockWeatherService())
91+
.name("getCurrentWeather")
92+
.description("Get the weather in location")
93+
.responseConverter(response -> "" + response.temp() + response.unit())
9494
.build()))
9595
.build();
9696

models/spring-ai-ollama/src/test/java/org/springframework/ai/ollama/OllamaChatModelFunctionCallingIT.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import org.springframework.ai.chat.model.ChatResponse;
3434
import org.springframework.ai.chat.model.Generation;
3535
import org.springframework.ai.chat.prompt.Prompt;
36-
import org.springframework.ai.model.function.FunctionCallbackWrapper;
36+
import org.springframework.ai.model.function.FunctionCallback;
3737
import org.springframework.ai.ollama.api.OllamaApi;
3838
import org.springframework.ai.ollama.api.OllamaOptions;
3939
import org.springframework.ai.ollama.api.tool.MockWeatherService;
@@ -63,11 +63,12 @@ void functionCallTest() {
6363

6464
var promptOptions = OllamaOptions.builder()
6565
.withModel(MODEL)
66-
.withFunctionCallbacks(List.of(FunctionCallbackWrapper.builder(new MockWeatherService())
67-
.withName("getCurrentWeather")
68-
.withDescription(
66+
.withFunctionCallbacks(List.of(FunctionCallback.builder(new MockWeatherService())
67+
.name("getCurrentWeather")
68+
.description(
6969
"Find the weather conditions, forecasts, and temperatures for a location, like a city or state.")
70-
.withResponseConverter(response -> "" + response.temp() + response.unit())
70+
.inputType(MockWeatherService.Request.class)
71+
.responseConverter(response -> "" + response.temp() + response.unit())
7172
.build()))
7273
.build();
7374

@@ -88,11 +89,12 @@ void streamFunctionCallTest() {
8889

8990
var promptOptions = OllamaOptions.builder()
9091
.withModel(MODEL)
91-
.withFunctionCallbacks(List.of(FunctionCallbackWrapper.builder(new MockWeatherService())
92-
.withName("getCurrentWeather")
93-
.withDescription(
92+
.withFunctionCallbacks(List.of(FunctionCallback.builder(new MockWeatherService())
93+
.name("getCurrentWeather")
94+
.description(
9495
"Find the weather conditions, forecasts, and temperatures for a location, like a city or state.")
95-
.withResponseConverter(response -> "" + response.temp() + response.unit())
96+
.inputType(MockWeatherService.Request.class)
97+
.responseConverter(response -> "" + response.temp() + response.unit())
9698
.build()))
9799
.build();
98100

0 commit comments

Comments
 (0)