Add OpenAI paralel funciton call option

Resolves #1143
This commit is contained in:
Christian Tzolov
2024-08-01 17:11:05 +02:00
parent 4bb6f6ed44
commit 3f19c4a6e5
2 changed files with 28 additions and 0 deletions

View File

@@ -141,6 +141,11 @@ public class OpenAiChatOptions implements FunctionCallingOptions, ChatOptions {
* A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.
*/
private @JsonProperty("user") String user;
/**
* Whether to enable <a href="https://platform.openai.com/docs/guides/function-calling/parallel-function-calling">parallel function calling</a> during tool use.
* Defaults to true.
*/
private @JsonProperty("parallel_tool_calls") Boolean parallelToolCalls;
/**
* OpenAI Tool Function Callbacks to register with the ChatModel.
@@ -272,6 +277,11 @@ public class OpenAiChatOptions implements FunctionCallingOptions, ChatOptions {
return this;
}
public Builder withParallelToolCalls(Boolean parallelToolCalls) {
this.options.parallelToolCalls = parallelToolCalls;
return this;
}
public Builder withFunctionCallbacks(List<FunctionCallback> functionCallbacks) {
this.options.functionCallbacks = functionCallbacks;
return this;
@@ -441,6 +451,14 @@ public class OpenAiChatOptions implements FunctionCallingOptions, ChatOptions {
this.user = user;
}
public Boolean getParallelToolCalls() {
return this.parallelToolCalls;
}
public void setParallelToolCalls(Boolean parallelToolCalls) {
this.parallelToolCalls = parallelToolCalls;
}
@Override
public List<FunctionCallback> getFunctionCallbacks() {
return this.functionCallbacks;
@@ -481,6 +499,7 @@ public class OpenAiChatOptions implements FunctionCallingOptions, ChatOptions {
result = prime * result + ((tools == null) ? 0 : tools.hashCode());
result = prime * result + ((toolChoice == null) ? 0 : toolChoice.hashCode());
result = prime * result + ((user == null) ? 0 : user.hashCode());
result = prime * result + ((parallelToolCalls == null) ? 0 : parallelToolCalls.hashCode());
return result;
}
@@ -595,6 +614,13 @@ public class OpenAiChatOptions implements FunctionCallingOptions, ChatOptions {
}
else if (!this.user.equals(other.user))
return false;
else if (this.parallelToolCalls == null) {
if (other.parallelToolCalls != null)
return false;
}
else if (!this.parallelToolCalls.equals(other.parallelToolCalls))
return false;
return true;
}
@@ -633,6 +659,7 @@ public class OpenAiChatOptions implements FunctionCallingOptions, ChatOptions {
.withTools(fromOptions.getTools())
.withToolChoice(fromOptions.getToolChoice())
.withUser(fromOptions.getUser())
.withParallelToolCalls(fromOptions.getParallelToolCalls())
.withFunctionCallbacks(fromOptions.getFunctionCallbacks())
.withFunctions(fromOptions.getFunctions())
.build();

View File

@@ -107,6 +107,7 @@ The prefix `spring.ai.openai.chat` is the property prefix that lets you configur
| spring.ai.openai.chat.options.user | A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. | -
| 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. | -
| 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
| 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
|====
NOTE: You can override the common `spring.ai.openai.base-url` and `spring.ai.openai.api-key` for the `ChatModel` and `EmbeddingModel` implementations.