Skip to content

Commit 101ff67

Browse files
committed
Introduce reasoningEffort and serviceTier config support for OpenAI
Closes: #1870
1 parent d6a8288 commit 101ff67

File tree

4 files changed

+225
-0
lines changed

4 files changed

+225
-0
lines changed

docs/modules/ROOT/pages/includes/quarkus-langchain4j-openai.adoc

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,54 @@ endif::add-copy-button-to-env-var[]
574574
|list of string
575575
|
576576

577+
a| [[quarkus-langchain4j-openai_quarkus-langchain4j-openai-chat-model-reasoning-effort]] [.property-path]##link:#quarkus-langchain4j-openai_quarkus-langchain4j-openai-chat-model-reasoning-effort[`quarkus.langchain4j.openai.chat-model.reasoning-effort`]##
578+
ifdef::add-copy-button-to-config-props[]
579+
config_property_copy_button:+++quarkus.langchain4j.openai.chat-model.reasoning-effort+++[]
580+
endif::add-copy-button-to-config-props[]
581+
582+
583+
[.description]
584+
--
585+
Constrains effort on reasoning for reasoning models. Currently supported values are `minimal`, `low`, `medium`, and `high`. Reducing reasoning effort can result in faster responses and fewer tokens used on reasoning in a response.
586+
587+
Note: The `gpt-5-pro` model defaults to (and only supports) high reasoning effort.
588+
589+
590+
ifdef::add-copy-button-to-env-var[]
591+
Environment variable: env_var_with_copy_button:+++QUARKUS_LANGCHAIN4J_OPENAI_CHAT_MODEL_REASONING_EFFORT+++[]
592+
endif::add-copy-button-to-env-var[]
593+
ifndef::add-copy-button-to-env-var[]
594+
Environment variable: `+++QUARKUS_LANGCHAIN4J_OPENAI_CHAT_MODEL_REASONING_EFFORT+++`
595+
endif::add-copy-button-to-env-var[]
596+
--
597+
|string
598+
|
599+
600+
a| [[quarkus-langchain4j-openai_quarkus-langchain4j-openai-chat-model-service-tier]] [.property-path]##link:#quarkus-langchain4j-openai_quarkus-langchain4j-openai-chat-model-service-tier[`quarkus.langchain4j.openai.chat-model.service-tier`]##
601+
ifdef::add-copy-button-to-config-props[]
602+
config_property_copy_button:+++quarkus.langchain4j.openai.chat-model.service-tier+++[]
603+
endif::add-copy-button-to-config-props[]
604+
605+
606+
[.description]
607+
--
608+
Specifies the processing type used for serving the request.
609+
610+
If set to `auto`, then the request will be processed with the service tier configured in the Project settings. If set to `default`, then the request will be processed with the standard pricing and performance for the selected model. If set to `flex` or `priority`, then the request will be processed with the corresponding service tier. When not set, the default behavior is `auto`.
611+
612+
When the service tier parameter is set, the response body will include the `service_tier` value based on the processing mode actually used to serve the request. This response value may be different from the value set in the parameter.
613+
614+
615+
ifdef::add-copy-button-to-env-var[]
616+
Environment variable: env_var_with_copy_button:+++QUARKUS_LANGCHAIN4J_OPENAI_CHAT_MODEL_SERVICE_TIER+++[]
617+
endif::add-copy-button-to-env-var[]
618+
ifndef::add-copy-button-to-env-var[]
619+
Environment variable: `+++QUARKUS_LANGCHAIN4J_OPENAI_CHAT_MODEL_SERVICE_TIER+++`
620+
endif::add-copy-button-to-env-var[]
621+
--
622+
|string
623+
|`default`
624+
577625
a| [[quarkus-langchain4j-openai_quarkus-langchain4j-openai-embedding-model-model-name]] [.property-path]##link:#quarkus-langchain4j-openai_quarkus-langchain4j-openai-embedding-model-model-name[`quarkus.langchain4j.openai.embedding-model.model-name`]##
578626
ifdef::add-copy-button-to-config-props[]
579627
config_property_copy_button:+++quarkus.langchain4j.openai.embedding-model.model-name+++[]
@@ -1457,6 +1505,54 @@ endif::add-copy-button-to-env-var[]
14571505
|list of string
14581506
|
14591507

