diff --git a/.release-please-manifest.json b/.release-please-manifest.json
index 05699935..fc0d7ff8 100644
--- a/.release-please-manifest.json
+++ b/.release-please-manifest.json
@@ -1,3 +1,3 @@
{
- ".": "0.44.5"
+ ".": "0.45.0"
}
\ No newline at end of file
diff --git a/.stats.yml b/.stats.yml
index e0e1a71e..037cba0b 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-4bce8217a697c729ac98046d4caf2c9e826b54c427fb0ab4f98e549a2e0ce31c.yml
-openapi_spec_hash: 7996d2c34cc44fe2ce9ffe93c0ab774e
-config_hash: bcd2cacdcb9fae9938f273cd167f613c
+configured_endpoints: 95
+openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-44b20fa9d24544217fe6bb48852037537030a1ad29b202936425110744fe66fb.yml
+openapi_spec_hash: ea86343b5e9858a74e85da8ab2c532f6
+config_hash: 69e3afd56ccb0f0f822a7a9dc130fc99
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0e7a2902..1ef56929 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,24 @@
# Changelog
+## 0.45.0 (2025-04-09)
+
+Full Changelog: [v0.44.5...v0.45.0](https://github.com/openai/openai-java/compare/v0.44.5...v0.45.0)
+
+### Features
+
+* **api:** Add evalapi to sdk ([b567998](https://github.com/openai/openai-java/commit/b56799843d71a81b8d99fae6fb04c0dff731afce))
+
+
+### Bug Fixes
+
+* **client:** trim '/' and empty character in base URL ([#424](https://github.com/openai/openai-java/issues/424)) ([37370df](https://github.com/openai/openai-java/commit/37370df673921c01a511dab2f87e0fe62107a151))
+
+
+### Chores
+
+* add missing `deploymentModel` ([acb132e](https://github.com/openai/openai-java/commit/acb132e45467fd74f5860c54d93a66ad8e1216a3))
+* **tests:** improve enum examples ([#416](https://github.com/openai/openai-java/issues/416)) ([a698758](https://github.com/openai/openai-java/commit/a69875817d67a60a612df14bf3ea06352e2fa265))
+
## 0.44.5 (2025-04-08)
Full Changelog: [v0.44.4...v0.44.5](https://github.com/openai/openai-java/compare/v0.44.4...v0.44.5)
diff --git a/README.md b/README.md
index 4c68ec05..01069e36 100644
--- a/README.md
+++ b/README.md
@@ -9,8 +9,8 @@
-[](https://central.sonatype.com/artifact/com.openai/openai-java/0.44.5)
-[](https://javadoc.io/doc/com.openai/openai-java/0.44.5)
+[](https://central.sonatype.com/artifact/com.openai/openai-java/0.45.0)
+[](https://javadoc.io/doc/com.openai/openai-java/0.45.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.44.5).
+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.45.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.44.5")
+implementation("com.openai:openai-java:0.45.0")
```
### Maven
@@ -38,7 +38,7 @@ implementation("com.openai:openai-java:0.44.5")
com.openaiopenai-java
- 0.44.5
+ 0.45.0
```
diff --git a/build.gradle.kts b/build.gradle.kts
index 656d54e6..b5cf7b4b 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -8,7 +8,7 @@ repositories {
allprojects {
group = "com.openai"
- version = "0.44.5" // x-release-please-version
+ version = "0.45.0" // x-release-please-version
}
subprojects {
diff --git a/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClient.kt b/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClient.kt
index 8a033491..3995c9ea 100644
--- a/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClient.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClient.kt
@@ -8,6 +8,7 @@ import com.openai.services.blocking.BetaService
import com.openai.services.blocking.ChatService
import com.openai.services.blocking.CompletionService
import com.openai.services.blocking.EmbeddingService
+import com.openai.services.blocking.EvalService
import com.openai.services.blocking.FileService
import com.openai.services.blocking.FineTuningService
import com.openai.services.blocking.ImageService
@@ -74,6 +75,8 @@ interface OpenAIClient {
fun responses(): ResponseService
+ fun evals(): EvalService
+
/**
* Closes this client, relinquishing any underlying resources.
*
@@ -117,5 +120,7 @@ interface OpenAIClient {
fun uploads(): UploadService.WithRawResponse
fun responses(): ResponseService.WithRawResponse
+
+ fun evals(): EvalService.WithRawResponse
}
}
diff --git a/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsync.kt b/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsync.kt
index 72f1c4d6..2a2d5894 100644
--- a/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsync.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsync.kt
@@ -8,6 +8,7 @@ import com.openai.services.async.BetaServiceAsync
import com.openai.services.async.ChatServiceAsync
import com.openai.services.async.CompletionServiceAsync
import com.openai.services.async.EmbeddingServiceAsync
+import com.openai.services.async.EvalServiceAsync
import com.openai.services.async.FileServiceAsync
import com.openai.services.async.FineTuningServiceAsync
import com.openai.services.async.ImageServiceAsync
@@ -74,6 +75,8 @@ interface OpenAIClientAsync {
fun responses(): ResponseServiceAsync
+ fun evals(): EvalServiceAsync
+
/**
* Closes this client, relinquishing any underlying resources.
*
@@ -117,5 +120,7 @@ interface OpenAIClientAsync {
fun uploads(): UploadServiceAsync.WithRawResponse
fun responses(): ResponseServiceAsync.WithRawResponse
+
+ fun evals(): EvalServiceAsync.WithRawResponse
}
}
diff --git a/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsyncImpl.kt
index be1a312a..2bbeb00b 100644
--- a/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsyncImpl.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsyncImpl.kt
@@ -16,6 +16,8 @@ import com.openai.services.async.CompletionServiceAsync
import com.openai.services.async.CompletionServiceAsyncImpl
import com.openai.services.async.EmbeddingServiceAsync
import com.openai.services.async.EmbeddingServiceAsyncImpl
+import com.openai.services.async.EvalServiceAsync
+import com.openai.services.async.EvalServiceAsyncImpl
import com.openai.services.async.FileServiceAsync
import com.openai.services.async.FileServiceAsyncImpl
import com.openai.services.async.FineTuningServiceAsync
@@ -100,6 +102,8 @@ class OpenAIClientAsyncImpl(private val clientOptions: ClientOptions) : OpenAICl
ResponseServiceAsyncImpl(clientOptionsWithUserAgent)
}
+ private val evals: EvalServiceAsync by lazy { EvalServiceAsyncImpl(clientOptionsWithUserAgent) }
+
override fun sync(): OpenAIClient = sync
override fun withRawResponse(): OpenAIClientAsync.WithRawResponse = withRawResponse
@@ -132,6 +136,8 @@ class OpenAIClientAsyncImpl(private val clientOptions: ClientOptions) : OpenAICl
override fun responses(): ResponseServiceAsync = responses
+ override fun evals(): EvalServiceAsync = evals
+
override fun close() = clientOptions.httpClient.close()
class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) :
@@ -193,6 +199,10 @@ class OpenAIClientAsyncImpl(private val clientOptions: ClientOptions) : OpenAICl
ResponseServiceAsyncImpl.WithRawResponseImpl(clientOptions)
}
+ private val evals: EvalServiceAsync.WithRawResponse by lazy {
+ EvalServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
override fun completions(): CompletionServiceAsync.WithRawResponse = completions
override fun chat(): ChatServiceAsync.WithRawResponse = chat
@@ -220,5 +230,7 @@ class OpenAIClientAsyncImpl(private val clientOptions: ClientOptions) : OpenAICl
override fun uploads(): UploadServiceAsync.WithRawResponse = uploads
override fun responses(): ResponseServiceAsync.WithRawResponse = responses
+
+ override fun evals(): EvalServiceAsync.WithRawResponse = evals
}
}
diff --git a/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientImpl.kt b/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientImpl.kt
index f415526a..17ad13b4 100644
--- a/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientImpl.kt
+++ b/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientImpl.kt
@@ -16,6 +16,8 @@ import com.openai.services.blocking.CompletionService
import com.openai.services.blocking.CompletionServiceImpl
import com.openai.services.blocking.EmbeddingService
import com.openai.services.blocking.EmbeddingServiceImpl
+import com.openai.services.blocking.EvalService
+import com.openai.services.blocking.EvalServiceImpl
import com.openai.services.blocking.FileService
import com.openai.services.blocking.FileServiceImpl
import com.openai.services.blocking.FineTuningService
@@ -90,6 +92,8 @@ class OpenAIClientImpl(private val clientOptions: ClientOptions) : OpenAIClient
ResponseServiceImpl(clientOptionsWithUserAgent)
}
+ private val evals: EvalService by lazy { EvalServiceImpl(clientOptionsWithUserAgent) }
+
override fun async(): OpenAIClientAsync = async
override fun withRawResponse(): OpenAIClient.WithRawResponse = withRawResponse
@@ -122,6 +126,8 @@ class OpenAIClientImpl(private val clientOptions: ClientOptions) : OpenAIClient
override fun responses(): ResponseService = responses
+ override fun evals(): EvalService = evals
+
override fun close() = clientOptions.httpClient.close()
class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) :
@@ -183,6 +189,10 @@ class OpenAIClientImpl(private val clientOptions: ClientOptions) : OpenAIClient
ResponseServiceImpl.WithRawResponseImpl(clientOptions)
}
+ private val evals: EvalService.WithRawResponse by lazy {
+ EvalServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
override fun completions(): CompletionService.WithRawResponse = completions
override fun chat(): ChatService.WithRawResponse = chat
@@ -210,5 +220,7 @@ class OpenAIClientImpl(private val clientOptions: ClientOptions) : OpenAIClient
override fun uploads(): UploadService.WithRawResponse = uploads
override fun responses(): ResponseService.WithRawResponse = responses
+
+ override fun evals(): EvalService.WithRawResponse = evals
}
}
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 0b11077b..bedd2149 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
@@ -93,7 +93,9 @@ internal fun Any?.contentToString(): String {
internal fun isAzureEndpoint(baseUrl: String): Boolean {
// Azure Endpoint should be in the format of `https://.openai.azure.com`.
// Or `https://.azure-api.net` for Azure OpenAI Management URL.
- return baseUrl.endsWith(".openai.azure.com", true) || baseUrl.endsWith(".azure-api.net", true)
+ val trimmedBaseUrl = baseUrl.trim().trimEnd('/')
+ return trimmedBaseUrl.endsWith(".openai.azure.com", true) ||
+ trimmedBaseUrl.endsWith(".azure-api.net", true)
}
internal interface Enum
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 b9077106..000b68bc 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
@@ -27,7 +27,7 @@ class AllModels
private constructor(
private val string: String? = null,
private val chatModel: ChatModel? = null,
- private val unionMember2: UnionMember2? = null,
+ private val responsesOnlyModel: ResponsesOnlyModel? = null,
private val _json: JsonValue? = null,
) {
@@ -35,19 +35,20 @@ private constructor(
fun chatModel(): Optional = Optional.ofNullable(chatModel)
- fun unionMember2(): Optional = Optional.ofNullable(unionMember2)
+ fun responsesOnlyModel(): Optional = Optional.ofNullable(responsesOnlyModel)
fun isString(): Boolean = string != null
fun isChatModel(): Boolean = chatModel != null
- fun isUnionMember2(): Boolean = unionMember2 != null
+ fun isResponsesOnlyModel(): Boolean = responsesOnlyModel != null
fun asString(): String = string.getOrThrow("string")
fun asChatModel(): ChatModel = chatModel.getOrThrow("chatModel")
- fun asUnionMember2(): UnionMember2 = unionMember2.getOrThrow("unionMember2")
+ fun asResponsesOnlyModel(): ResponsesOnlyModel =
+ responsesOnlyModel.getOrThrow("responsesOnlyModel")
fun _json(): Optional = Optional.ofNullable(_json)
@@ -55,7 +56,7 @@ private constructor(
when {
string != null -> visitor.visitString(string)
chatModel != null -> visitor.visitChatModel(chatModel)
- unionMember2 != null -> visitor.visitUnionMember2(unionMember2)
+ responsesOnlyModel != null -> visitor.visitResponsesOnlyModel(responsesOnlyModel)
else -> visitor.unknown(_json)
}
@@ -74,8 +75,8 @@ private constructor(
chatModel.validate()
}
- override fun visitUnionMember2(unionMember2: UnionMember2) {
- unionMember2.validate()
+ override fun visitResponsesOnlyModel(responsesOnlyModel: ResponsesOnlyModel) {
+ responsesOnlyModel.validate()
}
}
)
@@ -103,7 +104,8 @@ private constructor(
override fun visitChatModel(chatModel: ChatModel) = chatModel.validity()
- override fun visitUnionMember2(unionMember2: UnionMember2) = unionMember2.validity()
+ override fun visitResponsesOnlyModel(responsesOnlyModel: ResponsesOnlyModel) =
+ responsesOnlyModel.validity()
override fun unknown(json: JsonValue?) = 0
}
@@ -114,16 +116,16 @@ private constructor(
return true
}
- return /* spotless:off */ other is AllModels && string == other.string && chatModel == other.chatModel && unionMember2 == other.unionMember2 /* spotless:on */
+ return /* spotless:off */ other is AllModels && string == other.string && chatModel == other.chatModel && responsesOnlyModel == other.responsesOnlyModel /* spotless:on */
}
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(string, chatModel, unionMember2) /* spotless:on */
+ override fun hashCode(): Int = /* spotless:off */ Objects.hash(string, chatModel, responsesOnlyModel) /* spotless:on */
override fun toString(): String =
when {
string != null -> "AllModels{string=$string}"
chatModel != null -> "AllModels{chatModel=$chatModel}"
- unionMember2 != null -> "AllModels{unionMember2=$unionMember2}"
+ responsesOnlyModel != null -> "AllModels{responsesOnlyModel=$responsesOnlyModel}"
_json != null -> "AllModels{_unknown=$_json}"
else -> throw IllegalStateException("Invalid AllModels")
}
@@ -135,7 +137,8 @@ private constructor(
@JvmStatic fun ofChatModel(chatModel: ChatModel) = AllModels(chatModel = chatModel)
@JvmStatic
- fun ofUnionMember2(unionMember2: UnionMember2) = AllModels(unionMember2 = unionMember2)
+ fun ofResponsesOnlyModel(responsesOnlyModel: ResponsesOnlyModel) =
+ AllModels(responsesOnlyModel = responsesOnlyModel)
}
/** An interface that defines how to map each variant of [AllModels] to a value of type [T]. */
@@ -145,7 +148,7 @@ private constructor(
fun visitChatModel(chatModel: ChatModel): T
- fun visitUnionMember2(unionMember2: UnionMember2): T
+ fun visitResponsesOnlyModel(responsesOnlyModel: ResponsesOnlyModel): T
/**
* Maps an unknown variant of [AllModels] to a value of type [T].
@@ -171,8 +174,8 @@ private constructor(
tryDeserialize(node, jacksonTypeRef())?.let {
AllModels(chatModel = it, _json = json)
},
- tryDeserialize(node, jacksonTypeRef())?.let {
- AllModels(unionMember2 = it, _json = json)
+ tryDeserialize(node, jacksonTypeRef())?.let {
+ AllModels(responsesOnlyModel = it, _json = json)
},
tryDeserialize(node, jacksonTypeRef())?.let {
AllModels(string = it, _json = json)
@@ -203,15 +206,16 @@ private constructor(
when {
value.string != null -> generator.writeObject(value.string)
value.chatModel != null -> generator.writeObject(value.chatModel)
- value.unionMember2 != null -> generator.writeObject(value.unionMember2)
+ value.responsesOnlyModel != null -> generator.writeObject(value.responsesOnlyModel)
value._json != null -> generator.writeObject(value._json)
else -> throw IllegalStateException("Invalid AllModels")
}
}
}
- class UnionMember2 @JsonCreator private constructor(private val value: JsonField) :
- Enum {
+ class ResponsesOnlyModel
+ @JsonCreator
+ private constructor(private val value: JsonField) : Enum {
/**
* Returns this class instance's raw value.
@@ -233,10 +237,10 @@ private constructor(
@JvmField val COMPUTER_USE_PREVIEW_2025_03_11 = of("computer-use-preview-2025-03-11")
- @JvmStatic fun of(value: String) = UnionMember2(JsonField.of(value))
+ @JvmStatic fun of(value: String) = ResponsesOnlyModel(JsonField.of(value))
}
- /** An enum containing [UnionMember2]'s known values. */
+ /** An enum containing [ResponsesOnlyModel]'s known values. */
enum class Known {
O1_PRO,
O1_PRO_2025_03_19,
@@ -245,9 +249,9 @@ private constructor(
}
/**
- * An enum containing [UnionMember2]'s known values, as well as an [_UNKNOWN] member.
+ * An enum containing [ResponsesOnlyModel]'s known values, as well as an [_UNKNOWN] member.
*
- * An instance of [UnionMember2] can contain an unknown value in a couple of cases:
+ * An instance of [ResponsesOnlyModel] can contain an unknown value in a couple of cases:
* - It was deserialized from data that doesn't match any known member. For example, if the
* SDK is on an older version than the API, then the API may respond with new members that
* the SDK is unaware of.
@@ -259,7 +263,8 @@ private constructor(
COMPUTER_USE_PREVIEW,
COMPUTER_USE_PREVIEW_2025_03_11,
/**
- * An enum member indicating that [UnionMember2] was instantiated with an unknown value.
+ * An enum member indicating that [ResponsesOnlyModel] was instantiated with an unknown
+ * value.
*/
_UNKNOWN,
}
@@ -295,7 +300,7 @@ private constructor(
O1_PRO_2025_03_19 -> Known.O1_PRO_2025_03_19
COMPUTER_USE_PREVIEW -> Known.COMPUTER_USE_PREVIEW
COMPUTER_USE_PREVIEW_2025_03_11 -> Known.COMPUTER_USE_PREVIEW_2025_03_11
- else -> throw OpenAIInvalidDataException("Unknown UnionMember2: $value")
+ else -> throw OpenAIInvalidDataException("Unknown ResponsesOnlyModel: $value")
}
/**
@@ -312,7 +317,7 @@ private constructor(
private var validated: Boolean = false
- fun validate(): UnionMember2 = apply {
+ fun validate(): ResponsesOnlyModel = apply {
if (validated) {
return@apply
}
@@ -342,7 +347,7 @@ private constructor(
return true
}
- return /* spotless:off */ other is UnionMember2 && value == other.value /* spotless:on */
+ return /* spotless:off */ other is ResponsesOnlyModel && value == other.value /* spotless:on */
}
override fun hashCode() = value.hashCode()
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 c8479556..9ee5211f 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
@@ -27,7 +27,7 @@ class ResponsesModel
private constructor(
private val string: String? = null,
private val chat: ChatModel? = null,
- private val unionMember2: UnionMember2? = null,
+ private val only: ResponsesOnlyModel? = null,
private val _json: JsonValue? = null,
) {
@@ -35,19 +35,19 @@ private constructor(
fun chat(): Optional = Optional.ofNullable(chat)
- fun unionMember2(): Optional = Optional.ofNullable(unionMember2)
+ fun only(): Optional = Optional.ofNullable(only)
fun isString(): Boolean = string != null
fun isChat(): Boolean = chat != null
- fun isUnionMember2(): Boolean = unionMember2 != null
+ fun isOnly(): Boolean = only != null
fun asString(): String = string.getOrThrow("string")
fun asChat(): ChatModel = chat.getOrThrow("chat")
- fun asUnionMember2(): UnionMember2 = unionMember2.getOrThrow("unionMember2")
+ fun asOnly(): ResponsesOnlyModel = only.getOrThrow("only")
fun _json(): Optional = Optional.ofNullable(_json)
@@ -55,7 +55,7 @@ private constructor(
when {
string != null -> visitor.visitString(string)
chat != null -> visitor.visitChat(chat)
- unionMember2 != null -> visitor.visitUnionMember2(unionMember2)
+ only != null -> visitor.visitOnly(only)
else -> visitor.unknown(_json)
}
@@ -74,8 +74,8 @@ private constructor(
chat.validate()
}
- override fun visitUnionMember2(unionMember2: UnionMember2) {
- unionMember2.validate()
+ override fun visitOnly(only: ResponsesOnlyModel) {
+ only.validate()
}
}
)
@@ -103,7 +103,7 @@ private constructor(
override fun visitChat(chat: ChatModel) = chat.validity()
- override fun visitUnionMember2(unionMember2: UnionMember2) = unionMember2.validity()
+ override fun visitOnly(only: ResponsesOnlyModel) = only.validity()
override fun unknown(json: JsonValue?) = 0
}
@@ -114,16 +114,16 @@ private constructor(
return true
}
- return /* spotless:off */ other is ResponsesModel && string == other.string && chat == other.chat && unionMember2 == other.unionMember2 /* spotless:on */
+ return /* spotless:off */ other is ResponsesModel && string == other.string && chat == other.chat && only == other.only /* spotless:on */
}
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(string, chat, unionMember2) /* spotless:on */
+ override fun hashCode(): Int = /* spotless:off */ Objects.hash(string, chat, only) /* spotless:on */
override fun toString(): String =
when {
string != null -> "ResponsesModel{string=$string}"
chat != null -> "ResponsesModel{chat=$chat}"
- unionMember2 != null -> "ResponsesModel{unionMember2=$unionMember2}"
+ only != null -> "ResponsesModel{only=$only}"
_json != null -> "ResponsesModel{_unknown=$_json}"
else -> throw IllegalStateException("Invalid ResponsesModel")
}
@@ -134,8 +134,7 @@ private constructor(
@JvmStatic fun ofChat(chat: ChatModel) = ResponsesModel(chat = chat)
- @JvmStatic
- fun ofUnionMember2(unionMember2: UnionMember2) = ResponsesModel(unionMember2 = unionMember2)
+ @JvmStatic fun ofOnly(only: ResponsesOnlyModel) = ResponsesModel(only = only)
}
/**
@@ -147,7 +146,7 @@ private constructor(
fun visitChat(chat: ChatModel): T
- fun visitUnionMember2(unionMember2: UnionMember2): T
+ fun visitOnly(only: ResponsesOnlyModel): T
/**
* Maps an unknown variant of [ResponsesModel] to a value of type [T].
@@ -174,8 +173,8 @@ private constructor(
tryDeserialize(node, jacksonTypeRef())?.let {
ResponsesModel(chat = it, _json = json)
},
- tryDeserialize(node, jacksonTypeRef())?.let {
- ResponsesModel(unionMember2 = it, _json = json)
+ tryDeserialize(node, jacksonTypeRef())?.let {
+ ResponsesModel(only = it, _json = json)
},
tryDeserialize(node, jacksonTypeRef())?.let {
ResponsesModel(string = it, _json = json)
@@ -206,15 +205,16 @@ private constructor(
when {
value.string != null -> generator.writeObject(value.string)
value.chat != null -> generator.writeObject(value.chat)
- value.unionMember2 != null -> generator.writeObject(value.unionMember2)
+ value.only != null -> generator.writeObject(value.only)
value._json != null -> generator.writeObject(value._json)
else -> throw IllegalStateException("Invalid ResponsesModel")
}
}
}
- class UnionMember2 @JsonCreator private constructor(private val value: JsonField) :
- Enum {
+ class ResponsesOnlyModel
+ @JsonCreator
+ private constructor(private val value: JsonField) : Enum {
/**
* Returns this class instance's raw value.
@@ -236,10 +236,10 @@ private constructor(
@JvmField val COMPUTER_USE_PREVIEW_2025_03_11 = of("computer-use-preview-2025-03-11")
- @JvmStatic fun of(value: String) = UnionMember2(JsonField.of(value))
+ @JvmStatic fun of(value: String) = ResponsesOnlyModel(JsonField.of(value))
}
- /** An enum containing [UnionMember2]'s known values. */
+ /** An enum containing [ResponsesOnlyModel]'s known values. */
enum class Known {
O1_PRO,
O1_PRO_2025_03_19,
@@ -248,9 +248,9 @@ private constructor(
}
/**
- * An enum containing [UnionMember2]'s known values, as well as an [_UNKNOWN] member.
+ * An enum containing [ResponsesOnlyModel]'s known values, as well as an [_UNKNOWN] member.
*
- * An instance of [UnionMember2] can contain an unknown value in a couple of cases:
+ * An instance of [ResponsesOnlyModel] can contain an unknown value in a couple of cases:
* - It was deserialized from data that doesn't match any known member. For example, if the
* SDK is on an older version than the API, then the API may respond with new members that
* the SDK is unaware of.
@@ -262,7 +262,8 @@ private constructor(
COMPUTER_USE_PREVIEW,
COMPUTER_USE_PREVIEW_2025_03_11,
/**
- * An enum member indicating that [UnionMember2] was instantiated with an unknown value.
+ * An enum member indicating that [ResponsesOnlyModel] was instantiated with an unknown
+ * value.
*/
_UNKNOWN,
}
@@ -298,7 +299,7 @@ private constructor(
O1_PRO_2025_03_19 -> Known.O1_PRO_2025_03_19
COMPUTER_USE_PREVIEW -> Known.COMPUTER_USE_PREVIEW
COMPUTER_USE_PREVIEW_2025_03_11 -> Known.COMPUTER_USE_PREVIEW_2025_03_11
- else -> throw OpenAIInvalidDataException("Unknown UnionMember2: $value")
+ else -> throw OpenAIInvalidDataException("Unknown ResponsesOnlyModel: $value")
}
/**
@@ -315,7 +316,7 @@ private constructor(
private var validated: Boolean = false
- fun validate(): UnionMember2 = apply {
+ fun validate(): ResponsesOnlyModel = apply {
if (validated) {
return@apply
}
@@ -345,7 +346,7 @@ private constructor(
return true
}
- return /* spotless:off */ other is UnionMember2 && value == other.value /* spotless:on */
+ return /* spotless:off */ other is ResponsesOnlyModel && value == other.value /* spotless:on */
}
override fun hashCode() = value.hashCode()
diff --git a/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalCreateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalCreateParams.kt
new file mode 100644
index 00000000..e2302685
--- /dev/null
+++ b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalCreateParams.kt
@@ -0,0 +1,4672 @@
+// File generated from our OpenAPI spec by Stainless.
+
+package com.openai.models.evals
+
+import com.fasterxml.jackson.annotation.JsonAnyGetter
+import com.fasterxml.jackson.annotation.JsonAnySetter
+import com.fasterxml.jackson.annotation.JsonCreator
+import com.fasterxml.jackson.annotation.JsonProperty
+import com.fasterxml.jackson.core.JsonGenerator
+import com.fasterxml.jackson.core.ObjectCodec
+import com.fasterxml.jackson.databind.JsonNode
+import com.fasterxml.jackson.databind.SerializerProvider
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize
+import com.fasterxml.jackson.databind.annotation.JsonSerialize
+import com.fasterxml.jackson.module.kotlin.jacksonTypeRef
+import com.openai.core.BaseDeserializer
+import com.openai.core.BaseSerializer
+import com.openai.core.Enum
+import com.openai.core.ExcludeMissing
+import com.openai.core.JsonField
+import com.openai.core.JsonMissing
+import com.openai.core.JsonValue
+import com.openai.core.Params
+import com.openai.core.allMaxBy
+import com.openai.core.checkKnown
+import com.openai.core.checkRequired
+import com.openai.core.getOrThrow
+import com.openai.core.http.Headers
+import com.openai.core.http.QueryParams
+import com.openai.core.toImmutable
+import com.openai.errors.OpenAIInvalidDataException
+import java.util.Collections
+import java.util.Objects
+import java.util.Optional
+import kotlin.jvm.optionals.getOrNull
+
+/**
+ * Create the structure of an evaluation that can be used to test a model's performance. An
+ * evaluation is a set of testing criteria and a datasource. After creating an evaluation, you can
+ * run it on different models and model parameters. We support several types of graders and
+ * datasources. For more information, see the
+ * [Evals guide](https://platform.openai.com/docs/guides/evals).
+ */
+class EvalCreateParams
+private constructor(
+ private val body: Body,
+ private val additionalHeaders: Headers,
+ private val additionalQueryParams: QueryParams,
+) : Params {
+
+ /**
+ * The configuration for the data source used for the evaluation runs.
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is
+ * unexpectedly missing or null (e.g. if the server responded with an unexpected value).
+ */
+ fun dataSourceConfig(): DataSourceConfig = body.dataSourceConfig()
+
+ /**
+ * A list of graders for all eval runs in this group.
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is
+ * unexpectedly missing or null (e.g. if the server responded with an unexpected value).
+ */
+ fun testingCriteria(): List = body.testingCriteria()
+
+ /**
+ * 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
+ * API or the dashboard.
+ *
+ * Keys are strings with a maximum length of 64 characters. Values are strings with a maximum
+ * length of 512 characters.
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
+ * server responded with an unexpected value).
+ */
+ fun metadata(): Optional = body.metadata()
+
+ /**
+ * The name of the evaluation.
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
+ * server responded with an unexpected value).
+ */
+ fun name(): Optional = body.name()
+
+ /**
+ * Indicates whether the evaluation is shared with OpenAI.
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
+ * server responded with an unexpected value).
+ */
+ fun shareWithOpenAI(): Optional = body.shareWithOpenAI()
+
+ /**
+ * Returns the raw JSON value of [dataSourceConfig].
+ *
+ * Unlike [dataSourceConfig], this method doesn't throw if the JSON field has an unexpected
+ * type.
+ */
+ fun _dataSourceConfig(): JsonField = body._dataSourceConfig()
+
+ /**
+ * Returns the raw JSON value of [testingCriteria].
+ *
+ * Unlike [testingCriteria], this method doesn't throw if the JSON field has an unexpected type.
+ */
+ fun _testingCriteria(): JsonField> = body._testingCriteria()
+
+ /**
+ * Returns the raw JSON value of [metadata].
+ *
+ * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type.
+ */
+ fun _metadata(): JsonField = body._metadata()
+
+ /**
+ * Returns the raw JSON value of [name].
+ *
+ * Unlike [name], this method doesn't throw if the JSON field has an unexpected type.
+ */
+ fun _name(): JsonField = body._name()
+
+ /**
+ * Returns the raw JSON value of [shareWithOpenAI].
+ *
+ * Unlike [shareWithOpenAI], this method doesn't throw if the JSON field has an unexpected type.
+ */
+ fun _shareWithOpenAI(): JsonField = body._shareWithOpenAI()
+
+ fun _additionalBodyProperties(): Map = body._additionalProperties()
+
+ fun _additionalHeaders(): Headers = additionalHeaders
+
+ fun _additionalQueryParams(): QueryParams = additionalQueryParams
+
+ fun toBuilder() = Builder().from(this)
+
+ companion object {
+
+ /**
+ * Returns a mutable builder for constructing an instance of [EvalCreateParams].
+ *
+ * The following fields are required:
+ * ```java
+ * .dataSourceConfig()
+ * .testingCriteria()
+ * ```
+ */
+ @JvmStatic fun builder() = Builder()
+ }
+
+ /** A builder for [EvalCreateParams]. */
+ class Builder internal constructor() {
+
+ private var body: Body.Builder = Body.builder()
+ private var additionalHeaders: Headers.Builder = Headers.builder()
+ private var additionalQueryParams: QueryParams.Builder = QueryParams.builder()
+
+ @JvmSynthetic
+ internal fun from(evalCreateParams: EvalCreateParams) = apply {
+ body = evalCreateParams.body.toBuilder()
+ additionalHeaders = evalCreateParams.additionalHeaders.toBuilder()
+ additionalQueryParams = evalCreateParams.additionalQueryParams.toBuilder()
+ }
+
+ /**
+ * Sets the entire request body.
+ *
+ * This is generally only useful if you are already constructing the body separately.
+ * Otherwise, it's more convenient to use the top-level setters instead:
+ * - [dataSourceConfig]
+ * - [testingCriteria]
+ * - [metadata]
+ * - [name]
+ * - [shareWithOpenAI]
+ * - etc.
+ */
+ fun body(body: Body) = apply { this.body = body.toBuilder() }
+
+ /** The configuration for the data source used for the evaluation runs. */
+ fun dataSourceConfig(dataSourceConfig: DataSourceConfig) = apply {
+ body.dataSourceConfig(dataSourceConfig)
+ }
+
+ /**
+ * Sets [Builder.dataSourceConfig] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.dataSourceConfig] with a well-typed [DataSourceConfig]
+ * value instead. This method is primarily for setting the field to an undocumented or not
+ * yet supported value.
+ */
+ fun dataSourceConfig(dataSourceConfig: JsonField) = apply {
+ body.dataSourceConfig(dataSourceConfig)
+ }
+
+ /** Alias for calling [dataSourceConfig] with `DataSourceConfig.ofCustom(custom)`. */
+ fun dataSourceConfig(custom: DataSourceConfig.Custom) = apply {
+ body.dataSourceConfig(custom)
+ }
+
+ /**
+ * Alias for calling [dataSourceConfig] with the following:
+ * ```java
+ * DataSourceConfig.Custom.builder()
+ * .itemSchema(itemSchema)
+ * .build()
+ * ```
+ */
+ fun customDataSourceConfig(itemSchema: DataSourceConfig.Custom.ItemSchema) = apply {
+ body.customDataSourceConfig(itemSchema)
+ }
+
+ /**
+ * Alias for calling [dataSourceConfig] with
+ * `DataSourceConfig.ofStoredCompletions(storedCompletions)`.
+ */
+ fun dataSourceConfig(storedCompletions: DataSourceConfig.StoredCompletions) = apply {
+ body.dataSourceConfig(storedCompletions)
+ }
+
+ /** A list of graders for all eval runs in this group. */
+ fun testingCriteria(testingCriteria: List) = apply {
+ body.testingCriteria(testingCriteria)
+ }
+
+ /**
+ * Sets [Builder.testingCriteria] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.testingCriteria] with a well-typed
+ * `List` value instead. This method is primarily for setting the field to
+ * an undocumented or not yet supported value.
+ */
+ fun testingCriteria(testingCriteria: JsonField>) = apply {
+ body.testingCriteria(testingCriteria)
+ }
+
+ /**
+ * Adds a single [TestingCriterion] to [testingCriteria].
+ *
+ * @throws IllegalStateException if the field was previously set to a non-list.
+ */
+ fun addTestingCriterion(testingCriterion: TestingCriterion) = apply {
+ body.addTestingCriterion(testingCriterion)
+ }
+
+ /**
+ * Alias for calling [addTestingCriterion] with `TestingCriterion.ofLabelModel(labelModel)`.
+ */
+ fun addTestingCriterion(labelModel: TestingCriterion.LabelModel) = apply {
+ body.addTestingCriterion(labelModel)
+ }
+
+ /**
+ * Alias for calling [addTestingCriterion] with
+ * `TestingCriterion.ofStringCheck(stringCheck)`.
+ */
+ fun addTestingCriterion(stringCheck: EvalStringCheckGrader) = apply {
+ body.addTestingCriterion(stringCheck)
+ }
+
+ /**
+ * Alias for calling [addTestingCriterion] with
+ * `TestingCriterion.ofTextSimilarity(textSimilarity)`.
+ */
+ fun addTestingCriterion(textSimilarity: EvalTextSimilarityGrader) = apply {
+ body.addTestingCriterion(textSimilarity)
+ }
+
+ /**
+ * 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 API or the dashboard.
+ *
+ * Keys are strings with a maximum length of 64 characters. Values are strings with a
+ * maximum length of 512 characters.
+ */
+ fun metadata(metadata: Metadata?) = apply { body.metadata(metadata) }
+
+ /** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */
+ fun metadata(metadata: Optional) = metadata(metadata.getOrNull())
+
+ /**
+ * Sets [Builder.metadata] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.metadata] with a well-typed [Metadata] value instead.
+ * This method is primarily for setting the field to an undocumented or not yet supported
+ * value.
+ */
+ fun metadata(metadata: JsonField) = apply { body.metadata(metadata) }
+
+ /** The name of the evaluation. */
+ fun name(name: String) = apply { body.name(name) }
+
+ /**
+ * Sets [Builder.name] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.name] with a well-typed [String] value instead. This
+ * method is primarily for setting the field to an undocumented or not yet supported value.
+ */
+ fun name(name: JsonField) = apply { body.name(name) }
+
+ /** Indicates whether the evaluation is shared with OpenAI. */
+ fun shareWithOpenAI(shareWithOpenAI: Boolean) = apply {
+ body.shareWithOpenAI(shareWithOpenAI)
+ }
+
+ /**
+ * Sets [Builder.shareWithOpenAI] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.shareWithOpenAI] with a well-typed [Boolean] value
+ * instead. This method is primarily for setting the field to an undocumented or not yet
+ * supported value.
+ */
+ fun shareWithOpenAI(shareWithOpenAI: JsonField) = apply {
+ body.shareWithOpenAI(shareWithOpenAI)
+ }
+
+ fun additionalBodyProperties(additionalBodyProperties: Map) = apply {
+ body.additionalProperties(additionalBodyProperties)
+ }
+
+ fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply {
+ body.putAdditionalProperty(key, value)
+ }
+
+ fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) =
+ apply {
+ body.putAllAdditionalProperties(additionalBodyProperties)
+ }
+
+ fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) }
+
+ fun removeAllAdditionalBodyProperties(keys: Set) = apply {
+ body.removeAllAdditionalProperties(keys)
+ }
+
+ fun additionalHeaders(additionalHeaders: Headers) = apply {
+ this.additionalHeaders.clear()
+ putAllAdditionalHeaders(additionalHeaders)
+ }
+
+ fun additionalHeaders(additionalHeaders: Map>) = apply {
+ this.additionalHeaders.clear()
+ putAllAdditionalHeaders(additionalHeaders)
+ }
+
+ fun putAdditionalHeader(name: String, value: String) = apply {
+ additionalHeaders.put(name, value)
+ }
+
+ fun putAdditionalHeaders(name: String, values: Iterable) = apply {
+ additionalHeaders.put(name, values)
+ }
+
+ fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply {
+ this.additionalHeaders.putAll(additionalHeaders)
+ }
+
+ fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply {
+ this.additionalHeaders.putAll(additionalHeaders)
+ }
+
+ fun replaceAdditionalHeaders(name: String, value: String) = apply {
+ additionalHeaders.replace(name, value)
+ }
+
+ fun replaceAdditionalHeaders(name: String, values: Iterable) = apply {
+ additionalHeaders.replace(name, values)
+ }
+
+ fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply {
+ this.additionalHeaders.replaceAll(additionalHeaders)
+ }
+
+ fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply {
+ this.additionalHeaders.replaceAll(additionalHeaders)
+ }
+
+ fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) }
+
+ fun removeAllAdditionalHeaders(names: Set) = apply {
+ additionalHeaders.removeAll(names)
+ }
+
+ fun additionalQueryParams(additionalQueryParams: QueryParams) = apply {
+ this.additionalQueryParams.clear()
+ putAllAdditionalQueryParams(additionalQueryParams)
+ }
+
+ fun additionalQueryParams(additionalQueryParams: Map>) = apply {
+ this.additionalQueryParams.clear()
+ putAllAdditionalQueryParams(additionalQueryParams)
+ }
+
+ fun putAdditionalQueryParam(key: String, value: String) = apply {
+ additionalQueryParams.put(key, value)
+ }
+
+ fun putAdditionalQueryParams(key: String, values: Iterable) = apply {
+ additionalQueryParams.put(key, values)
+ }
+
+ fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply {
+ this.additionalQueryParams.putAll(additionalQueryParams)
+ }
+
+ fun putAllAdditionalQueryParams(additionalQueryParams: Map>) =
+ apply {
+ this.additionalQueryParams.putAll(additionalQueryParams)
+ }
+
+ fun replaceAdditionalQueryParams(key: String, value: String) = apply {
+ additionalQueryParams.replace(key, value)
+ }
+
+ fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply {
+ additionalQueryParams.replace(key, values)
+ }
+
+ fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply {
+ this.additionalQueryParams.replaceAll(additionalQueryParams)
+ }
+
+ fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) =
+ apply {
+ this.additionalQueryParams.replaceAll(additionalQueryParams)
+ }
+
+ fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) }
+
+ fun removeAllAdditionalQueryParams(keys: Set) = apply {
+ additionalQueryParams.removeAll(keys)
+ }
+
+ /**
+ * Returns an immutable instance of [EvalCreateParams].
+ *
+ * Further updates to this [Builder] will not mutate the returned instance.
+ *
+ * The following fields are required:
+ * ```java
+ * .dataSourceConfig()
+ * .testingCriteria()
+ * ```
+ *
+ * @throws IllegalStateException if any required field is unset.
+ */
+ fun build(): EvalCreateParams =
+ EvalCreateParams(body.build(), additionalHeaders.build(), additionalQueryParams.build())
+ }
+
+ fun _body(): Body = body
+
+ override fun _headers(): Headers = additionalHeaders
+
+ override fun _queryParams(): QueryParams = additionalQueryParams
+
+ class Body
+ private constructor(
+ private val dataSourceConfig: JsonField,
+ private val testingCriteria: JsonField>,
+ private val metadata: JsonField,
+ private val name: JsonField,
+ private val shareWithOpenAI: JsonField,
+ private val additionalProperties: MutableMap,
+ ) {
+
+ @JsonCreator
+ private constructor(
+ @JsonProperty("data_source_config")
+ @ExcludeMissing
+ dataSourceConfig: JsonField = JsonMissing.of(),
+ @JsonProperty("testing_criteria")
+ @ExcludeMissing
+ testingCriteria: JsonField> = JsonMissing.of(),
+ @JsonProperty("metadata")
+ @ExcludeMissing
+ metadata: JsonField = JsonMissing.of(),
+ @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(),
+ @JsonProperty("share_with_openai")
+ @ExcludeMissing
+ shareWithOpenAI: JsonField = JsonMissing.of(),
+ ) : this(dataSourceConfig, testingCriteria, metadata, name, shareWithOpenAI, mutableMapOf())
+
+ /**
+ * The configuration for the data source used for the evaluation runs.
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is
+ * unexpectedly missing or null (e.g. if the server responded with an unexpected value).
+ */
+ fun dataSourceConfig(): DataSourceConfig =
+ dataSourceConfig.getRequired("data_source_config")
+
+ /**
+ * A list of graders for all eval runs in this group.
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is
+ * unexpectedly missing or null (e.g. if the server responded with an unexpected value).
+ */
+ fun testingCriteria(): List =
+ testingCriteria.getRequired("testing_criteria")
+
+ /**
+ * 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 API or the dashboard.
+ *
+ * Keys are strings with a maximum length of 64 characters. Values are strings with a
+ * maximum length of 512 characters.
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
+ * server responded with an unexpected value).
+ */
+ fun metadata(): Optional = metadata.getOptional("metadata")
+
+ /**
+ * The name of the evaluation.
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
+ * server responded with an unexpected value).
+ */
+ fun name(): Optional = name.getOptional("name")
+
+ /**
+ * Indicates whether the evaluation is shared with OpenAI.
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
+ * server responded with an unexpected value).
+ */
+ fun shareWithOpenAI(): Optional = shareWithOpenAI.getOptional("share_with_openai")
+
+ /**
+ * Returns the raw JSON value of [dataSourceConfig].
+ *
+ * Unlike [dataSourceConfig], this method doesn't throw if the JSON field has an unexpected
+ * type.
+ */
+ @JsonProperty("data_source_config")
+ @ExcludeMissing
+ fun _dataSourceConfig(): JsonField = dataSourceConfig
+
+ /**
+ * Returns the raw JSON value of [testingCriteria].
+ *
+ * Unlike [testingCriteria], this method doesn't throw if the JSON field has an unexpected
+ * type.
+ */
+ @JsonProperty("testing_criteria")
+ @ExcludeMissing
+ fun _testingCriteria(): JsonField> = testingCriteria
+
+ /**
+ * Returns the raw JSON value of [metadata].
+ *
+ * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type.
+ */
+ @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata
+
+ /**
+ * Returns the raw JSON value of [name].
+ *
+ * Unlike [name], this method doesn't throw if the JSON field has an unexpected type.
+ */
+ @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name
+
+ /**
+ * Returns the raw JSON value of [shareWithOpenAI].
+ *
+ * Unlike [shareWithOpenAI], this method doesn't throw if the JSON field has an unexpected
+ * type.
+ */
+ @JsonProperty("share_with_openai")
+ @ExcludeMissing
+ fun _shareWithOpenAI(): JsonField = shareWithOpenAI
+
+ @JsonAnySetter
+ private fun putAdditionalProperty(key: String, value: JsonValue) {
+ additionalProperties.put(key, value)
+ }
+
+ @JsonAnyGetter
+ @ExcludeMissing
+ fun _additionalProperties(): Map =
+ Collections.unmodifiableMap(additionalProperties)
+
+ fun toBuilder() = Builder().from(this)
+
+ companion object {
+
+ /**
+ * Returns a mutable builder for constructing an instance of [Body].
+ *
+ * The following fields are required:
+ * ```java
+ * .dataSourceConfig()
+ * .testingCriteria()
+ * ```
+ */
+ @JvmStatic fun builder() = Builder()
+ }
+
+ /** A builder for [Body]. */
+ class Builder internal constructor() {
+
+ private var dataSourceConfig: JsonField? = null
+ private var testingCriteria: JsonField>? = null
+ private var metadata: JsonField = JsonMissing.of()
+ private var name: JsonField = JsonMissing.of()
+ private var shareWithOpenAI: JsonField = JsonMissing.of()
+ private var additionalProperties: MutableMap = mutableMapOf()
+
+ @JvmSynthetic
+ internal fun from(body: Body) = apply {
+ dataSourceConfig = body.dataSourceConfig
+ testingCriteria = body.testingCriteria.map { it.toMutableList() }
+ metadata = body.metadata
+ name = body.name
+ shareWithOpenAI = body.shareWithOpenAI
+ additionalProperties = body.additionalProperties.toMutableMap()
+ }
+
+ /** The configuration for the data source used for the evaluation runs. */
+ fun dataSourceConfig(dataSourceConfig: DataSourceConfig) =
+ dataSourceConfig(JsonField.of(dataSourceConfig))
+
+ /**
+ * Sets [Builder.dataSourceConfig] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.dataSourceConfig] with a well-typed
+ * [DataSourceConfig] value instead. This method is primarily for setting the field to
+ * an undocumented or not yet supported value.
+ */
+ fun dataSourceConfig(dataSourceConfig: JsonField) = apply {
+ this.dataSourceConfig = dataSourceConfig
+ }
+
+ /** Alias for calling [dataSourceConfig] with `DataSourceConfig.ofCustom(custom)`. */
+ fun dataSourceConfig(custom: DataSourceConfig.Custom) =
+ dataSourceConfig(DataSourceConfig.ofCustom(custom))
+
+ /**
+ * Alias for calling [dataSourceConfig] with the following:
+ * ```java
+ * DataSourceConfig.Custom.builder()
+ * .itemSchema(itemSchema)
+ * .build()
+ * ```
+ */
+ fun customDataSourceConfig(itemSchema: DataSourceConfig.Custom.ItemSchema) =
+ dataSourceConfig(DataSourceConfig.Custom.builder().itemSchema(itemSchema).build())
+
+ /**
+ * Alias for calling [dataSourceConfig] with
+ * `DataSourceConfig.ofStoredCompletions(storedCompletions)`.
+ */
+ fun dataSourceConfig(storedCompletions: DataSourceConfig.StoredCompletions) =
+ dataSourceConfig(DataSourceConfig.ofStoredCompletions(storedCompletions))
+
+ /** A list of graders for all eval runs in this group. */
+ fun testingCriteria(testingCriteria: List) =
+ testingCriteria(JsonField.of(testingCriteria))
+
+ /**
+ * Sets [Builder.testingCriteria] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.testingCriteria] with a well-typed
+ * `List` value instead. This method is primarily for setting the
+ * field to an undocumented or not yet supported value.
+ */
+ fun testingCriteria(testingCriteria: JsonField>) = apply {
+ this.testingCriteria = testingCriteria.map { it.toMutableList() }
+ }
+
+ /**
+ * Adds a single [TestingCriterion] to [testingCriteria].
+ *
+ * @throws IllegalStateException if the field was previously set to a non-list.
+ */
+ fun addTestingCriterion(testingCriterion: TestingCriterion) = apply {
+ testingCriteria =
+ (testingCriteria ?: JsonField.of(mutableListOf())).also {
+ checkKnown("testingCriteria", it).add(testingCriterion)
+ }
+ }
+
+ /**
+ * Alias for calling [addTestingCriterion] with
+ * `TestingCriterion.ofLabelModel(labelModel)`.
+ */
+ fun addTestingCriterion(labelModel: TestingCriterion.LabelModel) =
+ addTestingCriterion(TestingCriterion.ofLabelModel(labelModel))
+
+ /**
+ * Alias for calling [addTestingCriterion] with
+ * `TestingCriterion.ofStringCheck(stringCheck)`.
+ */
+ fun addTestingCriterion(stringCheck: EvalStringCheckGrader) =
+ addTestingCriterion(TestingCriterion.ofStringCheck(stringCheck))
+
+ /**
+ * Alias for calling [addTestingCriterion] with
+ * `TestingCriterion.ofTextSimilarity(textSimilarity)`.
+ */
+ fun addTestingCriterion(textSimilarity: EvalTextSimilarityGrader) =
+ addTestingCriterion(TestingCriterion.ofTextSimilarity(textSimilarity))
+
+ /**
+ * 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 API or the dashboard.
+ *
+ * Keys are strings with a maximum length of 64 characters. Values are strings with a
+ * maximum length of 512 characters.
+ */
+ fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata))
+
+ /** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */
+ fun metadata(metadata: Optional) = metadata(metadata.getOrNull())
+
+ /**
+ * Sets [Builder.metadata] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.metadata] with a well-typed [Metadata] value
+ * instead. This method is primarily for setting the field to an undocumented or not yet
+ * supported value.
+ */
+ fun metadata(metadata: JsonField) = apply { this.metadata = metadata }
+
+ /** The name of the evaluation. */
+ fun name(name: String) = name(JsonField.of(name))
+
+ /**
+ * Sets [Builder.name] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.name] with a well-typed [String] value instead. This
+ * method is primarily for setting the field to an undocumented or not yet supported
+ * value.
+ */
+ fun name(name: JsonField) = apply { this.name = name }
+
+ /** Indicates whether the evaluation is shared with OpenAI. */
+ fun shareWithOpenAI(shareWithOpenAI: Boolean) =
+ shareWithOpenAI(JsonField.of(shareWithOpenAI))
+
+ /**
+ * Sets [Builder.shareWithOpenAI] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.shareWithOpenAI] with a well-typed [Boolean] value
+ * instead. This method is primarily for setting the field to an undocumented or not yet
+ * supported value.
+ */
+ fun shareWithOpenAI(shareWithOpenAI: JsonField) = apply {
+ this.shareWithOpenAI = shareWithOpenAI
+ }
+
+ fun additionalProperties(additionalProperties: Map) = apply {
+ this.additionalProperties.clear()
+ putAllAdditionalProperties(additionalProperties)
+ }
+
+ fun putAdditionalProperty(key: String, value: JsonValue) = apply {
+ additionalProperties.put(key, value)
+ }
+
+ fun putAllAdditionalProperties(additionalProperties: Map) = apply {
+ this.additionalProperties.putAll(additionalProperties)
+ }
+
+ fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) }
+
+ fun removeAllAdditionalProperties(keys: Set) = apply {
+ keys.forEach(::removeAdditionalProperty)
+ }
+
+ /**
+ * Returns an immutable instance of [Body].
+ *
+ * Further updates to this [Builder] will not mutate the returned instance.
+ *
+ * The following fields are required:
+ * ```java
+ * .dataSourceConfig()
+ * .testingCriteria()
+ * ```
+ *
+ * @throws IllegalStateException if any required field is unset.
+ */
+ fun build(): Body =
+ Body(
+ checkRequired("dataSourceConfig", dataSourceConfig),
+ checkRequired("testingCriteria", testingCriteria).map { it.toImmutable() },
+ metadata,
+ name,
+ shareWithOpenAI,
+ additionalProperties.toMutableMap(),
+ )
+ }
+
+ private var validated: Boolean = false
+
+ fun validate(): Body = apply {
+ if (validated) {
+ return@apply
+ }
+
+ dataSourceConfig().validate()
+ testingCriteria().forEach { it.validate() }
+ metadata().ifPresent { it.validate() }
+ name()
+ shareWithOpenAI()
+ 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 =
+ (dataSourceConfig.asKnown().getOrNull()?.validity() ?: 0) +
+ (testingCriteria.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) +
+ (metadata.asKnown().getOrNull()?.validity() ?: 0) +
+ (if (name.asKnown().isPresent) 1 else 0) +
+ (if (shareWithOpenAI.asKnown().isPresent) 1 else 0)
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return /* spotless:off */ other is Body && dataSourceConfig == other.dataSourceConfig && testingCriteria == other.testingCriteria && metadata == other.metadata && name == other.name && shareWithOpenAI == other.shareWithOpenAI && additionalProperties == other.additionalProperties /* spotless:on */
+ }
+
+ /* spotless:off */
+ private val hashCode: Int by lazy { Objects.hash(dataSourceConfig, testingCriteria, metadata, name, shareWithOpenAI, additionalProperties) }
+ /* spotless:on */
+
+ override fun hashCode(): Int = hashCode
+
+ override fun toString() =
+ "Body{dataSourceConfig=$dataSourceConfig, testingCriteria=$testingCriteria, metadata=$metadata, name=$name, shareWithOpenAI=$shareWithOpenAI, additionalProperties=$additionalProperties}"
+ }
+
+ /** The configuration for the data source used for the evaluation runs. */
+ @JsonDeserialize(using = DataSourceConfig.Deserializer::class)
+ @JsonSerialize(using = DataSourceConfig.Serializer::class)
+ class DataSourceConfig
+ private constructor(
+ private val custom: Custom? = null,
+ private val storedCompletions: StoredCompletions? = null,
+ private val _json: JsonValue? = null,
+ ) {
+
+ /**
+ * A CustomDataSourceConfig object that defines the schema for the data source used for the
+ * evaluation runs. This schema is used to define the shape of the data that will be:
+ * - Used to define your testing criteria and
+ * - What data is required when creating a run
+ */
+ fun custom(): Optional = Optional.ofNullable(custom)
+
+ /**
+ * A data source config which specifies the metadata property of your stored completions
+ * query. This is usually metadata like `usecase=chatbot` or `prompt-version=v2`, etc.
+ */
+ fun storedCompletions(): Optional =
+ Optional.ofNullable(storedCompletions)
+
+ fun isCustom(): Boolean = custom != null
+
+ fun isStoredCompletions(): Boolean = storedCompletions != null
+
+ /**
+ * A CustomDataSourceConfig object that defines the schema for the data source used for the
+ * evaluation runs. This schema is used to define the shape of the data that will be:
+ * - Used to define your testing criteria and
+ * - What data is required when creating a run
+ */
+ fun asCustom(): Custom = custom.getOrThrow("custom")
+
+ /**
+ * A data source config which specifies the metadata property of your stored completions
+ * query. This is usually metadata like `usecase=chatbot` or `prompt-version=v2`, etc.
+ */
+ fun asStoredCompletions(): StoredCompletions =
+ storedCompletions.getOrThrow("storedCompletions")
+
+ fun _json(): Optional = Optional.ofNullable(_json)
+
+ fun accept(visitor: Visitor): T =
+ when {
+ custom != null -> visitor.visitCustom(custom)
+ storedCompletions != null -> visitor.visitStoredCompletions(storedCompletions)
+ else -> visitor.unknown(_json)
+ }
+
+ private var validated: Boolean = false
+
+ fun validate(): DataSourceConfig = apply {
+ if (validated) {
+ return@apply
+ }
+
+ accept(
+ object : Visitor {
+ override fun visitCustom(custom: Custom) {
+ custom.validate()
+ }
+
+ override fun visitStoredCompletions(storedCompletions: StoredCompletions) {
+ storedCompletions.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 visitCustom(custom: Custom) = custom.validity()
+
+ override fun visitStoredCompletions(storedCompletions: StoredCompletions) =
+ storedCompletions.validity()
+
+ override fun unknown(json: JsonValue?) = 0
+ }
+ )
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return /* spotless:off */ other is DataSourceConfig && custom == other.custom && storedCompletions == other.storedCompletions /* spotless:on */
+ }
+
+ override fun hashCode(): Int = /* spotless:off */ Objects.hash(custom, storedCompletions) /* spotless:on */
+
+ override fun toString(): String =
+ when {
+ custom != null -> "DataSourceConfig{custom=$custom}"
+ storedCompletions != null ->
+ "DataSourceConfig{storedCompletions=$storedCompletions}"
+ _json != null -> "DataSourceConfig{_unknown=$_json}"
+ else -> throw IllegalStateException("Invalid DataSourceConfig")
+ }
+
+ companion object {
+
+ /**
+ * A CustomDataSourceConfig object that defines the schema for the data source used for
+ * the evaluation runs. This schema is used to define the shape of the data that will
+ * be:
+ * - Used to define your testing criteria and
+ * - What data is required when creating a run
+ */
+ @JvmStatic fun ofCustom(custom: Custom) = DataSourceConfig(custom = custom)
+
+ /**
+ * A data source config which specifies the metadata property of your stored completions
+ * query. This is usually metadata like `usecase=chatbot` or `prompt-version=v2`, etc.
+ */
+ @JvmStatic
+ fun ofStoredCompletions(storedCompletions: StoredCompletions) =
+ DataSourceConfig(storedCompletions = storedCompletions)
+ }
+
+ /**
+ * An interface that defines how to map each variant of [DataSourceConfig] to a value of
+ * type [T].
+ */
+ interface Visitor {
+
+ /**
+ * A CustomDataSourceConfig object that defines the schema for the data source used for
+ * the evaluation runs. This schema is used to define the shape of the data that will
+ * be:
+ * - Used to define your testing criteria and
+ * - What data is required when creating a run
+ */
+ fun visitCustom(custom: Custom): T
+
+ /**
+ * A data source config which specifies the metadata property of your stored completions
+ * query. This is usually metadata like `usecase=chatbot` or `prompt-version=v2`, etc.
+ */
+ fun visitStoredCompletions(storedCompletions: StoredCompletions): T
+
+ /**
+ * Maps an unknown variant of [DataSourceConfig] to a value of type [T].
+ *
+ * An instance of [DataSourceConfig] can contain an unknown variant if it was
+ * deserialized from data that doesn't match any known variant. For example, if the SDK
+ * is on an older version than the API, then the API may respond with new variants that
+ * the SDK is unaware of.
+ *
+ * @throws OpenAIInvalidDataException in the default implementation.
+ */
+ fun unknown(json: JsonValue?): T {
+ throw OpenAIInvalidDataException("Unknown DataSourceConfig: $json")
+ }
+ }
+
+ internal class Deserializer : BaseDeserializer(DataSourceConfig::class) {
+
+ override fun ObjectCodec.deserialize(node: JsonNode): DataSourceConfig {
+ val json = JsonValue.fromJsonNode(node)
+ val type = json.asObject().getOrNull()?.get("type")?.asString()?.getOrNull()
+
+ when (type) {
+ "custom" -> {
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ DataSourceConfig(custom = it, _json = json)
+ } ?: DataSourceConfig(_json = json)
+ }
+ "stored_completions" -> {
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ DataSourceConfig(storedCompletions = it, _json = json)
+ } ?: DataSourceConfig(_json = json)
+ }
+ }
+
+ return DataSourceConfig(_json = json)
+ }
+ }
+
+ internal class Serializer : BaseSerializer(DataSourceConfig::class) {
+
+ override fun serialize(
+ value: DataSourceConfig,
+ generator: JsonGenerator,
+ provider: SerializerProvider,
+ ) {
+ when {
+ value.custom != null -> generator.writeObject(value.custom)
+ value.storedCompletions != null ->
+ generator.writeObject(value.storedCompletions)
+ value._json != null -> generator.writeObject(value._json)
+ else -> throw IllegalStateException("Invalid DataSourceConfig")
+ }
+ }
+ }
+
+ /**
+ * A CustomDataSourceConfig object that defines the schema for the data source used for the
+ * evaluation runs. This schema is used to define the shape of the data that will be:
+ * - Used to define your testing criteria and
+ * - What data is required when creating a run
+ */
+ class Custom
+ private constructor(
+ private val itemSchema: JsonField,
+ private val type: JsonValue,
+ private val includeSampleSchema: JsonField,
+ private val additionalProperties: MutableMap,
+ ) {
+
+ @JsonCreator
+ private constructor(
+ @JsonProperty("item_schema")
+ @ExcludeMissing
+ itemSchema: JsonField = JsonMissing.of(),
+ @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(),
+ @JsonProperty("include_sample_schema")
+ @ExcludeMissing
+ includeSampleSchema: JsonField = JsonMissing.of(),
+ ) : this(itemSchema, type, includeSampleSchema, mutableMapOf())
+
+ /**
+ * The json schema for the run data source items.
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is
+ * unexpectedly missing or null (e.g. if the server responded with an unexpected
+ * value).
+ */
+ fun itemSchema(): ItemSchema = itemSchema.getRequired("item_schema")
+
+ /**
+ * The type of data source. Always `custom`.
+ *
+ * Expected to always return the following:
+ * ```java
+ * JsonValue.from("custom")
+ * ```
+ *
+ * However, this method can be useful for debugging and logging (e.g. if the server
+ * responded with an unexpected value).
+ */
+ @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type
+
+ /**
+ * Whether to include the sample schema in the data source.
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if
+ * the server responded with an unexpected value).
+ */
+ fun includeSampleSchema(): Optional =
+ includeSampleSchema.getOptional("include_sample_schema")
+
+ /**
+ * Returns the raw JSON value of [itemSchema].
+ *
+ * Unlike [itemSchema], this method doesn't throw if the JSON field has an unexpected
+ * type.
+ */
+ @JsonProperty("item_schema")
+ @ExcludeMissing
+ fun _itemSchema(): JsonField = itemSchema
+
+ /**
+ * Returns the raw JSON value of [includeSampleSchema].
+ *
+ * Unlike [includeSampleSchema], this method doesn't throw if the JSON field has an
+ * unexpected type.
+ */
+ @JsonProperty("include_sample_schema")
+ @ExcludeMissing
+ fun _includeSampleSchema(): JsonField = includeSampleSchema
+
+ @JsonAnySetter
+ private fun putAdditionalProperty(key: String, value: JsonValue) {
+ additionalProperties.put(key, value)
+ }
+
+ @JsonAnyGetter
+ @ExcludeMissing
+ fun _additionalProperties(): Map =
+ Collections.unmodifiableMap(additionalProperties)
+
+ fun toBuilder() = Builder().from(this)
+
+ companion object {
+
+ /**
+ * Returns a mutable builder for constructing an instance of [Custom].
+ *
+ * The following fields are required:
+ * ```java
+ * .itemSchema()
+ * ```
+ */
+ @JvmStatic fun builder() = Builder()
+ }
+
+ /** A builder for [Custom]. */
+ class Builder internal constructor() {
+
+ private var itemSchema: JsonField? = null
+ private var type: JsonValue = JsonValue.from("custom")
+ private var includeSampleSchema: JsonField = JsonMissing.of()
+ private var additionalProperties: MutableMap = mutableMapOf()
+
+ @JvmSynthetic
+ internal fun from(custom: Custom) = apply {
+ itemSchema = custom.itemSchema
+ type = custom.type
+ includeSampleSchema = custom.includeSampleSchema
+ additionalProperties = custom.additionalProperties.toMutableMap()
+ }
+
+ /** The json schema for the run data source items. */
+ fun itemSchema(itemSchema: ItemSchema) = itemSchema(JsonField.of(itemSchema))
+
+ /**
+ * Sets [Builder.itemSchema] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.itemSchema] with a well-typed [ItemSchema] value
+ * instead. This method is primarily for setting the field to an undocumented or not
+ * yet supported value.
+ */
+ fun itemSchema(itemSchema: JsonField) = apply {
+ this.itemSchema = itemSchema
+ }
+
+ /**
+ * Sets the field to an arbitrary JSON value.
+ *
+ * It is usually unnecessary to call this method because the field defaults to the
+ * following:
+ * ```java
+ * JsonValue.from("custom")
+ * ```
+ *
+ * This method is primarily for setting the field to an undocumented or not yet
+ * supported value.
+ */
+ fun type(type: JsonValue) = apply { this.type = type }
+
+ /** Whether to include the sample schema in the data source. */
+ fun includeSampleSchema(includeSampleSchema: Boolean) =
+ includeSampleSchema(JsonField.of(includeSampleSchema))
+
+ /**
+ * Sets [Builder.includeSampleSchema] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.includeSampleSchema] with a well-typed [Boolean]
+ * value instead. This method is primarily for setting the field to an undocumented
+ * or not yet supported value.
+ */
+ fun includeSampleSchema(includeSampleSchema: JsonField) = apply {
+ this.includeSampleSchema = includeSampleSchema
+ }
+
+ fun additionalProperties(additionalProperties: Map) = apply {
+ this.additionalProperties.clear()
+ putAllAdditionalProperties(additionalProperties)
+ }
+
+ fun putAdditionalProperty(key: String, value: JsonValue) = apply {
+ additionalProperties.put(key, value)
+ }
+
+ fun putAllAdditionalProperties(additionalProperties: Map) =
+ apply {
+ this.additionalProperties.putAll(additionalProperties)
+ }
+
+ fun removeAdditionalProperty(key: String) = apply {
+ additionalProperties.remove(key)
+ }
+
+ fun removeAllAdditionalProperties(keys: Set) = apply {
+ keys.forEach(::removeAdditionalProperty)
+ }
+
+ /**
+ * Returns an immutable instance of [Custom].
+ *
+ * Further updates to this [Builder] will not mutate the returned instance.
+ *
+ * The following fields are required:
+ * ```java
+ * .itemSchema()
+ * ```
+ *
+ * @throws IllegalStateException if any required field is unset.
+ */
+ fun build(): Custom =
+ Custom(
+ checkRequired("itemSchema", itemSchema),
+ type,
+ includeSampleSchema,
+ additionalProperties.toMutableMap(),
+ )
+ }
+
+ private var validated: Boolean = false
+
+ fun validate(): Custom = apply {
+ if (validated) {
+ return@apply
+ }
+
+ itemSchema().validate()
+ _type().let {
+ if (it != JsonValue.from("custom")) {
+ throw OpenAIInvalidDataException("'type' is invalid, received $it")
+ }
+ }
+ includeSampleSchema()
+ 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 =
+ (itemSchema.asKnown().getOrNull()?.validity() ?: 0) +
+ type.let { if (it == JsonValue.from("custom")) 1 else 0 } +
+ (if (includeSampleSchema.asKnown().isPresent) 1 else 0)
+
+ /** The json schema for the run data source items. */
+ class ItemSchema
+ @JsonCreator
+ private constructor(
+ @com.fasterxml.jackson.annotation.JsonValue
+ private val additionalProperties: Map
+ ) {
+
+ @JsonAnyGetter
+ @ExcludeMissing
+ fun _additionalProperties(): Map = additionalProperties
+
+ fun toBuilder() = Builder().from(this)
+
+ companion object {
+
+ /** Returns a mutable builder for constructing an instance of [ItemSchema]. */
+ @JvmStatic fun builder() = Builder()
+ }
+
+ /** A builder for [ItemSchema]. */
+ class Builder internal constructor() {
+
+ private var additionalProperties: MutableMap = mutableMapOf()
+
+ @JvmSynthetic
+ internal fun from(itemSchema: ItemSchema) = apply {
+ additionalProperties = itemSchema.additionalProperties.toMutableMap()
+ }
+
+ fun additionalProperties(additionalProperties: Map) = apply {
+ this.additionalProperties.clear()
+ putAllAdditionalProperties(additionalProperties)
+ }
+
+ fun putAdditionalProperty(key: String, value: JsonValue) = apply {
+ additionalProperties.put(key, value)
+ }
+
+ fun putAllAdditionalProperties(additionalProperties: Map) =
+ apply {
+ this.additionalProperties.putAll(additionalProperties)
+ }
+
+ fun removeAdditionalProperty(key: String) = apply {
+ additionalProperties.remove(key)
+ }
+
+ fun removeAllAdditionalProperties(keys: Set) = apply {
+ keys.forEach(::removeAdditionalProperty)
+ }
+
+ /**
+ * Returns an immutable instance of [ItemSchema].
+ *
+ * Further updates to this [Builder] will not mutate the returned instance.
+ */
+ fun build(): ItemSchema = ItemSchema(additionalProperties.toImmutable())
+ }
+
+ private var validated: Boolean = false
+
+ fun validate(): ItemSchema = apply {
+ if (validated) {
+ return@apply
+ }
+
+ 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
+ }
+
+ return /* spotless:off */ other is ItemSchema && additionalProperties == other.additionalProperties /* spotless:on */
+ }
+
+ /* spotless:off */
+ private val hashCode: Int by lazy { Objects.hash(additionalProperties) }
+ /* spotless:on */
+
+ override fun hashCode(): Int = hashCode
+
+ override fun toString() = "ItemSchema{additionalProperties=$additionalProperties}"
+ }
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return /* spotless:off */ other is Custom && itemSchema == other.itemSchema && type == other.type && includeSampleSchema == other.includeSampleSchema && additionalProperties == other.additionalProperties /* spotless:on */
+ }
+
+ /* spotless:off */
+ private val hashCode: Int by lazy { Objects.hash(itemSchema, type, includeSampleSchema, additionalProperties) }
+ /* spotless:on */
+
+ override fun hashCode(): Int = hashCode
+
+ override fun toString() =
+ "Custom{itemSchema=$itemSchema, type=$type, includeSampleSchema=$includeSampleSchema, additionalProperties=$additionalProperties}"
+ }
+
+ /**
+ * A data source config which specifies the metadata property of your stored completions
+ * query. This is usually metadata like `usecase=chatbot` or `prompt-version=v2`, etc.
+ */
+ class StoredCompletions
+ private constructor(
+ private val type: JsonValue,
+ private val metadata: JsonField,
+ private val additionalProperties: MutableMap,
+ ) {
+
+ @JsonCreator
+ private constructor(
+ @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(),
+ @JsonProperty("metadata")
+ @ExcludeMissing
+ metadata: JsonField = JsonMissing.of(),
+ ) : this(type, metadata, mutableMapOf())
+
+ /**
+ * The type of data source. Always `stored_completions`.
+ *
+ * Expected to always return the following:
+ * ```java
+ * JsonValue.from("stored_completions")
+ * ```
+ *
+ * However, this method can be useful for debugging and logging (e.g. if the server
+ * responded with an unexpected value).
+ */
+ @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type
+
+ /**
+ * 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 API or the dashboard.
+ *
+ * Keys are strings with a maximum length of 64 characters. Values are strings with a
+ * maximum length of 512 characters.
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if
+ * the server responded with an unexpected value).
+ */
+ fun metadata(): Optional = metadata.getOptional("metadata")
+
+ /**
+ * Returns the raw JSON value of [metadata].
+ *
+ * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected
+ * type.
+ */
+ @JsonProperty("metadata")
+ @ExcludeMissing
+ fun _metadata(): JsonField = metadata
+
+ @JsonAnySetter
+ private fun putAdditionalProperty(key: String, value: JsonValue) {
+ additionalProperties.put(key, value)
+ }
+
+ @JsonAnyGetter
+ @ExcludeMissing
+ fun _additionalProperties(): Map =
+ Collections.unmodifiableMap(additionalProperties)
+
+ fun toBuilder() = Builder().from(this)
+
+ companion object {
+
+ /**
+ * Returns a mutable builder for constructing an instance of [StoredCompletions].
+ */
+ @JvmStatic fun builder() = Builder()
+ }
+
+ /** A builder for [StoredCompletions]. */
+ class Builder internal constructor() {
+
+ private var type: JsonValue = JsonValue.from("stored_completions")
+ private var metadata: JsonField = JsonMissing.of()
+ private var additionalProperties: MutableMap = mutableMapOf()
+
+ @JvmSynthetic
+ internal fun from(storedCompletions: StoredCompletions) = apply {
+ type = storedCompletions.type
+ metadata = storedCompletions.metadata
+ additionalProperties = storedCompletions.additionalProperties.toMutableMap()
+ }
+
+ /**
+ * Sets the field to an arbitrary JSON value.
+ *
+ * It is usually unnecessary to call this method because the field defaults to the
+ * following:
+ * ```java
+ * JsonValue.from("stored_completions")
+ * ```
+ *
+ * This method is primarily for setting the field to an undocumented or not yet
+ * supported value.
+ */
+ fun type(type: JsonValue) = apply { this.type = type }
+
+ /**
+ * 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 API or the dashboard.
+ *
+ * Keys are strings with a maximum length of 64 characters. Values are strings with
+ * a maximum length of 512 characters.
+ */
+ fun metadata(metadata: Metadata?) = metadata(JsonField.ofNullable(metadata))
+
+ /** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */
+ fun metadata(metadata: Optional) = metadata(metadata.getOrNull())
+
+ /**
+ * Sets [Builder.metadata] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.metadata] with a well-typed [Metadata] value
+ * instead. This method is primarily for setting the field to an undocumented or not
+ * yet supported value.
+ */
+ fun metadata(metadata: JsonField) = apply { this.metadata = metadata }
+
+ fun additionalProperties(additionalProperties: Map) = apply {
+ this.additionalProperties.clear()
+ putAllAdditionalProperties(additionalProperties)
+ }
+
+ fun putAdditionalProperty(key: String, value: JsonValue) = apply {
+ additionalProperties.put(key, value)
+ }
+
+ fun putAllAdditionalProperties(additionalProperties: Map) =
+ apply {
+ this.additionalProperties.putAll(additionalProperties)
+ }
+
+ fun removeAdditionalProperty(key: String) = apply {
+ additionalProperties.remove(key)
+ }
+
+ fun removeAllAdditionalProperties(keys: Set) = apply {
+ keys.forEach(::removeAdditionalProperty)
+ }
+
+ /**
+ * Returns an immutable instance of [StoredCompletions].
+ *
+ * Further updates to this [Builder] will not mutate the returned instance.
+ */
+ fun build(): StoredCompletions =
+ StoredCompletions(type, metadata, additionalProperties.toMutableMap())
+ }
+
+ private var validated: Boolean = false
+
+ fun validate(): StoredCompletions = apply {
+ if (validated) {
+ return@apply
+ }
+
+ _type().let {
+ if (it != JsonValue.from("stored_completions")) {
+ throw OpenAIInvalidDataException("'type' is invalid, received $it")
+ }
+ }
+ 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 =
+ type.let { if (it == JsonValue.from("stored_completions")) 1 else 0 } +
+ (metadata.asKnown().getOrNull()?.validity() ?: 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 API or the dashboard.
+ *
+ * Keys are strings with a maximum length of 64 characters. Values are strings with a
+ * maximum length of 512 characters.
+ */
+ class Metadata
+ @JsonCreator
+ private constructor(
+ @com.fasterxml.jackson.annotation.JsonValue
+ private val additionalProperties: Map
+ ) {
+
+ @JsonAnyGetter
+ @ExcludeMissing
+ fun _additionalProperties(): Map = additionalProperties
+
+ fun toBuilder() = Builder().from(this)
+
+ companion object {
+
+ /** Returns a mutable builder for constructing an instance of [Metadata]. */
+ @JvmStatic fun builder() = Builder()
+ }
+
+ /** A builder for [Metadata]. */
+ class Builder internal constructor() {
+
+ private var additionalProperties: MutableMap = mutableMapOf()
+
+ @JvmSynthetic
+ internal fun from(metadata: Metadata) = apply {
+ additionalProperties = metadata.additionalProperties.toMutableMap()
+ }
+
+ fun additionalProperties(additionalProperties: Map) = apply {
+ this.additionalProperties.clear()
+ putAllAdditionalProperties(additionalProperties)
+ }
+
+ fun putAdditionalProperty(key: String, value: JsonValue) = apply {
+ additionalProperties.put(key, value)
+ }
+
+ fun putAllAdditionalProperties(additionalProperties: Map) =
+ apply {
+ this.additionalProperties.putAll(additionalProperties)
+ }
+
+ fun removeAdditionalProperty(key: String) = apply {
+ additionalProperties.remove(key)
+ }
+
+ fun removeAllAdditionalProperties(keys: Set) = apply {
+ keys.forEach(::removeAdditionalProperty)
+ }
+
+ /**
+ * Returns an immutable instance of [Metadata].
+ *
+ * Further updates to this [Builder] will not mutate the returned instance.
+ */
+ fun build(): Metadata = Metadata(additionalProperties.toImmutable())
+ }
+
+ private var validated: Boolean = false
+
+ fun validate(): Metadata = apply {
+ if (validated) {
+ return@apply
+ }
+
+ 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
+ }
+
+ return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */
+ }
+
+ /* spotless:off */
+ private val hashCode: Int by lazy { Objects.hash(additionalProperties) }
+ /* spotless:on */
+
+ override fun hashCode(): Int = hashCode
+
+ override fun toString() = "Metadata{additionalProperties=$additionalProperties}"
+ }
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return /* spotless:off */ other is StoredCompletions && type == other.type && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */
+ }
+
+ /* spotless:off */
+ private val hashCode: Int by lazy { Objects.hash(type, metadata, additionalProperties) }
+ /* spotless:on */
+
+ override fun hashCode(): Int = hashCode
+
+ override fun toString() =
+ "StoredCompletions{type=$type, metadata=$metadata, additionalProperties=$additionalProperties}"
+ }
+ }
+
+ /**
+ * A LabelModelGrader object which uses a model to assign labels to each item in the evaluation.
+ */
+ @JsonDeserialize(using = TestingCriterion.Deserializer::class)
+ @JsonSerialize(using = TestingCriterion.Serializer::class)
+ class TestingCriterion
+ private constructor(
+ private val labelModel: LabelModel? = null,
+ private val stringCheck: EvalStringCheckGrader? = null,
+ private val textSimilarity: EvalTextSimilarityGrader? = null,
+ private val _json: JsonValue? = null,
+ ) {
+
+ /**
+ * A LabelModelGrader object which uses a model to assign labels to each item in the
+ * evaluation.
+ */
+ fun labelModel(): Optional = Optional.ofNullable(labelModel)
+
+ /**
+ * A StringCheckGrader object that performs a string comparison between input and reference
+ * using a specified operation.
+ */
+ fun stringCheck(): Optional = Optional.ofNullable(stringCheck)
+
+ /** A TextSimilarityGrader object which grades text based on similarity metrics. */
+ fun textSimilarity(): Optional =
+ Optional.ofNullable(textSimilarity)
+
+ fun isLabelModel(): Boolean = labelModel != null
+
+ fun isStringCheck(): Boolean = stringCheck != null
+
+ fun isTextSimilarity(): Boolean = textSimilarity != null
+
+ /**
+ * A LabelModelGrader object which uses a model to assign labels to each item in the
+ * evaluation.
+ */
+ fun asLabelModel(): LabelModel = labelModel.getOrThrow("labelModel")
+
+ /**
+ * A StringCheckGrader object that performs a string comparison between input and reference
+ * using a specified operation.
+ */
+ fun asStringCheck(): EvalStringCheckGrader = stringCheck.getOrThrow("stringCheck")
+
+ /** A TextSimilarityGrader object which grades text based on similarity metrics. */
+ fun asTextSimilarity(): EvalTextSimilarityGrader =
+ textSimilarity.getOrThrow("textSimilarity")
+
+ fun _json(): Optional = Optional.ofNullable(_json)
+
+ fun accept(visitor: Visitor): T =
+ when {
+ labelModel != null -> visitor.visitLabelModel(labelModel)
+ stringCheck != null -> visitor.visitStringCheck(stringCheck)
+ textSimilarity != null -> visitor.visitTextSimilarity(textSimilarity)
+ else -> visitor.unknown(_json)
+ }
+
+ private var validated: Boolean = false
+
+ fun validate(): TestingCriterion = apply {
+ if (validated) {
+ return@apply
+ }
+
+ accept(
+ object : Visitor {
+ override fun visitLabelModel(labelModel: LabelModel) {
+ labelModel.validate()
+ }
+
+ override fun visitStringCheck(stringCheck: EvalStringCheckGrader) {
+ stringCheck.validate()
+ }
+
+ override fun visitTextSimilarity(textSimilarity: EvalTextSimilarityGrader) {
+ textSimilarity.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 visitLabelModel(labelModel: LabelModel) = labelModel.validity()
+
+ override fun visitStringCheck(stringCheck: EvalStringCheckGrader) =
+ stringCheck.validity()
+
+ override fun visitTextSimilarity(textSimilarity: EvalTextSimilarityGrader) =
+ textSimilarity.validity()
+
+ override fun unknown(json: JsonValue?) = 0
+ }
+ )
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return /* spotless:off */ other is TestingCriterion && labelModel == other.labelModel && stringCheck == other.stringCheck && textSimilarity == other.textSimilarity /* spotless:on */
+ }
+
+ override fun hashCode(): Int = /* spotless:off */ Objects.hash(labelModel, stringCheck, textSimilarity) /* spotless:on */
+
+ override fun toString(): String =
+ when {
+ labelModel != null -> "TestingCriterion{labelModel=$labelModel}"
+ stringCheck != null -> "TestingCriterion{stringCheck=$stringCheck}"
+ textSimilarity != null -> "TestingCriterion{textSimilarity=$textSimilarity}"
+ _json != null -> "TestingCriterion{_unknown=$_json}"
+ else -> throw IllegalStateException("Invalid TestingCriterion")
+ }
+
+ companion object {
+
+ /**
+ * A LabelModelGrader object which uses a model to assign labels to each item in the
+ * evaluation.
+ */
+ @JvmStatic
+ fun ofLabelModel(labelModel: LabelModel) = TestingCriterion(labelModel = labelModel)
+
+ /**
+ * A StringCheckGrader object that performs a string comparison between input and
+ * reference using a specified operation.
+ */
+ @JvmStatic
+ fun ofStringCheck(stringCheck: EvalStringCheckGrader) =
+ TestingCriterion(stringCheck = stringCheck)
+
+ /** A TextSimilarityGrader object which grades text based on similarity metrics. */
+ @JvmStatic
+ fun ofTextSimilarity(textSimilarity: EvalTextSimilarityGrader) =
+ TestingCriterion(textSimilarity = textSimilarity)
+ }
+
+ /**
+ * An interface that defines how to map each variant of [TestingCriterion] to a value of
+ * type [T].
+ */
+ interface Visitor {
+
+ /**
+ * A LabelModelGrader object which uses a model to assign labels to each item in the
+ * evaluation.
+ */
+ fun visitLabelModel(labelModel: LabelModel): T
+
+ /**
+ * A StringCheckGrader object that performs a string comparison between input and
+ * reference using a specified operation.
+ */
+ fun visitStringCheck(stringCheck: EvalStringCheckGrader): T
+
+ /** A TextSimilarityGrader object which grades text based on similarity metrics. */
+ fun visitTextSimilarity(textSimilarity: EvalTextSimilarityGrader): T
+
+ /**
+ * Maps an unknown variant of [TestingCriterion] to a value of type [T].
+ *
+ * An instance of [TestingCriterion] can contain an unknown variant if it was
+ * deserialized from data that doesn't match any known variant. For example, if the SDK
+ * is on an older version than the API, then the API may respond with new variants that
+ * the SDK is unaware of.
+ *
+ * @throws OpenAIInvalidDataException in the default implementation.
+ */
+ fun unknown(json: JsonValue?): T {
+ throw OpenAIInvalidDataException("Unknown TestingCriterion: $json")
+ }
+ }
+
+ internal class Deserializer : BaseDeserializer(TestingCriterion::class) {
+
+ override fun ObjectCodec.deserialize(node: JsonNode): TestingCriterion {
+ val json = JsonValue.fromJsonNode(node)
+ val type = json.asObject().getOrNull()?.get("type")?.asString()?.getOrNull()
+
+ when (type) {
+ "label_model" -> {
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ TestingCriterion(labelModel = it, _json = json)
+ } ?: TestingCriterion(_json = json)
+ }
+ "string_check" -> {
+ return tryDeserialize(node, jacksonTypeRef())?.let {
+ TestingCriterion(stringCheck = it, _json = json)
+ } ?: TestingCriterion(_json = json)
+ }
+ "text_similarity" -> {
+ return tryDeserialize(node, jacksonTypeRef())
+ ?.let { TestingCriterion(textSimilarity = it, _json = json) }
+ ?: TestingCriterion(_json = json)
+ }
+ }
+
+ return TestingCriterion(_json = json)
+ }
+ }
+
+ internal class Serializer : BaseSerializer(TestingCriterion::class) {
+
+ override fun serialize(
+ value: TestingCriterion,
+ generator: JsonGenerator,
+ provider: SerializerProvider,
+ ) {
+ when {
+ value.labelModel != null -> generator.writeObject(value.labelModel)
+ value.stringCheck != null -> generator.writeObject(value.stringCheck)
+ value.textSimilarity != null -> generator.writeObject(value.textSimilarity)
+ value._json != null -> generator.writeObject(value._json)
+ else -> throw IllegalStateException("Invalid TestingCriterion")
+ }
+ }
+ }
+
+ /**
+ * A LabelModelGrader object which uses a model to assign labels to each item in the
+ * evaluation.
+ */
+ class LabelModel
+ private constructor(
+ private val input: JsonField>,
+ private val labels: JsonField>,
+ private val model: JsonField,
+ private val name: JsonField,
+ private val passingLabels: JsonField>,
+ private val type: JsonValue,
+ private val additionalProperties: MutableMap,
+ ) {
+
+ @JsonCreator
+ private constructor(
+ @JsonProperty("input")
+ @ExcludeMissing
+ input: JsonField> = JsonMissing.of(),
+ @JsonProperty("labels")
+ @ExcludeMissing
+ labels: JsonField> = JsonMissing.of(),
+ @JsonProperty("model") @ExcludeMissing model: JsonField = JsonMissing.of(),
+ @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(),
+ @JsonProperty("passing_labels")
+ @ExcludeMissing
+ passingLabels: JsonField> = JsonMissing.of(),
+ @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(),
+ ) : this(input, labels, model, name, passingLabels, type, mutableMapOf())
+
+ /**
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is
+ * unexpectedly missing or null (e.g. if the server responded with an unexpected
+ * value).
+ */
+ fun input(): List = input.getRequired("input")
+
+ /**
+ * The labels to classify to each item in the evaluation.
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is
+ * unexpectedly missing or null (e.g. if the server responded with an unexpected
+ * value).
+ */
+ fun labels(): List = labels.getRequired("labels")
+
+ /**
+ * The model to use for the evaluation. Must support structured outputs.
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is
+ * unexpectedly missing or null (e.g. if the server responded with an unexpected
+ * value).
+ */
+ fun model(): String = model.getRequired("model")
+
+ /**
+ * The name of the grader.
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is
+ * unexpectedly missing or null (e.g. if the server responded with an unexpected
+ * value).
+ */
+ fun name(): String = name.getRequired("name")
+
+ /**
+ * The labels that indicate a passing result. Must be a subset of labels.
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is
+ * unexpectedly missing or null (e.g. if the server responded with an unexpected
+ * value).
+ */
+ fun passingLabels(): List = passingLabels.getRequired("passing_labels")
+
+ /**
+ * The object type, which is always `label_model`.
+ *
+ * Expected to always return the following:
+ * ```java
+ * JsonValue.from("label_model")
+ * ```
+ *
+ * However, this method can be useful for debugging and logging (e.g. if the server
+ * responded with an unexpected value).
+ */
+ @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type
+
+ /**
+ * Returns the raw JSON value of [input].
+ *
+ * Unlike [input], this method doesn't throw if the JSON field has an unexpected type.
+ */
+ @JsonProperty("input") @ExcludeMissing fun _input(): JsonField> = input
+
+ /**
+ * Returns the raw JSON value of [labels].
+ *
+ * Unlike [labels], this method doesn't throw if the JSON field has an unexpected type.
+ */
+ @JsonProperty("labels") @ExcludeMissing fun _labels(): JsonField> = labels
+
+ /**
+ * Returns the raw JSON value of [model].
+ *
+ * Unlike [model], this method doesn't throw if the JSON field has an unexpected type.
+ */
+ @JsonProperty("model") @ExcludeMissing fun _model(): JsonField = model
+
+ /**
+ * Returns the raw JSON value of [name].
+ *
+ * Unlike [name], this method doesn't throw if the JSON field has an unexpected type.
+ */
+ @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name
+
+ /**
+ * Returns the raw JSON value of [passingLabels].
+ *
+ * Unlike [passingLabels], this method doesn't throw if the JSON field has an unexpected
+ * type.
+ */
+ @JsonProperty("passing_labels")
+ @ExcludeMissing
+ fun _passingLabels(): JsonField> = passingLabels
+
+ @JsonAnySetter
+ private fun putAdditionalProperty(key: String, value: JsonValue) {
+ additionalProperties.put(key, value)
+ }
+
+ @JsonAnyGetter
+ @ExcludeMissing
+ fun _additionalProperties(): Map =
+ Collections.unmodifiableMap(additionalProperties)
+
+ fun toBuilder() = Builder().from(this)
+
+ companion object {
+
+ /**
+ * Returns a mutable builder for constructing an instance of [LabelModel].
+ *
+ * The following fields are required:
+ * ```java
+ * .input()
+ * .labels()
+ * .model()
+ * .name()
+ * .passingLabels()
+ * ```
+ */
+ @JvmStatic fun builder() = Builder()
+ }
+
+ /** A builder for [LabelModel]. */
+ class Builder internal constructor() {
+
+ private var input: JsonField>? = null
+ private var labels: JsonField>? = null
+ private var model: JsonField? = null
+ private var name: JsonField? = null
+ private var passingLabels: JsonField>? = null
+ private var type: JsonValue = JsonValue.from("label_model")
+ private var additionalProperties: MutableMap = mutableMapOf()
+
+ @JvmSynthetic
+ internal fun from(labelModel: LabelModel) = apply {
+ input = labelModel.input.map { it.toMutableList() }
+ labels = labelModel.labels.map { it.toMutableList() }
+ model = labelModel.model
+ name = labelModel.name
+ passingLabels = labelModel.passingLabels.map { it.toMutableList() }
+ type = labelModel.type
+ additionalProperties = labelModel.additionalProperties.toMutableMap()
+ }
+
+ fun input(input: List) = input(JsonField.of(input))
+
+ /**
+ * Sets [Builder.input] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.input] with a well-typed `List` value
+ * instead. This method is primarily for setting the field to an undocumented or not
+ * yet supported value.
+ */
+ fun input(input: JsonField>) = apply {
+ this.input = input.map { it.toMutableList() }
+ }
+
+ /**
+ * Adds a single [Input] to [Builder.input].
+ *
+ * @throws IllegalStateException if the field was previously set to a non-list.
+ */
+ fun addInput(input: Input) = apply {
+ this.input =
+ (this.input ?: JsonField.of(mutableListOf())).also {
+ checkKnown("input", it).add(input)
+ }
+ }
+
+ /**
+ * Alias for calling [addInput] with
+ * `Input.ofSimpleInputMessage(simpleInputMessage)`.
+ */
+ fun addInput(simpleInputMessage: Input.SimpleInputMessage) =
+ addInput(Input.ofSimpleInputMessage(simpleInputMessage))
+
+ /** Alias for calling [addInput] with `Input.ofMessage(message)`. */
+ fun addInput(message: Input.InputMessage) = addInput(Input.ofMessage(message))
+
+ /** Alias for calling [addInput] with `Input.ofOutputMessage(outputMessage)`. */
+ fun addInput(outputMessage: Input.OutputMessage) =
+ addInput(Input.ofOutputMessage(outputMessage))
+
+ /** The labels to classify to each item in the evaluation. */
+ fun labels(labels: List) = labels(JsonField.of(labels))
+
+ /**
+ * Sets [Builder.labels] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.labels] with a well-typed `List` value
+ * instead. This method is primarily for setting the field to an undocumented or not
+ * yet supported value.
+ */
+ fun labels(labels: JsonField>) = apply {
+ this.labels = labels.map { it.toMutableList() }
+ }
+
+ /**
+ * Adds a single [String] to [labels].
+ *
+ * @throws IllegalStateException if the field was previously set to a non-list.
+ */
+ fun addLabel(label: String) = apply {
+ labels =
+ (labels ?: JsonField.of(mutableListOf())).also {
+ checkKnown("labels", it).add(label)
+ }
+ }
+
+ /** The model to use for the evaluation. Must support structured outputs. */
+ fun model(model: String) = model(JsonField.of(model))
+
+ /**
+ * Sets [Builder.model] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.model] with a well-typed [String] value instead.
+ * This method is primarily for setting the field to an undocumented or not yet
+ * supported value.
+ */
+ fun model(model: JsonField) = apply { this.model = model }
+
+ /** The name of the grader. */
+ fun name(name: String) = name(JsonField.of(name))
+
+ /**
+ * Sets [Builder.name] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.name] with a well-typed [String] value instead.
+ * This method is primarily for setting the field to an undocumented or not yet
+ * supported value.
+ */
+ fun name(name: JsonField) = apply { this.name = name }
+
+ /** The labels that indicate a passing result. Must be a subset of labels. */
+ fun passingLabels(passingLabels: List) =
+ passingLabels(JsonField.of(passingLabels))
+
+ /**
+ * Sets [Builder.passingLabels] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.passingLabels] with a well-typed `List`
+ * value instead. This method is primarily for setting the field to an undocumented
+ * or not yet supported value.
+ */
+ fun passingLabels(passingLabels: JsonField>) = apply {
+ this.passingLabels = passingLabels.map { it.toMutableList() }
+ }
+
+ /**
+ * Adds a single [String] to [passingLabels].
+ *
+ * @throws IllegalStateException if the field was previously set to a non-list.
+ */
+ fun addPassingLabel(passingLabel: String) = apply {
+ passingLabels =
+ (passingLabels ?: JsonField.of(mutableListOf())).also {
+ checkKnown("passingLabels", it).add(passingLabel)
+ }
+ }
+
+ /**
+ * Sets the field to an arbitrary JSON value.
+ *
+ * It is usually unnecessary to call this method because the field defaults to the
+ * following:
+ * ```java
+ * JsonValue.from("label_model")
+ * ```
+ *
+ * This method is primarily for setting the field to an undocumented or not yet
+ * supported value.
+ */
+ fun type(type: JsonValue) = apply { this.type = type }
+
+ fun additionalProperties(additionalProperties: Map) = apply {
+ this.additionalProperties.clear()
+ putAllAdditionalProperties(additionalProperties)
+ }
+
+ fun putAdditionalProperty(key: String, value: JsonValue) = apply {
+ additionalProperties.put(key, value)
+ }
+
+ fun putAllAdditionalProperties(additionalProperties: Map) =
+ apply {
+ this.additionalProperties.putAll(additionalProperties)
+ }
+
+ fun removeAdditionalProperty(key: String) = apply {
+ additionalProperties.remove(key)
+ }
+
+ fun removeAllAdditionalProperties(keys: Set) = apply {
+ keys.forEach(::removeAdditionalProperty)
+ }
+
+ /**
+ * Returns an immutable instance of [LabelModel].
+ *
+ * Further updates to this [Builder] will not mutate the returned instance.
+ *
+ * The following fields are required:
+ * ```java
+ * .input()
+ * .labels()
+ * .model()
+ * .name()
+ * .passingLabels()
+ * ```
+ *
+ * @throws IllegalStateException if any required field is unset.
+ */
+ fun build(): LabelModel =
+ LabelModel(
+ checkRequired("input", input).map { it.toImmutable() },
+ checkRequired("labels", labels).map { it.toImmutable() },
+ checkRequired("model", model),
+ checkRequired("name", name),
+ checkRequired("passingLabels", passingLabels).map { it.toImmutable() },
+ type,
+ additionalProperties.toMutableMap(),
+ )
+ }
+
+ private var validated: Boolean = false
+
+ fun validate(): LabelModel = apply {
+ if (validated) {
+ return@apply
+ }
+
+ input().forEach { it.validate() }
+ labels()
+ model()
+ name()
+ passingLabels()
+ _type().let {
+ if (it != JsonValue.from("label_model")) {
+ throw OpenAIInvalidDataException("'type' is invalid, received $it")
+ }
+ }
+ 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 =
+ (input.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) +
+ (labels.asKnown().getOrNull()?.size ?: 0) +
+ (if (model.asKnown().isPresent) 1 else 0) +
+ (if (name.asKnown().isPresent) 1 else 0) +
+ (passingLabels.asKnown().getOrNull()?.size ?: 0) +
+ type.let { if (it == JsonValue.from("label_model")) 1 else 0 }
+
+ @JsonDeserialize(using = Input.Deserializer::class)
+ @JsonSerialize(using = Input.Serializer::class)
+ class Input
+ private constructor(
+ private val simpleInputMessage: SimpleInputMessage? = null,
+ private val message: InputMessage? = null,
+ private val outputMessage: OutputMessage? = null,
+ private val _json: JsonValue? = null,
+ ) {
+
+ fun simpleInputMessage(): Optional =
+ Optional.ofNullable(simpleInputMessage)
+
+ fun message(): Optional = Optional.ofNullable(message)
+
+ fun outputMessage(): Optional = Optional.ofNullable(outputMessage)
+
+ fun isSimpleInputMessage(): Boolean = simpleInputMessage != null
+
+ fun isMessage(): Boolean = message != null
+
+ fun isOutputMessage(): Boolean = outputMessage != null
+
+ fun asSimpleInputMessage(): SimpleInputMessage =
+ simpleInputMessage.getOrThrow("simpleInputMessage")
+
+ fun asMessage(): InputMessage = message.getOrThrow("message")
+
+ fun asOutputMessage(): OutputMessage = outputMessage.getOrThrow("outputMessage")
+
+ fun _json(): Optional = Optional.ofNullable(_json)
+
+ fun accept(visitor: Visitor): T =
+ when {
+ simpleInputMessage != null ->
+ visitor.visitSimpleInputMessage(simpleInputMessage)
+ message != null -> visitor.visitMessage(message)
+ outputMessage != null -> visitor.visitOutputMessage(outputMessage)
+ else -> visitor.unknown(_json)
+ }
+
+ private var validated: Boolean = false
+
+ fun validate(): Input = apply {
+ if (validated) {
+ return@apply
+ }
+
+ accept(
+ object : Visitor {
+ override fun visitSimpleInputMessage(
+ simpleInputMessage: SimpleInputMessage
+ ) {
+ simpleInputMessage.validate()
+ }
+
+ override fun visitMessage(message: InputMessage) {
+ message.validate()
+ }
+
+ override fun visitOutputMessage(outputMessage: OutputMessage) {
+ outputMessage.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 visitSimpleInputMessage(
+ simpleInputMessage: SimpleInputMessage
+ ) = simpleInputMessage.validity()
+
+ override fun visitMessage(message: InputMessage) = message.validity()
+
+ override fun visitOutputMessage(outputMessage: OutputMessage) =
+ outputMessage.validity()
+
+ override fun unknown(json: JsonValue?) = 0
+ }
+ )
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return /* spotless:off */ other is Input && simpleInputMessage == other.simpleInputMessage && message == other.message && outputMessage == other.outputMessage /* spotless:on */
+ }
+
+ override fun hashCode(): Int = /* spotless:off */ Objects.hash(simpleInputMessage, message, outputMessage) /* spotless:on */
+
+ override fun toString(): String =
+ when {
+ simpleInputMessage != null ->
+ "Input{simpleInputMessage=$simpleInputMessage}"
+ message != null -> "Input{message=$message}"
+ outputMessage != null -> "Input{outputMessage=$outputMessage}"
+ _json != null -> "Input{_unknown=$_json}"
+ else -> throw IllegalStateException("Invalid Input")
+ }
+
+ companion object {
+
+ @JvmStatic
+ fun ofSimpleInputMessage(simpleInputMessage: SimpleInputMessage) =
+ Input(simpleInputMessage = simpleInputMessage)
+
+ @JvmStatic fun ofMessage(message: InputMessage) = Input(message = message)
+
+ @JvmStatic
+ fun ofOutputMessage(outputMessage: OutputMessage) =
+ Input(outputMessage = outputMessage)
+ }
+
+ /**
+ * An interface that defines how to map each variant of [Input] to a value of type
+ * [T].
+ */
+ interface Visitor {
+
+ fun visitSimpleInputMessage(simpleInputMessage: SimpleInputMessage): T
+
+ fun visitMessage(message: InputMessage): T
+
+ fun visitOutputMessage(outputMessage: OutputMessage): T
+
+ /**
+ * Maps an unknown variant of [Input] to a value of type [T].
+ *
+ * An instance of [Input] can contain an unknown variant if it was deserialized
+ * from data that doesn't match any known variant. For example, if the SDK is on
+ * an older version than the API, then the API may respond with new variants
+ * that the SDK is unaware of.
+ *
+ * @throws OpenAIInvalidDataException in the default implementation.
+ */
+ fun unknown(json: JsonValue?): T {
+ throw OpenAIInvalidDataException("Unknown Input: $json")
+ }
+ }
+
+ internal class Deserializer : BaseDeserializer(Input::class) {
+
+ override fun ObjectCodec.deserialize(node: JsonNode): Input {
+ val json = JsonValue.fromJsonNode(node)
+
+ val bestMatches =
+ sequenceOf(
+ tryDeserialize(node, jacksonTypeRef())
+ ?.let { Input(simpleInputMessage = it, _json = json) },
+ tryDeserialize(node, jacksonTypeRef())?.let {
+ Input(message = it, _json = json)
+ },
+ tryDeserialize(node, jacksonTypeRef())?.let {
+ Input(outputMessage = 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 -> Input(_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()
+ }
+ }
+ }
+
+ internal class Serializer : BaseSerializer(Input::class) {
+
+ override fun serialize(
+ value: Input,
+ generator: JsonGenerator,
+ provider: SerializerProvider,
+ ) {
+ when {
+ value.simpleInputMessage != null ->
+ generator.writeObject(value.simpleInputMessage)
+ value.message != null -> generator.writeObject(value.message)
+ value.outputMessage != null ->
+ generator.writeObject(value.outputMessage)
+ value._json != null -> generator.writeObject(value._json)
+ else -> throw IllegalStateException("Invalid Input")
+ }
+ }
+ }
+
+ class SimpleInputMessage
+ private constructor(
+ private val content: JsonField,
+ private val role: JsonField,
+ private val additionalProperties: MutableMap,
+ ) {
+
+ @JsonCreator
+ private constructor(
+ @JsonProperty("content")
+ @ExcludeMissing
+ content: JsonField = JsonMissing.of(),
+ @JsonProperty("role")
+ @ExcludeMissing
+ role: JsonField = JsonMissing.of(),
+ ) : this(content, role, mutableMapOf())
+
+ /**
+ * The content of the message.
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type
+ * or is unexpectedly missing or null (e.g. if the server responded with an
+ * unexpected value).
+ */
+ fun content(): String = content.getRequired("content")
+
+ /**
+ * The role of the message (e.g. "system", "assistant", "user").
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type
+ * or is unexpectedly missing or null (e.g. if the server responded with an
+ * unexpected value).
+ */
+ fun role(): String = role.getRequired("role")
+
+ /**
+ * Returns the raw JSON value of [content].
+ *
+ * Unlike [content], this method doesn't throw if the JSON field has an
+ * unexpected type.
+ */
+ @JsonProperty("content")
+ @ExcludeMissing
+ fun _content(): JsonField = content
+
+ /**
+ * Returns the raw JSON value of [role].
+ *
+ * Unlike [role], this method doesn't throw if the JSON field has an unexpected
+ * type.
+ */
+ @JsonProperty("role") @ExcludeMissing fun _role(): JsonField = role
+
+ @JsonAnySetter
+ private fun putAdditionalProperty(key: String, value: JsonValue) {
+ additionalProperties.put(key, value)
+ }
+
+ @JsonAnyGetter
+ @ExcludeMissing
+ fun _additionalProperties(): Map =
+ Collections.unmodifiableMap(additionalProperties)
+
+ fun toBuilder() = Builder().from(this)
+
+ companion object {
+
+ /**
+ * Returns a mutable builder for constructing an instance of
+ * [SimpleInputMessage].
+ *
+ * The following fields are required:
+ * ```java
+ * .content()
+ * .role()
+ * ```
+ */
+ @JvmStatic fun builder() = Builder()
+ }
+
+ /** A builder for [SimpleInputMessage]. */
+ class Builder internal constructor() {
+
+ private var content: JsonField? = null
+ private var role: JsonField? = null
+ private var additionalProperties: MutableMap =
+ mutableMapOf()
+
+ @JvmSynthetic
+ internal fun from(simpleInputMessage: SimpleInputMessage) = apply {
+ content = simpleInputMessage.content
+ role = simpleInputMessage.role
+ additionalProperties =
+ simpleInputMessage.additionalProperties.toMutableMap()
+ }
+
+ /** The content of the message. */
+ fun content(content: String) = content(JsonField.of(content))
+
+ /**
+ * Sets [Builder.content] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.content] with a well-typed [String]
+ * value instead. This method is primarily for setting the field to an
+ * undocumented or not yet supported value.
+ */
+ fun content(content: JsonField) = apply { this.content = content }
+
+ /** The role of the message (e.g. "system", "assistant", "user"). */
+ fun role(role: String) = role(JsonField.of(role))
+
+ /**
+ * Sets [Builder.role] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.role] with a well-typed [String] value
+ * instead. This method is primarily for setting the field to an
+ * undocumented or not yet supported value.
+ */
+ fun role(role: JsonField) = apply { this.role = role }
+
+ fun additionalProperties(additionalProperties: Map) =
+ apply {
+ this.additionalProperties.clear()
+ putAllAdditionalProperties(additionalProperties)
+ }
+
+ fun putAdditionalProperty(key: String, value: JsonValue) = apply {
+ additionalProperties.put(key, value)
+ }
+
+ fun putAllAdditionalProperties(
+ additionalProperties: Map
+ ) = apply { this.additionalProperties.putAll(additionalProperties) }
+
+ fun removeAdditionalProperty(key: String) = apply {
+ additionalProperties.remove(key)
+ }
+
+ fun removeAllAdditionalProperties(keys: Set) = apply {
+ keys.forEach(::removeAdditionalProperty)
+ }
+
+ /**
+ * Returns an immutable instance of [SimpleInputMessage].
+ *
+ * Further updates to this [Builder] will not mutate the returned instance.
+ *
+ * The following fields are required:
+ * ```java
+ * .content()
+ * .role()
+ * ```
+ *
+ * @throws IllegalStateException if any required field is unset.
+ */
+ fun build(): SimpleInputMessage =
+ SimpleInputMessage(
+ checkRequired("content", content),
+ checkRequired("role", role),
+ additionalProperties.toMutableMap(),
+ )
+ }
+
+ private var validated: Boolean = false
+
+ fun validate(): SimpleInputMessage = apply {
+ if (validated) {
+ return@apply
+ }
+
+ content()
+ role()
+ 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 (content.asKnown().isPresent) 1 else 0) +
+ (if (role.asKnown().isPresent) 1 else 0)
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return /* spotless:off */ other is SimpleInputMessage && content == other.content && role == other.role && additionalProperties == other.additionalProperties /* spotless:on */
+ }
+
+ /* spotless:off */
+ private val hashCode: Int by lazy { Objects.hash(content, role, additionalProperties) }
+ /* spotless:on */
+
+ override fun hashCode(): Int = hashCode
+
+ override fun toString() =
+ "SimpleInputMessage{content=$content, role=$role, additionalProperties=$additionalProperties}"
+ }
+
+ class InputMessage
+ private constructor(
+ private val content: JsonField,
+ private val role: JsonField,
+ private val type: JsonField,
+ private val additionalProperties: MutableMap,
+ ) {
+
+ @JsonCreator
+ private constructor(
+ @JsonProperty("content")
+ @ExcludeMissing
+ content: JsonField = JsonMissing.of(),
+ @JsonProperty("role")
+ @ExcludeMissing
+ role: JsonField = JsonMissing.of(),
+ @JsonProperty("type")
+ @ExcludeMissing
+ type: JsonField = JsonMissing.of(),
+ ) : this(content, role, type, mutableMapOf())
+
+ /**
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type
+ * or is unexpectedly missing or null (e.g. if the server responded with an
+ * unexpected value).
+ */
+ fun content(): Content = content.getRequired("content")
+
+ /**
+ * The role of the message. One of `user`, `system`, or `developer`.
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type
+ * or is unexpectedly missing or null (e.g. if the server responded with an
+ * unexpected value).
+ */
+ fun role(): Role = role.getRequired("role")
+
+ /**
+ * The type of item, which is always `message`.
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type
+ * or is unexpectedly missing or null (e.g. if the server responded with an
+ * unexpected value).
+ */
+ fun type(): Type = type.getRequired("type")
+
+ /**
+ * Returns the raw JSON value of [content].
+ *
+ * Unlike [content], this method doesn't throw if the JSON field has an
+ * unexpected type.
+ */
+ @JsonProperty("content")
+ @ExcludeMissing
+ fun _content(): JsonField = content
+
+ /**
+ * Returns the raw JSON value of [role].
+ *
+ * Unlike [role], this method doesn't throw if the JSON field has an unexpected
+ * type.
+ */
+ @JsonProperty("role") @ExcludeMissing fun _role(): JsonField = role
+
+ /**
+ * Returns the raw JSON value of [type].
+ *
+ * Unlike [type], this method doesn't throw if the JSON field has an unexpected
+ * type.
+ */
+ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type
+
+ @JsonAnySetter
+ private fun putAdditionalProperty(key: String, value: JsonValue) {
+ additionalProperties.put(key, value)
+ }
+
+ @JsonAnyGetter
+ @ExcludeMissing
+ fun _additionalProperties(): Map =
+ Collections.unmodifiableMap(additionalProperties)
+
+ fun toBuilder() = Builder().from(this)
+
+ companion object {
+
+ /**
+ * Returns a mutable builder for constructing an instance of [InputMessage].
+ *
+ * The following fields are required:
+ * ```java
+ * .content()
+ * .role()
+ * .type()
+ * ```
+ */
+ @JvmStatic fun builder() = Builder()
+ }
+
+ /** A builder for [InputMessage]. */
+ class Builder internal constructor() {
+
+ private var content: JsonField? = null
+ private var role: JsonField? = null
+ private var type: JsonField? = null
+ private var additionalProperties: MutableMap =
+ mutableMapOf()
+
+ @JvmSynthetic
+ internal fun from(inputMessage: InputMessage) = apply {
+ content = inputMessage.content
+ role = inputMessage.role
+ type = inputMessage.type
+ additionalProperties = inputMessage.additionalProperties.toMutableMap()
+ }
+
+ fun content(content: Content) = content(JsonField.of(content))
+
+ /**
+ * Sets [Builder.content] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.content] with a well-typed [Content]
+ * value instead. This method is primarily for setting the field to an
+ * undocumented or not yet supported value.
+ */
+ fun content(content: JsonField) = apply { this.content = content }
+
+ /** The role of the message. One of `user`, `system`, or `developer`. */
+ fun role(role: Role) = role(JsonField.of(role))
+
+ /**
+ * Sets [Builder.role] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.role] with a well-typed [Role] value
+ * instead. This method is primarily for setting the field to an
+ * undocumented or not yet supported value.
+ */
+ fun role(role: JsonField) = apply { this.role = role }
+
+ /** The type of item, which is always `message`. */
+ fun type(type: Type) = type(JsonField.of(type))
+
+ /**
+ * Sets [Builder.type] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.type] with a well-typed [Type] value
+ * instead. This method is primarily for setting the field to an
+ * undocumented or not yet supported value.
+ */
+ fun type(type: JsonField) = apply { this.type = type }
+
+ fun additionalProperties(additionalProperties: Map) =
+ apply {
+ this.additionalProperties.clear()
+ putAllAdditionalProperties(additionalProperties)
+ }
+
+ fun putAdditionalProperty(key: String, value: JsonValue) = apply {
+ additionalProperties.put(key, value)
+ }
+
+ fun putAllAdditionalProperties(
+ additionalProperties: Map
+ ) = apply { this.additionalProperties.putAll(additionalProperties) }
+
+ fun removeAdditionalProperty(key: String) = apply {
+ additionalProperties.remove(key)
+ }
+
+ fun removeAllAdditionalProperties(keys: Set) = apply {
+ keys.forEach(::removeAdditionalProperty)
+ }
+
+ /**
+ * Returns an immutable instance of [InputMessage].
+ *
+ * Further updates to this [Builder] will not mutate the returned instance.
+ *
+ * The following fields are required:
+ * ```java
+ * .content()
+ * .role()
+ * .type()
+ * ```
+ *
+ * @throws IllegalStateException if any required field is unset.
+ */
+ fun build(): InputMessage =
+ InputMessage(
+ checkRequired("content", content),
+ checkRequired("role", role),
+ checkRequired("type", type),
+ additionalProperties.toMutableMap(),
+ )
+ }
+
+ private var validated: Boolean = false
+
+ fun validate(): InputMessage = apply {
+ if (validated) {
+ return@apply
+ }
+
+ content().validate()
+ role().validate()
+ 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 =
+ (content.asKnown().getOrNull()?.validity() ?: 0) +
+ (role.asKnown().getOrNull()?.validity() ?: 0) +
+ (type.asKnown().getOrNull()?.validity() ?: 0)
+
+ class Content
+ private constructor(
+ private val text: JsonField,
+ private val type: JsonField,
+ private val additionalProperties: MutableMap,
+ ) {
+
+ @JsonCreator
+ private constructor(
+ @JsonProperty("text")
+ @ExcludeMissing
+ text: JsonField = JsonMissing.of(),
+ @JsonProperty("type")
+ @ExcludeMissing
+ type: JsonField = JsonMissing.of(),
+ ) : this(text, type, mutableMapOf())
+
+ /**
+ * The text content.
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected
+ * type or is unexpectedly missing or null (e.g. if the server responded
+ * with an unexpected value).
+ */
+ fun text(): String = text.getRequired("text")
+
+ /**
+ * The type of content, which is always `input_text`.
+ *
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected
+ * type or is unexpectedly missing or null (e.g. if the server responded
+ * with an unexpected value).
+ */
+ fun type(): Type = type.getRequired("type")
+
+ /**
+ * Returns the raw JSON value of [text].
+ *
+ * Unlike [text], this method doesn't throw if the JSON field has an
+ * unexpected type.
+ */
+ @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text
+
+ /**
+ * Returns the raw JSON value of [type].
+ *
+ * Unlike [type], this method doesn't throw if the JSON field has an
+ * unexpected type.
+ */
+ @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type
+
+ @JsonAnySetter
+ private fun putAdditionalProperty(key: String, value: JsonValue) {
+ additionalProperties.put(key, value)
+ }
+
+ @JsonAnyGetter
+ @ExcludeMissing
+ fun _additionalProperties(): Map