Skip to content

Commit 10ae729

Browse files
authored
feat(chat): add reasoning effort, max completion tokens, store options for reasoning model support (#415)
1 parent a161d11 commit 10ae729

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

openai-core/src/commonMain/kotlin/com.aallam.openai.api/chat/ChatCompletionRequest.kt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ public data class ChatCompletionRequest(
2525
*/
2626
@SerialName("messages") public val messages: List<ChatMessage>,
2727

28+
/**
29+
* Constrains effort on reasoning for reasoning models. Currently supported values are low, medium, and high.
30+
* Reducing reasoning effort can result in faster responses and fewer tokens used on reasoning in a response.
31+
*/
32+
@SerialName("reasoning_effort") public val reasoningEffort: Effort? = null,
33+
2834
/**
2935
* What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random,
3036
* while lower values like 0.2 will make it more focused and deterministic.
@@ -52,12 +58,24 @@ public data class ChatCompletionRequest(
5258
*/
5359
@SerialName("stop") public val stop: List<String>? = null,
5460

61+
/**
62+
* Whether to store the output of this chat completion request for use in our model distillation or evals products
63+
*/
64+
@SerialName("store") public val store: Boolean? = null,
65+
5566
/**
5667
* The maximum number of tokens allowed for the generated answer. By default, the number of tokens the model can
5768
* return will be (4096 - prompt tokens).
5869
*/
70+
@Deprecated(message = "Deprecated in favor of `max_completion_tokens`")
5971
@SerialName("max_tokens") public val maxTokens: Int? = null,
6072

73+
/**
74+
* An upper bound for the number of tokens that can be generated for a completion,
75+
* including visible output tokens and reasoning tokens.
76+
*/
77+
@SerialName("max_completion_tokens") public val maxCompletionTokens: Int? = null,
78+
6179
/**
6280
* Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far,
6381
* increasing the model's likelihood to talk about new topics.
@@ -191,6 +209,12 @@ public class ChatCompletionRequestBuilder {
191209
*/
192210
public var messages: List<ChatMessage>? = null
193211

212+
/**
213+
* Constrains effort on reasoning for reasoning models. Currently supported values are low, medium, and high.
214+
* Reducing reasoning effort can result in faster responses and fewer tokens used on reasoning in a response.
215+
*/
216+
public val reasoningEffort: Effort? = null
217+
194218
/**
195219
* What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random,
196220
* while lower values like 0.2 will make it more focused and deterministic.
@@ -218,12 +242,24 @@ public class ChatCompletionRequestBuilder {
218242
*/
219243
public var stop: List<String>? = null
220244

245+
/**
246+
* Whether to store the output of this chat completion request for use in our model distillation or evals products
247+
*/
248+
public val store: Boolean? = null
249+
221250
/**
222251
* The maximum number of tokens allowed for the generated answer. By default, the number of tokens the model can
223252
* return will be (4096 - prompt tokens).
224253
*/
254+
@Deprecated(message = "Deprecated in favor of `max_completion_tokens`")
225255
public var maxTokens: Int? = null
226256

257+
/**
258+
* An upper bound for the number of tokens that can be generated for a completion,
259+
* including visible output tokens and reasoning tokens.
260+
*/
261+
public val maxCompletionTokens: Int? = null
262+
227263
/**
228264
* Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far,
229265
* increasing the model's likelihood to talk about new topics.
@@ -354,11 +390,14 @@ public class ChatCompletionRequestBuilder {
354390
public fun build(): ChatCompletionRequest = ChatCompletionRequest(
355391
model = requireNotNull(model) { "model is required" },
356392
messages = requireNotNull(messages) { "messages is required" },
393+
reasoningEffort = reasoningEffort,
357394
temperature = temperature,
358395
topP = topP,
359396
n = n,
360397
stop = stop,
398+
store = store,
361399
maxTokens = maxTokens,
400+
maxCompletionTokens = maxCompletionTokens,
362401
presencePenalty = presencePenalty,
363402
frequencyPenalty = frequencyPenalty,
364403
logitBias = logitBias,
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.aallam.openai.api.chat
2+
3+
import kotlinx.serialization.Serializable
4+
import kotlin.jvm.JvmInline
5+
6+
/**
7+
* Reasoning Effort.
8+
*/
9+
@Serializable
10+
@JvmInline
11+
public value class Effort(public val id: String)

0 commit comments

Comments
 (0)