Skip to content

Commit 24c905e

Browse files
feat(api): o1-pro now available through the API (#337)
1 parent 33130fd commit 24c905e

18 files changed

+827
-103
lines changed

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
configured_endpoints: 78
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-f3bce04386c4fcfd5037e0477fbaa39010003fd1558eb5185fe4a71dd6a05fdd.yml
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-b26121d5df6eb5d3032a45a267473798b15fcfec76dd44a3256cf1238be05fa4.yml
Lines changed: 319 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,319 @@
1+
// File generated from our OpenAPI spec by Stainless.
2+
3+
package com.openai.models
4+
5+
import com.fasterxml.jackson.annotation.JsonCreator
6+
import com.fasterxml.jackson.core.JsonGenerator
7+
import com.fasterxml.jackson.core.ObjectCodec
8+
import com.fasterxml.jackson.databind.JsonNode
9+
import com.fasterxml.jackson.databind.SerializerProvider
10+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
11+
import com.fasterxml.jackson.databind.annotation.JsonSerialize
12+
import com.fasterxml.jackson.module.kotlin.jacksonTypeRef
13+
import com.openai.core.BaseDeserializer
14+
import com.openai.core.BaseSerializer
15+
import com.openai.core.Enum
16+
import com.openai.core.JsonField
17+
import com.openai.core.JsonValue
18+
import com.openai.core.getOrThrow
19+
import com.openai.errors.OpenAIInvalidDataException
20+
import java.util.Objects
21+
import java.util.Optional
22+
23+
@JsonDeserialize(using = AllModels.Deserializer::class)
24+
@JsonSerialize(using = AllModels.Serializer::class)
25+
class AllModels
26+
private constructor(
27+
private val string: String? = null,
28+
private val chatModel: ChatModel? = null,
29+
private val string: String? = null,
30+
private val chatModel: ChatModel? = null,
31+
private val unionMember4: UnionMember4? = null,
32+
private val _json: JsonValue? = null,
33+
) {
34+
35+
fun string(): Optional<String> = Optional.ofNullable(string)
36+
37+
fun chatModel(): Optional<ChatModel> = Optional.ofNullable(chatModel)
38+
39+
fun string(): Optional<String> = Optional.ofNullable(string)
40+
41+
fun chatModel(): Optional<ChatModel> = Optional.ofNullable(chatModel)
42+
43+
fun unionMember4(): Optional<UnionMember4> = Optional.ofNullable(unionMember4)
44+
45+
fun isString(): Boolean = string != null
46+
47+
fun isChatModel(): Boolean = chatModel != null
48+
49+
fun isString(): Boolean = string != null
50+
51+
fun isChatModel(): Boolean = chatModel != null
52+
53+
fun isUnionMember4(): Boolean = unionMember4 != null
54+
55+
fun asString(): String = string.getOrThrow("string")
56+
57+
fun asChatModel(): ChatModel = chatModel.getOrThrow("chatModel")
58+
59+
fun asString(): String = string.getOrThrow("string")
60+
61+
fun asChatModel(): ChatModel = chatModel.getOrThrow("chatModel")
62+
63+
fun asUnionMember4(): UnionMember4 = unionMember4.getOrThrow("unionMember4")
64+
65+
fun _json(): Optional<JsonValue> = Optional.ofNullable(_json)
66+
67+
fun <T> accept(visitor: Visitor<T>): T {
68+
return when {
69+
string != null -> visitor.visitString(string)
70+
chatModel != null -> visitor.visitChatModel(chatModel)
71+
string != null -> visitor.visitString(string)
72+
chatModel != null -> visitor.visitChatModel(chatModel)
73+
unionMember4 != null -> visitor.visitUnionMember4(unionMember4)
74+
else -> visitor.unknown(_json)
75+
}
76+
}
77+
78+
private var validated: Boolean = false
79+
80+
fun validate(): AllModels = apply {
81+
if (validated) {
82+
return@apply
83+
}
84+
85+
accept(
86+
object : Visitor<Unit> {
87+
override fun visitString(string: String) {}
88+
89+
override fun visitChatModel(chatModel: ChatModel) {}
90+
91+
override fun visitString(string: String) {}
92+
93+
override fun visitChatModel(chatModel: ChatModel) {}
94+
95+
override fun visitUnionMember4(unionMember4: UnionMember4) {}
96+
}
97+
)
98+
validated = true
99+
}
100+
101+
override fun equals(other: Any?): Boolean {
102+
if (this === other) {
103+
return true
104+
}
105+
106+
return /* spotless:off */ other is AllModels && string == other.string && chatModel == other.chatModel && string == other.string && chatModel == other.chatModel && unionMember4 == other.unionMember4 /* spotless:on */
107+
}
108+
109+
override fun hashCode(): Int = /* spotless:off */ Objects.hash(string, chatModel, string, chatModel, unionMember4) /* spotless:on */
110+
111+
override fun toString(): String =
112+
when {
113+
string != null -> "AllModels{string=$string}"
114+
chatModel != null -> "AllModels{chatModel=$chatModel}"
115+
string != null -> "AllModels{string=$string}"
116+
chatModel != null -> "AllModels{chatModel=$chatModel}"
117+
unionMember4 != null -> "AllModels{unionMember4=$unionMember4}"
118+
_json != null -> "AllModels{_unknown=$_json}"
119+
else -> throw IllegalStateException("Invalid AllModels")
120+
}
121+
122+
companion object {
123+
124+
@JvmStatic fun ofString(string: String) = AllModels(string = string)
125+
126+
@JvmStatic fun ofChatModel(chatModel: ChatModel) = AllModels(chatModel = chatModel)
127+
128+
@JvmStatic fun ofString(string: String) = AllModels(string = string)
129+
130+
@JvmStatic fun ofChatModel(chatModel: ChatModel) = AllModels(chatModel = chatModel)
131+
132+
@JvmStatic
133+
fun ofUnionMember4(unionMember4: UnionMember4) = AllModels(unionMember4 = unionMember4)
134+
}
135+
136+
/** An interface that defines how to map each variant of [AllModels] to a value of type [T]. */
137+
interface Visitor<out T> {
138+
139+
fun visitString(string: String): T
140+
141+
fun visitChatModel(chatModel: ChatModel): T
142+
143+
fun visitString(string: String): T
144+
145+
fun visitChatModel(chatModel: ChatModel): T
146+
147+
fun visitUnionMember4(unionMember4: UnionMember4): T
148+
149+
/**
150+
* Maps an unknown variant of [AllModels] to a value of type [T].
151+
*
152+
* An instance of [AllModels] can contain an unknown variant if it was deserialized from
153+
* data that doesn't match any known variant. For example, if the SDK is on an older version
154+
* than the API, then the API may respond with new variants that the SDK is unaware of.
155+
*
156+
* @throws OpenAIInvalidDataException in the default implementation.
157+
*/
158+
fun unknown(json: JsonValue?): T {
159+
throw OpenAIInvalidDataException("Unknown AllModels: $json")
160+
}
161+
}
162+
163+
internal class Deserializer : BaseDeserializer<AllModels>(AllModels::class) {
164+
165+
override fun ObjectCodec.deserialize(node: JsonNode): AllModels {
166+
val json = JsonValue.fromJsonNode(node)
167+
168+
tryDeserialize(node, jacksonTypeRef<String>())?.let {
169+
return AllModels(string = it, _json = json)
170+
}
171+
tryDeserialize(node, jacksonTypeRef<ChatModel>())?.let {
172+
return AllModels(chatModel = it, _json = json)
173+
}
174+
tryDeserialize(node, jacksonTypeRef<String>())?.let {
175+
return AllModels(string = it, _json = json)
176+
}
177+
tryDeserialize(node, jacksonTypeRef<ChatModel>())?.let {
178+
return AllModels(chatModel = it, _json = json)
179+
}
180+
tryDeserialize(node, jacksonTypeRef<UnionMember4>())?.let {
181+
return AllModels(unionMember4 = it, _json = json)
182+
}
183+
184+
return AllModels(_json = json)
185+
}
186+
}
187+
188+
internal class Serializer : BaseSerializer<AllModels>(AllModels::class) {
189+
190+
override fun serialize(
191+
value: AllModels,
192+
generator: JsonGenerator,
193+
provider: SerializerProvider,
194+
) {
195+
when {
196+
value.string != null -> generator.writeObject(value.string)
197+
value.chatModel != null -> generator.writeObject(value.chatModel)
198+
value.string != null -> generator.writeObject(value.string)
199+
value.chatModel != null -> generator.writeObject(value.chatModel)
200+
value.unionMember4 != null -> generator.writeObject(value.unionMember4)
201+
value._json != null -> generator.writeObject(value._json)
202+
else -> throw IllegalStateException("Invalid AllModels")
203+
}
204+
}
205+
}
206+
207+
class UnionMember4 @JsonCreator private constructor(private val value: JsonField<String>) :
208+
Enum {
209+
210+
/**
211+
* Returns this class instance's raw value.
212+
*
213+
* This is usually only useful if this instance was deserialized from data that doesn't
214+
* match any known member, and you want to know that value. For example, if the SDK is on an
215+
* older version than the API, then the API may respond with new members that the SDK is
216+
* unaware of.
217+
*/
218+
@com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField<String> = value
219+
220+
companion object {
221+
222+
@JvmField val O1_PRO = of("o1-pro")
223+
224+
@JvmField val O1_PRO_2025_03_19 = of("o1-pro-2025-03-19")
225+
226+
@JvmField val COMPUTER_USE_PREVIEW = of("computer-use-preview")
227+
228+
@JvmField val COMPUTER_USE_PREVIEW_2025_03_11 = of("computer-use-preview-2025-03-11")
229+
230+
@JvmStatic fun of(value: String) = UnionMember4(JsonField.of(value))
231+
}
232+
233+
/** An enum containing [UnionMember4]'s known values. */
234+
enum class Known {
235+
O1_PRO,
236+
O1_PRO_2025_03_19,
237+
COMPUTER_USE_PREVIEW,
238+
COMPUTER_USE_PREVIEW_2025_03_11,
239+
}
240+
241+
/**
242+
* An enum containing [UnionMember4]'s known values, as well as an [_UNKNOWN] member.
243+
*
244+
* An instance of [UnionMember4] can contain an unknown value in a couple of cases:
245+
* - It was deserialized from data that doesn't match any known member. For example, if the
246+
* SDK is on an older version than the API, then the API may respond with new members that
247+
* the SDK is unaware of.
248+
* - It was constructed with an arbitrary value using the [of] method.
249+
*/
250+
enum class Value {
251+
O1_PRO,
252+
O1_PRO_2025_03_19,
253+
COMPUTER_USE_PREVIEW,
254+
COMPUTER_USE_PREVIEW_2025_03_11,
255+
/**
256+
* An enum member indicating that [UnionMember4] was instantiated with an unknown value.
257+
*/
258+
_UNKNOWN,
259+
}
260+
261+
/**
262+
* Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN]
263+
* if the class was instantiated with an unknown value.
264+
*
265+
* Use the [known] method instead if you're certain the value is always known or if you want
266+
* to throw for the unknown case.
267+
*/
268+
fun value(): Value =
269+
when (this) {
270+
O1_PRO -> Value.O1_PRO
271+
O1_PRO_2025_03_19 -> Value.O1_PRO_2025_03_19
272+
COMPUTER_USE_PREVIEW -> Value.COMPUTER_USE_PREVIEW
273+
COMPUTER_USE_PREVIEW_2025_03_11 -> Value.COMPUTER_USE_PREVIEW_2025_03_11
274+
else -> Value._UNKNOWN
275+
}
276+
277+
/**
278+
* Returns an enum member corresponding to this class instance's value.
279+
*
280+
* Use the [value] method instead if you're uncertain the value is always known and don't
281+
* want to throw for the unknown case.
282+
*
283+
* @throws OpenAIInvalidDataException if this class instance's value is a not a known
284+
* member.
285+
*/
286+
fun known(): Known =
287+
when (this) {
288+
O1_PRO -> Known.O1_PRO
289+
O1_PRO_2025_03_19 -> Known.O1_PRO_2025_03_19
290+
COMPUTER_USE_PREVIEW -> Known.COMPUTER_USE_PREVIEW
291+
COMPUTER_USE_PREVIEW_2025_03_11 -> Known.COMPUTER_USE_PREVIEW_2025_03_11
292+
else -> throw OpenAIInvalidDataException("Unknown UnionMember4: $value")
293+
}
294+
295+
/**
296+
* Returns this class instance's primitive wire representation.
297+
*
298+
* This differs from the [toString] method because that method is primarily for debugging
299+
* and generally doesn't throw.
300+
*
301+
* @throws OpenAIInvalidDataException if this class instance's value does not have the
302+
* expected primitive type.
303+
*/
304+
fun asString(): String =
305+
_value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") }
306+
307+
override fun equals(other: Any?): Boolean {
308+
if (this === other) {
309+
return true
310+
}
311+
312+
return /* spotless:off */ other is UnionMember4 && value == other.value /* spotless:on */
313+
}
314+
315+
override fun hashCode() = value.hashCode()
316+
317+
override fun toString() = value.toString()
318+
}
319+
}

0 commit comments

Comments
 (0)