diff --git a/.release-please-manifest.json b/.release-please-manifest.json
index 2adb41ca8..52afe059d 100644
--- a/.release-please-manifest.json
+++ b/.release-please-manifest.json
@@ -1,3 +1,3 @@
{
- ".": "0.41.1"
+ ".": "0.42.0"
}
\ No newline at end of file
diff --git a/.stats.yml b/.stats.yml
index b21d5dae7..1f1a1736b 100644
--- a/.stats.yml
+++ b/.stats.yml
@@ -1,4 +1,4 @@
configured_endpoints: 80
-openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-6663c59193eb95b201e492de17dcbd5e126ba03d18ce66287a3e2c632ca56fe7.yml
+openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-4bce8217a697c729ac98046d4caf2c9e826b54c427fb0ab4f98e549a2e0ce31c.yml
openapi_spec_hash: 7996d2c34cc44fe2ce9ffe93c0ab774e
-config_hash: 2daae06cc598821ccf87201de0861e40
+config_hash: 178ba1bfb1237bf6b94abb3408072aa7
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0f53c2fbd..d05d1214e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,22 @@
# Changelog
+## 0.42.0 (2025-04-02)
+
+Full Changelog: [v0.41.1...v0.42.0](https://github.com/openai/openai-java/compare/v0.41.1...v0.42.0)
+
+### Features
+
+* **api:** manual updates ([0440105](https://github.com/openai/openai-java/commit/0440105162ce52cd187ce8ab8d5d1dc20682a4ed))
+* **client:** add enum validation method ([a641218](https://github.com/openai/openai-java/commit/a6412183ccea1ac3e9105793372693d5ec8c6d72))
+* **client:** make union deserialization more robust ([#385](https://github.com/openai/openai-java/issues/385)) ([a641218](https://github.com/openai/openai-java/commit/a6412183ccea1ac3e9105793372693d5ec8c6d72))
+
+
+### Chores
+
+* **client:** remove unnecessary json state from some query param classes ([a641218](https://github.com/openai/openai-java/commit/a6412183ccea1ac3e9105793372693d5ec8c6d72))
+* **internal:** add invalid json deserialization tests ([a641218](https://github.com/openai/openai-java/commit/a6412183ccea1ac3e9105793372693d5ec8c6d72))
+* **internal:** add json roundtripping tests ([a641218](https://github.com/openai/openai-java/commit/a6412183ccea1ac3e9105793372693d5ec8c6d72))
+
## 0.41.1 (2025-04-01)
Full Changelog: [v0.41.0...v0.41.1](https://github.com/openai/openai-java/compare/v0.41.0...v0.41.1)
diff --git a/README.md b/README.md
index 898c552f0..f1d9f7ba3 100644
--- a/README.md
+++ b/README.md
@@ -9,8 +9,8 @@
-[](https://central.sonatype.com/artifact/com.openai/openai-java/0.41.1)
-[](https://javadoc.io/doc/com.openai/openai-java/0.41.1)
+[](https://central.sonatype.com/artifact/com.openai/openai-java/0.42.0)
+[](https://javadoc.io/doc/com.openai/openai-java/0.42.0)
@@ -18,7 +18,7 @@ The OpenAI Java SDK provides convenient access to the [OpenAI REST API](https://
-The REST API documentation can be found on [platform.openai.com](https://platform.openai.com/docs). Javadocs are also available on [javadoc.io](https://javadoc.io/doc/com.openai/openai-java/0.41.1).
+The REST API documentation can be found on [platform.openai.com](https://platform.openai.com/docs). Javadocs are also available on [javadoc.io](https://javadoc.io/doc/com.openai/openai-java/0.42.0).
@@ -29,7 +29,7 @@ The REST API documentation can be found on [platform.openai.com](https://platfor
### Gradle
```kotlin
-implementation("com.openai:openai-java:0.41.1")
+implementation("com.openai:openai-java:0.42.0")
```
### Maven
@@ -38,7 +38,7 @@ implementation("com.openai:openai-java:0.41.1")
com.openai
openai-java
- 0.41.1
+ 0.42.0
```
diff --git a/build.gradle.kts b/build.gradle.kts
index 00332ab66..12705605e 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -8,7 +8,7 @@ repositories {
allprojects {
group = "com.openai"
- version = "0.41.1" // x-release-please-version
+ version = "0.42.0" // x-release-please-version
}
subprojects {
diff --git a/openai-java-core/src/main/kotlin/com/openai/core/BaseDeserializer.kt b/openai-java-core/src/main/kotlin/com/openai/core/BaseDeserializer.kt
index d30fb36da..c6dc038b4 100644
--- a/openai-java-core/src/main/kotlin/com/openai/core/BaseDeserializer.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/core/BaseDeserializer.kt
@@ -7,11 +7,9 @@ import com.fasterxml.jackson.databind.BeanProperty
import com.fasterxml.jackson.databind.DeserializationContext
import com.fasterxml.jackson.databind.JavaType
import com.fasterxml.jackson.databind.JsonDeserializer
-import com.fasterxml.jackson.databind.JsonMappingException
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.deser.ContextualDeserializer
import com.fasterxml.jackson.databind.deser.std.StdDeserializer
-import com.openai.errors.OpenAIInvalidDataException
import kotlin.reflect.KClass
abstract class BaseDeserializer(type: KClass) :
@@ -30,38 +28,17 @@ abstract class BaseDeserializer(type: KClass) :
protected abstract fun ObjectCodec.deserialize(node: JsonNode): T
- protected fun ObjectCodec.deserialize(node: JsonNode, type: TypeReference): T =
+ protected fun ObjectCodec.tryDeserialize(node: JsonNode, type: TypeReference): T? =
try {
readValue(treeAsTokens(node), type)
} catch (e: Exception) {
- throw OpenAIInvalidDataException("Error deserializing", e)
- }
-
- protected fun ObjectCodec.tryDeserialize(
- node: JsonNode,
- type: TypeReference,
- validate: (T) -> Unit = {},
- ): T? {
- return try {
- readValue(treeAsTokens(node), type).apply(validate)
- } catch (e: JsonMappingException) {
- null
- } catch (e: RuntimeException) {
null
}
- }
- protected fun ObjectCodec.tryDeserialize(
- node: JsonNode,
- type: JavaType,
- validate: (T) -> Unit = {},
- ): T? {
- return try {
- readValue(treeAsTokens(node), type).apply(validate)
- } catch (e: JsonMappingException) {
- null
- } catch (e: RuntimeException) {
+ protected fun ObjectCodec.tryDeserialize(node: JsonNode, type: JavaType): T? =
+ try {
+ readValue(treeAsTokens(node), type)
+ } catch (e: Exception) {
null
}
- }
}
diff --git a/openai-java-core/src/main/kotlin/com/openai/core/Utils.kt b/openai-java-core/src/main/kotlin/com/openai/core/Utils.kt
index a63ef98b6..0b11077b0 100644
--- a/openai-java-core/src/main/kotlin/com/openai/core/Utils.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/core/Utils.kt
@@ -25,6 +25,34 @@ internal fun , V> SortedMap.toImmutable(): SortedMap> Sequence.allMaxBy(selector: (T) -> R): List {
+ var maxValue: R? = null
+ val maxElements = mutableListOf()
+
+ val iterator = iterator()
+ while (iterator.hasNext()) {
+ val element = iterator.next()
+ val value = selector(element)
+ if (maxValue == null || value > maxValue) {
+ maxValue = value
+ maxElements.clear()
+ maxElements.add(element)
+ } else if (value == maxValue) {
+ maxElements.add(element)
+ }
+ }
+
+ return maxElements
+}
+
/**
* Returns whether [this] is equal to [other].
*
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/AllModels.kt b/openai-java-core/src/main/kotlin/com/openai/models/AllModels.kt
index 99061d321..b9077106b 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/AllModels.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/AllModels.kt
@@ -15,6 +15,7 @@ import com.openai.core.BaseSerializer
import com.openai.core.Enum
import com.openai.core.JsonField
import com.openai.core.JsonValue
+import com.openai.core.allMaxBy
import com.openai.core.getOrThrow
import com.openai.errors.OpenAIInvalidDataException
import java.util.Objects
@@ -50,14 +51,13 @@ private constructor(
fun _json(): Optional = Optional.ofNullable(_json)
- fun accept(visitor: Visitor): T {
- return when {
+ fun accept(visitor: Visitor): T =
+ when {
string != null -> visitor.visitString(string)
chatModel != null -> visitor.visitChatModel(chatModel)
unionMember2 != null -> visitor.visitUnionMember2(unionMember2)
else -> visitor.unknown(_json)
}
- }
private var validated: Boolean = false
@@ -70,14 +70,45 @@ private constructor(
object : Visitor {
override fun visitString(string: String) {}
- override fun visitChatModel(chatModel: ChatModel) {}
+ override fun visitChatModel(chatModel: ChatModel) {
+ chatModel.validate()
+ }
- override fun visitUnionMember2(unionMember2: UnionMember2) {}
+ override fun visitUnionMember2(unionMember2: UnionMember2) {
+ unionMember2.validate()
+ }
}
)
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ accept(
+ object : Visitor {
+ override fun visitString(string: String) = 1
+
+ override fun visitChatModel(chatModel: ChatModel) = chatModel.validity()
+
+ override fun visitUnionMember2(unionMember2: UnionMember2) = unionMember2.validity()
+
+ override fun unknown(json: JsonValue?) = 0
+ }
+ )
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -135,17 +166,30 @@ private constructor(
override fun ObjectCodec.deserialize(node: JsonNode): AllModels {
val json = JsonValue.fromJsonNode(node)
- tryDeserialize(node, jacksonTypeRef())?.let {
- return AllModels(string = it, _json = json)
- }
- tryDeserialize(node, jacksonTypeRef())?.let {
- return AllModels(chatModel = it, _json = json)
- }
- tryDeserialize(node, jacksonTypeRef())?.let {
- return AllModels(unionMember2 = it, _json = json)
+ val bestMatches =
+ sequenceOf(
+ tryDeserialize(node, jacksonTypeRef())?.let {
+ AllModels(chatModel = it, _json = json)
+ },
+ tryDeserialize(node, jacksonTypeRef())?.let {
+ AllModels(unionMember2 = it, _json = json)
+ },
+ tryDeserialize(node, jacksonTypeRef())?.let {
+ AllModels(string = it, _json = json)
+ },
+ )
+ .filterNotNull()
+ .allMaxBy { it.validity() }
+ .toList()
+ return when (bestMatches.size) {
+ // This can happen if what we're deserializing is completely incompatible with all
+ // the possible variants (e.g. deserializing from object).
+ 0 -> AllModels(_json = json)
+ 1 -> bestMatches.single()
+ // If there's more than one match with the highest validity, then use the first
+ // completely valid match, or simply the first match if none are completely valid.
+ else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first()
}
-
- return AllModels(_json = json)
}
}
@@ -266,6 +310,33 @@ private constructor(
fun asString(): String =
_value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") }
+ private var validated: Boolean = false
+
+ fun validate(): UnionMember2 = apply {
+ if (validated) {
+ return@apply
+ }
+
+ known()
+ validated = true
+ }
+
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/ChatModel.kt b/openai-java-core/src/main/kotlin/com/openai/models/ChatModel.kt
index 81584236b..3db434916 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/ChatModel.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/ChatModel.kt
@@ -338,6 +338,32 @@ class ChatModel @JsonCreator private constructor(private val value: JsonField = Optional.ofNullable(_json)
- fun accept(visitor: Visitor): T {
- return when {
+ fun accept(visitor: Visitor): T =
+ when {
string != null -> visitor.visitString(string)
number != null -> visitor.visitNumber(number)
bool != null -> visitor.visitBool(bool)
else -> visitor.unknown(_json)
}
- }
private var validated: Boolean = false
@@ -440,6 +487,34 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ accept(
+ object : Visitor {
+ override fun visitString(string: String) = 1
+
+ override fun visitNumber(number: Double) = 1
+
+ override fun visitBool(bool: Boolean) = 1
+
+ override fun unknown(json: JsonValue?) = 0
+ }
+ )
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -497,17 +572,31 @@ private constructor(
override fun ObjectCodec.deserialize(node: JsonNode): Value {
val json = JsonValue.fromJsonNode(node)
- tryDeserialize(node, jacksonTypeRef())?.let {
- return Value(string = it, _json = json)
- }
- tryDeserialize(node, jacksonTypeRef())?.let {
- return Value(number = it, _json = json)
+ val bestMatches =
+ sequenceOf(
+ tryDeserialize(node, jacksonTypeRef())?.let {
+ Value(string = it, _json = json)
+ },
+ tryDeserialize(node, jacksonTypeRef())?.let {
+ Value(number = it, _json = json)
+ },
+ tryDeserialize(node, jacksonTypeRef())?.let {
+ Value(bool = it, _json = json)
+ },
+ )
+ .filterNotNull()
+ .allMaxBy { it.validity() }
+ .toList()
+ return when (bestMatches.size) {
+ // This can happen if what we're deserializing is completely incompatible with
+ // all the possible variants (e.g. deserializing from object).
+ 0 -> Value(_json = json)
+ 1 -> bestMatches.single()
+ // If there's more than one match with the highest validity, then use the first
+ // completely valid match, or simply the first match if none are completely
+ // valid.
+ else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first()
}
- tryDeserialize(node, jacksonTypeRef())?.let {
- return Value(bool = it, _json = json)
- }
-
- return Value(_json = json)
}
}
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/CompoundFilter.kt b/openai-java-core/src/main/kotlin/com/openai/models/CompoundFilter.kt
index 19825efa6..6a33b4972 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/CompoundFilter.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/CompoundFilter.kt
@@ -20,6 +20,7 @@ import com.openai.core.ExcludeMissing
import com.openai.core.JsonField
import com.openai.core.JsonMissing
import com.openai.core.JsonValue
+import com.openai.core.allMaxBy
import com.openai.core.checkKnown
import com.openai.core.checkRequired
import com.openai.core.getOrThrow
@@ -28,6 +29,7 @@ import com.openai.errors.OpenAIInvalidDataException
import java.util.Collections
import java.util.Objects
import java.util.Optional
+import kotlin.jvm.optionals.getOrNull
/** Combine multiple filters using `and` or `or`. */
class CompoundFilter
@@ -206,10 +208,28 @@ private constructor(
}
filters().forEach { it.validate() }
- type()
+ type().validate()
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (filters.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) +
+ (type.asKnown().getOrNull()?.validity() ?: 0)
+
/**
* A filter used to compare a specified attribute key to a given value using a defined
* comparison operation.
@@ -245,13 +265,12 @@ private constructor(
fun _json(): Optional = Optional.ofNullable(_json)
- fun accept(visitor: Visitor): T {
- return when {
+ fun accept(visitor: Visitor): T =
+ when {
comparison != null -> visitor.visitComparison(comparison)
jsonValue != null -> visitor.visitJsonValue(jsonValue)
else -> visitor.unknown(_json)
}
- }
private var validated: Boolean = false
@@ -272,6 +291,33 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ accept(
+ object : Visitor {
+ override fun visitComparison(comparison: ComparisonFilter) =
+ comparison.validity()
+
+ override fun visitJsonValue(jsonValue: JsonValue) = 1
+
+ override fun unknown(json: JsonValue?) = 0
+ }
+ )
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -333,15 +379,28 @@ private constructor(
override fun ObjectCodec.deserialize(node: JsonNode): Filter {
val json = JsonValue.fromJsonNode(node)
- tryDeserialize(node, jacksonTypeRef()) { it.validate() }
- ?.let {
- return Filter(comparison = it, _json = json)
- }
- tryDeserialize(node, jacksonTypeRef())?.let {
- return Filter(jsonValue = it, _json = json)
+ val bestMatches =
+ sequenceOf(
+ tryDeserialize(node, jacksonTypeRef())?.let {
+ Filter(comparison = it, _json = json)
+ },
+ tryDeserialize(node, jacksonTypeRef())?.let {
+ Filter(jsonValue = it, _json = json)
+ },
+ )
+ .filterNotNull()
+ .allMaxBy { it.validity() }
+ .toList()
+ return when (bestMatches.size) {
+ // This can happen if what we're deserializing is completely incompatible with
+ // all the possible variants.
+ 0 -> Filter(_json = json)
+ 1 -> bestMatches.single()
+ // If there's more than one match with the highest validity, then use the first
+ // completely valid match, or simply the first match if none are completely
+ // valid.
+ else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first()
}
-
- return Filter(_json = json)
}
}
@@ -448,6 +507,33 @@ private constructor(
fun asString(): String =
_value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") }
+ private var validated: Boolean = false
+
+ fun validate(): Type = apply {
+ if (validated) {
+ return@apply
+ }
+
+ known()
+ validated = true
+ }
+
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/ErrorObject.kt b/openai-java-core/src/main/kotlin/com/openai/models/ErrorObject.kt
index 0160fae8c..25d94a0e8 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/ErrorObject.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/ErrorObject.kt
@@ -236,6 +236,26 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (if (code.asKnown().isPresent) 1 else 0) +
+ (if (message.asKnown().isPresent) 1 else 0) +
+ (if (param.asKnown().isPresent) 1 else 0) +
+ (if (type.asKnown().isPresent) 1 else 0)
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/FunctionDefinition.kt b/openai-java-core/src/main/kotlin/com/openai/models/FunctionDefinition.kt
index 4b4e7d7b7..f0d56969e 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/FunctionDefinition.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/FunctionDefinition.kt
@@ -286,6 +286,26 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (if (name.asKnown().isPresent) 1 else 0) +
+ (if (description.asKnown().isPresent) 1 else 0) +
+ (parameters.asKnown().getOrNull()?.validity() ?: 0) +
+ (if (strict.asKnown().isPresent) 1 else 0)
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/FunctionParameters.kt b/openai-java-core/src/main/kotlin/com/openai/models/FunctionParameters.kt
index d78babcfe..f80f48f18 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/FunctionParameters.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/FunctionParameters.kt
@@ -7,6 +7,7 @@ import com.fasterxml.jackson.annotation.JsonCreator
import com.openai.core.ExcludeMissing
import com.openai.core.JsonValue
import com.openai.core.toImmutable
+import com.openai.errors.OpenAIInvalidDataException
import java.util.Objects
/**
@@ -83,6 +84,23 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/Reasoning.kt b/openai-java-core/src/main/kotlin/com/openai/models/Reasoning.kt
index 5028a1257..63f75e5bc 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/Reasoning.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/Reasoning.kt
@@ -193,11 +193,29 @@ private constructor(
return@apply
}
- effort()
- generateSummary()
+ effort().ifPresent { it.validate() }
+ generateSummary().ifPresent { it.validate() }
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (effort.asKnown().getOrNull()?.validity() ?: 0) +
+ (generateSummary.asKnown().getOrNull()?.validity() ?: 0)
+
/**
* **computer_use_preview only**
*
@@ -293,6 +311,33 @@ private constructor(
fun asString(): String =
_value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") }
+ private var validated: Boolean = false
+
+ fun validate(): GenerateSummary = apply {
+ if (validated) {
+ return@apply
+ }
+
+ known()
+ validated = true
+ }
+
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/ReasoningEffort.kt b/openai-java-core/src/main/kotlin/com/openai/models/ReasoningEffort.kt
index 0c3fb2848..f0b62aa50 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/ReasoningEffort.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/ReasoningEffort.kt
@@ -107,6 +107,32 @@ class ReasoningEffort @JsonCreator private constructor(private val value: JsonFi
fun asString(): String =
_value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") }
+ private var validated: Boolean = false
+
+ fun validate(): ReasoningEffort = apply {
+ if (validated) {
+ return@apply
+ }
+
+ known()
+ validated = true
+ }
+
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/ResponseFormatJsonObject.kt b/openai-java-core/src/main/kotlin/com/openai/models/ResponseFormatJsonObject.kt
index 7570bffff..99b9814de 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/ResponseFormatJsonObject.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/ResponseFormatJsonObject.kt
@@ -129,6 +129,22 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int = type.let { if (it == JsonValue.from("json_object")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/ResponseFormatJsonSchema.kt b/openai-java-core/src/main/kotlin/com/openai/models/ResponseFormatJsonSchema.kt
index 6584c82d9..9b8052424 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/ResponseFormatJsonSchema.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/ResponseFormatJsonSchema.kt
@@ -187,6 +187,24 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (jsonSchema.asKnown().getOrNull()?.validity() ?: 0) +
+ type.let { if (it == JsonValue.from("json_schema")) 1 else 0 }
+
/** Structured Outputs configuration options, including a JSON Schema. */
class JsonSchema
private constructor(
@@ -448,6 +466,27 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (if (name.asKnown().isPresent) 1 else 0) +
+ (if (description.asKnown().isPresent) 1 else 0) +
+ (schema.asKnown().getOrNull()?.validity() ?: 0) +
+ (if (strict.asKnown().isPresent) 1 else 0)
+
/**
* The schema for the response format, described as a JSON Schema object. Learn how to build
* JSON schemas [here](https://json-schema.org/).
@@ -521,6 +560,24 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/ResponseFormatText.kt b/openai-java-core/src/main/kotlin/com/openai/models/ResponseFormatText.kt
index 099bf9a5c..7daa00978 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/ResponseFormatText.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/ResponseFormatText.kt
@@ -125,6 +125,22 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int = type.let { if (it == JsonValue.from("text")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/ResponsesModel.kt b/openai-java-core/src/main/kotlin/com/openai/models/ResponsesModel.kt
index 3620dd701..c84795566 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/ResponsesModel.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/ResponsesModel.kt
@@ -15,6 +15,7 @@ import com.openai.core.BaseSerializer
import com.openai.core.Enum
import com.openai.core.JsonField
import com.openai.core.JsonValue
+import com.openai.core.allMaxBy
import com.openai.core.getOrThrow
import com.openai.errors.OpenAIInvalidDataException
import java.util.Objects
@@ -50,14 +51,13 @@ private constructor(
fun _json(): Optional = Optional.ofNullable(_json)
- fun accept(visitor: Visitor): T {
- return when {
+ fun accept(visitor: Visitor): T =
+ when {
string != null -> visitor.visitString(string)
chat != null -> visitor.visitChat(chat)
unionMember2 != null -> visitor.visitUnionMember2(unionMember2)
else -> visitor.unknown(_json)
}
- }
private var validated: Boolean = false
@@ -70,14 +70,45 @@ private constructor(
object : Visitor {
override fun visitString(string: String) {}
- override fun visitChat(chat: ChatModel) {}
+ override fun visitChat(chat: ChatModel) {
+ chat.validate()
+ }
- override fun visitUnionMember2(unionMember2: UnionMember2) {}
+ override fun visitUnionMember2(unionMember2: UnionMember2) {
+ unionMember2.validate()
+ }
}
)
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ accept(
+ object : Visitor {
+ override fun visitString(string: String) = 1
+
+ override fun visitChat(chat: ChatModel) = chat.validity()
+
+ override fun visitUnionMember2(unionMember2: UnionMember2) = unionMember2.validity()
+
+ override fun unknown(json: JsonValue?) = 0
+ }
+ )
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -138,17 +169,30 @@ private constructor(
override fun ObjectCodec.deserialize(node: JsonNode): ResponsesModel {
val json = JsonValue.fromJsonNode(node)
- tryDeserialize(node, jacksonTypeRef())?.let {
- return ResponsesModel(string = it, _json = json)
- }
- tryDeserialize(node, jacksonTypeRef())?.let {
- return ResponsesModel(chat = it, _json = json)
+ val bestMatches =
+ sequenceOf(
+ tryDeserialize(node, jacksonTypeRef())?.let {
+ ResponsesModel(chat = it, _json = json)
+ },
+ tryDeserialize(node, jacksonTypeRef())?.let {
+ ResponsesModel(unionMember2 = it, _json = json)
+ },
+ tryDeserialize(node, jacksonTypeRef())?.let {
+ ResponsesModel(string = it, _json = json)
+ },
+ )
+ .filterNotNull()
+ .allMaxBy { it.validity() }
+ .toList()
+ return when (bestMatches.size) {
+ // This can happen if what we're deserializing is completely incompatible with all
+ // the possible variants (e.g. deserializing from object).
+ 0 -> ResponsesModel(_json = json)
+ 1 -> bestMatches.single()
+ // If there's more than one match with the highest validity, then use the first
+ // completely valid match, or simply the first match if none are completely valid.
+ else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first()
}
- tryDeserialize(node, jacksonTypeRef())?.let {
- return ResponsesModel(unionMember2 = it, _json = json)
- }
-
- return ResponsesModel(_json = json)
}
}
@@ -269,6 +313,33 @@ private constructor(
fun asString(): String =
_value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") }
+ private var validated: Boolean = false
+
+ fun validate(): UnionMember2 = apply {
+ if (validated) {
+ return@apply
+ }
+
+ known()
+ validated = true
+ }
+
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/audio/AudioModel.kt b/openai-java-core/src/main/kotlin/com/openai/models/audio/AudioModel.kt
index 8f06688a0..5f80b466d 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/audio/AudioModel.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/audio/AudioModel.kt
@@ -96,6 +96,32 @@ class AudioModel @JsonCreator private constructor(private val value: JsonField,
@@ -389,6 +408,26 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (if (token.asKnown().isPresent) 1 else 0) +
+ (bytes.asKnown().getOrNull()?.size ?: 0) +
+ (if (logprob.asKnown().isPresent) 1 else 0)
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/audio/transcriptions/TranscriptionCreateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/audio/transcriptions/TranscriptionCreateParams.kt
index 49f092ede..5ff32133d 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/audio/transcriptions/TranscriptionCreateParams.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/audio/transcriptions/TranscriptionCreateParams.kt
@@ -960,16 +960,24 @@ private constructor(
}
file()
- model()
- include()
+ model().validate()
+ include().ifPresent { it.forEach { it.validate() } }
language()
prompt()
- responseFormat()
+ responseFormat().ifPresent { it.validate() }
temperature()
- timestampGranularities()
+ timestampGranularities().ifPresent { it.forEach { it.validate() } }
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -1079,6 +1087,33 @@ private constructor(
fun asString(): String =
_value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") }
+ private var validated: Boolean = false
+
+ fun validate(): TimestampGranularity = apply {
+ if (validated) {
+ return@apply
+ }
+
+ known()
+ validated = true
+ }
+
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/audio/transcriptions/TranscriptionCreateResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/audio/transcriptions/TranscriptionCreateResponse.kt
index d739c6749..1e3c0c4fa 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/audio/transcriptions/TranscriptionCreateResponse.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/audio/transcriptions/TranscriptionCreateResponse.kt
@@ -12,6 +12,7 @@ import com.fasterxml.jackson.module.kotlin.jacksonTypeRef
import com.openai.core.BaseDeserializer
import com.openai.core.BaseSerializer
import com.openai.core.JsonValue
+import com.openai.core.allMaxBy
import com.openai.core.getOrThrow
import com.openai.errors.OpenAIInvalidDataException
import java.util.Objects
@@ -51,13 +52,12 @@ private constructor(
fun _json(): Optional = Optional.ofNullable(_json)
- fun accept(visitor: Visitor): T {
- return when {
+ fun accept(visitor: Visitor): T =
+ when {
transcription != null -> visitor.visitTranscription(transcription)
verbose != null -> visitor.visitVerbose(verbose)
else -> visitor.unknown(_json)
}
- }
private var validated: Boolean = false
@@ -80,6 +80,32 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ accept(
+ object : Visitor {
+ override fun visitTranscription(transcription: Transcription) =
+ transcription.validity()
+
+ override fun visitVerbose(verbose: TranscriptionVerbose) = verbose.validity()
+
+ override fun unknown(json: JsonValue?) = 0
+ }
+ )
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -150,16 +176,27 @@ private constructor(
override fun ObjectCodec.deserialize(node: JsonNode): TranscriptionCreateResponse {
val json = JsonValue.fromJsonNode(node)
- tryDeserialize(node, jacksonTypeRef()) { it.validate() }
- ?.let {
- return TranscriptionCreateResponse(transcription = it, _json = json)
- }
- tryDeserialize(node, jacksonTypeRef()) { it.validate() }
- ?.let {
- return TranscriptionCreateResponse(verbose = it, _json = json)
- }
-
- return TranscriptionCreateResponse(_json = json)
+ val bestMatches =
+ sequenceOf(
+ tryDeserialize(node, jacksonTypeRef())?.let {
+ TranscriptionCreateResponse(transcription = it, _json = json)
+ },
+ tryDeserialize(node, jacksonTypeRef())?.let {
+ TranscriptionCreateResponse(verbose = it, _json = json)
+ },
+ )
+ .filterNotNull()
+ .allMaxBy { it.validity() }
+ .toList()
+ return when (bestMatches.size) {
+ // This can happen if what we're deserializing is completely incompatible with all
+ // the possible variants (e.g. deserializing from boolean).
+ 0 -> TranscriptionCreateResponse(_json = json)
+ 1 -> bestMatches.single()
+ // If there's more than one match with the highest validity, then use the first
+ // completely valid match, or simply the first match if none are completely valid.
+ else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first()
+ }
}
}
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/audio/transcriptions/TranscriptionInclude.kt b/openai-java-core/src/main/kotlin/com/openai/models/audio/transcriptions/TranscriptionInclude.kt
index fb3e65689..2b15a3685 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/audio/transcriptions/TranscriptionInclude.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/audio/transcriptions/TranscriptionInclude.kt
@@ -88,6 +88,32 @@ class TranscriptionInclude @JsonCreator private constructor(private val value: J
fun asString(): String =
_value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") }
+ private var validated: Boolean = false
+
+ fun validate(): TranscriptionInclude = apply {
+ if (validated) {
+ return@apply
+ }
+
+ known()
+ validated = true
+ }
+
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/audio/transcriptions/TranscriptionSegment.kt b/openai-java-core/src/main/kotlin/com/openai/models/audio/transcriptions/TranscriptionSegment.kt
index 6d846bc9b..ffd5f56d7 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/audio/transcriptions/TranscriptionSegment.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/audio/transcriptions/TranscriptionSegment.kt
@@ -16,6 +16,7 @@ import com.openai.core.toImmutable
import com.openai.errors.OpenAIInvalidDataException
import java.util.Collections
import java.util.Objects
+import kotlin.jvm.optionals.getOrNull
class TranscriptionSegment
private constructor(
@@ -506,6 +507,32 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (if (id.asKnown().isPresent) 1 else 0) +
+ (if (avgLogprob.asKnown().isPresent) 1 else 0) +
+ (if (compressionRatio.asKnown().isPresent) 1 else 0) +
+ (if (end.asKnown().isPresent) 1 else 0) +
+ (if (noSpeechProb.asKnown().isPresent) 1 else 0) +
+ (if (seek.asKnown().isPresent) 1 else 0) +
+ (if (start.asKnown().isPresent) 1 else 0) +
+ (if (temperature.asKnown().isPresent) 1 else 0) +
+ (if (text.asKnown().isPresent) 1 else 0) +
+ (tokens.asKnown().getOrNull()?.size ?: 0)
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/audio/transcriptions/TranscriptionStreamEvent.kt b/openai-java-core/src/main/kotlin/com/openai/models/audio/transcriptions/TranscriptionStreamEvent.kt
index 7ce4db533..5082a8439 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/audio/transcriptions/TranscriptionStreamEvent.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/audio/transcriptions/TranscriptionStreamEvent.kt
@@ -75,13 +75,12 @@ private constructor(
fun _json(): Optional = Optional.ofNullable(_json)
- fun accept(visitor: Visitor): T {
- return when {
+ fun accept(visitor: Visitor): T =
+ when {
transcriptTextDelta != null -> visitor.visitTranscriptTextDelta(transcriptTextDelta)
transcriptTextDone != null -> visitor.visitTranscriptTextDone(transcriptTextDone)
else -> visitor.unknown(_json)
}
- }
private var validated: Boolean = false
@@ -108,6 +107,35 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ accept(
+ object : Visitor {
+ override fun visitTranscriptTextDelta(
+ transcriptTextDelta: TranscriptionTextDeltaEvent
+ ) = transcriptTextDelta.validity()
+
+ override fun visitTranscriptTextDone(
+ transcriptTextDone: TranscriptionTextDoneEvent
+ ) = transcriptTextDone.validity()
+
+ override fun unknown(json: JsonValue?) = 0
+ }
+ )
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -197,18 +225,14 @@ private constructor(
when (type) {
"transcript.text.delta" -> {
- return TranscriptionStreamEvent(
- transcriptTextDelta =
- deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())
+ ?.let { TranscriptionStreamEvent(transcriptTextDelta = it, _json = json) }
+ ?: TranscriptionStreamEvent(_json = json)
}
"transcript.text.done" -> {
- return TranscriptionStreamEvent(
- transcriptTextDone =
- deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ TranscriptionStreamEvent(transcriptTextDone = it, _json = json)
+ } ?: TranscriptionStreamEvent(_json = json)
}
}
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/audio/transcriptions/TranscriptionTextDeltaEvent.kt b/openai-java-core/src/main/kotlin/com/openai/models/audio/transcriptions/TranscriptionTextDeltaEvent.kt
index 6ceb607c0..0347259ff 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/audio/transcriptions/TranscriptionTextDeltaEvent.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/audio/transcriptions/TranscriptionTextDeltaEvent.kt
@@ -17,6 +17,7 @@ import com.openai.errors.OpenAIInvalidDataException
import java.util.Collections
import java.util.Objects
import java.util.Optional
+import kotlin.jvm.optionals.getOrNull
/**
* Emitted when there is an additional text delta. This is also the first event emitted when the
@@ -239,6 +240,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (if (delta.asKnown().isPresent) 1 else 0) +
+ type.let { if (it == JsonValue.from("transcript.text.delta")) 1 else 0 } +
+ (logprobs.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0)
+
class Logprob
private constructor(
private val token: JsonField,
@@ -431,6 +451,26 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (if (token.asKnown().isPresent) 1 else 0) +
+ (bytes.asKnown().getOrNull()?.size ?: 0) +
+ (if (logprob.asKnown().isPresent) 1 else 0)
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/audio/transcriptions/TranscriptionTextDoneEvent.kt b/openai-java-core/src/main/kotlin/com/openai/models/audio/transcriptions/TranscriptionTextDoneEvent.kt
index fde69760c..be812ec52 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/audio/transcriptions/TranscriptionTextDoneEvent.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/audio/transcriptions/TranscriptionTextDoneEvent.kt
@@ -17,6 +17,7 @@ import com.openai.errors.OpenAIInvalidDataException
import java.util.Collections
import java.util.Objects
import java.util.Optional
+import kotlin.jvm.optionals.getOrNull
/**
* Emitted when the transcription is complete. Contains the complete transcription text. Only
@@ -239,6 +240,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (if (text.asKnown().isPresent) 1 else 0) +
+ type.let { if (it == JsonValue.from("transcript.text.done")) 1 else 0 } +
+ (logprobs.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0)
+
class Logprob
private constructor(
private val token: JsonField,
@@ -431,6 +451,26 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (if (token.asKnown().isPresent) 1 else 0) +
+ (bytes.asKnown().getOrNull()?.size ?: 0) +
+ (if (logprob.asKnown().isPresent) 1 else 0)
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/audio/transcriptions/TranscriptionVerbose.kt b/openai-java-core/src/main/kotlin/com/openai/models/audio/transcriptions/TranscriptionVerbose.kt
index d5000b2db..80c584207 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/audio/transcriptions/TranscriptionVerbose.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/audio/transcriptions/TranscriptionVerbose.kt
@@ -17,6 +17,7 @@ import com.openai.errors.OpenAIInvalidDataException
import java.util.Collections
import java.util.Objects
import java.util.Optional
+import kotlin.jvm.optionals.getOrNull
/**
* Represents a verbose json transcription response returned by model, based on the provided input.
@@ -311,6 +312,27 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (if (duration.asKnown().isPresent) 1 else 0) +
+ (if (language.asKnown().isPresent) 1 else 0) +
+ (if (text.asKnown().isPresent) 1 else 0) +
+ (segments.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) +
+ (words.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0)
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/audio/transcriptions/TranscriptionWord.kt b/openai-java-core/src/main/kotlin/com/openai/models/audio/transcriptions/TranscriptionWord.kt
index 994383066..e17f25058 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/audio/transcriptions/TranscriptionWord.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/audio/transcriptions/TranscriptionWord.kt
@@ -206,6 +206,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (if (end.asKnown().isPresent) 1 else 0) +
+ (if (start.asKnown().isPresent) 1 else 0) +
+ (if (word.asKnown().isPresent) 1 else 0)
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/audio/translations/Translation.kt b/openai-java-core/src/main/kotlin/com/openai/models/audio/translations/Translation.kt
index 1f620f5f0..9936b6440 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/audio/translations/Translation.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/audio/translations/Translation.kt
@@ -132,6 +132,21 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic internal fun validity(): Int = (if (text.asKnown().isPresent) 1 else 0)
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/audio/translations/TranslationCreateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/audio/translations/TranslationCreateParams.kt
index 70ddd99d7..dc7565f58 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/audio/translations/TranslationCreateParams.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/audio/translations/TranslationCreateParams.kt
@@ -664,13 +664,21 @@ private constructor(
}
file()
- model()
+ model().validate()
prompt()
- responseFormat()
+ responseFormat().ifPresent { it.validate() }
temperature()
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -800,6 +808,33 @@ private constructor(
fun asString(): String =
_value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") }
+ private var validated: Boolean = false
+
+ fun validate(): ResponseFormat = apply {
+ if (validated) {
+ return@apply
+ }
+
+ known()
+ validated = true
+ }
+
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/audio/translations/TranslationCreateResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/audio/translations/TranslationCreateResponse.kt
index f4851777f..16d1bb45f 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/audio/translations/TranslationCreateResponse.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/audio/translations/TranslationCreateResponse.kt
@@ -12,6 +12,7 @@ import com.fasterxml.jackson.module.kotlin.jacksonTypeRef
import com.openai.core.BaseDeserializer
import com.openai.core.BaseSerializer
import com.openai.core.JsonValue
+import com.openai.core.allMaxBy
import com.openai.core.getOrThrow
import com.openai.errors.OpenAIInvalidDataException
import java.util.Objects
@@ -40,13 +41,12 @@ private constructor(
fun _json(): Optional = Optional.ofNullable(_json)
- fun accept(visitor: Visitor): T {
- return when {
+ fun accept(visitor: Visitor): T =
+ when {
translation != null -> visitor.visitTranslation(translation)
verbose != null -> visitor.visitVerbose(verbose)
else -> visitor.unknown(_json)
}
- }
private var validated: Boolean = false
@@ -69,6 +69,31 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ accept(
+ object : Visitor {
+ override fun visitTranslation(translation: Translation) = translation.validity()
+
+ override fun visitVerbose(verbose: TranslationVerbose) = verbose.validity()
+
+ override fun unknown(json: JsonValue?) = 0
+ }
+ )
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -128,16 +153,27 @@ private constructor(
override fun ObjectCodec.deserialize(node: JsonNode): TranslationCreateResponse {
val json = JsonValue.fromJsonNode(node)
- tryDeserialize(node, jacksonTypeRef()) { it.validate() }
- ?.let {
- return TranslationCreateResponse(translation = it, _json = json)
- }
- tryDeserialize(node, jacksonTypeRef()) { it.validate() }
- ?.let {
- return TranslationCreateResponse(verbose = it, _json = json)
- }
-
- return TranslationCreateResponse(_json = json)
+ val bestMatches =
+ sequenceOf(
+ tryDeserialize(node, jacksonTypeRef())?.let {
+ TranslationCreateResponse(translation = it, _json = json)
+ },
+ tryDeserialize(node, jacksonTypeRef())?.let {
+ TranslationCreateResponse(verbose = it, _json = json)
+ },
+ )
+ .filterNotNull()
+ .allMaxBy { it.validity() }
+ .toList()
+ return when (bestMatches.size) {
+ // This can happen if what we're deserializing is completely incompatible with all
+ // the possible variants (e.g. deserializing from boolean).
+ 0 -> TranslationCreateResponse(_json = json)
+ 1 -> bestMatches.single()
+ // If there's more than one match with the highest validity, then use the first
+ // completely valid match, or simply the first match if none are completely valid.
+ else -> bestMatches.firstOrNull { it.isValid() } ?: bestMatches.first()
+ }
}
}
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/audio/translations/TranslationVerbose.kt b/openai-java-core/src/main/kotlin/com/openai/models/audio/translations/TranslationVerbose.kt
index 8163dda1a..d39dec566 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/audio/translations/TranslationVerbose.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/audio/translations/TranslationVerbose.kt
@@ -18,6 +18,7 @@ import com.openai.models.audio.transcriptions.TranscriptionSegment
import java.util.Collections
import java.util.Objects
import java.util.Optional
+import kotlin.jvm.optionals.getOrNull
class TranslationVerbose
private constructor(
@@ -262,6 +263,26 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (if (duration.asKnown().isPresent) 1 else 0) +
+ (if (language.asKnown().isPresent) 1 else 0) +
+ (if (text.asKnown().isPresent) 1 else 0) +
+ (segments.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0)
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/batches/Batch.kt b/openai-java-core/src/main/kotlin/com/openai/models/batches/Batch.kt
index 79fad7cc1..8e52d00dd 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/batches/Batch.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/batches/Batch.kt
@@ -842,7 +842,7 @@ private constructor(
throw OpenAIInvalidDataException("'object_' is invalid, received $it")
}
}
- status()
+ status().validate()
cancelledAt()
cancellingAt()
completedAt()
@@ -859,6 +859,42 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (if (id.asKnown().isPresent) 1 else 0) +
+ (if (completionWindow.asKnown().isPresent) 1 else 0) +
+ (if (createdAt.asKnown().isPresent) 1 else 0) +
+ (if (endpoint.asKnown().isPresent) 1 else 0) +
+ (if (inputFileId.asKnown().isPresent) 1 else 0) +
+ object_.let { if (it == JsonValue.from("batch")) 1 else 0 } +
+ (status.asKnown().getOrNull()?.validity() ?: 0) +
+ (if (cancelledAt.asKnown().isPresent) 1 else 0) +
+ (if (cancellingAt.asKnown().isPresent) 1 else 0) +
+ (if (completedAt.asKnown().isPresent) 1 else 0) +
+ (if (errorFileId.asKnown().isPresent) 1 else 0) +
+ (errors.asKnown().getOrNull()?.validity() ?: 0) +
+ (if (expiredAt.asKnown().isPresent) 1 else 0) +
+ (if (expiresAt.asKnown().isPresent) 1 else 0) +
+ (if (failedAt.asKnown().isPresent) 1 else 0) +
+ (if (finalizingAt.asKnown().isPresent) 1 else 0) +
+ (if (inProgressAt.asKnown().isPresent) 1 else 0) +
+ (metadata.asKnown().getOrNull()?.validity() ?: 0) +
+ (if (outputFileId.asKnown().isPresent) 1 else 0) +
+ (requestCounts.asKnown().getOrNull()?.validity() ?: 0)
+
/** The current status of the batch. */
class Status @JsonCreator private constructor(private val value: JsonField) : Enum {
@@ -981,6 +1017,33 @@ private constructor(
fun asString(): String =
_value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") }
+ private var validated: Boolean = false
+
+ fun validate(): Status = apply {
+ if (validated) {
+ return@apply
+ }
+
+ known()
+ validated = true
+ }
+
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -1150,6 +1213,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) +
+ (if (object_.asKnown().isPresent) 1 else 0)
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -1242,6 +1324,24 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/batches/BatchCreateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/batches/BatchCreateParams.kt
index abf1570ff..f03e6ec70 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/batches/BatchCreateParams.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/batches/BatchCreateParams.kt
@@ -652,13 +652,34 @@ private constructor(
return@apply
}
- completionWindow()
- endpoint()
+ completionWindow().validate()
+ endpoint().validate()
inputFileId()
metadata().ifPresent { it.validate() }
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (completionWindow.asKnown().getOrNull()?.validity() ?: 0) +
+ (endpoint.asKnown().getOrNull()?.validity() ?: 0) +
+ (if (inputFileId.asKnown().isPresent) 1 else 0) +
+ (metadata.asKnown().getOrNull()?.validity() ?: 0)
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -763,6 +784,33 @@ private constructor(
fun asString(): String =
_value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") }
+ private var validated: Boolean = false
+
+ fun validate(): CompletionWindow = apply {
+ if (validated) {
+ return@apply
+ }
+
+ known()
+ validated = true
+ }
+
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -879,6 +927,33 @@ private constructor(
fun asString(): String =
_value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") }
+ private var validated: Boolean = false
+
+ fun validate(): Endpoint = apply {
+ if (validated) {
+ return@apply
+ }
+
+ known()
+ validated = true
+ }
+
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -966,6 +1041,24 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/batches/BatchError.kt b/openai-java-core/src/main/kotlin/com/openai/models/batches/BatchError.kt
index bb39a74b4..ce543992a 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/batches/BatchError.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/batches/BatchError.kt
@@ -228,6 +228,26 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (if (code.asKnown().isPresent) 1 else 0) +
+ (if (line.asKnown().isPresent) 1 else 0) +
+ (if (message.asKnown().isPresent) 1 else 0) +
+ (if (param.asKnown().isPresent) 1 else 0)
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/batches/BatchListPage.kt b/openai-java-core/src/main/kotlin/com/openai/models/batches/BatchListPage.kt
index ed757ab48..3a82bac4d 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/batches/BatchListPage.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/batches/BatchListPage.kt
@@ -10,6 +10,7 @@ import com.openai.core.ExcludeMissing
import com.openai.core.JsonField
import com.openai.core.JsonMissing
import com.openai.core.JsonValue
+import com.openai.errors.OpenAIInvalidDataException
import com.openai.services.blocking.BatchService
import java.util.Collections
import java.util.Objects
@@ -114,6 +115,14 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
fun toBuilder() = Builder().from(this)
override fun equals(other: Any?): Boolean {
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/batches/BatchListPageAsync.kt b/openai-java-core/src/main/kotlin/com/openai/models/batches/BatchListPageAsync.kt
index d4f6fcc2f..e521f3e3e 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/batches/BatchListPageAsync.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/batches/BatchListPageAsync.kt
@@ -10,6 +10,7 @@ import com.openai.core.ExcludeMissing
import com.openai.core.JsonField
import com.openai.core.JsonMissing
import com.openai.core.JsonValue
+import com.openai.errors.OpenAIInvalidDataException
import com.openai.services.async.BatchServiceAsync
import java.util.Collections
import java.util.Objects
@@ -116,6 +117,14 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
fun toBuilder() = Builder().from(this)
override fun equals(other: Any?): Boolean {
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/batches/BatchRequestCounts.kt b/openai-java-core/src/main/kotlin/com/openai/models/batches/BatchRequestCounts.kt
index 1bfafacc3..87d8cafec 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/batches/BatchRequestCounts.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/batches/BatchRequestCounts.kt
@@ -207,6 +207,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (if (completed.asKnown().isPresent) 1 else 0) +
+ (if (failed.asKnown().isPresent) 1 else 0) +
+ (if (total.asKnown().isPresent) 1 else 0)
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/Assistant.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/Assistant.kt
index d6ef22949..48e15613b 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/Assistant.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/Assistant.kt
@@ -789,6 +789,35 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (if (id.asKnown().isPresent) 1 else 0) +
+ (if (createdAt.asKnown().isPresent) 1 else 0) +
+ (if (description.asKnown().isPresent) 1 else 0) +
+ (if (instructions.asKnown().isPresent) 1 else 0) +
+ (metadata.asKnown().getOrNull()?.validity() ?: 0) +
+ (if (model.asKnown().isPresent) 1 else 0) +
+ (if (name.asKnown().isPresent) 1 else 0) +
+ object_.let { if (it == JsonValue.from("assistant")) 1 else 0 } +
+ (tools.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) +
+ (responseFormat.asKnown().getOrNull()?.validity() ?: 0) +
+ (if (temperature.asKnown().isPresent) 1 else 0) +
+ (toolResources.asKnown().getOrNull()?.validity() ?: 0) +
+ (if (topP.asKnown().isPresent) 1 else 0)
+
/**
* Set of 16 key-value pairs that can be attached to an object. This can be useful for storing
* additional information about the object in a structured format, and querying for objects via
@@ -863,6 +892,24 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -1034,6 +1081,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (codeInterpreter.asKnown().getOrNull()?.validity() ?: 0) +
+ (fileSearch.asKnown().getOrNull()?.validity() ?: 0)
+
class CodeInterpreter
private constructor(
private val fileIds: JsonField>,
@@ -1172,6 +1238,22 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic internal fun validity(): Int = (fileIds.asKnown().getOrNull()?.size ?: 0)
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -1332,6 +1414,23 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int = (vectorStoreIds.asKnown().getOrNull()?.size ?: 0)
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantCreateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantCreateParams.kt
index 4d7cda26e..dc3ecf128 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantCreateParams.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantCreateParams.kt
@@ -1466,12 +1466,12 @@ private constructor(
return@apply
}
- model()
+ model().validate()
description()
instructions()
metadata().ifPresent { it.validate() }
name()
- reasoningEffort()
+ reasoningEffort().ifPresent { it.validate() }
responseFormat().ifPresent { it.validate() }
temperature()
toolResources().ifPresent { it.validate() }
@@ -1480,6 +1480,34 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (model.asKnown().getOrNull()?.validity() ?: 0) +
+ (if (description.asKnown().isPresent) 1 else 0) +
+ (if (instructions.asKnown().isPresent) 1 else 0) +
+ (metadata.asKnown().getOrNull()?.validity() ?: 0) +
+ (if (name.asKnown().isPresent) 1 else 0) +
+ (reasoningEffort.asKnown().getOrNull()?.validity() ?: 0) +
+ (responseFormat.asKnown().getOrNull()?.validity() ?: 0) +
+ (if (temperature.asKnown().isPresent) 1 else 0) +
+ (toolResources.asKnown().getOrNull()?.validity() ?: 0) +
+ (tools.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) +
+ (if (topP.asKnown().isPresent) 1 else 0)
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -1572,6 +1600,24 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -1743,6 +1789,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (codeInterpreter.asKnown().getOrNull()?.validity() ?: 0) +
+ (fileSearch.asKnown().getOrNull()?.validity() ?: 0)
+
class CodeInterpreter
private constructor(
private val fileIds: JsonField>,
@@ -1881,6 +1946,22 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic internal fun validity(): Int = (fileIds.asKnown().getOrNull()?.size ?: 0)
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -2103,6 +2184,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (vectorStoreIds.asKnown().getOrNull()?.size ?: 0) +
+ (vectorStores.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0)
+
class VectorStore
private constructor(
private val chunkingStrategy: JsonField,
@@ -2364,6 +2464,26 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (chunkingStrategy.asKnown().getOrNull()?.validity() ?: 0) +
+ (fileIds.asKnown().getOrNull()?.size ?: 0) +
+ (metadata.asKnown().getOrNull()?.validity() ?: 0)
+
/**
* The chunking strategy used to chunk the file(s). If not set, will use the `auto`
* strategy.
@@ -2399,13 +2519,12 @@ private constructor(
fun _json(): Optional = Optional.ofNullable(_json)
- fun accept(visitor: Visitor): T {
- return when {
+ fun accept(visitor: Visitor): T =
+ when {
auto != null -> visitor.visitAuto(auto)
static_ != null -> visitor.visitStatic(static_)
else -> visitor.unknown(_json)
}
- }
private var validated: Boolean = false
@@ -2434,6 +2553,35 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ accept(
+ object : Visitor {
+ override fun visitAuto(auto: JsonValue) =
+ auto.let {
+ if (it == JsonValue.from(mapOf("type" to "auto"))) 1 else 0
+ }
+
+ override fun visitStatic(static_: StaticObject) = static_.validity()
+
+ override fun unknown(json: JsonValue?) = 0
+ }
+ )
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -2505,16 +2653,14 @@ private constructor(
when (type) {
"auto" -> {
- return ChunkingStrategy(
- auto = deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())
+ ?.let { ChunkingStrategy(auto = it, _json = json) }
+ ?.takeIf { it.isValid() } ?: ChunkingStrategy(_json = json)
}
"static" -> {
- return ChunkingStrategy(
- static_ = deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())
+ ?.let { ChunkingStrategy(static_ = it, _json = json) }
+ ?: ChunkingStrategy(_json = json)
}
}
@@ -2714,6 +2860,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this
+ * object recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (static_.asKnown().getOrNull()?.validity() ?: 0) +
+ type.let { if (it == JsonValue.from("static")) 1 else 0 }
+
class Static
private constructor(
private val chunkOverlapTokens: JsonField,
@@ -2918,6 +3083,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in
+ * this object recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (if (chunkOverlapTokens.asKnown().isPresent) 1 else 0) +
+ (if (maxChunkSizeTokens.asKnown().isPresent) 1 else 0)
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -3033,6 +3217,26 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ additionalProperties.count { (_, value) ->
+ !value.isNull() && !value.isMissing()
+ }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantDeleted.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantDeleted.kt
index 6f2905dc9..807cc7887 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantDeleted.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantDeleted.kt
@@ -201,6 +201,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (if (id.asKnown().isPresent) 1 else 0) +
+ (if (deleted.asKnown().isPresent) 1 else 0) +
+ object_.let { if (it == JsonValue.from("assistant.deleted")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantListPage.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantListPage.kt
index c9e39876b..696f3b0f6 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantListPage.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantListPage.kt
@@ -10,6 +10,7 @@ import com.openai.core.ExcludeMissing
import com.openai.core.JsonField
import com.openai.core.JsonMissing
import com.openai.core.JsonValue
+import com.openai.errors.OpenAIInvalidDataException
import com.openai.services.blocking.beta.AssistantService
import java.util.Collections
import java.util.Objects
@@ -117,6 +118,14 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
fun toBuilder() = Builder().from(this)
override fun equals(other: Any?): Boolean {
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantListPageAsync.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantListPageAsync.kt
index e512c3b35..c784c1c29 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantListPageAsync.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantListPageAsync.kt
@@ -10,6 +10,7 @@ import com.openai.core.ExcludeMissing
import com.openai.core.JsonField
import com.openai.core.JsonMissing
import com.openai.core.JsonValue
+import com.openai.errors.OpenAIInvalidDataException
import com.openai.services.async.beta.AssistantServiceAsync
import java.util.Collections
import java.util.Objects
@@ -119,6 +120,14 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
fun toBuilder() = Builder().from(this)
override fun equals(other: Any?): Boolean {
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantListParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantListParams.kt
index 18612f48d..f7a3dde2a 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantListParams.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantListParams.kt
@@ -347,6 +347,33 @@ private constructor(
fun asString(): String =
_value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") }
+ private var validated: Boolean = false
+
+ fun validate(): Order = apply {
+ if (validated) {
+ return@apply
+ }
+
+ known()
+ validated = true
+ }
+
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantStreamEvent.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantStreamEvent.kt
index 5870d4c49..915f0eea8 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantStreamEvent.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantStreamEvent.kt
@@ -447,8 +447,8 @@ private constructor(
fun _json(): Optional = Optional.ofNullable(_json)
- fun accept(visitor: Visitor): T {
- return when {
+ fun accept(visitor: Visitor): T =
+ when {
threadCreated != null -> visitor.visitThreadCreated(threadCreated)
threadRunCreated != null -> visitor.visitThreadRunCreated(threadRunCreated)
threadRunQueued != null -> visitor.visitThreadRunQueued(threadRunQueued)
@@ -482,7 +482,6 @@ private constructor(
errorEvent != null -> visitor.visitErrorEvent(errorEvent)
else -> visitor.unknown(_json)
}
- }
private var validated: Boolean = false
@@ -607,6 +606,105 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ accept(
+ object : Visitor {
+ override fun visitThreadCreated(threadCreated: ThreadCreated) =
+ threadCreated.validity()
+
+ override fun visitThreadRunCreated(threadRunCreated: ThreadRunCreated) =
+ threadRunCreated.validity()
+
+ override fun visitThreadRunQueued(threadRunQueued: ThreadRunQueued) =
+ threadRunQueued.validity()
+
+ override fun visitThreadRunInProgress(threadRunInProgress: ThreadRunInProgress) =
+ threadRunInProgress.validity()
+
+ override fun visitThreadRunRequiresAction(
+ threadRunRequiresAction: ThreadRunRequiresAction
+ ) = threadRunRequiresAction.validity()
+
+ override fun visitThreadRunCompleted(threadRunCompleted: ThreadRunCompleted) =
+ threadRunCompleted.validity()
+
+ override fun visitThreadRunIncomplete(threadRunIncomplete: ThreadRunIncomplete) =
+ threadRunIncomplete.validity()
+
+ override fun visitThreadRunFailed(threadRunFailed: ThreadRunFailed) =
+ threadRunFailed.validity()
+
+ override fun visitThreadRunCancelling(threadRunCancelling: ThreadRunCancelling) =
+ threadRunCancelling.validity()
+
+ override fun visitThreadRunCancelled(threadRunCancelled: ThreadRunCancelled) =
+ threadRunCancelled.validity()
+
+ override fun visitThreadRunExpired(threadRunExpired: ThreadRunExpired) =
+ threadRunExpired.validity()
+
+ override fun visitThreadRunStepCreated(threadRunStepCreated: ThreadRunStepCreated) =
+ threadRunStepCreated.validity()
+
+ override fun visitThreadRunStepInProgress(
+ threadRunStepInProgress: ThreadRunStepInProgress
+ ) = threadRunStepInProgress.validity()
+
+ override fun visitThreadRunStepDelta(threadRunStepDelta: ThreadRunStepDelta) =
+ threadRunStepDelta.validity()
+
+ override fun visitThreadRunStepCompleted(
+ threadRunStepCompleted: ThreadRunStepCompleted
+ ) = threadRunStepCompleted.validity()
+
+ override fun visitThreadRunStepFailed(threadRunStepFailed: ThreadRunStepFailed) =
+ threadRunStepFailed.validity()
+
+ override fun visitThreadRunStepCancelled(
+ threadRunStepCancelled: ThreadRunStepCancelled
+ ) = threadRunStepCancelled.validity()
+
+ override fun visitThreadRunStepExpired(threadRunStepExpired: ThreadRunStepExpired) =
+ threadRunStepExpired.validity()
+
+ override fun visitThreadMessageCreated(threadMessageCreated: ThreadMessageCreated) =
+ threadMessageCreated.validity()
+
+ override fun visitThreadMessageInProgress(
+ threadMessageInProgress: ThreadMessageInProgress
+ ) = threadMessageInProgress.validity()
+
+ override fun visitThreadMessageDelta(threadMessageDelta: ThreadMessageDelta) =
+ threadMessageDelta.validity()
+
+ override fun visitThreadMessageCompleted(
+ threadMessageCompleted: ThreadMessageCompleted
+ ) = threadMessageCompleted.validity()
+
+ override fun visitThreadMessageIncomplete(
+ threadMessageIncomplete: ThreadMessageIncomplete
+ ) = threadMessageIncomplete.validity()
+
+ override fun visitErrorEvent(errorEvent: ErrorEvent) = errorEvent.validity()
+
+ override fun unknown(json: JsonValue?) = 0
+ }
+ )
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -1041,166 +1139,124 @@ private constructor(
when (event) {
"thread.created" -> {
- return AssistantStreamEvent(
- threadCreated = deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ AssistantStreamEvent(threadCreated = it, _json = json)
+ } ?: AssistantStreamEvent(_json = json)
}
"thread.run.created" -> {
- return AssistantStreamEvent(
- threadRunCreated = deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ AssistantStreamEvent(threadRunCreated = it, _json = json)
+ } ?: AssistantStreamEvent(_json = json)
}
"thread.run.queued" -> {
- return AssistantStreamEvent(
- threadRunQueued = deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ AssistantStreamEvent(threadRunQueued = it, _json = json)
+ } ?: AssistantStreamEvent(_json = json)
}
"thread.run.in_progress" -> {
- return AssistantStreamEvent(
- threadRunInProgress =
- deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ AssistantStreamEvent(threadRunInProgress = it, _json = json)
+ } ?: AssistantStreamEvent(_json = json)
}
"thread.run.requires_action" -> {
- return AssistantStreamEvent(
- threadRunRequiresAction =
- deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ AssistantStreamEvent(threadRunRequiresAction = it, _json = json)
+ } ?: AssistantStreamEvent(_json = json)
}
"thread.run.completed" -> {
- return AssistantStreamEvent(
- threadRunCompleted =
- deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ AssistantStreamEvent(threadRunCompleted = it, _json = json)
+ } ?: AssistantStreamEvent(_json = json)
}
"thread.run.incomplete" -> {
- return AssistantStreamEvent(
- threadRunIncomplete =
- deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ AssistantStreamEvent(threadRunIncomplete = it, _json = json)
+ } ?: AssistantStreamEvent(_json = json)
}
"thread.run.failed" -> {
- return AssistantStreamEvent(
- threadRunFailed = deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ AssistantStreamEvent(threadRunFailed = it, _json = json)
+ } ?: AssistantStreamEvent(_json = json)
}
"thread.run.cancelling" -> {
- return AssistantStreamEvent(
- threadRunCancelling =
- deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ AssistantStreamEvent(threadRunCancelling = it, _json = json)
+ } ?: AssistantStreamEvent(_json = json)
}
"thread.run.cancelled" -> {
- return AssistantStreamEvent(
- threadRunCancelled =
- deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ AssistantStreamEvent(threadRunCancelled = it, _json = json)
+ } ?: AssistantStreamEvent(_json = json)
}
"thread.run.expired" -> {
- return AssistantStreamEvent(
- threadRunExpired = deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ AssistantStreamEvent(threadRunExpired = it, _json = json)
+ } ?: AssistantStreamEvent(_json = json)
}
"thread.run.step.created" -> {
- return AssistantStreamEvent(
- threadRunStepCreated =
- deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ AssistantStreamEvent(threadRunStepCreated = it, _json = json)
+ } ?: AssistantStreamEvent(_json = json)
}
"thread.run.step.in_progress" -> {
- return AssistantStreamEvent(
- threadRunStepInProgress =
- deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ AssistantStreamEvent(threadRunStepInProgress = it, _json = json)
+ } ?: AssistantStreamEvent(_json = json)
}
"thread.run.step.delta" -> {
- return AssistantStreamEvent(
- threadRunStepDelta =
- deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ AssistantStreamEvent(threadRunStepDelta = it, _json = json)
+ } ?: AssistantStreamEvent(_json = json)
}
"thread.run.step.completed" -> {
- return AssistantStreamEvent(
- threadRunStepCompleted =
- deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ AssistantStreamEvent(threadRunStepCompleted = it, _json = json)
+ } ?: AssistantStreamEvent(_json = json)
}
"thread.run.step.failed" -> {
- return AssistantStreamEvent(
- threadRunStepFailed =
- deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ AssistantStreamEvent(threadRunStepFailed = it, _json = json)
+ } ?: AssistantStreamEvent(_json = json)
}
"thread.run.step.cancelled" -> {
- return AssistantStreamEvent(
- threadRunStepCancelled =
- deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ AssistantStreamEvent(threadRunStepCancelled = it, _json = json)
+ } ?: AssistantStreamEvent(_json = json)
}
"thread.run.step.expired" -> {
- return AssistantStreamEvent(
- threadRunStepExpired =
- deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ AssistantStreamEvent(threadRunStepExpired = it, _json = json)
+ } ?: AssistantStreamEvent(_json = json)
}
"thread.message.created" -> {
- return AssistantStreamEvent(
- threadMessageCreated =
- deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ AssistantStreamEvent(threadMessageCreated = it, _json = json)
+ } ?: AssistantStreamEvent(_json = json)
}
"thread.message.in_progress" -> {
- return AssistantStreamEvent(
- threadMessageInProgress =
- deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ AssistantStreamEvent(threadMessageInProgress = it, _json = json)
+ } ?: AssistantStreamEvent(_json = json)
}
"thread.message.delta" -> {
- return AssistantStreamEvent(
- threadMessageDelta =
- deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ AssistantStreamEvent(threadMessageDelta = it, _json = json)
+ } ?: AssistantStreamEvent(_json = json)
}
"thread.message.completed" -> {
- return AssistantStreamEvent(
- threadMessageCompleted =
- deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ AssistantStreamEvent(threadMessageCompleted = it, _json = json)
+ } ?: AssistantStreamEvent(_json = json)
}
"thread.message.incomplete" -> {
- return AssistantStreamEvent(
- threadMessageIncomplete =
- deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ AssistantStreamEvent(threadMessageIncomplete = it, _json = json)
+ } ?: AssistantStreamEvent(_json = json)
}
"error" -> {
- return AssistantStreamEvent(
- errorEvent = deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ AssistantStreamEvent(errorEvent = it, _json = json)
+ } ?: AssistantStreamEvent(_json = json)
}
}
@@ -1460,6 +1516,26 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("thread.created")) 1 else 0 } +
+ (if (enabled.asKnown().isPresent) 1 else 0)
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -1645,6 +1721,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("thread.run.created")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -1830,6 +1925,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("thread.run.queued")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -2015,6 +2129,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("thread.run.in_progress")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -2200,6 +2333,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("thread.run.requires_action")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -2384,6 +2536,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("thread.run.completed")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -2569,6 +2740,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("thread.run.incomplete")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -2751,6 +2941,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("thread.run.failed")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -2936,6 +3145,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("thread.run.cancelling")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -3120,6 +3348,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("thread.run.cancelled")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -3302,6 +3549,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("thread.run.expired")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -3483,6 +3749,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("thread.run.step.created")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -3665,6 +3950,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("thread.run.step.in_progress")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -3851,6 +4155,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("thread.run.step.delta")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -4033,6 +4356,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("thread.run.step.completed")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -4214,6 +4556,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("thread.run.step.failed")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -4396,6 +4757,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("thread.run.step.cancelled")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -4577,6 +4957,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("thread.run.step.expired")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -4762,6 +5161,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("thread.message.created")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -4947,6 +5365,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("thread.message.in_progress")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -5130,6 +5567,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("thread.message.delta")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -5315,6 +5771,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("thread.message.completed")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -5500,6 +5975,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("thread.message.incomplete")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -5674,6 +6168,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("error")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantTool.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantTool.kt
index 0acd60b84..1d2261a75 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantTool.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantTool.kt
@@ -48,14 +48,13 @@ private constructor(
fun _json(): Optional = Optional.ofNullable(_json)
- fun accept(visitor: Visitor): T {
- return when {
+ fun accept(visitor: Visitor): T =
+ when {
codeInterpreter != null -> visitor.visitCodeInterpreter(codeInterpreter)
fileSearch != null -> visitor.visitFileSearch(fileSearch)
function != null -> visitor.visitFunction(function)
else -> visitor.unknown(_json)
}
- }
private var validated: Boolean = false
@@ -82,6 +81,34 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ accept(
+ object : Visitor {
+ override fun visitCodeInterpreter(codeInterpreter: CodeInterpreterTool) =
+ codeInterpreter.validity()
+
+ override fun visitFileSearch(fileSearch: FileSearchTool) = fileSearch.validity()
+
+ override fun visitFunction(function: FunctionTool) = function.validity()
+
+ override fun unknown(json: JsonValue?) = 0
+ }
+ )
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -146,22 +173,19 @@ private constructor(
when (type) {
"code_interpreter" -> {
- return AssistantTool(
- codeInterpreter = deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ AssistantTool(codeInterpreter = it, _json = json)
+ } ?: AssistantTool(_json = json)
}
"file_search" -> {
- return AssistantTool(
- fileSearch = deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ AssistantTool(fileSearch = it, _json = json)
+ } ?: AssistantTool(_json = json)
}
"function" -> {
- return AssistantTool(
- function = deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ AssistantTool(function = it, _json = json)
+ } ?: AssistantTool(_json = json)
}
}
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantUpdateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantUpdateParams.kt
index 2d3bfcbec..556269003 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantUpdateParams.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantUpdateParams.kt
@@ -1461,7 +1461,7 @@ private constructor(
metadata().ifPresent { it.validate() }
model()
name()
- reasoningEffort()
+ reasoningEffort().ifPresent { it.validate() }
responseFormat().ifPresent { it.validate() }
temperature()
toolResources().ifPresent { it.validate() }
@@ -1470,6 +1470,34 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (if (description.asKnown().isPresent) 1 else 0) +
+ (if (instructions.asKnown().isPresent) 1 else 0) +
+ (metadata.asKnown().getOrNull()?.validity() ?: 0) +
+ (if (model.asKnown().isPresent) 1 else 0) +
+ (if (name.asKnown().isPresent) 1 else 0) +
+ (reasoningEffort.asKnown().getOrNull()?.validity() ?: 0) +
+ (responseFormat.asKnown().getOrNull()?.validity() ?: 0) +
+ (if (temperature.asKnown().isPresent) 1 else 0) +
+ (toolResources.asKnown().getOrNull()?.validity() ?: 0) +
+ (tools.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) +
+ (if (topP.asKnown().isPresent) 1 else 0)
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -1562,6 +1590,24 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -1838,6 +1884,33 @@ private constructor(
fun asString(): String =
_value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") }
+ private var validated: Boolean = false
+
+ fun validate(): Model = apply {
+ if (validated) {
+ return@apply
+ }
+
+ known()
+ validated = true
+ }
+
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -2005,6 +2078,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (codeInterpreter.asKnown().getOrNull()?.validity() ?: 0) +
+ (fileSearch.asKnown().getOrNull()?.validity() ?: 0)
+
class CodeInterpreter
private constructor(
private val fileIds: JsonField>,
@@ -2144,6 +2236,22 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic internal fun validity(): Int = (fileIds.asKnown().getOrNull()?.size ?: 0)
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -2304,6 +2412,23 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int = (vectorStoreIds.asKnown().getOrNull()?.size ?: 0)
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/CodeInterpreterTool.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/CodeInterpreterTool.kt
index a0f04b7a2..e79c0d336 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/CodeInterpreterTool.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/CodeInterpreterTool.kt
@@ -124,6 +124,23 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ type.let { if (it == JsonValue.from("code_interpreter")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/FileSearchTool.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/FileSearchTool.kt
index 6a3fabcbd..0aca3ceca 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/FileSearchTool.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/FileSearchTool.kt
@@ -16,6 +16,7 @@ import com.openai.errors.OpenAIInvalidDataException
import java.util.Collections
import java.util.Objects
import java.util.Optional
+import kotlin.jvm.optionals.getOrNull
class FileSearchTool
private constructor(
@@ -165,6 +166,24 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ type.let { if (it == JsonValue.from("file_search")) 1 else 0 } +
+ (fileSearch.asKnown().getOrNull()?.validity() ?: 0)
+
/** Overrides for the file search tool. */
class FileSearch
private constructor(
@@ -349,6 +368,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (if (maxNumResults.asKnown().isPresent) 1 else 0) +
+ (rankingOptions.asKnown().getOrNull()?.validity() ?: 0)
+
/**
* The ranking options for the file search. If not specified, the file search tool will use
* the `auto` ranker and a score_threshold of 0.
@@ -529,10 +567,29 @@ private constructor(
}
scoreThreshold()
- ranker()
+ ranker().ifPresent { it.validate() }
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (if (scoreThreshold.asKnown().isPresent) 1 else 0) +
+ (ranker.asKnown().getOrNull()?.validity() ?: 0)
+
/**
* The ranker to use for the file search. If not specified will use the `auto` ranker.
*/
@@ -627,6 +684,33 @@ private constructor(
OpenAIInvalidDataException("Value is not a String")
}
+ private var validated: Boolean = false
+
+ fun validate(): Ranker = apply {
+ if (validated) {
+ return@apply
+ }
+
+ known()
+ validated = true
+ }
+
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/FunctionTool.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/FunctionTool.kt
index c5f987185..91f91bad3 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/FunctionTool.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/FunctionTool.kt
@@ -15,6 +15,7 @@ import com.openai.errors.OpenAIInvalidDataException
import com.openai.models.FunctionDefinition
import java.util.Collections
import java.util.Objects
+import kotlin.jvm.optionals.getOrNull
class FunctionTool
private constructor(
@@ -178,6 +179,24 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (function.asKnown().getOrNull()?.validity() ?: 0) +
+ type.let { if (it == JsonValue.from("function")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/MessageStreamEvent.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/MessageStreamEvent.kt
index 50d3e5127..aba8270e6 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/MessageStreamEvent.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/MessageStreamEvent.kt
@@ -126,8 +126,8 @@ private constructor(
fun _json(): Optional = Optional.ofNullable(_json)
- fun accept(visitor: Visitor): T {
- return when {
+ fun accept(visitor: Visitor): T =
+ when {
threadMessageCreated != null -> visitor.visitThreadMessageCreated(threadMessageCreated)
threadMessageInProgress != null ->
visitor.visitThreadMessageInProgress(threadMessageInProgress)
@@ -138,7 +138,6 @@ private constructor(
visitor.visitThreadMessageIncomplete(threadMessageIncomplete)
else -> visitor.unknown(_json)
}
- }
private var validated: Boolean = false
@@ -179,6 +178,45 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ accept(
+ object : Visitor {
+ override fun visitThreadMessageCreated(threadMessageCreated: ThreadMessageCreated) =
+ threadMessageCreated.validity()
+
+ override fun visitThreadMessageInProgress(
+ threadMessageInProgress: ThreadMessageInProgress
+ ) = threadMessageInProgress.validity()
+
+ override fun visitThreadMessageDelta(threadMessageDelta: ThreadMessageDelta) =
+ threadMessageDelta.validity()
+
+ override fun visitThreadMessageCompleted(
+ threadMessageCompleted: ThreadMessageCompleted
+ ) = threadMessageCompleted.validity()
+
+ override fun visitThreadMessageIncomplete(
+ threadMessageIncomplete: ThreadMessageIncomplete
+ ) = threadMessageIncomplete.validity()
+
+ override fun unknown(json: JsonValue?) = 0
+ }
+ )
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -309,39 +347,29 @@ private constructor(
when (event) {
"thread.message.created" -> {
- return MessageStreamEvent(
- threadMessageCreated =
- deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ MessageStreamEvent(threadMessageCreated = it, _json = json)
+ } ?: MessageStreamEvent(_json = json)
}
"thread.message.in_progress" -> {
- return MessageStreamEvent(
- threadMessageInProgress =
- deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ MessageStreamEvent(threadMessageInProgress = it, _json = json)
+ } ?: MessageStreamEvent(_json = json)
}
"thread.message.delta" -> {
- return MessageStreamEvent(
- threadMessageDelta =
- deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ MessageStreamEvent(threadMessageDelta = it, _json = json)
+ } ?: MessageStreamEvent(_json = json)
}
"thread.message.completed" -> {
- return MessageStreamEvent(
- threadMessageCompleted =
- deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ MessageStreamEvent(threadMessageCompleted = it, _json = json)
+ } ?: MessageStreamEvent(_json = json)
}
"thread.message.incomplete" -> {
- return MessageStreamEvent(
- threadMessageIncomplete =
- deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ MessageStreamEvent(threadMessageIncomplete = it, _json = json)
+ } ?: MessageStreamEvent(_json = json)
}
}
@@ -539,6 +567,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("thread.message.created")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -724,6 +771,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("thread.message.in_progress")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -907,6 +973,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("thread.message.delta")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -1092,6 +1177,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("thread.message.completed")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -1277,6 +1381,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("thread.message.incomplete")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/RunStepStreamEvent.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/RunStepStreamEvent.kt
index c1d5a3fe8..18befa6a7 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/RunStepStreamEvent.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/RunStepStreamEvent.kt
@@ -168,8 +168,8 @@ private constructor(
fun _json(): Optional = Optional.ofNullable(_json)
- fun accept(visitor: Visitor): T {
- return when {
+ fun accept(visitor: Visitor): T =
+ when {
threadRunStepCreated != null -> visitor.visitThreadRunStepCreated(threadRunStepCreated)
threadRunStepInProgress != null ->
visitor.visitThreadRunStepInProgress(threadRunStepInProgress)
@@ -182,7 +182,6 @@ private constructor(
threadRunStepExpired != null -> visitor.visitThreadRunStepExpired(threadRunStepExpired)
else -> visitor.unknown(_json)
}
- }
private var validated: Boolean = false
@@ -231,6 +230,51 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ accept(
+ object : Visitor {
+ override fun visitThreadRunStepCreated(threadRunStepCreated: ThreadRunStepCreated) =
+ threadRunStepCreated.validity()
+
+ override fun visitThreadRunStepInProgress(
+ threadRunStepInProgress: ThreadRunStepInProgress
+ ) = threadRunStepInProgress.validity()
+
+ override fun visitThreadRunStepDelta(threadRunStepDelta: ThreadRunStepDelta) =
+ threadRunStepDelta.validity()
+
+ override fun visitThreadRunStepCompleted(
+ threadRunStepCompleted: ThreadRunStepCompleted
+ ) = threadRunStepCompleted.validity()
+
+ override fun visitThreadRunStepFailed(threadRunStepFailed: ThreadRunStepFailed) =
+ threadRunStepFailed.validity()
+
+ override fun visitThreadRunStepCancelled(
+ threadRunStepCancelled: ThreadRunStepCancelled
+ ) = threadRunStepCancelled.validity()
+
+ override fun visitThreadRunStepExpired(threadRunStepExpired: ThreadRunStepExpired) =
+ threadRunStepExpired.validity()
+
+ override fun unknown(json: JsonValue?) = 0
+ }
+ )
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -401,53 +445,39 @@ private constructor(
when (event) {
"thread.run.step.created" -> {
- return RunStepStreamEvent(
- threadRunStepCreated =
- deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ RunStepStreamEvent(threadRunStepCreated = it, _json = json)
+ } ?: RunStepStreamEvent(_json = json)
}
"thread.run.step.in_progress" -> {
- return RunStepStreamEvent(
- threadRunStepInProgress =
- deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ RunStepStreamEvent(threadRunStepInProgress = it, _json = json)
+ } ?: RunStepStreamEvent(_json = json)
}
"thread.run.step.delta" -> {
- return RunStepStreamEvent(
- threadRunStepDelta =
- deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ RunStepStreamEvent(threadRunStepDelta = it, _json = json)
+ } ?: RunStepStreamEvent(_json = json)
}
"thread.run.step.completed" -> {
- return RunStepStreamEvent(
- threadRunStepCompleted =
- deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ RunStepStreamEvent(threadRunStepCompleted = it, _json = json)
+ } ?: RunStepStreamEvent(_json = json)
}
"thread.run.step.failed" -> {
- return RunStepStreamEvent(
- threadRunStepFailed =
- deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ RunStepStreamEvent(threadRunStepFailed = it, _json = json)
+ } ?: RunStepStreamEvent(_json = json)
}
"thread.run.step.cancelled" -> {
- return RunStepStreamEvent(
- threadRunStepCancelled =
- deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ RunStepStreamEvent(threadRunStepCancelled = it, _json = json)
+ } ?: RunStepStreamEvent(_json = json)
}
"thread.run.step.expired" -> {
- return RunStepStreamEvent(
- threadRunStepExpired =
- deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ RunStepStreamEvent(threadRunStepExpired = it, _json = json)
+ } ?: RunStepStreamEvent(_json = json)
}
}
@@ -645,6 +675,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("thread.run.step.created")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -827,6 +876,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("thread.run.step.in_progress")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -1013,6 +1081,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("thread.run.step.delta")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -1195,6 +1282,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("thread.run.step.completed")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -1376,6 +1482,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("thread.run.step.failed")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -1558,6 +1683,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("thread.run.step.cancelled")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -1739,6 +1883,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("thread.run.step.expired")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/RunStreamEvent.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/RunStreamEvent.kt
index 67ae03da6..51f862b81 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/RunStreamEvent.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/RunStreamEvent.kt
@@ -184,8 +184,8 @@ private constructor(
fun _json(): Optional = Optional.ofNullable(_json)
- fun accept(visitor: Visitor): T {
- return when {
+ fun accept(visitor: Visitor): T =
+ when {
threadRunCreated != null -> visitor.visitThreadRunCreated(threadRunCreated)
threadRunQueued != null -> visitor.visitThreadRunQueued(threadRunQueued)
threadRunInProgress != null -> visitor.visitThreadRunInProgress(threadRunInProgress)
@@ -199,7 +199,6 @@ private constructor(
threadRunExpired != null -> visitor.visitThreadRunExpired(threadRunExpired)
else -> visitor.unknown(_json)
}
- }
private var validated: Boolean = false
@@ -256,6 +255,58 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ accept(
+ object : Visitor {
+ override fun visitThreadRunCreated(threadRunCreated: ThreadRunCreated) =
+ threadRunCreated.validity()
+
+ override fun visitThreadRunQueued(threadRunQueued: ThreadRunQueued) =
+ threadRunQueued.validity()
+
+ override fun visitThreadRunInProgress(threadRunInProgress: ThreadRunInProgress) =
+ threadRunInProgress.validity()
+
+ override fun visitThreadRunRequiresAction(
+ threadRunRequiresAction: ThreadRunRequiresAction
+ ) = threadRunRequiresAction.validity()
+
+ override fun visitThreadRunCompleted(threadRunCompleted: ThreadRunCompleted) =
+ threadRunCompleted.validity()
+
+ override fun visitThreadRunIncomplete(threadRunIncomplete: ThreadRunIncomplete) =
+ threadRunIncomplete.validity()
+
+ override fun visitThreadRunFailed(threadRunFailed: ThreadRunFailed) =
+ threadRunFailed.validity()
+
+ override fun visitThreadRunCancelling(threadRunCancelling: ThreadRunCancelling) =
+ threadRunCancelling.validity()
+
+ override fun visitThreadRunCancelled(threadRunCancelled: ThreadRunCancelled) =
+ threadRunCancelled.validity()
+
+ override fun visitThreadRunExpired(threadRunExpired: ThreadRunExpired) =
+ threadRunExpired.validity()
+
+ override fun unknown(json: JsonValue?) = 0
+ }
+ )
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -453,70 +504,54 @@ private constructor(
when (event) {
"thread.run.created" -> {
- return RunStreamEvent(
- threadRunCreated = deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ RunStreamEvent(threadRunCreated = it, _json = json)
+ } ?: RunStreamEvent(_json = json)
}
"thread.run.queued" -> {
- return RunStreamEvent(
- threadRunQueued = deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ RunStreamEvent(threadRunQueued = it, _json = json)
+ } ?: RunStreamEvent(_json = json)
}
"thread.run.in_progress" -> {
- return RunStreamEvent(
- threadRunInProgress =
- deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ RunStreamEvent(threadRunInProgress = it, _json = json)
+ } ?: RunStreamEvent(_json = json)
}
"thread.run.requires_action" -> {
- return RunStreamEvent(
- threadRunRequiresAction =
- deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ RunStreamEvent(threadRunRequiresAction = it, _json = json)
+ } ?: RunStreamEvent(_json = json)
}
"thread.run.completed" -> {
- return RunStreamEvent(
- threadRunCompleted =
- deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ RunStreamEvent(threadRunCompleted = it, _json = json)
+ } ?: RunStreamEvent(_json = json)
}
"thread.run.incomplete" -> {
- return RunStreamEvent(
- threadRunIncomplete =
- deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ RunStreamEvent(threadRunIncomplete = it, _json = json)
+ } ?: RunStreamEvent(_json = json)
}
"thread.run.failed" -> {
- return RunStreamEvent(
- threadRunFailed = deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ RunStreamEvent(threadRunFailed = it, _json = json)
+ } ?: RunStreamEvent(_json = json)
}
"thread.run.cancelling" -> {
- return RunStreamEvent(
- threadRunCancelling =
- deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ RunStreamEvent(threadRunCancelling = it, _json = json)
+ } ?: RunStreamEvent(_json = json)
}
"thread.run.cancelled" -> {
- return RunStreamEvent(
- threadRunCancelled =
- deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ RunStreamEvent(threadRunCancelled = it, _json = json)
+ } ?: RunStreamEvent(_json = json)
}
"thread.run.expired" -> {
- return RunStreamEvent(
- threadRunExpired = deserialize(node, jacksonTypeRef()),
- _json = json,
- )
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ RunStreamEvent(threadRunExpired = it, _json = json)
+ } ?: RunStreamEvent(_json = json)
}
}
@@ -719,6 +754,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("thread.run.created")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -904,6 +958,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("thread.run.queued")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -1089,6 +1162,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("thread.run.in_progress")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -1274,6 +1366,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("thread.run.requires_action")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -1458,6 +1569,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("thread.run.completed")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -1643,6 +1773,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("thread.run.incomplete")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -1825,6 +1974,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("thread.run.failed")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -2010,6 +2178,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("thread.run.cancelling")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -2194,6 +2381,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("thread.run.cancelled")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -2376,6 +2582,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object
+ * recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("thread.run.expired")) 1 else 0 }
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/ThreadStreamEvent.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/ThreadStreamEvent.kt
index ff540ff2b..6331fb7f4 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/ThreadStreamEvent.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/ThreadStreamEvent.kt
@@ -16,6 +16,7 @@ import com.openai.models.beta.threads.Thread
import java.util.Collections
import java.util.Objects
import java.util.Optional
+import kotlin.jvm.optionals.getOrNull
/**
* Occurs when a new [thread](https://platform.openai.com/docs/api-reference/threads/object) is
@@ -215,6 +216,25 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.validity() ?: 0) +
+ event.let { if (it == JsonValue.from("thread.created")) 1 else 0 } +
+ (if (enabled.asKnown().isPresent) 1 else 0)
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/AssistantResponseFormatOption.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/AssistantResponseFormatOption.kt
index 31b3815db..f6db5fda5 100644
--- a/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/AssistantResponseFormatOption.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/AssistantResponseFormatOption.kt
@@ -12,6 +12,7 @@ import com.fasterxml.jackson.module.kotlin.jacksonTypeRef
import com.openai.core.BaseDeserializer
import com.openai.core.BaseSerializer
import com.openai.core.JsonValue
+import com.openai.core.allMaxBy
import com.openai.core.getOrThrow
import com.openai.errors.OpenAIInvalidDataException
import com.openai.models.ResponseFormatJsonObject
@@ -104,8 +105,8 @@ private constructor(
fun _json(): Optional = Optional.ofNullable(_json)
- fun accept(visitor: Visitor): T {
- return when {
+ fun accept(visitor: Visitor): T =
+ when {
auto != null -> visitor.visitAuto(auto)
responseFormatText != null -> visitor.visitResponseFormatText(responseFormatText)
responseFormatJsonObject != null ->
@@ -114,7 +115,6 @@ private constructor(
visitor.visitResponseFormatJsonSchema(responseFormatJsonSchema)
else -> visitor.unknown(_json)
}
- }
private var validated: Boolean = false
@@ -153,6 +153,41 @@ private constructor(
validated = true
}
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OpenAIInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ accept(
+ object : Visitor {
+ override fun visitAuto(auto: JsonValue) =
+ auto.let { if (it == JsonValue.from("auto")) 1 else 0 }
+
+ override fun visitResponseFormatText(responseFormatText: ResponseFormatText) =
+ responseFormatText.validity()
+
+ override fun visitResponseFormatJsonObject(
+ responseFormatJsonObject: ResponseFormatJsonObject
+ ) = responseFormatJsonObject.validity()
+
+ override fun visitResponseFormatJsonSchema(
+ responseFormatJsonSchema: ResponseFormatJsonSchema
+ ) = responseFormatJsonSchema.validity()
+
+ override fun unknown(json: JsonValue?) = 0
+ }
+ )
+
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
@@ -250,36 +285,39 @@ private constructor(
override fun ObjectCodec.deserialize(node: JsonNode): AssistantResponseFormatOption {
val json = JsonValue.fromJsonNode(node)
- tryDeserialize(node, jacksonTypeRef()) {
- it.let {
- if (it != JsonValue.from("auto")) {
- throw OpenAIInvalidDataException("'auto' is invalid, received $it")
- }
- }
- }
- ?.let {
- return AssistantResponseFormatOption(auto = it, _json = json)
- }
- tryDeserialize(node, jacksonTypeRef()) { it.validate() }
- ?.let {
- return AssistantResponseFormatOption(responseFormatText = it, _json = json)
- }
- tryDeserialize(node, jacksonTypeRef()) { it.validate() }
- ?.let {
- return AssistantResponseFormatOption(
- responseFormatJsonObject = it,
- _json = json,
- )
- }
- tryDeserialize(node, jacksonTypeRef()) { it.validate() }
- ?.let {
- return AssistantResponseFormatOption(
- responseFormatJsonSchema = it,
- _json = json,
+ val bestMatches =
+ sequenceOf(
+ tryDeserialize(node, jacksonTypeRef