Skip to content

Commit 3f19c4a

Browse files
committed
Add OpenAI paralel funciton call option
Resolves #1143
1 parent 4bb6f6e commit 3f19c4a

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ public class OpenAiChatOptions implements FunctionCallingOptions, ChatOptions {
141141
* A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.
142142
*/
143143
private @JsonProperty("user") String user;
144+
/**
145+
* Whether to enable <a href="https://platform.openai.com/docs/guides/function-calling/parallel-function-calling">parallel function calling</a> during tool use.
146+
* Defaults to true.
147+
*/
148+
private @JsonProperty("parallel_tool_calls") Boolean parallelToolCalls;
144149

145150
/**
146151
* OpenAI Tool Function Callbacks to register with the ChatModel.
@@ -272,6 +277,11 @@ public Builder withUser(String user) {
272277
return this;
273278
}
274279

280+
public Builder withParallelToolCalls(Boolean parallelToolCalls) {
281+
this.options.parallelToolCalls = parallelToolCalls;
282+
return this;
283+
}
284+
275285
public Builder withFunctionCallbacks(List<FunctionCallback> functionCallbacks) {
276286
this.options.functionCallbacks = functionCallbacks;
277287
return this;
@@ -441,6 +451,14 @@ public void setUser(String user) {
441451
this.user = user;
442452
}
443453

454+
public Boolean getParallelToolCalls() {
455+
return this.parallelToolCalls;
456+
}
457+
458+
public void setParallelToolCalls(Boolean parallelToolCalls) {
459+
this.parallelToolCalls = parallelToolCalls;
460+
}
461+
444462
@Override
445463
public List<FunctionCallback> getFunctionCallbacks() {
446464
return this.functionCallbacks;
@@ -481,6 +499,7 @@ public int hashCode() {
481499
result = prime * result + ((tools == null) ? 0 : tools.hashCode());
482500
result = prime * result + ((toolChoice == null) ? 0 : toolChoice.hashCode());
483501
result = prime * result + ((user == null) ? 0 : user.hashCode());
502+
result = prime * result + ((parallelToolCalls == null) ? 0 : parallelToolCalls.hashCode());
484503
return result;
485504
}
486505

@@ -595,6 +614,13 @@ else if (!toolChoice.equals(other.toolChoice))
595614
}
596615
else if (!this.user.equals(other.user))
597616
return false;
617+
else if (this.parallelToolCalls == null) {
618+
if (other.parallelToolCalls != null)
619+
return false;
620+
}
621+
else if (!this.parallelToolCalls.equals(other.parallelToolCalls))
622+
return false;
623+
598624
return true;
599625
}
600626

@@ -633,6 +659,7 @@ public static OpenAiChatOptions fromOptions(OpenAiChatOptions fromOptions) {
633659
.withTools(fromOptions.getTools())
634660
.withToolChoice(fromOptions.getToolChoice())
635661
.withUser(fromOptions.getUser())
662+
.withParallelToolCalls(fromOptions.getParallelToolCalls())
636663
.withFunctionCallbacks(fromOptions.getFunctionCallbacks())
637664
.withFunctions(fromOptions.getFunctions())
638665
.build();

spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/openai-chat.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ The prefix `spring.ai.openai.chat` is the property prefix that lets you configur
107107
| spring.ai.openai.chat.options.user | A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. | -
108108
| spring.ai.openai.chat.options.functions | List of functions, identified by their names, to enable for function calling in a single prompt requests. Functions with those names must exist in the functionCallbacks registry. | -
109109
| spring.ai.openai.chat.options.stream-usage | (For streaming only) Set to add an additional chunk with token usage statistics for the entire request. The `choices` field for this chunk is an empty array and all other chunks will also include a usage field, but with a null value. | false
110+
| spring.ai.openai.chat.options.parallel-tool-calls | Whether to enable link:https://platform.openai.com/docs/guides/function-calling/parallel-function-calling[parallel function calling] during tool use. | true
110111
|====
111112

112113
NOTE: You can override the common `spring.ai.openai.base-url` and `spring.ai.openai.api-key` for the `ChatModel` and `EmbeddingModel` implementations.

0 commit comments

Comments
 (0)