Skip to content

Commit eded3a7

Browse files
committed
Remove FunctionCallback deprecations
- Remove the super type FunctionCallingOptions from ToolCallingChatOptions - Move toolContext builder methods into ToolCallingChatOptions - Remove Model chat options' function specific usages - Replace them with tooling: FunctionCallback -> ToolCallback functions -> toolNames - Remove proxyToolCalls use - Remove deprecated methods - Update ChatClient methods - Replace FunctionCallback -> ToolCallback - Remove deprecated methods - Update DefaultChatClient - functionNames -> toolNames - functionCallbacks -> toolCallbacks - Update AdviseRequest - functionNames -> toolNames - functionCallbacks -> toolCallbacks - Remove FunctionCallingOptions and replace it with ToolCallingOptions - Remove FunctionCallingHelper - Update DefaultToolCallingChatOptions, ToolCallbackResolvers, ToolCallbackProvider to use Tool calling types - Update documentation Resolves #2528 Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
1 parent 6b25b62 commit eded3a7

File tree

89 files changed

+533
-3101
lines changed

Some content is hidden

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

89 files changed

+533
-3101
lines changed

models/spring-ai-anthropic/src/main/java/org/springframework/ai/anthropic/AnthropicChatOptions.java

Lines changed: 6 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232

3333
import org.springframework.ai.anthropic.api.AnthropicApi;
3434
import org.springframework.ai.anthropic.api.AnthropicApi.ChatCompletionRequest;
35-
import org.springframework.ai.model.function.FunctionCallback;
3635
import org.springframework.ai.model.tool.ToolCallingChatOptions;
3736
import org.springframework.ai.tool.ToolCallback;
3837
import org.springframework.lang.Nullable;
@@ -44,6 +43,7 @@
4443
* @author Christian Tzolov
4544
* @author Thomas Vitale
4645
* @author Alexandros Pappas
46+
* @author Ilayaperumal Gopinathan
4747
* @since 1.0.0
4848
*/
4949
@JsonInclude(Include.NON_NULL)
@@ -63,7 +63,7 @@ public class AnthropicChatOptions implements ToolCallingChatOptions {
6363
* completion requests.
6464
*/
6565
@JsonIgnore
66-
private List<FunctionCallback> toolCallbacks = new ArrayList<>();
66+
private List<ToolCallback> toolCallbacks = new ArrayList<>();
6767

6868
/**
6969
* Collection of tool names to be resolved at runtime and used for tool calling in the
@@ -176,13 +176,13 @@ public void setTopK(Integer topK) {
176176

177177
@Override
178178
@JsonIgnore
179-
public List<FunctionCallback> getToolCallbacks() {
179+
public List<ToolCallback> getToolCallbacks() {
180180
return this.toolCallbacks;
181181
}
182182

183183
@Override
184184
@JsonIgnore
185-
public void setToolCallbacks(List<FunctionCallback> toolCallbacks) {
185+
public void setToolCallbacks(List<ToolCallback> toolCallbacks) {
186186
Assert.notNull(toolCallbacks, "toolCallbacks cannot be null");
187187
Assert.noNullElements(toolCallbacks, "toolCallbacks cannot contain null elements");
188188
this.toolCallbacks = toolCallbacks;
@@ -216,34 +216,6 @@ public void setInternalToolExecutionEnabled(@Nullable Boolean internalToolExecut
216216
this.internalToolExecutionEnabled = internalToolExecutionEnabled;
217217
}
218218

219-
@Override
220-
@Deprecated
221-
@JsonIgnore
222-
public List<FunctionCallback> getFunctionCallbacks() {
223-
return this.getToolCallbacks();
224-
}
225-
226-
@Override
227-
@Deprecated
228-
@JsonIgnore
229-
public void setFunctionCallbacks(List<FunctionCallback> functionCallbacks) {
230-
this.setToolCallbacks(functionCallbacks);
231-
}
232-
233-
@Override
234-
@Deprecated
235-
@JsonIgnore
236-
public Set<String> getFunctions() {
237-
return this.getToolNames();
238-
}
239-
240-
@Override
241-
@Deprecated
242-
@JsonIgnore
243-
public void setFunctions(Set<String> functionNames) {
244-
this.setToolNames(functionNames);
245-
}
246-
247219
@Override
248220
@JsonIgnore
249221
public Double getFrequencyPenalty() {
@@ -256,19 +228,6 @@ public Double getPresencePenalty() {
256228
return null;
257229
}
258230

259-
@Override
260-
@Deprecated
261-
@JsonIgnore
262-
public Boolean getProxyToolCalls() {
263-
return this.internalToolExecutionEnabled != null ? !this.internalToolExecutionEnabled : null;
264-
}
265-
266-
@Deprecated
267-
@JsonIgnore
268-
public void setProxyToolCalls(Boolean proxyToolCalls) {
269-
this.internalToolExecutionEnabled = proxyToolCalls != null ? !proxyToolCalls : null;
270-
}
271-
272231
@Override
273232
@JsonIgnore
274233
public Map<String, Object> getToolContext() {
@@ -365,12 +324,12 @@ public Builder topK(Integer topK) {
365324
return this;
366325
}
367326

368-
public Builder toolCallbacks(List<FunctionCallback> toolCallbacks) {
327+
public Builder toolCallbacks(List<ToolCallback> toolCallbacks) {
369328
this.options.setToolCallbacks(toolCallbacks);
370329
return this;
371330
}
372331

373-
public Builder toolCallbacks(FunctionCallback... toolCallbacks) {
332+
public Builder toolCallbacks(ToolCallback... toolCallbacks) {
374333
Assert.notNull(toolCallbacks, "toolCallbacks cannot be null");
375334
this.options.toolCallbacks.addAll(Arrays.asList(toolCallbacks));
376335
return this;
@@ -393,29 +352,6 @@ public Builder internalToolExecutionEnabled(@Nullable Boolean internalToolExecut
393352
return this;
394353
}
395354

396-
@Deprecated
397-
public Builder functionCallbacks(List<FunctionCallback> functionCallbacks) {
398-
return toolCallbacks(functionCallbacks);
399-
}
400-
401-
@Deprecated
402-
public Builder functions(Set<String> functionNames) {
403-
return toolNames(functionNames);
404-
}
405-
406-
@Deprecated
407-
public Builder function(String functionName) {
408-
return toolNames(functionName);
409-
}
410-
411-
@Deprecated
412-
public Builder proxyToolCalls(Boolean proxyToolCalls) {
413-
if (proxyToolCalls != null) {
414-
this.options.setInternalToolExecutionEnabled(!proxyToolCalls);
415-
}
416-
return this;
417-
}
418-
419355
public Builder toolContext(Map<String, Object> toolContext) {
420356
if (this.options.toolContext == null) {
421357
this.options.toolContext = toolContext;

models/spring-ai-azure-openai/src/main/java/org/springframework/ai/azure/openai/AzureOpenAiChatOptions.java

Lines changed: 8 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import com.fasterxml.jackson.annotation.JsonInclude.Include;
3333
import com.fasterxml.jackson.annotation.JsonProperty;
3434

35-
import org.springframework.ai.model.function.FunctionCallback;
3635
import org.springframework.ai.model.tool.ToolCallingChatOptions;
3736
import org.springframework.ai.tool.ToolCallback;
3837
import org.springframework.lang.Nullable;
@@ -185,7 +184,7 @@ public class AzureOpenAiChatOptions implements ToolCallingChatOptions {
185184
* completion requests.
186185
*/
187186
@JsonIgnore
188-
private List<FunctionCallback> toolCallbacks = new ArrayList<>();
187+
private List<ToolCallback> toolCallbacks = new ArrayList<>();
189188

190189
/**
191190
* Collection of tool names to be resolved at runtime and used for tool calling in the
@@ -202,13 +201,13 @@ public class AzureOpenAiChatOptions implements ToolCallingChatOptions {
202201

203202
@Override
204203
@JsonIgnore
205-
public List<FunctionCallback> getToolCallbacks() {
204+
public List<ToolCallback> getToolCallbacks() {
206205
return this.toolCallbacks;
207206
}
208207

209208
@Override
210209
@JsonIgnore
211-
public void setToolCallbacks(List<FunctionCallback> toolCallbacks) {
210+
public void setToolCallbacks(List<ToolCallback> toolCallbacks) {
212211
Assert.notNull(toolCallbacks, "toolCallbacks cannot be null");
213212
Assert.noNullElements(toolCallbacks, "toolCallbacks cannot contain null elements");
214213
this.toolCallbacks = toolCallbacks;
@@ -256,9 +255,9 @@ public static AzureOpenAiChatOptions fromOptions(AzureOpenAiChatOptions fromOpti
256255
.temperature(fromOptions.getTemperature())
257256
.topP(fromOptions.getTopP())
258257
.user(fromOptions.getUser())
259-
.functionCallbacks(fromOptions.getFunctionCallbacks() != null
260-
? new ArrayList<>(fromOptions.getFunctionCallbacks()) : null)
261-
.functions(fromOptions.getFunctions() != null ? new HashSet<>(fromOptions.getFunctions()) : null)
258+
.toolCallbacks(
259+
fromOptions.getToolCallbacks() != null ? new ArrayList<>(fromOptions.getToolCallbacks()) : null)
260+
.toolNames(fromOptions.getToolNames() != null ? new HashSet<>(fromOptions.getToolNames()) : null)
262261
.responseFormat(fromOptions.getResponseFormat())
263262
.seed(fromOptions.getSeed())
264263
.logprobs(fromOptions.isLogprobs())
@@ -380,27 +379,6 @@ public void setTopP(Double topP) {
380379
this.topP = topP;
381380
}
382381

383-
@Override
384-
@Deprecated
385-
@JsonIgnore
386-
public List<FunctionCallback> getFunctionCallbacks() {
387-
return this.getToolCallbacks();
388-
}
389-
390-
@Override
391-
@Deprecated
392-
@JsonIgnore
393-
public void setFunctionCallbacks(List<FunctionCallback> functionCallbacks) {
394-
this.setToolCallbacks(functionCallbacks);
395-
}
396-
397-
@Override
398-
@Deprecated
399-
@JsonIgnore
400-
public Set<String> getFunctions() {
401-
return this.getToolNames();
402-
}
403-
404382
public void setFunctions(Set<String> functions) {
405383
this.setToolNames(functions);
406384
}
@@ -451,19 +429,6 @@ public void setEnhancements(AzureChatEnhancementConfiguration enhancements) {
451429
this.enhancements = enhancements;
452430
}
453431

454-
@Override
455-
@Deprecated
456-
@JsonIgnore
457-
public Boolean getProxyToolCalls() {
458-
return this.internalToolExecutionEnabled != null ? !this.internalToolExecutionEnabled : null;
459-
}
460-
461-
@Deprecated
462-
@JsonIgnore
463-
public void setProxyToolCalls(Boolean proxyToolCalls) {
464-
this.internalToolExecutionEnabled = proxyToolCalls != null ? !proxyToolCalls : null;
465-
}
466-
467432
@Override
468433
public Map<String, Object> getToolContext() {
469434
return this.toolContext;
@@ -583,34 +548,11 @@ public Builder user(String user) {
583548
return this;
584549
}
585550

586-
@Deprecated
587-
public Builder functionCallbacks(List<FunctionCallback> functionCallbacks) {
588-
return toolCallbacks(functionCallbacks);
589-
}
590-
591-
@Deprecated
592-
public Builder functions(Set<String> functionNames) {
593-
return toolNames(functionNames);
594-
}
595-
596-
@Deprecated
597-
public Builder function(String functionName) {
598-
return toolNames(functionName);
599-
}
600-
601551
public Builder responseFormat(AzureOpenAiResponseFormat responseFormat) {
602552
this.options.responseFormat = responseFormat;
603553
return this;
604554
}
605555

606-
@Deprecated
607-
public Builder proxyToolCalls(Boolean proxyToolCalls) {
608-
if (proxyToolCalls != null) {
609-
this.options.setInternalToolExecutionEnabled(!proxyToolCalls);
610-
}
611-
return this;
612-
}
613-
614556
public Builder seed(Long seed) {
615557
this.options.seed = seed;
616558
return this;
@@ -646,12 +588,12 @@ public Builder streamOptions(ChatCompletionStreamOptions streamOptions) {
646588
return this;
647589
}
648590

649-
public Builder toolCallbacks(List<FunctionCallback> toolCallbacks) {
591+
public Builder toolCallbacks(List<ToolCallback> toolCallbacks) {
650592
this.options.setToolCallbacks(toolCallbacks);
651593
return this;
652594
}
653595

654-
public Builder toolCallbacks(FunctionCallback... toolCallbacks) {
596+
public Builder toolCallbacks(ToolCallback... toolCallbacks) {
655597
Assert.notNull(toolCallbacks, "toolCallbacks cannot be null");
656598
this.options.toolCallbacks.addAll(Arrays.asList(toolCallbacks));
657599
return this;

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ void functionCallTest() {
7070

7171
var promptOptions = AzureOpenAiChatOptions.builder()
7272
.deploymentName(this.selectedModel)
73-
.functionCallbacks(List.of(FunctionToolCallback.builder("getCurrentWeather", new MockWeatherService())
73+
.toolCallbacks(List.of(FunctionToolCallback.builder("getCurrentWeather", new MockWeatherService())
7474
.description("Get the current weather in a given location")
7575
.inputType(MockWeatherService.Request.class)
7676
.build()))
@@ -98,7 +98,7 @@ void functionCallSequentialTest() {
9898

9999
var promptOptions = AzureOpenAiChatOptions.builder()
100100
.deploymentName(this.selectedModel)
101-
.functionCallbacks(List.of(FunctionToolCallback.builder("getCurrentWeather", new MockWeatherService())
101+
.toolCallbacks(List.of(FunctionToolCallback.builder("getCurrentWeather", new MockWeatherService())
102102
.description("Get the current weather in a given location")
103103
.inputType(MockWeatherService.Request.class)
104104
.build()))
@@ -119,7 +119,7 @@ void streamFunctionCallTest() {
119119

120120
var promptOptions = AzureOpenAiChatOptions.builder()
121121
.deploymentName(this.selectedModel)
122-
.functionCallbacks(List.of(FunctionToolCallback.builder("getCurrentWeather", new MockWeatherService())
122+
.toolCallbacks(List.of(FunctionToolCallback.builder("getCurrentWeather", new MockWeatherService())
123123
.description("Get the current weather in a given location")
124124
.inputType(MockWeatherService.Request.class)
125125
.build()))
@@ -156,7 +156,7 @@ void streamFunctionCallUsageTest() {
156156

157157
var promptOptions = AzureOpenAiChatOptions.builder()
158158
.deploymentName(this.selectedModel)
159-
.functionCallbacks(List.of(FunctionToolCallback.builder("getCurrentWeather", new MockWeatherService())
159+
.toolCallbacks(List.of(FunctionToolCallback.builder("getCurrentWeather", new MockWeatherService())
160160
.description("Get the current weather in a given location")
161161
.inputType(MockWeatherService.Request.class)
162162
.build()))
@@ -182,7 +182,7 @@ void functionCallSequentialAndStreamTest() {
182182

183183
var promptOptions = AzureOpenAiChatOptions.builder()
184184
.deploymentName(this.selectedModel)
185-
.functionCallbacks(List.of(FunctionToolCallback.builder("getCurrentWeather", new MockWeatherService())
185+
.toolCallbacks(List.of(FunctionToolCallback.builder("getCurrentWeather", new MockWeatherService())
186186
.description("Get the current weather in a given location")
187187
.inputType(MockWeatherService.Request.class)
188188
.build()))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ public static Document getChatOptionsAdditionalModelRequestFields(ChatOptions de
329329
attributes.remove("proxyToolCalls");
330330
attributes.remove("functions");
331331
attributes.remove("toolContext");
332-
attributes.remove("functionCallbacks");
332+
attributes.remove("toolCallbacks");
333333

334334
attributes.remove("toolCallbacks");
335335
attributes.remove("toolNames");

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.springframework.ai.minimax.api.MiniMaxApi;
2525
import org.springframework.ai.minimax.api.MockWeatherService;
2626
import org.springframework.ai.model.function.FunctionCallback;
27+
import org.springframework.ai.tool.function.FunctionToolCallback;
2728

2829
import static org.assertj.core.api.Assertions.assertThat;
2930

@@ -64,16 +65,13 @@ public void promptOptionsTools() {
6465
var client = new MiniMaxChatModel(new MiniMaxApi("TEST"),
6566
MiniMaxChatOptions.builder().model("DEFAULT_MODEL").build());
6667

67-
var request = client.createRequest(new Prompt("Test message content",
68-
MiniMaxChatOptions.builder()
69-
.model("PROMPT_MODEL")
70-
.functionCallbacks(List.of(FunctionCallback.builder()
71-
.function(TOOL_FUNCTION_NAME, new MockWeatherService())
72-
.description("Get the weather in location")
73-
.inputType(MockWeatherService.Request.class)
74-
.build()))
75-
.build()),
76-
false);
68+
var request = client.createRequest(new Prompt("Test message content", MiniMaxChatOptions.builder()
69+
.model("PROMPT_MODEL")
70+
.functionCallbacks(List.of(FunctionToolCallback.builder(TOOL_FUNCTION_NAME, new MockWeatherService())
71+
.description("Get the weather in location")
72+
.inputType(MockWeatherService.Request.class)
73+
.build()))
74+
.build()), false);
7775

7876
assertThat(client.getFunctionCallbackRegister()).hasSize(1);
7977
assertThat(client.getFunctionCallbackRegister()).containsKeys(TOOL_FUNCTION_NAME);

models/spring-ai-mistral-ai/src/main/java/org/springframework/ai/mistralai/MistralAiChatModel.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,6 @@ Prompt buildRequestPrompt(Prompt prompt) {
364364
runtimeOptions = ModelOptionsUtils.copyToTarget(toolCallingChatOptions, ToolCallingChatOptions.class,
365365
MistralAiChatOptions.class);
366366
}
367-
else if (prompt.getOptions() instanceof FunctionCallingOptions functionCallingOptions) {
368-
runtimeOptions = ModelOptionsUtils.copyToTarget(functionCallingOptions, FunctionCallingOptions.class,
369-
MistralAiChatOptions.class);
370-
}
371367
else {
372368
runtimeOptions = ModelOptionsUtils.copyToTarget(prompt.getOptions(), ChatOptions.class,
373369
MistralAiChatOptions.class);

0 commit comments

Comments
 (0)