1508+
a| [[quarkus-langchain4j-openai_quarkus-langchain4j-openai-model-name-chat-model-reasoning-effort]] [.property-path]##link:#quarkus-langchain4j-openai_quarkus-langchain4j-openai-model-name-chat-model-reasoning-effort[`quarkus.langchain4j.openai."model-name".chat-model.reasoning-effort`]##
1509+
ifdef::add-copy-button-to-config-props[]
1510+
config_property_copy_button:+++quarkus.langchain4j.openai."model-name".chat-model.reasoning-effort+++[]
1511+
endif::add-copy-button-to-config-props[]
1512+
1513+
1514+
[.description]
1515+
--
1516+
Constrains effort on reasoning for reasoning models. Currently supported values are `minimal`, `low`, `medium`, and `high`. Reducing reasoning effort can result in faster responses and fewer tokens used on reasoning in a response.
1517+
1518+
Note: The `gpt-5-pro` model defaults to (and only supports) high reasoning effort.
1519+
1520+
1521+
ifdef::add-copy-button-to-env-var[]
1522+
Environment variable: env_var_with_copy_button:+++QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__CHAT_MODEL_REASONING_EFFORT+++[]
1523+
endif::add-copy-button-to-env-var[]
1524+
ifndef::add-copy-button-to-env-var[]
1525+
Environment variable: `+++QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__CHAT_MODEL_REASONING_EFFORT+++`
1526+
endif::add-copy-button-to-env-var[]
1527+
--
1528+
|string
1529+
|
1530+
1531+
a| [[quarkus-langchain4j-openai_quarkus-langchain4j-openai-model-name-chat-model-service-tier]] [.property-path]##link:#quarkus-langchain4j-openai_quarkus-langchain4j-openai-model-name-chat-model-service-tier[`quarkus.langchain4j.openai."model-name".chat-model.service-tier`]##
1532+
ifdef::add-copy-button-to-config-props[]
1533+
config_property_copy_button:+++quarkus.langchain4j.openai."model-name".chat-model.service-tier+++[]
1534+
endif::add-copy-button-to-config-props[]
1535+
1536+
1537+
[.description]
1538+
--
1539+
Specifies the processing type used for serving the request.
1540+
1541+
If set to `auto`, then the request will be processed with the service tier configured in the Project settings. If set to `default`, then the request will be processed with the standard pricing and performance for the selected model. If set to `flex` or `priority`, then the request will be processed with the corresponding service tier. When not set, the default behavior is `auto`.
1542+
1543+
When the service tier parameter is set, the response body will include the `service_tier` value based on the processing mode actually used to serve the request. This response value may be different from the value set in the parameter.
1544+
1545+
1546+
ifdef::add-copy-button-to-env-var[]
1547+
Environment variable: env_var_with_copy_button:+++QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__CHAT_MODEL_SERVICE_TIER+++[]
1548+
endif::add-copy-button-to-env-var[]
1549+
ifndef::add-copy-button-to-env-var[]
1550+
Environment variable: `+++QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__CHAT_MODEL_SERVICE_TIER+++`
1551+
endif::add-copy-button-to-env-var[]
1552+
--
1553+
|string
1554+
|`default`
1555+
14601556
a| [[quarkus-langchain4j-openai_quarkus-langchain4j-openai-model-name-embedding-model-model-name]] [.property-path]##link:#quarkus-langchain4j-openai_quarkus-langchain4j-openai-model-name-embedding-model-model-name[`quarkus.langchain4j.openai."model-name".embedding-model.model-name`]##
14611557
ifdef::add-copy-button-to-config-props[]
14621558
config_property_copy_button:+++quarkus.langchain4j.openai."model-name".embedding-model.model-name+++[]

