Skip to content

Commit b06ab7b

Browse files
feat(api): Add responses.input_tokens.count
1 parent d7408c3 commit b06ab7b

File tree

15 files changed

+3795
-4
lines changed

15 files changed

+3795
-4
lines changed

.stats.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 134
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-b062c33330de7e3bbf992fd4f0799afd868c30a66c39418dd2c62f4add3b45b6.yml
3-
openapi_spec_hash: fe067f5b1c0e93799b5ea7fde3c4b1b3
4-
config_hash: 4b6f471b24d659514b86b736c90a0c0a
1+
configured_endpoints: 135
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-812a10f8fb54c584efc914422b574cb3f43dc238b5733b13f6a0b2308b7d9910.yml
3+
openapi_spec_hash: 0222041ba12a5ff6b94924a834fa91a2
4+
config_hash: 50ee3382a63c021a9f821a935950e926

openai-java-core/src/main/kotlin/com/openai/models/responses/inputtokens/InputTokenCountParams.kt

Lines changed: 2890 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
// File generated from our OpenAPI spec by Stainless.
2+
3+
package com.openai.models.responses.inputtokens
4+
5+
import com.fasterxml.jackson.annotation.JsonAnyGetter
6+
import com.fasterxml.jackson.annotation.JsonAnySetter
7+
import com.fasterxml.jackson.annotation.JsonCreator
8+
import com.fasterxml.jackson.annotation.JsonProperty
9+
import com.openai.core.ExcludeMissing
10+
import com.openai.core.JsonField
11+
import com.openai.core.JsonMissing
12+
import com.openai.core.JsonValue
13+
import com.openai.core.checkRequired
14+
import com.openai.errors.OpenAIInvalidDataException
15+
import java.util.Collections
16+
import java.util.Objects
17+
18+
class InputTokenCountResponse
19+
@JsonCreator(mode = JsonCreator.Mode.DISABLED)
20+
private constructor(
21+
private val inputTokens: JsonField<Long>,
22+
private val object_: JsonValue,
23+
private val additionalProperties: MutableMap<String, JsonValue>,
24+
) {
25+
26+
@JsonCreator
27+
private constructor(
28+
@JsonProperty("input_tokens")
29+
@ExcludeMissing
30+
inputTokens: JsonField<Long> = JsonMissing.of(),
31+
@JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(),
32+
) : this(inputTokens, object_, mutableMapOf())
33+
34+
/**
35+
* @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is
36+
* unexpectedly missing or null (e.g. if the server responded with an unexpected value).
37+
*/
38+
fun inputTokens(): Long = inputTokens.getRequired("input_tokens")
39+
40+
/**
41+
* Expected to always return the following:
42+
* ```java
43+
* JsonValue.from("response.input_tokens")
44+
* ```
45+
*
46+
* However, this method can be useful for debugging and logging (e.g. if the server responded
47+
* with an unexpected value).
48+
*/
49+
@JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_
50+
51+
/**
52+
* Returns the raw JSON value of [inputTokens].
53+
*
54+
* Unlike [inputTokens], this method doesn't throw if the JSON field has an unexpected type.
55+
*/
56+
@JsonProperty("input_tokens") @ExcludeMissing fun _inputTokens(): JsonField<Long> = inputTokens
57+
58+
@JsonAnySetter
59+
private fun putAdditionalProperty(key: String, value: JsonValue) {
60+
additionalProperties.put(key, value)
61+
}
62+
63+
@JsonAnyGetter
64+
@ExcludeMissing
65+
fun _additionalProperties(): Map<String, JsonValue> =
66+
Collections.unmodifiableMap(additionalProperties)
67+
68+
fun toBuilder() = Builder().from(this)
69+
70+
companion object {
71+
72+
/**
73+
* Returns a mutable builder for constructing an instance of [InputTokenCountResponse].
74+
*
75+
* The following fields are required:
76+
* ```java
77+
* .inputTokens()
78+
* ```
79+
*/
80+
@JvmStatic fun builder() = Builder()
81+
}
82+
83+
/** A builder for [InputTokenCountResponse]. */
84+
class Builder internal constructor() {
85+
86+
private var inputTokens: JsonField<Long>? = null
87+
private var object_: JsonValue = JsonValue.from("response.input_tokens")
88+
private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()
89+
90+
@JvmSynthetic
91+
internal fun from(inputTokenCountResponse: InputTokenCountResponse) = apply {
92+
inputTokens = inputTokenCountResponse.inputTokens
93+
object_ = inputTokenCountResponse.object_
94+
additionalProperties = inputTokenCountResponse.additionalProperties.toMutableMap()
95+
}
96+
97+
fun inputTokens(inputTokens: Long) = inputTokens(JsonField.of(inputTokens))
98+
99+
/**
100+
* Sets [Builder.inputTokens] to an arbitrary JSON value.
101+
*
102+
* You should usually call [Builder.inputTokens] with a well-typed [Long] value instead.
103+
* This method is primarily for setting the field to an undocumented or not yet supported
104+
* value.
105+
*/
106+
fun inputTokens(inputTokens: JsonField<Long>) = apply { this.inputTokens = inputTokens }
107+
108+
/**
109+
* Sets the field to an arbitrary JSON value.
110+
*
111+
* It is usually unnecessary to call this method because the field defaults to the
112+
* following:
113+
* ```java
114+
* JsonValue.from("response.input_tokens")
115+
* ```
116+
*
117+
* This method is primarily for setting the field to an undocumented or not yet supported
118+
* value.
119+
*/
120+
fun object_(object_: JsonValue) = apply { this.object_ = object_ }
121+
122+
fun additionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
123+
this.additionalProperties.clear()
124+
putAllAdditionalProperties(additionalProperties)
125+
}
126+
127+
fun putAdditionalProperty(key: String, value: JsonValue) = apply {
128+
additionalProperties.put(key, value)
129+
}
130+
131+
fun putAllAdditionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
132+
this.additionalProperties.putAll(additionalProperties)
133+
}
134+
135+
fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) }
136+
137+
fun removeAllAdditionalProperties(keys: Set<String>) = apply {
138+
keys.forEach(::removeAdditionalProperty)
139+
}
140+
141+
/**
142+
* Returns an immutable instance of [InputTokenCountResponse].
143+
*
144+
* Further updates to this [Builder] will not mutate the returned instance.
145+
*
146+
* The following fields are required:
147+
* ```java
148+
* .inputTokens()
149+
* ```
150+
*
151+
* @throws IllegalStateException if any required field is unset.
152+
*/
153+
fun build(): InputTokenCountResponse =
154+
InputTokenCountResponse(
155+
checkRequired("inputTokens", inputTokens),
156+
object_,
157+
additionalProperties.toMutableMap(),
158+
)
159+
}
160+
161+
private var validated: Boolean = false
162+
163+
fun validate(): InputTokenCountResponse = apply {
164+
if (validated) {
165+
return@apply
166+
}
167+
168+
inputTokens()
169+
_object_().let {
170+
if (it != JsonValue.from("response.input_tokens")) {
171+
throw OpenAIInvalidDataException("'object_' is invalid, received $it")
172+
}
173+
}
174+
validated = true
175+
}
176+
177+
fun isValid(): Boolean =
178+
try {
179+
validate()
180+
true
181+
} catch (e: OpenAIInvalidDataException) {
182+
false
183+
}
184+
185+
/**
186+
* Returns a score indicating how many valid values are contained in this object recursively.
187+
*
188+
* Used for best match union deserialization.
189+
*/
190+
@JvmSynthetic
191+
internal fun validity(): Int =
192+
(if (inputTokens.asKnown().isPresent) 1 else 0) +
193+
object_.let { if (it == JsonValue.from("response.input_tokens")) 1 else 0 }
194+
195+
override fun equals(other: Any?): Boolean {
196+
if (this === other) {
197+
return true
198+
}
199+
200+
return other is InputTokenCountResponse &&
201+
inputTokens == other.inputTokens &&
202+
object_ == other.object_ &&
203+
additionalProperties == other.additionalProperties
204+
}
205+
206+
private val hashCode: Int by lazy { Objects.hash(inputTokens, object_, additionalProperties) }
207+
208+
override fun hashCode(): Int = hashCode
209+
210+
override fun toString() =
211+
"InputTokenCountResponse{inputTokens=$inputTokens, object_=$object_, additionalProperties=$additionalProperties}"
212+
}

