Skip to content

feat: options and ChatCompletionRequest add property enable_thinking #2940

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ public class OpenAiChatOptions implements ToolCallingChatOptions {
*/
private @JsonProperty("reasoning_effort") String reasoningEffort;

/**
* Whether to enable the thinking mode
*/
private @JsonProperty("enable_thinking") Boolean enableThinking;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what to do with these differences emerging, in particular in the reasoning models. This option is not part of openai.

Maybe we can have a subclass of OpenAiChatOptions such as QwenAiChatOptions?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about utilizing something like the template pattern? Apart from the openai compatible apis, in general, most of the models just have a few differences on request and response objects

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@apappascs can you elaborate more please?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@apappascs can you elaborate more please?


/**
* Collection of {@link ToolCallback}s to be used for tool calling in the chat completion requests.
*/
Expand Down Expand Up @@ -259,6 +264,7 @@ public static OpenAiChatOptions fromOptions(OpenAiChatOptions fromOptions) {
.store(fromOptions.getStore())
.metadata(fromOptions.getMetadata())
.reasoningEffort(fromOptions.getReasoningEffort())
.enableThinking(fromOptions.getEnableThinking())
.build();
}

Expand Down Expand Up @@ -547,6 +553,14 @@ public void setReasoningEffort(String reasoningEffort) {
this.reasoningEffort = reasoningEffort;
}

public Boolean getEnableThinking() {
return this.enableThinking;
}

public void setEnableThinking(Boolean enableThinking) {
this.enableThinking = enableThinking;
}

@Override
public OpenAiChatOptions copy() {
return OpenAiChatOptions.fromOptions(this);
Expand All @@ -559,7 +573,7 @@ public int hashCode() {
this.streamOptions, this.seed, this.stop, this.temperature, this.topP, this.tools, this.toolChoice,
this.user, this.parallelToolCalls, this.toolCallbacks, this.toolNames, this.httpHeaders,
this.internalToolExecutionEnabled, this.toolContext, this.outputModalities, this.outputAudio,
this.store, this.metadata, this.reasoningEffort);
this.store, this.metadata, this.reasoningEffort, this.enableThinking);
}

@Override
Expand Down Expand Up @@ -591,7 +605,8 @@ public boolean equals(Object o) {
&& Objects.equals(this.outputModalities, other.outputModalities)
&& Objects.equals(this.outputAudio, other.outputAudio) && Objects.equals(this.store, other.store)
&& Objects.equals(this.metadata, other.metadata)
&& Objects.equals(this.reasoningEffort, other.reasoningEffort);
&& Objects.equals(this.reasoningEffort, other.reasoningEffort)
&& Objects.equals(this.enableThinking, other.enableThinking);
}

@Override
Expand Down Expand Up @@ -779,6 +794,11 @@ public Builder reasoningEffort(String reasoningEffort) {
return this;
}

public Builder enableThinking(boolean enableThinking) {
this.options.enableThinking = enableThinking;
return this;
}

public OpenAiChatOptions build() {
return this.options;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,8 @@ public record ChatCompletionRequest(// @formatter:off
@JsonProperty("tool_choice") Object toolChoice,
@JsonProperty("parallel_tool_calls") Boolean parallelToolCalls,
@JsonProperty("user") String user,
@JsonProperty("reasoning_effort") String reasoningEffort) {
@JsonProperty("reasoning_effort") String reasoningEffort,
@JsonProperty("enable_thinking") Boolean enableThinking) {

/**
* Shortcut constructor for a chat completion request with the given messages, model and temperature.
Expand All @@ -991,7 +992,7 @@ public record ChatCompletionRequest(// @formatter:off
public ChatCompletionRequest(List<ChatCompletionMessage> messages, String model, Double temperature) {
this(messages, model, null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, false, null, temperature, null,
null, null, null, null, null);
null, null, null, null, null, null);
}

/**
Expand All @@ -1005,7 +1006,7 @@ public ChatCompletionRequest(List<ChatCompletionMessage> messages, String model,
this(messages, model, null, null, null, null, null, null,
null, null, null, List.of(OutputModality.AUDIO, OutputModality.TEXT), audio, null, null,
null, null, null, stream, null, null, null,
null, null, null, null, null);
null, null, null, null, null, null);
}

/**
Expand All @@ -1020,7 +1021,7 @@ public ChatCompletionRequest(List<ChatCompletionMessage> messages, String model,
public ChatCompletionRequest(List<ChatCompletionMessage> messages, String model, Double temperature, boolean stream) {
this(messages, model, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, stream, null, temperature, null,
null, null, null, null, null);
null, null, null, null, null, null);
}

/**
Expand All @@ -1036,7 +1037,7 @@ public ChatCompletionRequest(List<ChatCompletionMessage> messages, String model,
List<FunctionTool> tools, Object toolChoice) {
this(messages, model, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, false, null, 0.8, null,
tools, toolChoice, null, null, null);
tools, toolChoice, null, null, null, null);
}

/**
Expand All @@ -1049,7 +1050,7 @@ public ChatCompletionRequest(List<ChatCompletionMessage> messages, String model,
public ChatCompletionRequest(List<ChatCompletionMessage> messages, Boolean stream) {
this(messages, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, stream, null, null, null,
null, null, null, null, null);
null, null, null, null, null, null);
}

/**
Expand All @@ -1062,7 +1063,7 @@ public ChatCompletionRequest streamOptions(StreamOptions streamOptions) {
return new ChatCompletionRequest(this.messages, this.model, this.store, this.metadata, this.frequencyPenalty, this.logitBias, this.logprobs,
this.topLogprobs, this.maxTokens, this.maxCompletionTokens, this.n, this.outputModalities, this.audioParameters, this.presencePenalty,
this.responseFormat, this.seed, this.serviceTier, this.stop, this.stream, streamOptions, this.temperature, this.topP,
this.tools, this.toolChoice, this.parallelToolCalls, this.user, this.reasoningEffort);
this.tools, this.toolChoice, this.parallelToolCalls, this.user, this.reasoningEffort, this.enableThinking);
}

/**
Expand Down