docs/modules/ROOT/pages/includes/quarkus-langchain4j-openai_quarkus.langchain4j.adoc

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,54 @@ endif::add-copy-button-to-env-var[]
574574
|list of string
575575
|
576576

577+
a| [[quarkus-langchain4j-openai_quarkus-langchain4j-openai-chat-model-reasoning-effort]] [.property-path]##link:#quarkus-langchain4j-openai_quarkus-langchain4j-openai-chat-model-reasoning-effort[`quarkus.langchain4j.openai.chat-model.reasoning-effort`]##
578+
ifdef::add-copy-button-to-config-props[]
579+
config_property_copy_button:+++quarkus.langchain4j.openai.chat-model.reasoning-effort+++[]
580+
endif::add-copy-button-to-config-props[]
581+
582+
583+
[.description]
584+
--
585+
Constrains effort on reasoning for reasoning models. Currently supported values are `minimal`, `low`, `medium`, and `high`. Reducing reasoning effort can result in faster responses and fewer tokens used on reasoning in a response.
586+
587+
Note: The `gpt-5-pro` model defaults to (and only supports) high reasoning effort.
588+
589+
590+
ifdef::add-copy-button-to-env-var[]
591+
Environment variable: env_var_with_copy_button:+++QUARKUS_LANGCHAIN4J_OPENAI_CHAT_MODEL_REASONING_EFFORT+++[]
592+
endif::add-copy-button-to-env-var[]
593+
ifndef::add-copy-button-to-env-var[]
594+
Environment variable: `+++QUARKUS_LANGCHAIN4J_OPENAI_CHAT_MODEL_REASONING_EFFORT+++`
595+
endif::add-copy-button-to-env-var[]
596+
--
597+
|string
598+
|
599+
600+
a| [[quarkus-langchain4j-openai_quarkus-langchain4j-openai-chat-model-service-tier]] [.property-path]##link:#quarkus-langchain4j-openai_quarkus-langchain4j-openai-chat-model-service-tier[`quarkus.langchain4j.openai.chat-model.service-tier`]##
601+
ifdef::add-copy-button-to-config-props[]
602+
config_property_copy_button:+++quarkus.langchain4j.openai.chat-model.service-tier+++[]
603+
endif::add-copy-button-to-config-props[]
604+
605+
606+
[.description]
607+
--
608+
Specifies the processing type used for serving the request.
609+
610+
If set to `auto`, then the request will be processed with the service tier configured in the Project settings. If set to `default`, then the request will be processed with the standard pricing and performance for the selected model. If set to `flex` or `priority`, then the request will be processed with the corresponding service tier. When not set, the default behavior is `auto`.
611+
612+
When the service tier parameter is set, the response body will include the `service_tier` value based on the processing mode actually used to serve the request. This response value may be different from the value set in the parameter.
613+
614+
615+
ifdef::add-copy-button-to-env-var[]
616+
Environment variable: env_var_with_copy_button:+++QUARKUS_LANGCHAIN4J_OPENAI_CHAT_MODEL_SERVICE_TIER+++[]
617+
endif::add-copy-button-to-env-var[]
618+
ifndef::add-copy-button-to-env-var[]
619+
Environment variable: `+++QUARKUS_LANGCHAIN4J_OPENAI_CHAT_MODEL_SERVICE_TIER+++`
620+
endif::add-copy-button-to-env-var[]
621+
--
622+
|string
623+
|`default`
624+
577625
a| [[quarkus-langchain4j-openai_quarkus-langchain4j-openai-embedding-model-model-name]] [.property-path]##link:#quarkus-langchain4j-openai_quarkus-langchain4j-openai-embedding-model-model-name[`quarkus.langchain4j.openai.embedding-model.model-name`]##
578626
ifdef::add-copy-button-to-config-props[]
579627
config_property_copy_button:+++quarkus.langchain4j.openai.embedding-model.model-name+++[]
@@ -1457,6 +1505,54 @@ endif::add-copy-button-to-env-var[]
14571505
|list of string
14581506
|
14591507

