Skip to content

Commit 72bceab

Browse files
committed
ToolCallingChatOptions support internalToolExecutionMaxIterations
Signed-off-by: lambochen <[email protected]>
1 parent 1f2bd08 commit 72bceab

File tree

11 files changed

+217
-9
lines changed

11 files changed

+217
-9
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
* @author Thomas Vitale
4545
* @author Alexandros Pappas
4646
* @author Ilayaperumal Gopinathan
47+
* @author lambochen
4748
* @since 1.0.0
4849
*/
4950
@JsonInclude(Include.NON_NULL)
@@ -79,6 +80,9 @@ public class AnthropicChatOptions implements ToolCallingChatOptions {
7980
@JsonIgnore
8081
private Boolean internalToolExecutionEnabled;
8182

83+
@JsonIgnore
84+
private Integer internalToolExecutionMaxIterations;
85+
8286
@JsonIgnore
8387
private Map<String, Object> toolContext = new HashMap<>();
8488

@@ -226,6 +230,16 @@ public void setInternalToolExecutionEnabled(@Nullable Boolean internalToolExecut
226230
this.internalToolExecutionEnabled = internalToolExecutionEnabled;
227231
}
228232

233+
@Override
234+
public Integer getInternalToolExecutionMaxIterations() {
235+
return this.internalToolExecutionMaxIterations;
236+
}
237+
238+
@Override
239+
public void setInternalToolExecutionMaxIterations(Integer internalToolExecutionMaxIterations) {
240+
this.internalToolExecutionMaxIterations = internalToolExecutionMaxIterations;
241+
}
242+
229243
@Override
230244
@JsonIgnore
231245
public Double getFrequencyPenalty() {

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
* @author Ilayaperumal Gopinathan
4949
* @author Alexandros Pappas
5050
* @author Andres da Silva Santos
51+
* @author lambochen
5152
*/
5253
@JsonInclude(Include.NON_NULL)
5354
public class AzureOpenAiChatOptions implements ToolCallingChatOptions {
@@ -200,6 +201,9 @@ public class AzureOpenAiChatOptions implements ToolCallingChatOptions {
200201
@JsonIgnore
201202
private Boolean internalToolExecutionEnabled;
202203

204+
@JsonIgnore
205+
private Integer internalToolExecutionMaxIterations;
206+
203207
/**
204208
* Whether to include token usage information in streaming chat completion responses.
205209
* Only applies to streaming responses.
@@ -257,6 +261,16 @@ public void setInternalToolExecutionEnabled(@Nullable Boolean internalToolExecut
257261
this.internalToolExecutionEnabled = internalToolExecutionEnabled;
258262
}
259263

264+
@Override
265+
public Integer getInternalToolExecutionMaxIterations() {
266+
return this.internalToolExecutionMaxIterations;
267+
}
268+
269+
@Override
270+
public void setInternalToolExecutionMaxIterations(Integer internalToolExecutionMaxIterations) {
271+
this.internalToolExecutionMaxIterations = internalToolExecutionMaxIterations;
272+
}
273+
260274
public static Builder builder() {
261275
return new Builder();
262276
}
@@ -504,6 +518,7 @@ public boolean equals(Object o) {
504518
&& Objects.equals(this.toolCallbacks, that.toolCallbacks)
505519
&& Objects.equals(this.toolNames, that.toolNames)
506520
&& Objects.equals(this.internalToolExecutionEnabled, that.internalToolExecutionEnabled)
521+
&& Objects.equals(this.internalToolExecutionMaxIterations, that.internalToolExecutionMaxIterations)
507522
&& Objects.equals(this.logprobs, that.logprobs) && Objects.equals(this.topLogProbs, that.topLogProbs)
508523
&& Objects.equals(this.enhancements, that.enhancements)
509524
&& Objects.equals(this.streamOptions, that.streamOptions)
@@ -518,10 +533,10 @@ public boolean equals(Object o) {
518533
@Override
519534
public int hashCode() {
520535
return Objects.hash(this.logitBias, this.user, this.n, this.stop, this.deploymentName, this.responseFormat,
521-
this.toolCallbacks, this.toolNames, this.internalToolExecutionEnabled, this.seed, this.logprobs,
522-
this.topLogProbs, this.enhancements, this.streamOptions, this.reasoningEffort, this.enableStreamUsage,
523-
this.toolContext, this.maxTokens, this.frequencyPenalty, this.presencePenalty, this.temperature,
524-
this.topP);
536+
this.toolCallbacks, this.toolNames, this.internalToolExecutionEnabled,
537+
this.internalToolExecutionMaxIterations, this.seed, this.logprobs, this.topLogProbs, this.enhancements,
538+
this.streamOptions, this.reasoningEffort, this.enableStreamUsage, this.toolContext, this.maxTokens,
539+
this.frequencyPenalty, this.presencePenalty, this.temperature, this.topP);
525540
}
526541

527542
public static class Builder {
@@ -664,6 +679,11 @@ public Builder internalToolExecutionEnabled(@Nullable Boolean internalToolExecut
664679
return this;
665680
}
666681

682+
public Builder InternalToolExecutionMaxIterations(@Nullable Integer internalToolExecutionMaxIterations) {
683+
this.options.setInternalToolExecutionMaxIterations(internalToolExecutionMaxIterations);
684+
return this;
685+
}
686+
667687
public AzureOpenAiChatOptions build() {
668688
return this.options;
669689
}

models/spring-ai-deepseek/src/main/java/org/springframework/ai/deepseek/DeepSeekChatOptions.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
* chat completion</a>
4444
*
4545
* @author Geng Rong
46+
* @author lambochen
4647
*/
4748
@JsonInclude(Include.NON_NULL)
4849
public class DeepSeekChatOptions implements ToolCallingChatOptions {
@@ -289,6 +290,18 @@ public void setInternalToolExecutionEnabled(@Nullable Boolean internalToolExecut
289290
this.internalToolExecutionEnabled = internalToolExecutionEnabled;
290291
}
291292

293+
@Override
294+
@JsonIgnore
295+
public Integer getInternalToolExecutionMaxIterations() {
296+
return 0;
297+
}
298+
299+
@Override
300+
@JsonIgnore
301+
public void setInternalToolExecutionMaxIterations(Integer internalToolExecutionMaxIterations) {
302+
303+
}
304+
292305
public Boolean getLogprobs() {
293306
return this.logprobs;
294307
}

models/spring-ai-minimax/src/main/java/org/springframework/ai/minimax/MiniMaxChatOptions.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
* @author Geng Rong
4646
* @author Thomas Vitale
4747
* @author Ilayaperumal Gopinathan
48+
* @author lambochen
4849
* @since 1.0.0 M1
4950
*/
5051
@JsonInclude(Include.NON_NULL)
@@ -153,6 +154,12 @@ public class MiniMaxChatOptions implements ToolCallingChatOptions {
153154
@JsonIgnore
154155
private Boolean internalToolExecutionEnabled;
155156

157+
/**
158+
* The maximum number of iterations for tool execution.
159+
*/
160+
@JsonIgnore
161+
private Integer internalToolExecutionMaxIterations;
162+
156163
// @formatter:on
157164

158165
public static Builder builder() {
@@ -349,6 +356,16 @@ public void setInternalToolExecutionEnabled(@Nullable Boolean internalToolExecut
349356
this.internalToolExecutionEnabled = internalToolExecutionEnabled;
350357
}
351358

359+
@Override
360+
public Integer getInternalToolExecutionMaxIterations() {
361+
return 0;
362+
}
363+
364+
@Override
365+
public void setInternalToolExecutionMaxIterations(Integer internalToolExecutionMaxIterations) {
366+
367+
}
368+
352369
@Override
353370
public Map<String, Object> getToolContext() {
354371
return this.toolContext;

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
* @author Christian Tzolov
4646
* @author Thomas Vitale
4747
* @author Alexandros Pappas
48+
* @author lambochen
4849
* @since 0.8.1
4950
*/
5051
@JsonInclude(JsonInclude.Include.NON_NULL)
@@ -156,6 +157,9 @@ public class MistralAiChatOptions implements ToolCallingChatOptions {
156157
@JsonIgnore
157158
private Boolean internalToolExecutionEnabled;
158159

160+
@JsonIgnore
161+
private Integer internalToolExecutionMaxIterations;
162+
159163
@JsonIgnore
160164
private Map<String, Object> toolContext = new HashMap<>();
161165

@@ -180,6 +184,7 @@ public static MistralAiChatOptions fromOptions(MistralAiChatOptions fromOptions)
180184
.toolCallbacks(fromOptions.getToolCallbacks())
181185
.toolNames(fromOptions.getToolNames())
182186
.internalToolExecutionEnabled(fromOptions.getInternalToolExecutionEnabled())
187+
.internalToolExecutionMaxIterations(fromOptions.getInternalToolExecutionMaxIterations())
183188
.toolContext(fromOptions.getToolContext())
184189
.build();
185190
}
@@ -347,6 +352,16 @@ public void setInternalToolExecutionEnabled(@Nullable Boolean internalToolExecut
347352
this.internalToolExecutionEnabled = internalToolExecutionEnabled;
348353
}
349354

355+
@Override
356+
public Integer getInternalToolExecutionMaxIterations() {
357+
return this.internalToolExecutionMaxIterations;
358+
}
359+
360+
@Override
361+
public void setInternalToolExecutionMaxIterations(Integer internalToolExecutionMaxIterations) {
362+
this.internalToolExecutionMaxIterations = internalToolExecutionMaxIterations;
363+
}
364+
350365
@Override
351366
@JsonIgnore
352367
public Integer getTopK() {
@@ -374,7 +389,8 @@ public MistralAiChatOptions copy() {
374389
public int hashCode() {
375390
return Objects.hash(this.model, this.temperature, this.topP, this.maxTokens, this.safePrompt, this.randomSeed,
376391
this.responseFormat, this.stop, this.frequencyPenalty, this.presencePenalty, this.n, this.tools,
377-
this.toolChoice, this.toolCallbacks, this.tools, this.internalToolExecutionEnabled, this.toolContext);
392+
this.toolChoice, this.toolCallbacks, this.tools, this.internalToolExecutionEnabled,
393+
this.internalToolExecutionMaxIterations, this.toolContext);
378394
}
379395

380396
@Override
@@ -400,6 +416,7 @@ public boolean equals(Object obj) {
400416
&& Objects.equals(this.toolCallbacks, other.toolCallbacks)
401417
&& Objects.equals(this.toolNames, other.toolNames)
402418
&& Objects.equals(this.internalToolExecutionEnabled, other.internalToolExecutionEnabled)
419+
&& Objects.equals(this.internalToolExecutionMaxIterations, other.internalToolExecutionMaxIterations)
403420
&& Objects.equals(this.toolContext, other.toolContext);
404421
}
405422

@@ -505,6 +522,11 @@ public Builder internalToolExecutionEnabled(@Nullable Boolean internalToolExecut
505522
return this;
506523
}
507524

525+
public Builder internalToolExecutionMaxIterations(@Nullable Integer internalToolExecutionMaxIterations) {
526+
this.options.setInternalToolExecutionMaxIterations(internalToolExecutionMaxIterations);
527+
return this;
528+
}
529+
508530
public Builder toolContext(Map<String, Object> toolContext) {
509531
if (this.options.toolContext == null) {
510532
this.options.toolContext = toolContext;

models/spring-ai-ollama/src/main/java/org/springframework/ai/ollama/api/OllamaOptions.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
* @author Christian Tzolov
4545
* @author Thomas Vitale
4646
* @author Ilayaperumal Gopinathan
47+
* @author lambochen
4748
* @since 0.8.0
4849
* @see <a href=
4950
* "https://github.com/ollama/ollama/blob/main/docs/modelfile.md#valid-parameters-and-values">Ollama
@@ -320,6 +321,8 @@ public class OllamaOptions implements ToolCallingChatOptions, EmbeddingOptions {
320321

321322
@JsonIgnore
322323
private Boolean internalToolExecutionEnabled;
324+
@JsonIgnore
325+
private Integer internalToolExecutionMaxIterations;
323326

324327
/**
325328
* Tool Function Callbacks to register with the ChatModel.
@@ -397,6 +400,7 @@ public static OllamaOptions fromOptions(OllamaOptions fromOptions) {
397400
.stop(fromOptions.getStop())
398401
.toolNames(fromOptions.getToolNames())
399402
.internalToolExecutionEnabled(fromOptions.getInternalToolExecutionEnabled())
403+
.internalToolExecutionMaxIterations(fromOptions.getInternalToolExecutionMaxIterations())
400404
.toolCallbacks(fromOptions.getToolCallbacks())
401405
.toolContext(fromOptions.getToolContext()).build();
402406
}
@@ -746,6 +750,16 @@ public void setInternalToolExecutionEnabled(@Nullable Boolean internalToolExecut
746750
this.internalToolExecutionEnabled = internalToolExecutionEnabled;
747751
}
748752

753+
@Override
754+
public Integer getInternalToolExecutionMaxIterations() {
755+
return this.internalToolExecutionMaxIterations;
756+
}
757+
758+
@Override
759+
public void setInternalToolExecutionMaxIterations(Integer internalToolExecutionMaxIterations) {
760+
this.internalToolExecutionMaxIterations = internalToolExecutionMaxIterations;
761+
}
762+
749763
@Override
750764
@JsonIgnore
751765
public Integer getDimensions() {
@@ -809,6 +823,7 @@ public boolean equals(Object o) {
809823
&& Objects.equals(this.penalizeNewline, that.penalizeNewline) && Objects.equals(this.stop, that.stop)
810824
&& Objects.equals(this.toolCallbacks, that.toolCallbacks)
811825
&& Objects.equals(this.internalToolExecutionEnabled, that.internalToolExecutionEnabled)
826+
&& Objects.equals(this.internalToolExecutionMaxIterations, that.internalToolExecutionMaxIterations)
812827
&& Objects.equals(this.toolNames, that.toolNames) && Objects.equals(this.toolContext, that.toolContext);
813828
}
814829

@@ -820,7 +835,7 @@ public int hashCode() {
820835
this.topP, this.minP, this.tfsZ, this.typicalP, this.repeatLastN, this.temperature, this.repeatPenalty,
821836
this.presencePenalty, this.frequencyPenalty, this.mirostat, this.mirostatTau, this.mirostatEta,
822837
this.penalizeNewline, this.stop, this.toolCallbacks, this.toolNames, this.internalToolExecutionEnabled,
823-
this.toolContext);
838+
this.internalToolExecutionMaxIterations, this.toolContext);
824839
}
825840

826841
public static class Builder {
@@ -1029,6 +1044,11 @@ public Builder internalToolExecutionEnabled(@Nullable Boolean internalToolExecut
10291044
return this;
10301045
}
10311046

1047+
public Builder internalToolExecutionMaxIterations(@Nullable Integer internalToolExecutionMaxIterations) {
1048+
this.options.setInternalToolExecutionMaxIterations(internalToolExecutionMaxIterations);
1049+
return this;
1050+
}
1051+
10321052
public Builder toolContext(Map<String, Object> toolContext) {
10331053
if (this.options.toolContext == null) {
10341054
this.options.toolContext = toolContext;

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
* @author Mariusz Bernacki
5050
* @author Thomas Vitale
5151
* @author Ilayaperumal Gopinathan
52+
* @author lambochen
5253
* @since 0.8.0
5354
*/
5455
@JsonInclude(Include.NON_NULL)
@@ -218,6 +219,9 @@ public class OpenAiChatOptions implements ToolCallingChatOptions {
218219
@JsonIgnore
219220
private Boolean internalToolExecutionEnabled;
220221

222+
@JsonIgnore
223+
private Integer internalToolExecutionMaxIterations;
224+
221225
/**
222226
* Optional HTTP headers to be added to the chat completion request.
223227
*/
@@ -262,6 +266,7 @@ public static OpenAiChatOptions fromOptions(OpenAiChatOptions fromOptions) {
262266
.toolNames(fromOptions.getToolNames() != null ? new HashSet<>(fromOptions.getToolNames()) : null)
263267
.httpHeaders(fromOptions.getHttpHeaders() != null ? new HashMap<>(fromOptions.getHttpHeaders()) : null)
264268
.internalToolExecutionEnabled(fromOptions.getInternalToolExecutionEnabled())
269+
.internalToolExecutionMaxIterations(fromOptions.getInternalToolExecutionMaxIterations())
265270
.toolContext(fromOptions.getToolContext() != null ? new HashMap<>(fromOptions.getToolContext()) : null)
266271
.store(fromOptions.getStore())
267272
.metadata(fromOptions.getMetadata())
@@ -504,6 +509,16 @@ public void setInternalToolExecutionEnabled(@Nullable Boolean internalToolExecut
504509
this.internalToolExecutionEnabled = internalToolExecutionEnabled;
505510
}
506511

512+
@Override
513+
public Integer getInternalToolExecutionMaxIterations() {
514+
return this.internalToolExecutionMaxIterations;
515+
}
516+
517+
@Override
518+
public void setInternalToolExecutionMaxIterations(Integer internalToolExecutionMaxIterations) {
519+
this.internalToolExecutionMaxIterations = internalToolExecutionMaxIterations;
520+
}
521+
507522
public Map<String, String> getHttpHeaders() {
508523
return this.httpHeaders;
509524
}
@@ -573,8 +588,9 @@ public int hashCode() {
573588
this.maxTokens, this.maxCompletionTokens, this.n, this.presencePenalty, this.responseFormat,
574589
this.streamOptions, this.seed, this.stop, this.temperature, this.topP, this.tools, this.toolChoice,
575590
this.user, this.parallelToolCalls, this.toolCallbacks, this.toolNames, this.httpHeaders,
576-
this.internalToolExecutionEnabled, this.toolContext, this.outputModalities, this.outputAudio,
577-
this.store, this.metadata, this.reasoningEffort, this.webSearchOptions);
591+
this.internalToolExecutionEnabled, this.internalToolExecutionMaxIterations, this.toolContext,
592+
this.outputModalities, this.outputAudio, this.store, this.metadata, this.reasoningEffort,
593+
this.webSearchOptions);
578594
}
579595

580596
@Override
@@ -603,6 +619,7 @@ public boolean equals(Object o) {
603619
&& Objects.equals(this.httpHeaders, other.httpHeaders)
604620
&& Objects.equals(this.toolContext, other.toolContext)
605621
&& Objects.equals(this.internalToolExecutionEnabled, other.internalToolExecutionEnabled)
622+
&& Objects.equals(this.internalToolExecutionMaxIterations, other.internalToolExecutionMaxIterations)
606623
&& Objects.equals(this.outputModalities, other.outputModalities)
607624
&& Objects.equals(this.outputAudio, other.outputAudio) && Objects.equals(this.store, other.store)
608625
&& Objects.equals(this.metadata, other.metadata)
@@ -765,6 +782,11 @@ public Builder internalToolExecutionEnabled(@Nullable Boolean internalToolExecut
765782
return this;
766783
}
767784

785+
public Builder internalToolExecutionMaxIterations(@Nullable Integer internalToolExecutionMaxIterations) {
786+
this.options.setInternalToolExecutionMaxIterations(internalToolExecutionMaxIterations);
787+
return this;
788+
}
789+
768790
public Builder httpHeaders(Map<String, String> httpHeaders) {
769791
this.options.httpHeaders = httpHeaders;
770792
return this;

0 commit comments

Comments
 (0)