openai-java-core/src/main/kotlin/com/openai/services/async/ResponseServiceAsync.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import com.openai.models.responses.ResponseStreamEvent
1818
import com.openai.models.responses.StructuredResponse
1919
import com.openai.models.responses.StructuredResponseCreateParams
2020
import com.openai.services.async.responses.InputItemServiceAsync
21+
import com.openai.services.async.responses.InputTokenServiceAsync
2122
import java.util.concurrent.CompletableFuture
2223
import java.util.function.Consumer
2324

@@ -37,6 +38,8 @@ interface ResponseServiceAsync {
3738

3839
fun inputItems(): InputItemServiceAsync
3940

41+
fun inputTokens(): InputTokenServiceAsync
42+
4043
/**
4144
* Creates a model response. Provide [text](https://platform.openai.com/docs/guides/text) or
4245
* [image](https://platform.openai.com/docs/guides/images) inputs to generate
@@ -291,6 +294,8 @@ interface ResponseServiceAsync {
291294

292295
fun inputItems(): InputItemServiceAsync.WithRawResponse
293296

297+
fun inputTokens(): InputTokenServiceAsync.WithRawResponse
298+
294299
/**
295300
* Returns a raw HTTP response for `post /responses`, but is otherwise the same as
296301
* [ResponseServiceAsync.create].

openai-java-core/src/main/kotlin/com/openai/services/async/ResponseServiceAsyncImpl.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ import com.openai.models.responses.ResponseRetrieveParams
3232
import com.openai.models.responses.ResponseStreamEvent
3333
import com.openai.services.async.responses.InputItemServiceAsync
3434
import com.openai.services.async.responses.InputItemServiceAsyncImpl
35+
import com.openai.services.async.responses.InputTokenServiceAsync
36+
import com.openai.services.async.responses.InputTokenServiceAsyncImpl
3537
import java.util.concurrent.CompletableFuture
3638
import java.util.function.Consumer
3739
import kotlin.jvm.optionals.getOrNull
@@ -47,13 +49,19 @@ class ResponseServiceAsyncImpl internal constructor(private val clientOptions: C
4749
InputItemServiceAsyncImpl(clientOptions)
4850
}
4951

52+
private val inputTokens: InputTokenServiceAsync by lazy {
53+
InputTokenServiceAsyncImpl(clientOptions)
54+
}
55+
5056
override fun withRawResponse(): ResponseServiceAsync.WithRawResponse = withRawResponse
5157

5258
override fun withOptions(modifier: Consumer<ClientOptions.Builder>): ResponseServiceAsync =
5359
ResponseServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build())
5460

5561
override fun inputItems(): InputItemServiceAsync = inputItems
5662

63+
override fun inputTokens(): InputTokenServiceAsync = inputTokens
64+
5765
override fun create(
5866
params: ResponseCreateParams,
5967
requestOptions: RequestOptions,
@@ -112,6 +120,10 @@ class ResponseServiceAsyncImpl internal constructor(private val clientOptions: C
112120
InputItemServiceAsyncImpl.WithRawResponseImpl(clientOptions)
113121
}
114122

123+
private val inputTokens: InputTokenServiceAsync.WithRawResponse by lazy {
124+
InputTokenServiceAsyncImpl.WithRawResponseImpl(clientOptions)
125+
}
126+
115127
override fun withOptions(
116128
modifier: Consumer<ClientOptions.Builder>
117129
): ResponseServiceAsync.WithRawResponse =
@@ -121,6 +133,8 @@ class ResponseServiceAsyncImpl internal constructor(private val clientOptions: C
121133

122134
override fun inputItems(): InputItemServiceAsync.WithRawResponse = inputItems
123135

136+
override fun inputTokens(): InputTokenServiceAsync.WithRawResponse = inputTokens
137+
124138
private val createHandler: Handler<Response> =
125139
jsonHandler<Response>(clientOptions.jsonMapper)
126140

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// File generated from our OpenAPI spec by Stainless.
2+
3+
package com.openai.services.async.responses
4+
5+
import com.openai.core.ClientOptions
6+
import com.openai.core.RequestOptions
7+
import com.openai.core.http.HttpResponseFor
8+
import com.openai.models.responses.inputtokens.InputTokenCountParams
9+
import com.openai.models.responses.inputtokens.InputTokenCountResponse
10+
import java.util.concurrent.CompletableFuture
11+
import java.util.function.Consumer
12+
13+
interface InputTokenServiceAsync {
14+
15+
/**
16+
* Returns a view of this service that provides access to raw HTTP responses for each method.
17+
*/
18+
fun withRawResponse(): WithRawResponse
19+
20+
/**
21+
* Returns a view of this service with the given option modifications applied.
22+
*
23+
* The original service is not modified.
24+
*/
25+
fun withOptions(modifier: Consumer<ClientOptions.Builder>): InputTokenServiceAsync
26+
27+
/** Get input token counts */
28+
fun count(): CompletableFuture<InputTokenCountResponse> = count(InputTokenCountParams.none())
29+
30+
/** @see count */
31+
fun count(
32+
params: InputTokenCountParams = InputTokenCountParams.none(),
33+
requestOptions: RequestOptions = RequestOptions.none(),
34+
): CompletableFuture<InputTokenCountResponse>
35+
36+
/** @see count */
37+
fun count(
38+
params: InputTokenCountParams = InputTokenCountParams.none()
39+
): CompletableFuture<InputTokenCountResponse> = count(params, RequestOptions.none())
40+
41+
/** @see count */
42+
fun count(requestOptions: RequestOptions): CompletableFuture<InputTokenCountResponse> =
43+
count(InputTokenCountParams.none(), requestOptions)
44+
45+
/**
46+
* A view of [InputTokenServiceAsync] that provides access to raw HTTP responses for each
47+
* method.
48+
*/
49+
interface WithRawResponse {
50+
51+
/**
52+
* Returns a view of this service with the given option modifications applied.
53+
*
54+
* The original service is not modified.
55+
*/
56+
fun withOptions(
57+
modifier: Consumer<ClientOptions.Builder>
58+
): InputTokenServiceAsync.WithRawResponse
59+
60+
/**
61+
* Returns a raw HTTP response for `post /responses/input_tokens`, but is otherwise the same
62+
* as [InputTokenServiceAsync.count].
63+
*/
64+
fun count(): CompletableFuture<HttpResponseFor<InputTokenCountResponse>> =
65+
count(InputTokenCountParams.none())
66+
67+
/** @see count */
68+
fun count(
69+
params: InputTokenCountParams = InputTokenCountParams.none(),
70+
requestOptions: RequestOptions = RequestOptions.none(),
71+
): CompletableFuture<HttpResponseFor<InputTokenCountResponse>>
72+
73+
/** @see count */
74+
fun count(
75+
params: InputTokenCountParams = InputTokenCountParams.none()
76+
): CompletableFuture<HttpResponseFor<InputTokenCountResponse>> =
77+
count(params, RequestOptions.none())
78+
79+
/** @see count */
80+
fun count(
81+
requestOptions: RequestOptions
82+
): CompletableFuture<HttpResponseFor<InputTokenCountResponse>> =
83+
count(InputTokenCountParams.none(), requestOptions)
84+
}
85+
}

0 commit comments

Comments
 (0)