1508+
a| [[quarkus-langchain4j-openai_quarkus-langchain4j-openai-model-name-chat-model-reasoning-effort]] [.property-path]##link:#quarkus-langchain4j-openai_quarkus-langchain4j-openai-model-name-chat-model-reasoning-effort[`quarkus.langchain4j.openai."model-name".chat-model.reasoning-effort`]##
1509+
ifdef::add-copy-button-to-config-props[]
1510+
config_property_copy_button:+++quarkus.langchain4j.openai."model-name".chat-model.reasoning-effort+++[]
1511+
endif::add-copy-button-to-config-props[]
1512+
1513+
1514+
[.description]
1515+
--
1516+
Constrains effort on reasoning for reasoning models. Currently supported values are `minimal`, `low`, `medium`, and `high`. Reducing reasoning effort can result in faster responses and fewer tokens used on reasoning in a response.
1517+
1518+
Note: The `gpt-5-pro` model defaults to (and only supports) high reasoning effort.
1519+
1520+
1521+
ifdef::add-copy-button-to-env-var[]
1522+
Environment variable: env_var_with_copy_button:+++QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__CHAT_MODEL_REASONING_EFFORT+++[]
1523+
endif::add-copy-button-to-env-var[]
1524+
ifndef::add-copy-button-to-env-var[]
1525+
Environment variable: `+++QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__CHAT_MODEL_REASONING_EFFORT+++`
1526+
endif::add-copy-button-to-env-var[]
1527+
--
1528+
|string
1529+
|
1530+
1531+
a| [[quarkus-langchain4j-openai_quarkus-langchain4j-openai-model-name-chat-model-service-tier]] [.property-path]##link:#quarkus-langchain4j-openai_quarkus-langchain4j-openai-model-name-chat-model-service-tier[`quarkus.langchain4j.openai."model-name".chat-model.service-tier`]##
1532+
ifdef::add-copy-button-to-config-props[]
1533+
config_property_copy_button:+++quarkus.langchain4j.openai."model-name".chat-model.service-tier+++[]
1534+
endif::add-copy-button-to-config-props[]
1535+
1536+
1537+
[.description]
1538+
--
1539+
Specifies the processing type used for serving the request.
1540+
1541+
If set to `auto`, then the request will be processed with the service tier configured in the Project settings. If set to `default`, then the request will be processed with the standard pricing and performance for the selected model. If set to `flex` or `priority`, then the request will be processed with the corresponding service tier. When not set, the default behavior is `auto`.
1542+
1543+
When the service tier parameter is set, the response body will include the `service_tier` value based on the processing mode actually used to serve the request. This response value may be different from the value set in the parameter.
1544+
1545+
1546+
ifdef::add-copy-button-to-env-var[]
1547+
Environment variable: env_var_with_copy_button:+++QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__CHAT_MODEL_SERVICE_TIER+++[]
1548+
endif::add-copy-button-to-env-var[]
1549+
ifndef::add-copy-button-to-env-var[]
1550+
Environment variable: `+++QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__CHAT_MODEL_SERVICE_TIER+++`
1551+
endif::add-copy-button-to-env-var[]
1552+
--
1553+
|string
1554+
|`default`
1555+
14601556
a| [[quarkus-langchain4j-openai_quarkus-langchain4j-openai-model-name-embedding-model-model-name]] [.property-path]##link:#quarkus-langchain4j-openai_quarkus-langchain4j-openai-model-name-embedding-model-model-name[`quarkus.langchain4j.openai."model-name".embedding-model.model-name`]##
14611557
ifdef::add-copy-button-to-config-props[]
14621558
config_property_copy_button:+++quarkus.langchain4j.openai."model-name".embedding-model.model-name+++[]

