Skip to content

Commit 5b67970

Browse files
committed
feat: options and ChatCompletionRequest add property enable_thinking. enable_thinking is used to control whether the Qwen3 model enables the thinking mode.
1 parent a1db00a commit 5b67970

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

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

+22-2
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,11 @@ public class OpenAiChatOptions implements ToolCallingChatOptions {
193193
*/
194194
private @JsonProperty("reasoning_effort") String reasoningEffort;
195195

196+
/**
197+
* Whether to enable the thinking mode
198+
*/
199+
private @JsonProperty("enable_thinking") Boolean enableThinking;
200+
196201
/**
197202
* Collection of {@link ToolCallback}s to be used for tool calling in the chat completion requests.
198203
*/
@@ -259,6 +264,7 @@ public static OpenAiChatOptions fromOptions(OpenAiChatOptions fromOptions) {
259264
.store(fromOptions.getStore())
260265
.metadata(fromOptions.getMetadata())
261266
.reasoningEffort(fromOptions.getReasoningEffort())
267+
.enableThinking(fromOptions.getEnableThinking())
262268
.build();
263269
}
264270

@@ -547,6 +553,14 @@ public void setReasoningEffort(String reasoningEffort) {
547553
this.reasoningEffort = reasoningEffort;
548554
}
549555

556+
public Boolean getEnableThinking() {
557+
return this.enableThinking;
558+
}
559+
560+
public void setEnableThinking(Boolean enableThinking) {
561+
this.enableThinking = enableThinking;
562+
}
563+
550564
@Override
551565
public OpenAiChatOptions copy() {
552566
return OpenAiChatOptions.fromOptions(this);
@@ -559,7 +573,7 @@ public int hashCode() {
559573
this.streamOptions, this.seed, this.stop, this.temperature, this.topP, this.tools, this.toolChoice,
560574
this.user, this.parallelToolCalls, this.toolCallbacks, this.toolNames, this.httpHeaders,
561575
this.internalToolExecutionEnabled, this.toolContext, this.outputModalities, this.outputAudio,
562-
this.store, this.metadata, this.reasoningEffort);
576+
this.store, this.metadata, this.reasoningEffort, this.enableThinking);
563577
}
564578

565579
@Override
@@ -591,7 +605,8 @@ public boolean equals(Object o) {
591605
&& Objects.equals(this.outputModalities, other.outputModalities)
592606
&& Objects.equals(this.outputAudio, other.outputAudio) && Objects.equals(this.store, other.store)
593607
&& Objects.equals(this.metadata, other.metadata)
594-
&& Objects.equals(this.reasoningEffort, other.reasoningEffort);
608+
&& Objects.equals(this.reasoningEffort, other.reasoningEffort)
609+
&& Objects.equals(this.enableThinking, other.enableThinking);
595610
}
596611

597612
@Override
@@ -779,6 +794,11 @@ public Builder reasoningEffort(String reasoningEffort) {
779794
return this;
780795
}
781796

797+
public Builder enableThinking(boolean enableThinking) {
798+
this.options.enableThinking = enableThinking;
799+
return this;
800+
}
801+
782802
public OpenAiChatOptions build() {
783803
return this.options;
784804
}

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

+8-7
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,8 @@ public record ChatCompletionRequest(// @formatter:off
979979
@JsonProperty("tool_choice") Object toolChoice,
980980
@JsonProperty("parallel_tool_calls") Boolean parallelToolCalls,
981981
@JsonProperty("user") String user,
982-
@JsonProperty("reasoning_effort") String reasoningEffort) {
982+
@JsonProperty("reasoning_effort") String reasoningEffort,
983+
@JsonProperty("enable_thinking") Boolean enableThinking) {
983984

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

997998
/**
@@ -1005,7 +1006,7 @@ public ChatCompletionRequest(List<ChatCompletionMessage> messages, String model,
10051006
this(messages, model, null, null, null, null, null, null,
10061007
null, null, null, List.of(OutputModality.AUDIO, OutputModality.TEXT), audio, null, null,
10071008
null, null, null, stream, null, null, null,
1008-
null, null, null, null, null);
1009+
null, null, null, null, null, null);
10091010
}
10101011

10111012
/**
@@ -1020,7 +1021,7 @@ public ChatCompletionRequest(List<ChatCompletionMessage> messages, String model,
10201021
public ChatCompletionRequest(List<ChatCompletionMessage> messages, String model, Double temperature, boolean stream) {
10211022
this(messages, model, null, null, null, null, null, null, null, null, null,
10221023
null, null, null, null, null, null, null, stream, null, temperature, null,
1023-
null, null, null, null, null);
1024+
null, null, null, null, null, null);
10241025
}
10251026

10261027
/**
@@ -1036,7 +1037,7 @@ public ChatCompletionRequest(List<ChatCompletionMessage> messages, String model,
10361037
List<FunctionTool> tools, Object toolChoice) {
10371038
this(messages, model, null, null, null, null, null, null, null, null, null,
10381039
null, null, null, null, null, null, null, false, null, 0.8, null,
1039-
tools, toolChoice, null, null, null);
1040+
tools, toolChoice, null, null, null, null);
10401041
}
10411042

10421043
/**
@@ -1049,7 +1050,7 @@ public ChatCompletionRequest(List<ChatCompletionMessage> messages, String model,
10491050
public ChatCompletionRequest(List<ChatCompletionMessage> messages, Boolean stream) {
10501051
this(messages, null, null, null, null, null, null, null, null, null, null,
10511052
null, null, null, null, null, null, null, stream, null, null, null,
1052-
null, null, null, null, null);
1053+
null, null, null, null, null, null);
10531054
}
10541055

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

10681069
/**

0 commit comments

Comments
 (0)