model-providers/openai/openai-vanilla/runtime/src/main/java/io/quarkiverse/langchain4j/openai/runtime/OpenAiRecorder.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import dev.langchain4j.model.moderation.DisabledModerationModel;
2929
import dev.langchain4j.model.moderation.ModerationModel;
3030
import dev.langchain4j.model.openai.OpenAiChatModel;
31+
import dev.langchain4j.model.openai.OpenAiChatRequestParameters;
3132
import dev.langchain4j.model.openai.OpenAiEmbeddingModel;
3233
import dev.langchain4j.model.openai.OpenAiModerationModel;
3334
import dev.langchain4j.model.openai.OpenAiStreamingChatModel;
@@ -77,6 +78,11 @@ public Function<SyntheticCreationalContext<ChatModel>, ChatModel> chatModel(Stri
7778
ChatModelConfig chatModelConfig = openAiConfig.chatModel();
7879
var builder = (QuarkusOpenAiChatModelBuilderFactory.Builder) OpenAiChatModel.builder();
7980

81+
OpenAiChatRequestParameters.Builder defaultChatRequestParametersBuilder = OpenAiChatRequestParameters.builder();
82+
if (chatModelConfig.reasoningEffort().isPresent()) {
83+
defaultChatRequestParametersBuilder.reasoningEffort(chatModelConfig.reasoningEffort().get());
84+
}
85+
8086
builder
8187
.tlsConfigurationName(openAiConfig.tlsConfigurationName().orElse(null))
8288
.configName(configName)
@@ -92,7 +98,9 @@ public Function<SyntheticCreationalContext<ChatModel>, ChatModel> chatModel(Stri
9298
.presencePenalty(chatModelConfig.presencePenalty())
9399
.frequencyPenalty(chatModelConfig.frequencyPenalty())
94100
.responseFormat(chatModelConfig.responseFormat().orElse(null))
101+
.defaultRequestParameters(defaultChatRequestParametersBuilder.build())
95102
.strictJsonSchema(chatModelConfig.strictJsonSchema().orElse(null))
103+
.serviceTier(chatModelConfig.serviceTier().orElse(null))
96104
.stop(chatModelConfig.stop().orElse(null));
97105

98106
openAiConfig.organizationId().ifPresent(builder::organizationId);

model-providers/openai/openai-vanilla/runtime/src/main/java/io/quarkiverse/langchain4j/openai/runtime/config/ChatModelConfig.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,29 @@ public interface ChatModelConfig {
9696
* @return
9797
*/
9898
Optional<List<String>> stop();
99+
100+
/**
101+
* Constrains effort on reasoning for reasoning models.
102+
* Currently supported values are {@code minimal}, {@code low}, {@code medium}, and {@code high}.
103+
* Reducing reasoning effort can result in faster responses and fewer tokens used on reasoning in a response.
104+
* <p>
105+
* Note: The {@code gpt-5-pro} model defaults to (and only supports) high reasoning effort.
106+
*/
107+
Optional<String> reasoningEffort();
108+
109+
/**
110+
* Specifies the processing type used for serving the request.
111+
* <p>
112+
* If set to {@code auto}, then the request will be processed with the service tier configured in the Project settings.
113+
* If set to {@code default}, then the request will be processed with the standard pricing and performance for the selected
114+
* model.
115+
* If set to {@code flex} or {@code priority}, then the request will be processed with the corresponding service tier.
116+
* When not set, the default behavior is {@code auto}.
117+
* <p>
118+
* When the service tier parameter is set, the response body will include the {@code service_tier} value based on the
119+
* processing mode actually used to serve the request.
120+
* This response value may be different from the value set in the parameter.
121+
*/
122+
@ConfigDocDefault("default")
123+
Optional<String> serviceTier();
99124
}

0 commit comments

Comments
 (0)