diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 751389532..f391d4162 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "3.5.3" + ".": "3.6.0" } \ No newline at end of file diff --git a/.stats.yml b/.stats.yml index 905a02c44..c961e232c 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 118 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-d30ff992a48873c1466c49f3c01f2ec8933faebff23424748f8d056065b1bcef.yml -openapi_spec_hash: e933ec43b46f45c348adb78840e5808d -config_hash: bf45940f0a7805b4ec2017eecdd36893 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-ea23db36b0899cc715f56d0098956069b2d92880f448adff3a4ac1bb53cb2cec.yml +openapi_spec_hash: 36f76ea31297c9593bcfae453f6255cc +config_hash: 666d6bb4b564f0d9d431124b5d1a0665 diff --git a/CHANGELOG.md b/CHANGELOG.md index 20dbaf706..b43458517 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,20 @@ # Changelog +## 3.6.0 (2025-09-19) + +Full Changelog: [v3.5.3...v3.6.0](https://github.com/openai/openai-java/compare/v3.5.3...v3.6.0) + +### Features + +* **api:** add reasoning_text ([2bde290](https://github.com/openai/openai-java/commit/2bde29036040664aa4ae54f6522e5e5336ed2c87)) +* **api:** type updates for conversations, reasoning_effort and results for evals ([364a176](https://github.com/openai/openai-java/commit/364a1766d34b6cc19fca81a445b287fc9ccefe2c)) +* **client:** expose sleeper option ([a5ffd57](https://github.com/openai/openai-java/commit/a5ffd57e75b6f0abe14d326c87f58abd2048cf73)) + + +### Bug Fixes + +* **client:** ensure single timer is created per client ([a5ffd57](https://github.com/openai/openai-java/commit/a5ffd57e75b6f0abe14d326c87f58abd2048cf73)) + ## 3.5.3 (2025-09-15) Full Changelog: [v3.5.2...v3.5.3](https://github.com/openai/openai-java/compare/v3.5.2...v3.5.3) diff --git a/README.md b/README.md index a8e593227..50bf0b89f 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ -[![Maven Central](https://img.shields.io/maven-central/v/com.openai/openai-java)](https://central.sonatype.com/artifact/com.openai/openai-java/3.5.3) -[![javadoc](https://javadoc.io/badge2/com.openai/openai-java/3.5.3/javadoc.svg)](https://javadoc.io/doc/com.openai/openai-java/3.5.3) +[![Maven Central](https://img.shields.io/maven-central/v/com.openai/openai-java)](https://central.sonatype.com/artifact/com.openai/openai-java/3.6.0) +[![javadoc](https://javadoc.io/badge2/com.openai/openai-java/3.6.0/javadoc.svg)](https://javadoc.io/doc/com.openai/openai-java/3.6.0) @@ -11,7 +11,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 available on [javadoc.io](https://javadoc.io/doc/com.openai/openai-java/3.5.3). +The REST API documentation can be found on [platform.openai.com](https://platform.openai.com/docs). Javadocs are available on [javadoc.io](https://javadoc.io/doc/com.openai/openai-java/3.6.0). @@ -24,7 +24,7 @@ The REST API documentation can be found on [platform.openai.com](https://platfor ### Gradle ```kotlin -implementation("com.openai:openai-java:3.5.3") +implementation("com.openai:openai-java:3.6.0") ``` ### Maven @@ -33,7 +33,7 @@ implementation("com.openai:openai-java:3.5.3") com.openai openai-java - 3.5.3 + 3.6.0 ``` @@ -1342,7 +1342,7 @@ If you're using Spring Boot, then you can use the SDK's [Spring Boot starter](ht #### Gradle ```kotlin -implementation("com.openai:openai-java-spring-boot-starter:3.5.3") +implementation("com.openai:openai-java-spring-boot-starter:3.6.0") ``` #### Maven @@ -1351,7 +1351,7 @@ implementation("com.openai:openai-java-spring-boot-starter:3.5.3") com.openai openai-java-spring-boot-starter - 3.5.3 + 3.6.0 ``` diff --git a/build.gradle.kts b/build.gradle.kts index 46de19e37..fd0c9dd35 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ repositories { allprojects { group = "com.openai" - version = "3.5.3" // x-release-please-version + version = "3.6.0" // x-release-please-version } subprojects { diff --git a/openai-java-client-okhttp/src/main/kotlin/com/openai/client/okhttp/OpenAIOkHttpClient.kt b/openai-java-client-okhttp/src/main/kotlin/com/openai/client/okhttp/OpenAIOkHttpClient.kt index 353f94f1c..818d0f824 100644 --- a/openai-java-client-okhttp/src/main/kotlin/com/openai/client/okhttp/OpenAIOkHttpClient.kt +++ b/openai-java-client-okhttp/src/main/kotlin/com/openai/client/okhttp/OpenAIOkHttpClient.kt @@ -8,6 +8,7 @@ import com.openai.azure.AzureUrlPathMode import com.openai.client.OpenAIClient import com.openai.client.OpenAIClientImpl import com.openai.core.ClientOptions +import com.openai.core.Sleeper import com.openai.core.Timeout import com.openai.core.http.AsyncStreamResponse import com.openai.core.http.Headers @@ -135,6 +136,17 @@ class OpenAIOkHttpClient private constructor() { clientOptions.streamHandlerExecutor(streamHandlerExecutor) } + /** + * The interface to use for delaying execution, like during retries. + * + * This is primarily useful for using fake delays in tests. + * + * Defaults to real execution delays. + * + * This class takes ownership of the sleeper and closes it when closed. + */ + fun sleeper(sleeper: Sleeper) = apply { clientOptions.sleeper(sleeper) } + /** * The clock to use for operations that require timing, like retries. * diff --git a/openai-java-client-okhttp/src/main/kotlin/com/openai/client/okhttp/OpenAIOkHttpClientAsync.kt b/openai-java-client-okhttp/src/main/kotlin/com/openai/client/okhttp/OpenAIOkHttpClientAsync.kt index 9707fffb3..bb3352e39 100644 --- a/openai-java-client-okhttp/src/main/kotlin/com/openai/client/okhttp/OpenAIOkHttpClientAsync.kt +++ b/openai-java-client-okhttp/src/main/kotlin/com/openai/client/okhttp/OpenAIOkHttpClientAsync.kt @@ -8,6 +8,7 @@ import com.openai.azure.AzureUrlPathMode import com.openai.client.OpenAIClientAsync import com.openai.client.OpenAIClientAsyncImpl import com.openai.core.ClientOptions +import com.openai.core.Sleeper import com.openai.core.Timeout import com.openai.core.http.AsyncStreamResponse import com.openai.core.http.Headers @@ -135,6 +136,17 @@ class OpenAIOkHttpClientAsync private constructor() { clientOptions.streamHandlerExecutor(streamHandlerExecutor) } + /** + * The interface to use for delaying execution, like during retries. + * + * This is primarily useful for using fake delays in tests. + * + * Defaults to real execution delays. + * + * This class takes ownership of the sleeper and closes it when closed. + */ + fun sleeper(sleeper: Sleeper) = apply { clientOptions.sleeper(sleeper) } + /** * The clock to use for operations that require timing, like retries. * diff --git a/openai-java-core/src/main/kotlin/com/openai/core/ClientOptions.kt b/openai-java-core/src/main/kotlin/com/openai/core/ClientOptions.kt index 515eb4f49..70ff74e6a 100644 --- a/openai-java-core/src/main/kotlin/com/openai/core/ClientOptions.kt +++ b/openai-java-core/src/main/kotlin/com/openai/core/ClientOptions.kt @@ -60,6 +60,16 @@ private constructor( * This class takes ownership of the executor and shuts it down, if possible, when closed. */ @get:JvmName("streamHandlerExecutor") val streamHandlerExecutor: Executor, + /** + * The interface to use for delaying execution, like during retries. + * + * This is primarily useful for using fake delays in tests. + * + * Defaults to real execution delays. + * + * This class takes ownership of the sleeper and closes it when closed. + */ + @get:JvmName("sleeper") val sleeper: Sleeper, /** * The clock to use for operations that require timing, like retries. * @@ -162,6 +172,7 @@ private constructor( private var checkJacksonVersionCompatibility: Boolean = true private var jsonMapper: JsonMapper = jsonMapper() private var streamHandlerExecutor: Executor? = null + private var sleeper: Sleeper? = null private var clock: Clock = Clock.systemUTC() private var baseUrl: String? = null private var headers: Headers.Builder = Headers.builder() @@ -182,6 +193,7 @@ private constructor( checkJacksonVersionCompatibility = clientOptions.checkJacksonVersionCompatibility jsonMapper = clientOptions.jsonMapper streamHandlerExecutor = clientOptions.streamHandlerExecutor + sleeper = clientOptions.sleeper clock = clientOptions.clock baseUrl = clientOptions.baseUrl headers = clientOptions.headers.toBuilder() @@ -241,6 +253,17 @@ private constructor( else streamHandlerExecutor } + /** + * The interface to use for delaying execution, like during retries. + * + * This is primarily useful for using fake delays in tests. + * + * Defaults to real execution delays. + * + * This class takes ownership of the sleeper and closes it when closed. + */ + fun sleeper(sleeper: Sleeper) = apply { this.sleeper = PhantomReachableSleeper(sleeper) } + /** * The clock to use for operations that require timing, like retries. * @@ -479,6 +502,25 @@ private constructor( */ fun build(): ClientOptions { val httpClient = checkRequired("httpClient", httpClient) + val streamHandlerExecutor = + streamHandlerExecutor + ?: PhantomReachableExecutorService( + Executors.newCachedThreadPool( + object : ThreadFactory { + + private val threadFactory: ThreadFactory = + Executors.defaultThreadFactory() + private val count = AtomicLong(0) + + override fun newThread(runnable: Runnable): Thread = + threadFactory.newThread(runnable).also { + it.name = + "openai-stream-handler-thread-${count.getAndIncrement()}" + } + } + ) + ) + val sleeper = sleeper ?: PhantomReachableSleeper(DefaultSleeper()) val credential = checkRequired("credential", credential) val headers = Headers.builder() @@ -530,26 +572,14 @@ private constructor( httpClient, RetryingHttpClient.builder() .httpClient(httpClient) + .sleeper(sleeper) .clock(clock) .maxRetries(maxRetries) .build(), checkJacksonVersionCompatibility, jsonMapper, - streamHandlerExecutor - ?: Executors.newCachedThreadPool( - object : ThreadFactory { - - private val threadFactory: ThreadFactory = - Executors.defaultThreadFactory() - private val count = AtomicLong(0) - - override fun newThread(runnable: Runnable): Thread = - threadFactory.newThread(runnable).also { - it.name = - "openai-stream-handler-thread-${count.getAndIncrement()}" - } - } - ), + streamHandlerExecutor, + sleeper, clock, baseUrl, headers.build(), @@ -580,5 +610,6 @@ private constructor( fun close() { httpClient.close() (streamHandlerExecutor as? ExecutorService)?.shutdown() + sleeper.close() } } diff --git a/openai-java-core/src/main/kotlin/com/openai/core/DefaultSleeper.kt b/openai-java-core/src/main/kotlin/com/openai/core/DefaultSleeper.kt new file mode 100644 index 000000000..bd8b250b0 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/core/DefaultSleeper.kt @@ -0,0 +1,28 @@ +package com.openai.core + +import java.time.Duration +import java.util.Timer +import java.util.TimerTask +import java.util.concurrent.CompletableFuture + +class DefaultSleeper : Sleeper { + + private val timer = Timer("DefaultSleeper", true) + + override fun sleep(duration: Duration) = Thread.sleep(duration.toMillis()) + + override fun sleepAsync(duration: Duration): CompletableFuture { + val future = CompletableFuture() + timer.schedule( + object : TimerTask() { + override fun run() { + future.complete(null) + } + }, + duration.toMillis(), + ) + return future + } + + override fun close() = timer.cancel() +} diff --git a/openai-java-core/src/main/kotlin/com/openai/core/PhantomReachableSleeper.kt b/openai-java-core/src/main/kotlin/com/openai/core/PhantomReachableSleeper.kt new file mode 100644 index 000000000..65ec40080 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/core/PhantomReachableSleeper.kt @@ -0,0 +1,23 @@ +package com.openai.core + +import java.time.Duration +import java.util.concurrent.CompletableFuture + +/** + * A delegating wrapper around a [Sleeper] that closes it once it's only phantom reachable. + * + * This class ensures the [Sleeper] is closed even if the user forgets to do it. + */ +internal class PhantomReachableSleeper(private val sleeper: Sleeper) : Sleeper { + + init { + closeWhenPhantomReachable(this, sleeper) + } + + override fun sleep(duration: Duration) = sleeper.sleep(duration) + + override fun sleepAsync(duration: Duration): CompletableFuture = + sleeper.sleepAsync(duration) + + override fun close() = sleeper.close() +} diff --git a/openai-java-core/src/main/kotlin/com/openai/core/Sleeper.kt b/openai-java-core/src/main/kotlin/com/openai/core/Sleeper.kt new file mode 100644 index 000000000..788bb1c16 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/core/Sleeper.kt @@ -0,0 +1,21 @@ +package com.openai.core + +import java.time.Duration +import java.util.concurrent.CompletableFuture + +/** + * An interface for delaying execution for a specified amount of time. + * + * Useful for testing and cleaning up resources. + */ +interface Sleeper : AutoCloseable { + + /** Synchronously pauses execution for the given [duration]. */ + fun sleep(duration: Duration) + + /** Asynchronously pauses execution for the given [duration]. */ + fun sleepAsync(duration: Duration): CompletableFuture + + /** Overridden from [AutoCloseable] to not have a checked exception in its signature. */ + override fun close() +} diff --git a/openai-java-core/src/main/kotlin/com/openai/core/http/RetryingHttpClient.kt b/openai-java-core/src/main/kotlin/com/openai/core/http/RetryingHttpClient.kt index cf515198d..6eaa33a25 100644 --- a/openai-java-core/src/main/kotlin/com/openai/core/http/RetryingHttpClient.kt +++ b/openai-java-core/src/main/kotlin/com/openai/core/http/RetryingHttpClient.kt @@ -1,6 +1,8 @@ package com.openai.core.http +import com.openai.core.DefaultSleeper import com.openai.core.RequestOptions +import com.openai.core.Sleeper import com.openai.core.checkRequired import com.openai.errors.OpenAIIoException import com.openai.errors.OpenAIRetryableException @@ -11,8 +13,6 @@ import java.time.OffsetDateTime import java.time.format.DateTimeFormatter import java.time.format.DateTimeParseException import java.time.temporal.ChronoUnit -import java.util.Timer -import java.util.TimerTask import java.util.UUID import java.util.concurrent.CompletableFuture import java.util.concurrent.ThreadLocalRandom @@ -130,7 +130,10 @@ private constructor( return executeWithRetries(modifiedRequest, requestOptions) } - override fun close() = httpClient.close() + override fun close() { + httpClient.close() + sleeper.close() + } private fun isRetryable(request: HttpRequest): Boolean = // Some requests, such as when a request body is being streamed, cannot be retried because @@ -235,33 +238,14 @@ private constructor( class Builder internal constructor() { private var httpClient: HttpClient? = null - private var sleeper: Sleeper = - object : Sleeper { - - private val timer = Timer("RetryingHttpClient", true) - - override fun sleep(duration: Duration) = Thread.sleep(duration.toMillis()) - - override fun sleepAsync(duration: Duration): CompletableFuture { - val future = CompletableFuture() - timer.schedule( - object : TimerTask() { - override fun run() { - future.complete(null) - } - }, - duration.toMillis(), - ) - return future - } - } + private var sleeper: Sleeper? = null private var clock: Clock = Clock.systemUTC() private var maxRetries: Int = 2 private var idempotencyHeader: String? = null fun httpClient(httpClient: HttpClient) = apply { this.httpClient = httpClient } - @JvmSynthetic internal fun sleeper(sleeper: Sleeper) = apply { this.sleeper = sleeper } + fun sleeper(sleeper: Sleeper) = apply { this.sleeper = sleeper } fun clock(clock: Clock) = apply { this.clock = clock } @@ -272,17 +256,10 @@ private constructor( fun build(): HttpClient = RetryingHttpClient( checkRequired("httpClient", httpClient), - sleeper, + sleeper ?: DefaultSleeper(), clock, maxRetries, idempotencyHeader, ) } - - internal interface Sleeper { - - fun sleep(duration: Duration) - - fun sleepAsync(duration: Duration): CompletableFuture - } } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/conversations/ComputerScreenshotContent.kt b/openai-java-core/src/main/kotlin/com/openai/models/conversations/ComputerScreenshotContent.kt index 39efe0bb0..a3d5cb6a9 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/conversations/ComputerScreenshotContent.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/conversations/ComputerScreenshotContent.kt @@ -17,6 +17,7 @@ import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull +/** A screenshot of a computer. */ class ComputerScreenshotContent private constructor( private val fileId: JsonField, diff --git a/openai-java-core/src/main/kotlin/com/openai/models/conversations/ContainerFileCitationBody.kt b/openai-java-core/src/main/kotlin/com/openai/models/conversations/ContainerFileCitationBody.kt deleted file mode 100644 index 67c0ff2d5..000000000 --- a/openai-java-core/src/main/kotlin/com/openai/models/conversations/ContainerFileCitationBody.kt +++ /dev/null @@ -1,372 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.openai.models.conversations - -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.openai.core.ExcludeMissing -import com.openai.core.JsonField -import com.openai.core.JsonMissing -import com.openai.core.JsonValue -import com.openai.core.checkRequired -import com.openai.errors.OpenAIInvalidDataException -import java.util.Collections -import java.util.Objects - -class ContainerFileCitationBody -private constructor( - private val containerId: JsonField, - private val endIndex: JsonField, - private val fileId: JsonField, - private val filename: JsonField, - private val startIndex: JsonField, - private val type: JsonValue, - private val additionalProperties: MutableMap, -) { - - @JsonCreator - private constructor( - @JsonProperty("container_id") - @ExcludeMissing - containerId: JsonField = JsonMissing.of(), - @JsonProperty("end_index") @ExcludeMissing endIndex: JsonField = JsonMissing.of(), - @JsonProperty("file_id") @ExcludeMissing fileId: JsonField = JsonMissing.of(), - @JsonProperty("filename") @ExcludeMissing filename: JsonField = JsonMissing.of(), - @JsonProperty("start_index") @ExcludeMissing startIndex: JsonField = JsonMissing.of(), - @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), - ) : this(containerId, endIndex, fileId, filename, startIndex, type, mutableMapOf()) - - /** - * The ID of the container file. - * - * @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 containerId(): String = containerId.getRequired("container_id") - - /** - * The index of the last character of the container file citation in 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 endIndex(): Long = endIndex.getRequired("end_index") - - /** - * The ID of the file. - * - * @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 fileId(): String = fileId.getRequired("file_id") - - /** - * The filename of the container file cited. - * - * @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 filename(): String = filename.getRequired("filename") - - /** - * The index of the first character of the container file citation in 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 startIndex(): Long = startIndex.getRequired("start_index") - - /** - * The type of the container file citation. Always `container_file_citation`. - * - * Expected to always return the following: - * ```java - * JsonValue.from("container_file_citation") - * ``` - * - * 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 [containerId]. - * - * Unlike [containerId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("container_id") - @ExcludeMissing - fun _containerId(): JsonField = containerId - - /** - * Returns the raw JSON value of [endIndex]. - * - * Unlike [endIndex], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("end_index") @ExcludeMissing fun _endIndex(): JsonField = endIndex - - /** - * Returns the raw JSON value of [fileId]. - * - * Unlike [fileId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("file_id") @ExcludeMissing fun _fileId(): JsonField = fileId - - /** - * Returns the raw JSON value of [filename]. - * - * Unlike [filename], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("filename") @ExcludeMissing fun _filename(): JsonField = filename - - /** - * Returns the raw JSON value of [startIndex]. - * - * Unlike [startIndex], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("start_index") @ExcludeMissing fun _startIndex(): JsonField = startIndex - - @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 [ContainerFileCitationBody]. - * - * The following fields are required: - * ```java - * .containerId() - * .endIndex() - * .fileId() - * .filename() - * .startIndex() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [ContainerFileCitationBody]. */ - class Builder internal constructor() { - - private var containerId: JsonField? = null - private var endIndex: JsonField? = null - private var fileId: JsonField? = null - private var filename: JsonField? = null - private var startIndex: JsonField? = null - private var type: JsonValue = JsonValue.from("container_file_citation") - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(containerFileCitationBody: ContainerFileCitationBody) = apply { - containerId = containerFileCitationBody.containerId - endIndex = containerFileCitationBody.endIndex - fileId = containerFileCitationBody.fileId - filename = containerFileCitationBody.filename - startIndex = containerFileCitationBody.startIndex - type = containerFileCitationBody.type - additionalProperties = containerFileCitationBody.additionalProperties.toMutableMap() - } - - /** The ID of the container file. */ - fun containerId(containerId: String) = containerId(JsonField.of(containerId)) - - /** - * Sets [Builder.containerId] to an arbitrary JSON value. - * - * You should usually call [Builder.containerId] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun containerId(containerId: JsonField) = apply { this.containerId = containerId } - - /** The index of the last character of the container file citation in the message. */ - fun endIndex(endIndex: Long) = endIndex(JsonField.of(endIndex)) - - /** - * Sets [Builder.endIndex] to an arbitrary JSON value. - * - * You should usually call [Builder.endIndex] with a well-typed [Long] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun endIndex(endIndex: JsonField) = apply { this.endIndex = endIndex } - - /** The ID of the file. */ - fun fileId(fileId: String) = fileId(JsonField.of(fileId)) - - /** - * Sets [Builder.fileId] to an arbitrary JSON value. - * - * You should usually call [Builder.fileId] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun fileId(fileId: JsonField) = apply { this.fileId = fileId } - - /** The filename of the container file cited. */ - fun filename(filename: String) = filename(JsonField.of(filename)) - - /** - * Sets [Builder.filename] to an arbitrary JSON value. - * - * You should usually call [Builder.filename] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun filename(filename: JsonField) = apply { this.filename = filename } - - /** The index of the first character of the container file citation in the message. */ - fun startIndex(startIndex: Long) = startIndex(JsonField.of(startIndex)) - - /** - * Sets [Builder.startIndex] to an arbitrary JSON value. - * - * You should usually call [Builder.startIndex] with a well-typed [Long] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun startIndex(startIndex: JsonField) = apply { this.startIndex = startIndex } - - /** - * 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("container_file_citation") - * ``` - * - * 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 [ContainerFileCitationBody]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .containerId() - * .endIndex() - * .fileId() - * .filename() - * .startIndex() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): ContainerFileCitationBody = - ContainerFileCitationBody( - checkRequired("containerId", containerId), - checkRequired("endIndex", endIndex), - checkRequired("fileId", fileId), - checkRequired("filename", filename), - checkRequired("startIndex", startIndex), - type, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): ContainerFileCitationBody = apply { - if (validated) { - return@apply - } - - containerId() - endIndex() - fileId() - filename() - startIndex() - _type().let { - if (it != JsonValue.from("container_file_citation")) { - 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 = - (if (containerId.asKnown().isPresent) 1 else 0) + - (if (endIndex.asKnown().isPresent) 1 else 0) + - (if (fileId.asKnown().isPresent) 1 else 0) + - (if (filename.asKnown().isPresent) 1 else 0) + - (if (startIndex.asKnown().isPresent) 1 else 0) + - type.let { if (it == JsonValue.from("container_file_citation")) 1 else 0 } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is ContainerFileCitationBody && - containerId == other.containerId && - endIndex == other.endIndex && - fileId == other.fileId && - filename == other.filename && - startIndex == other.startIndex && - type == other.type && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash( - containerId, - endIndex, - fileId, - filename, - startIndex, - type, - additionalProperties, - ) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "ContainerFileCitationBody{containerId=$containerId, endIndex=$endIndex, fileId=$fileId, filename=$filename, startIndex=$startIndex, type=$type, additionalProperties=$additionalProperties}" -} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/conversations/FileCitationBody.kt b/openai-java-core/src/main/kotlin/com/openai/models/conversations/FileCitationBody.kt deleted file mode 100644 index e82bfe5df..000000000 --- a/openai-java-core/src/main/kotlin/com/openai/models/conversations/FileCitationBody.kt +++ /dev/null @@ -1,287 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.openai.models.conversations - -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.openai.core.ExcludeMissing -import com.openai.core.JsonField -import com.openai.core.JsonMissing -import com.openai.core.JsonValue -import com.openai.core.checkRequired -import com.openai.errors.OpenAIInvalidDataException -import java.util.Collections -import java.util.Objects - -class FileCitationBody -private constructor( - private val fileId: JsonField, - private val filename: JsonField, - private val index: JsonField, - private val type: JsonValue, - private val additionalProperties: MutableMap, -) { - - @JsonCreator - private constructor( - @JsonProperty("file_id") @ExcludeMissing fileId: JsonField = JsonMissing.of(), - @JsonProperty("filename") @ExcludeMissing filename: JsonField = JsonMissing.of(), - @JsonProperty("index") @ExcludeMissing index: JsonField = JsonMissing.of(), - @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), - ) : this(fileId, filename, index, type, mutableMapOf()) - - /** - * The ID of the file. - * - * @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 fileId(): String = fileId.getRequired("file_id") - - /** - * The filename of the file cited. - * - * @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 filename(): String = filename.getRequired("filename") - - /** - * The index of the file in the list of files. - * - * @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 index(): Long = index.getRequired("index") - - /** - * The type of the file citation. Always `file_citation`. - * - * Expected to always return the following: - * ```java - * JsonValue.from("file_citation") - * ``` - * - * 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 [fileId]. - * - * Unlike [fileId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("file_id") @ExcludeMissing fun _fileId(): JsonField = fileId - - /** - * Returns the raw JSON value of [filename]. - * - * Unlike [filename], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("filename") @ExcludeMissing fun _filename(): JsonField = filename - - /** - * Returns the raw JSON value of [index]. - * - * Unlike [index], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("index") @ExcludeMissing fun _index(): JsonField = index - - @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 [FileCitationBody]. - * - * The following fields are required: - * ```java - * .fileId() - * .filename() - * .index() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [FileCitationBody]. */ - class Builder internal constructor() { - - private var fileId: JsonField? = null - private var filename: JsonField? = null - private var index: JsonField? = null - private var type: JsonValue = JsonValue.from("file_citation") - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(fileCitationBody: FileCitationBody) = apply { - fileId = fileCitationBody.fileId - filename = fileCitationBody.filename - index = fileCitationBody.index - type = fileCitationBody.type - additionalProperties = fileCitationBody.additionalProperties.toMutableMap() - } - - /** The ID of the file. */ - fun fileId(fileId: String) = fileId(JsonField.of(fileId)) - - /** - * Sets [Builder.fileId] to an arbitrary JSON value. - * - * You should usually call [Builder.fileId] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun fileId(fileId: JsonField) = apply { this.fileId = fileId } - - /** The filename of the file cited. */ - fun filename(filename: String) = filename(JsonField.of(filename)) - - /** - * Sets [Builder.filename] to an arbitrary JSON value. - * - * You should usually call [Builder.filename] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun filename(filename: JsonField) = apply { this.filename = filename } - - /** The index of the file in the list of files. */ - fun index(index: Long) = index(JsonField.of(index)) - - /** - * Sets [Builder.index] to an arbitrary JSON value. - * - * You should usually call [Builder.index] with a well-typed [Long] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun index(index: JsonField) = apply { this.index = index } - - /** - * 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("file_citation") - * ``` - * - * 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 [FileCitationBody]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .fileId() - * .filename() - * .index() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): FileCitationBody = - FileCitationBody( - checkRequired("fileId", fileId), - checkRequired("filename", filename), - checkRequired("index", index), - type, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): FileCitationBody = apply { - if (validated) { - return@apply - } - - fileId() - filename() - index() - _type().let { - if (it != JsonValue.from("file_citation")) { - 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 = - (if (fileId.asKnown().isPresent) 1 else 0) + - (if (filename.asKnown().isPresent) 1 else 0) + - (if (index.asKnown().isPresent) 1 else 0) + - type.let { if (it == JsonValue.from("file_citation")) 1 else 0 } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is FileCitationBody && - fileId == other.fileId && - filename == other.filename && - index == other.index && - type == other.type && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(fileId, filename, index, type, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "FileCitationBody{fileId=$fileId, filename=$filename, index=$index, type=$type, additionalProperties=$additionalProperties}" -} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/conversations/InputFileContent.kt b/openai-java-core/src/main/kotlin/com/openai/models/conversations/InputFileContent.kt deleted file mode 100644 index 428456c98..000000000 --- a/openai-java-core/src/main/kotlin/com/openai/models/conversations/InputFileContent.kt +++ /dev/null @@ -1,288 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.openai.models.conversations - -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.openai.core.ExcludeMissing -import com.openai.core.JsonField -import com.openai.core.JsonMissing -import com.openai.core.JsonValue -import com.openai.core.checkRequired -import com.openai.errors.OpenAIInvalidDataException -import java.util.Collections -import java.util.Objects -import java.util.Optional -import kotlin.jvm.optionals.getOrNull - -class InputFileContent -private constructor( - private val fileId: JsonField, - private val type: JsonValue, - private val fileUrl: JsonField, - private val filename: JsonField, - private val additionalProperties: MutableMap, -) { - - @JsonCreator - private constructor( - @JsonProperty("file_id") @ExcludeMissing fileId: JsonField = JsonMissing.of(), - @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), - @JsonProperty("file_url") @ExcludeMissing fileUrl: JsonField = JsonMissing.of(), - @JsonProperty("filename") @ExcludeMissing filename: JsonField = JsonMissing.of(), - ) : this(fileId, type, fileUrl, filename, mutableMapOf()) - - /** - * The ID of the file to be sent to the model. - * - * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun fileId(): Optional = fileId.getOptional("file_id") - - /** - * The type of the input item. Always `input_file`. - * - * Expected to always return the following: - * ```java - * JsonValue.from("input_file") - * ``` - * - * 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 - - /** - * The URL of the file to be sent to the model. - * - * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun fileUrl(): Optional = fileUrl.getOptional("file_url") - - /** - * The name of the file to be sent to the model. - * - * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun filename(): Optional = filename.getOptional("filename") - - /** - * Returns the raw JSON value of [fileId]. - * - * Unlike [fileId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("file_id") @ExcludeMissing fun _fileId(): JsonField = fileId - - /** - * Returns the raw JSON value of [fileUrl]. - * - * Unlike [fileUrl], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("file_url") @ExcludeMissing fun _fileUrl(): JsonField = fileUrl - - /** - * Returns the raw JSON value of [filename]. - * - * Unlike [filename], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("filename") @ExcludeMissing fun _filename(): JsonField = filename - - @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 [InputFileContent]. - * - * The following fields are required: - * ```java - * .fileId() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [InputFileContent]. */ - class Builder internal constructor() { - - private var fileId: JsonField? = null - private var type: JsonValue = JsonValue.from("input_file") - private var fileUrl: JsonField = JsonMissing.of() - private var filename: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(inputFileContent: InputFileContent) = apply { - fileId = inputFileContent.fileId - type = inputFileContent.type - fileUrl = inputFileContent.fileUrl - filename = inputFileContent.filename - additionalProperties = inputFileContent.additionalProperties.toMutableMap() - } - - /** The ID of the file to be sent to the model. */ - fun fileId(fileId: String?) = fileId(JsonField.ofNullable(fileId)) - - /** Alias for calling [Builder.fileId] with `fileId.orElse(null)`. */ - fun fileId(fileId: Optional) = fileId(fileId.getOrNull()) - - /** - * Sets [Builder.fileId] to an arbitrary JSON value. - * - * You should usually call [Builder.fileId] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun fileId(fileId: JsonField) = apply { this.fileId = fileId } - - /** - * 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("input_file") - * ``` - * - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun type(type: JsonValue) = apply { this.type = type } - - /** The URL of the file to be sent to the model. */ - fun fileUrl(fileUrl: String) = fileUrl(JsonField.of(fileUrl)) - - /** - * Sets [Builder.fileUrl] to an arbitrary JSON value. - * - * You should usually call [Builder.fileUrl] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun fileUrl(fileUrl: JsonField) = apply { this.fileUrl = fileUrl } - - /** The name of the file to be sent to the model. */ - fun filename(filename: String) = filename(JsonField.of(filename)) - - /** - * Sets [Builder.filename] to an arbitrary JSON value. - * - * You should usually call [Builder.filename] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun filename(filename: JsonField) = apply { this.filename = filename } - - 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 [InputFileContent]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .fileId() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): InputFileContent = - InputFileContent( - checkRequired("fileId", fileId), - type, - fileUrl, - filename, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): InputFileContent = apply { - if (validated) { - return@apply - } - - fileId() - _type().let { - if (it != JsonValue.from("input_file")) { - throw OpenAIInvalidDataException("'type' is invalid, received $it") - } - } - fileUrl() - filename() - 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 (fileId.asKnown().isPresent) 1 else 0) + - type.let { if (it == JsonValue.from("input_file")) 1 else 0 } + - (if (fileUrl.asKnown().isPresent) 1 else 0) + - (if (filename.asKnown().isPresent) 1 else 0) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is InputFileContent && - fileId == other.fileId && - type == other.type && - fileUrl == other.fileUrl && - filename == other.filename && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(fileId, type, fileUrl, filename, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "InputFileContent{fileId=$fileId, type=$type, fileUrl=$fileUrl, filename=$filename, additionalProperties=$additionalProperties}" -} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/conversations/InputImageContent.kt b/openai-java-core/src/main/kotlin/com/openai/models/conversations/InputImageContent.kt deleted file mode 100644 index c0043c729..000000000 --- a/openai-java-core/src/main/kotlin/com/openai/models/conversations/InputImageContent.kt +++ /dev/null @@ -1,439 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.openai.models.conversations - -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.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.checkRequired -import com.openai.errors.OpenAIInvalidDataException -import java.util.Collections -import java.util.Objects -import java.util.Optional -import kotlin.jvm.optionals.getOrNull - -class InputImageContent -private constructor( - private val detail: JsonField, - private val fileId: JsonField, - private val imageUrl: JsonField, - private val type: JsonValue, - private val additionalProperties: MutableMap, -) { - - @JsonCreator - private constructor( - @JsonProperty("detail") @ExcludeMissing detail: JsonField = JsonMissing.of(), - @JsonProperty("file_id") @ExcludeMissing fileId: JsonField = JsonMissing.of(), - @JsonProperty("image_url") @ExcludeMissing imageUrl: JsonField = JsonMissing.of(), - @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), - ) : this(detail, fileId, imageUrl, type, mutableMapOf()) - - /** - * The detail level of the image to be sent to the model. One of `high`, `low`, or `auto`. - * Defaults to `auto`. - * - * @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 detail(): Detail = detail.getRequired("detail") - - /** - * The ID of the file to be sent to the model. - * - * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun fileId(): Optional = fileId.getOptional("file_id") - - /** - * The URL of the image to be sent to the model. A fully qualified URL or base64 encoded image - * in a data URL. - * - * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun imageUrl(): Optional = imageUrl.getOptional("image_url") - - /** - * The type of the input item. Always `input_image`. - * - * Expected to always return the following: - * ```java - * JsonValue.from("input_image") - * ``` - * - * 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 [detail]. - * - * Unlike [detail], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("detail") @ExcludeMissing fun _detail(): JsonField = detail - - /** - * Returns the raw JSON value of [fileId]. - * - * Unlike [fileId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("file_id") @ExcludeMissing fun _fileId(): JsonField = fileId - - /** - * Returns the raw JSON value of [imageUrl]. - * - * Unlike [imageUrl], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("image_url") @ExcludeMissing fun _imageUrl(): JsonField = imageUrl - - @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 [InputImageContent]. - * - * The following fields are required: - * ```java - * .detail() - * .fileId() - * .imageUrl() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [InputImageContent]. */ - class Builder internal constructor() { - - private var detail: JsonField? = null - private var fileId: JsonField? = null - private var imageUrl: JsonField? = null - private var type: JsonValue = JsonValue.from("input_image") - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(inputImageContent: InputImageContent) = apply { - detail = inputImageContent.detail - fileId = inputImageContent.fileId - imageUrl = inputImageContent.imageUrl - type = inputImageContent.type - additionalProperties = inputImageContent.additionalProperties.toMutableMap() - } - - /** - * The detail level of the image to be sent to the model. One of `high`, `low`, or `auto`. - * Defaults to `auto`. - */ - fun detail(detail: Detail) = detail(JsonField.of(detail)) - - /** - * Sets [Builder.detail] to an arbitrary JSON value. - * - * You should usually call [Builder.detail] with a well-typed [Detail] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun detail(detail: JsonField) = apply { this.detail = detail } - - /** The ID of the file to be sent to the model. */ - fun fileId(fileId: String?) = fileId(JsonField.ofNullable(fileId)) - - /** Alias for calling [Builder.fileId] with `fileId.orElse(null)`. */ - fun fileId(fileId: Optional) = fileId(fileId.getOrNull()) - - /** - * Sets [Builder.fileId] to an arbitrary JSON value. - * - * You should usually call [Builder.fileId] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun fileId(fileId: JsonField) = apply { this.fileId = fileId } - - /** - * The URL of the image to be sent to the model. A fully qualified URL or base64 encoded - * image in a data URL. - */ - fun imageUrl(imageUrl: String?) = imageUrl(JsonField.ofNullable(imageUrl)) - - /** Alias for calling [Builder.imageUrl] with `imageUrl.orElse(null)`. */ - fun imageUrl(imageUrl: Optional) = imageUrl(imageUrl.getOrNull()) - - /** - * Sets [Builder.imageUrl] to an arbitrary JSON value. - * - * You should usually call [Builder.imageUrl] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun imageUrl(imageUrl: JsonField) = apply { this.imageUrl = imageUrl } - - /** - * 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("input_image") - * ``` - * - * 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 [InputImageContent]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .detail() - * .fileId() - * .imageUrl() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): InputImageContent = - InputImageContent( - checkRequired("detail", detail), - checkRequired("fileId", fileId), - checkRequired("imageUrl", imageUrl), - type, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): InputImageContent = apply { - if (validated) { - return@apply - } - - detail().validate() - fileId() - imageUrl() - _type().let { - if (it != JsonValue.from("input_image")) { - 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 = - (detail.asKnown().getOrNull()?.validity() ?: 0) + - (if (fileId.asKnown().isPresent) 1 else 0) + - (if (imageUrl.asKnown().isPresent) 1 else 0) + - type.let { if (it == JsonValue.from("input_image")) 1 else 0 } - - /** - * The detail level of the image to be sent to the model. One of `high`, `low`, or `auto`. - * Defaults to `auto`. - */ - class Detail @JsonCreator private constructor(private val value: JsonField) : Enum { - - /** - * Returns this class instance's raw value. - * - * This is usually only useful if this instance was deserialized from data that doesn't - * match any known member, and you want to know that value. 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. - */ - @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value - - companion object { - - @JvmField val LOW = of("low") - - @JvmField val HIGH = of("high") - - @JvmField val AUTO = of("auto") - - @JvmStatic fun of(value: String) = Detail(JsonField.of(value)) - } - - /** An enum containing [Detail]'s known values. */ - enum class Known { - LOW, - HIGH, - AUTO, - } - - /** - * An enum containing [Detail]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [Detail] 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. - * - It was constructed with an arbitrary value using the [of] method. - */ - enum class Value { - LOW, - HIGH, - AUTO, - /** An enum member indicating that [Detail] was instantiated with an unknown value. */ - _UNKNOWN, - } - - /** - * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] - * if the class was instantiated with an unknown value. - * - * Use the [known] method instead if you're certain the value is always known or if you want - * to throw for the unknown case. - */ - fun value(): Value = - when (this) { - LOW -> Value.LOW - HIGH -> Value.HIGH - AUTO -> Value.AUTO - else -> Value._UNKNOWN - } - - /** - * Returns an enum member corresponding to this class instance's value. - * - * Use the [value] method instead if you're uncertain the value is always known and don't - * want to throw for the unknown case. - * - * @throws OpenAIInvalidDataException if this class instance's value is a not a known - * member. - */ - fun known(): Known = - when (this) { - LOW -> Known.LOW - HIGH -> Known.HIGH - AUTO -> Known.AUTO - else -> throw OpenAIInvalidDataException("Unknown Detail: $value") - } - - /** - * Returns this class instance's primitive wire representation. - * - * This differs from the [toString] method because that method is primarily for debugging - * and generally doesn't throw. - * - * @throws OpenAIInvalidDataException if this class instance's value does not have the - * expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") } - - private var validated: Boolean = false - - fun validate(): Detail = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object - * recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Detail && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is InputImageContent && - detail == other.detail && - fileId == other.fileId && - imageUrl == other.imageUrl && - type == other.type && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(detail, fileId, imageUrl, type, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "InputImageContent{detail=$detail, fileId=$fileId, imageUrl=$imageUrl, type=$type, additionalProperties=$additionalProperties}" -} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/conversations/InputTextContent.kt b/openai-java-core/src/main/kotlin/com/openai/models/conversations/InputTextContent.kt deleted file mode 100644 index 9b45525a0..000000000 --- a/openai-java-core/src/main/kotlin/com/openai/models/conversations/InputTextContent.kt +++ /dev/null @@ -1,209 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.openai.models.conversations - -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.openai.core.ExcludeMissing -import com.openai.core.JsonField -import com.openai.core.JsonMissing -import com.openai.core.JsonValue -import com.openai.core.checkRequired -import com.openai.errors.OpenAIInvalidDataException -import java.util.Collections -import java.util.Objects - -class InputTextContent -private constructor( - private val text: JsonField, - private val type: JsonValue, - private val additionalProperties: MutableMap, -) { - - @JsonCreator - private constructor( - @JsonProperty("text") @ExcludeMissing text: JsonField = JsonMissing.of(), - @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), - ) : this(text, type, mutableMapOf()) - - /** - * The text input to the model. - * - * @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 the input item. Always `input_text`. - * - * Expected to always return the following: - * ```java - * JsonValue.from("input_text") - * ``` - * - * 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 [text]. - * - * Unlike [text], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text - - @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 [InputTextContent]. - * - * The following fields are required: - * ```java - * .text() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [InputTextContent]. */ - class Builder internal constructor() { - - private var text: JsonField? = null - private var type: JsonValue = JsonValue.from("input_text") - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(inputTextContent: InputTextContent) = apply { - text = inputTextContent.text - type = inputTextContent.type - additionalProperties = inputTextContent.additionalProperties.toMutableMap() - } - - /** The text input to the model. */ - fun text(text: String) = text(JsonField.of(text)) - - /** - * Sets [Builder.text] to an arbitrary JSON value. - * - * You should usually call [Builder.text] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun text(text: JsonField) = apply { this.text = text } - - /** - * 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("input_text") - * ``` - * - * 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 [InputTextContent]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .text() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): InputTextContent = - InputTextContent(checkRequired("text", text), type, additionalProperties.toMutableMap()) - } - - private var validated: Boolean = false - - fun validate(): InputTextContent = apply { - if (validated) { - return@apply - } - - text() - _type().let { - if (it != JsonValue.from("input_text")) { - 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 = - (if (text.asKnown().isPresent) 1 else 0) + - type.let { if (it == JsonValue.from("input_text")) 1 else 0 } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is InputTextContent && - text == other.text && - type == other.type && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { Objects.hash(text, type, additionalProperties) } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "InputTextContent{text=$text, type=$type, additionalProperties=$additionalProperties}" -} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/conversations/LobProb.kt b/openai-java-core/src/main/kotlin/com/openai/models/conversations/LobProb.kt deleted file mode 100644 index af2ac367c..000000000 --- a/openai-java-core/src/main/kotlin/com/openai/models/conversations/LobProb.kt +++ /dev/null @@ -1,307 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.openai.models.conversations - -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.openai.core.ExcludeMissing -import com.openai.core.JsonField -import com.openai.core.JsonMissing -import com.openai.core.JsonValue -import com.openai.core.checkKnown -import com.openai.core.checkRequired -import com.openai.core.toImmutable -import com.openai.errors.OpenAIInvalidDataException -import java.util.Collections -import java.util.Objects -import kotlin.jvm.optionals.getOrNull - -class LobProb -private constructor( - private val token: JsonField, - private val bytes: JsonField>, - private val logprob: JsonField, - private val topLogprobs: JsonField>, - private val additionalProperties: MutableMap, -) { - - @JsonCreator - private constructor( - @JsonProperty("token") @ExcludeMissing token: JsonField = JsonMissing.of(), - @JsonProperty("bytes") @ExcludeMissing bytes: JsonField> = JsonMissing.of(), - @JsonProperty("logprob") @ExcludeMissing logprob: JsonField = JsonMissing.of(), - @JsonProperty("top_logprobs") - @ExcludeMissing - topLogprobs: JsonField> = JsonMissing.of(), - ) : this(token, bytes, logprob, topLogprobs, 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 token(): String = token.getRequired("token") - - /** - * @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 bytes(): List = bytes.getRequired("bytes") - - /** - * @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 logprob(): Double = logprob.getRequired("logprob") - - /** - * @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 topLogprobs(): List = topLogprobs.getRequired("top_logprobs") - - /** - * Returns the raw JSON value of [token]. - * - * Unlike [token], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("token") @ExcludeMissing fun _token(): JsonField = token - - /** - * Returns the raw JSON value of [bytes]. - * - * Unlike [bytes], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("bytes") @ExcludeMissing fun _bytes(): JsonField> = bytes - - /** - * Returns the raw JSON value of [logprob]. - * - * Unlike [logprob], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("logprob") @ExcludeMissing fun _logprob(): JsonField = logprob - - /** - * Returns the raw JSON value of [topLogprobs]. - * - * Unlike [topLogprobs], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("top_logprobs") - @ExcludeMissing - fun _topLogprobs(): JsonField> = topLogprobs - - @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 [LobProb]. - * - * The following fields are required: - * ```java - * .token() - * .bytes() - * .logprob() - * .topLogprobs() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [LobProb]. */ - class Builder internal constructor() { - - private var token: JsonField? = null - private var bytes: JsonField>? = null - private var logprob: JsonField? = null - private var topLogprobs: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(lobProb: LobProb) = apply { - token = lobProb.token - bytes = lobProb.bytes.map { it.toMutableList() } - logprob = lobProb.logprob - topLogprobs = lobProb.topLogprobs.map { it.toMutableList() } - additionalProperties = lobProb.additionalProperties.toMutableMap() - } - - fun token(token: String) = token(JsonField.of(token)) - - /** - * Sets [Builder.token] to an arbitrary JSON value. - * - * You should usually call [Builder.token] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun token(token: JsonField) = apply { this.token = token } - - fun bytes(bytes: List) = bytes(JsonField.of(bytes)) - - /** - * Sets [Builder.bytes] to an arbitrary JSON value. - * - * You should usually call [Builder.bytes] with a well-typed `List` value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun bytes(bytes: JsonField>) = apply { - this.bytes = bytes.map { it.toMutableList() } - } - - /** - * Adds a single [Long] to [bytes]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addByte(byte_: Long) = apply { - bytes = - (bytes ?: JsonField.of(mutableListOf())).also { checkKnown("bytes", it).add(byte_) } - } - - fun logprob(logprob: Double) = logprob(JsonField.of(logprob)) - - /** - * Sets [Builder.logprob] to an arbitrary JSON value. - * - * You should usually call [Builder.logprob] with a well-typed [Double] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun logprob(logprob: JsonField) = apply { this.logprob = logprob } - - fun topLogprobs(topLogprobs: List) = topLogprobs(JsonField.of(topLogprobs)) - - /** - * Sets [Builder.topLogprobs] to an arbitrary JSON value. - * - * You should usually call [Builder.topLogprobs] with a well-typed `List` value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun topLogprobs(topLogprobs: JsonField>) = apply { - this.topLogprobs = topLogprobs.map { it.toMutableList() } - } - - /** - * Adds a single [TopLogProb] to [topLogprobs]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addTopLogprob(topLogprob: TopLogProb) = apply { - topLogprobs = - (topLogprobs ?: JsonField.of(mutableListOf())).also { - checkKnown("topLogprobs", it).add(topLogprob) - } - } - - 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 [LobProb]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .token() - * .bytes() - * .logprob() - * .topLogprobs() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): LobProb = - LobProb( - checkRequired("token", token), - checkRequired("bytes", bytes).map { it.toImmutable() }, - checkRequired("logprob", logprob), - checkRequired("topLogprobs", topLogprobs).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): LobProb = apply { - if (validated) { - return@apply - } - - token() - bytes() - logprob() - topLogprobs().forEach { it.validate() } - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - (if (token.asKnown().isPresent) 1 else 0) + - (bytes.asKnown().getOrNull()?.size ?: 0) + - (if (logprob.asKnown().isPresent) 1 else 0) + - (topLogprobs.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is LobProb && - token == other.token && - bytes == other.bytes && - logprob == other.logprob && - topLogprobs == other.topLogprobs && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(token, bytes, logprob, topLogprobs, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "LobProb{token=$token, bytes=$bytes, logprob=$logprob, topLogprobs=$topLogprobs, additionalProperties=$additionalProperties}" -} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/conversations/Message.kt b/openai-java-core/src/main/kotlin/com/openai/models/conversations/Message.kt index f9fdc5a1f..b6ee32bf6 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/conversations/Message.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/conversations/Message.kt @@ -25,11 +25,17 @@ import com.openai.core.checkRequired import com.openai.core.getOrThrow import com.openai.core.toImmutable import com.openai.errors.OpenAIInvalidDataException +import com.openai.models.responses.ResponseInputFile +import com.openai.models.responses.ResponseInputImage +import com.openai.models.responses.ResponseInputText +import com.openai.models.responses.ResponseOutputRefusal +import com.openai.models.responses.ResponseOutputText import java.util.Collections import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull +/** A message to or from the model. */ class Message private constructor( private val id: JsonField, @@ -212,21 +218,22 @@ private constructor( } /** Alias for calling [addContent] with `Content.ofInputText(inputText)`. */ - fun addContent(inputText: InputTextContent) = addContent(Content.ofInputText(inputText)) + fun addContent(inputText: ResponseInputText) = addContent(Content.ofInputText(inputText)) /** * Alias for calling [addContent] with the following: * ```java - * InputTextContent.builder() + * ResponseInputText.builder() * .text(text) * .build() * ``` */ fun addInputTextContent(text: String) = - addContent(InputTextContent.builder().text(text).build()) + addContent(ResponseInputText.builder().text(text).build()) /** Alias for calling [addContent] with `Content.ofOutputText(outputText)`. */ - fun addContent(outputText: OutputTextContent) = addContent(Content.ofOutputText(outputText)) + fun addContent(outputText: ResponseOutputText) = + addContent(Content.ofOutputText(outputText)) /** Alias for calling [addContent] with `Content.ofText(text)`. */ fun addContent(text: TextContent) = addContent(Content.ofText(text)) @@ -256,45 +263,58 @@ private constructor( fun addSummaryTextContent(text: String) = addContent(SummaryTextContent.builder().text(text).build()) - /** Alias for calling [addContent] with `Content.ofRefusal(refusal)`. */ - fun addContent(refusal: RefusalContent) = addContent(Content.ofRefusal(refusal)) + /** Alias for calling [addContent] with `Content.ofReasoningText(reasoningText)`. */ + fun addContent(reasoningText: Content.ReasoningText) = + addContent(Content.ofReasoningText(reasoningText)) /** * Alias for calling [addContent] with the following: * ```java - * RefusalContent.builder() - * .refusal(refusal) + * Content.ReasoningText.builder() + * .text(text) * .build() * ``` */ - fun addRefusalContent(refusal: String) = - addContent(RefusalContent.builder().refusal(refusal).build()) + fun addReasoningTextContent(text: String) = + addContent(Content.ReasoningText.builder().text(text).build()) - /** Alias for calling [addContent] with `Content.ofInputImage(inputImage)`. */ - fun addContent(inputImage: InputImageContent) = addContent(Content.ofInputImage(inputImage)) + /** Alias for calling [addContent] with `Content.ofRefusal(refusal)`. */ + fun addContent(refusal: ResponseOutputRefusal) = addContent(Content.ofRefusal(refusal)) /** - * Alias for calling [addContent] with `Content.ofComputerScreenshot(computerScreenshot)`. + * Alias for calling [addContent] with the following: + * ```java + * ResponseOutputRefusal.builder() + * .refusal(refusal) + * .build() + * ``` */ - fun addContent(computerScreenshot: ComputerScreenshotContent) = - addContent(Content.ofComputerScreenshot(computerScreenshot)) + fun addRefusalContent(refusal: String) = + addContent(ResponseOutputRefusal.builder().refusal(refusal).build()) - /** Alias for calling [addContent] with `Content.ofInputFile(inputFile)`. */ - fun addContent(inputFile: InputFileContent) = addContent(Content.ofInputFile(inputFile)) + /** Alias for calling [addContent] with `Content.ofInputImage(inputImage)`. */ + fun addContent(inputImage: ResponseInputImage) = + addContent(Content.ofInputImage(inputImage)) /** * Alias for calling [addContent] with the following: * ```java - * InputFileContent.builder() - * .fileId(fileId) + * ResponseInputImage.builder() + * .detail(detail) * .build() * ``` */ - fun addInputFileContent(fileId: String?) = - addContent(InputFileContent.builder().fileId(fileId).build()) + fun addInputImageContent(detail: ResponseInputImage.Detail) = + addContent(ResponseInputImage.builder().detail(detail).build()) - /** Alias for calling [addInputFileContent] with `fileId.orElse(null)`. */ - fun addInputFileContent(fileId: Optional) = addInputFileContent(fileId.getOrNull()) + /** + * Alias for calling [addContent] with `Content.ofComputerScreenshot(computerScreenshot)`. + */ + fun addContent(computerScreenshot: ComputerScreenshotContent) = + addContent(Content.ofComputerScreenshot(computerScreenshot)) + + /** Alias for calling [addContent] with `Content.ofInputFile(inputFile)`. */ + fun addContent(inputFile: ResponseInputFile) = addContent(Content.ofInputFile(inputFile)) /** * The role of the message. One of `unknown`, `user`, `assistant`, `system`, `critic`, @@ -423,37 +443,53 @@ private constructor( (status.asKnown().getOrNull()?.validity() ?: 0) + type.let { if (it == JsonValue.from("message")) 1 else 0 } + /** A text input to the model. */ @JsonDeserialize(using = Content.Deserializer::class) @JsonSerialize(using = Content.Serializer::class) class Content private constructor( - private val inputText: InputTextContent? = null, - private val outputText: OutputTextContent? = null, + private val inputText: ResponseInputText? = null, + private val outputText: ResponseOutputText? = null, private val text: TextContent? = null, private val summaryText: SummaryTextContent? = null, - private val refusal: RefusalContent? = null, - private val inputImage: InputImageContent? = null, + private val reasoningText: ReasoningText? = null, + private val refusal: ResponseOutputRefusal? = null, + private val inputImage: ResponseInputImage? = null, private val computerScreenshot: ComputerScreenshotContent? = null, - private val inputFile: InputFileContent? = null, + private val inputFile: ResponseInputFile? = null, private val _json: JsonValue? = null, ) { - fun inputText(): Optional = Optional.ofNullable(inputText) + /** A text input to the model. */ + fun inputText(): Optional = Optional.ofNullable(inputText) - fun outputText(): Optional = Optional.ofNullable(outputText) + /** A text output from the model. */ + fun outputText(): Optional = Optional.ofNullable(outputText) + /** A text content. */ fun text(): Optional = Optional.ofNullable(text) + /** A summary text from the model. */ fun summaryText(): Optional = Optional.ofNullable(summaryText) - fun refusal(): Optional = Optional.ofNullable(refusal) + /** Reasoning text from the model. */ + fun reasoningText(): Optional = Optional.ofNullable(reasoningText) + + /** A refusal from the model. */ + fun refusal(): Optional = Optional.ofNullable(refusal) - fun inputImage(): Optional = Optional.ofNullable(inputImage) + /** + * An image input to the model. Learn about + * [image inputs](https://platform.openai.com/docs/guides/vision). + */ + fun inputImage(): Optional = Optional.ofNullable(inputImage) + /** A screenshot of a computer. */ fun computerScreenshot(): Optional = Optional.ofNullable(computerScreenshot) - fun inputFile(): Optional = Optional.ofNullable(inputFile) + /** A file input to the model. */ + fun inputFile(): Optional = Optional.ofNullable(inputFile) fun isInputText(): Boolean = inputText != null @@ -463,6 +499,8 @@ private constructor( fun isSummaryText(): Boolean = summaryText != null + fun isReasoningText(): Boolean = reasoningText != null + fun isRefusal(): Boolean = refusal != null fun isInputImage(): Boolean = inputImage != null @@ -471,22 +509,36 @@ private constructor( fun isInputFile(): Boolean = inputFile != null - fun asInputText(): InputTextContent = inputText.getOrThrow("inputText") + /** A text input to the model. */ + fun asInputText(): ResponseInputText = inputText.getOrThrow("inputText") - fun asOutputText(): OutputTextContent = outputText.getOrThrow("outputText") + /** A text output from the model. */ + fun asOutputText(): ResponseOutputText = outputText.getOrThrow("outputText") + /** A text content. */ fun asText(): TextContent = text.getOrThrow("text") + /** A summary text from the model. */ fun asSummaryText(): SummaryTextContent = summaryText.getOrThrow("summaryText") - fun asRefusal(): RefusalContent = refusal.getOrThrow("refusal") + /** Reasoning text from the model. */ + fun asReasoningText(): ReasoningText = reasoningText.getOrThrow("reasoningText") - fun asInputImage(): InputImageContent = inputImage.getOrThrow("inputImage") + /** A refusal from the model. */ + fun asRefusal(): ResponseOutputRefusal = refusal.getOrThrow("refusal") + /** + * An image input to the model. Learn about + * [image inputs](https://platform.openai.com/docs/guides/vision). + */ + fun asInputImage(): ResponseInputImage = inputImage.getOrThrow("inputImage") + + /** A screenshot of a computer. */ fun asComputerScreenshot(): ComputerScreenshotContent = computerScreenshot.getOrThrow("computerScreenshot") - fun asInputFile(): InputFileContent = inputFile.getOrThrow("inputFile") + /** A file input to the model. */ + fun asInputFile(): ResponseInputFile = inputFile.getOrThrow("inputFile") fun _json(): Optional = Optional.ofNullable(_json) @@ -496,6 +548,7 @@ private constructor( outputText != null -> visitor.visitOutputText(outputText) text != null -> visitor.visitText(text) summaryText != null -> visitor.visitSummaryText(summaryText) + reasoningText != null -> visitor.visitReasoningText(reasoningText) refusal != null -> visitor.visitRefusal(refusal) inputImage != null -> visitor.visitInputImage(inputImage) computerScreenshot != null -> visitor.visitComputerScreenshot(computerScreenshot) @@ -512,11 +565,11 @@ private constructor( accept( object : Visitor { - override fun visitInputText(inputText: InputTextContent) { + override fun visitInputText(inputText: ResponseInputText) { inputText.validate() } - override fun visitOutputText(outputText: OutputTextContent) { + override fun visitOutputText(outputText: ResponseOutputText) { outputText.validate() } @@ -528,11 +581,15 @@ private constructor( summaryText.validate() } - override fun visitRefusal(refusal: RefusalContent) { + override fun visitReasoningText(reasoningText: ReasoningText) { + reasoningText.validate() + } + + override fun visitRefusal(refusal: ResponseOutputRefusal) { refusal.validate() } - override fun visitInputImage(inputImage: InputImageContent) { + override fun visitInputImage(inputImage: ResponseInputImage) { inputImage.validate() } @@ -542,7 +599,7 @@ private constructor( computerScreenshot.validate() } - override fun visitInputFile(inputFile: InputFileContent) { + override fun visitInputFile(inputFile: ResponseInputFile) { inputFile.validate() } } @@ -568,9 +625,9 @@ private constructor( internal fun validity(): Int = accept( object : Visitor { - override fun visitInputText(inputText: InputTextContent) = inputText.validity() + override fun visitInputText(inputText: ResponseInputText) = inputText.validity() - override fun visitOutputText(outputText: OutputTextContent) = + override fun visitOutputText(outputText: ResponseOutputText) = outputText.validity() override fun visitText(text: TextContent) = text.validity() @@ -578,16 +635,19 @@ private constructor( override fun visitSummaryText(summaryText: SummaryTextContent) = summaryText.validity() - override fun visitRefusal(refusal: RefusalContent) = refusal.validity() + override fun visitReasoningText(reasoningText: ReasoningText) = + reasoningText.validity() - override fun visitInputImage(inputImage: InputImageContent) = + override fun visitRefusal(refusal: ResponseOutputRefusal) = refusal.validity() + + override fun visitInputImage(inputImage: ResponseInputImage) = inputImage.validity() override fun visitComputerScreenshot( computerScreenshot: ComputerScreenshotContent ) = computerScreenshot.validity() - override fun visitInputFile(inputFile: InputFileContent) = inputFile.validity() + override fun visitInputFile(inputFile: ResponseInputFile) = inputFile.validity() override fun unknown(json: JsonValue?) = 0 } @@ -603,6 +663,7 @@ private constructor( outputText == other.outputText && text == other.text && summaryText == other.summaryText && + reasoningText == other.reasoningText && refusal == other.refusal && inputImage == other.inputImage && computerScreenshot == other.computerScreenshot && @@ -615,6 +676,7 @@ private constructor( outputText, text, summaryText, + reasoningText, refusal, inputImage, computerScreenshot, @@ -627,6 +689,7 @@ private constructor( outputText != null -> "Content{outputText=$outputText}" text != null -> "Content{text=$text}" summaryText != null -> "Content{summaryText=$summaryText}" + reasoningText != null -> "Content{reasoningText=$reasoningText}" refusal != null -> "Content{refusal=$refusal}" inputImage != null -> "Content{inputImage=$inputImage}" computerScreenshot != null -> "Content{computerScreenshot=$computerScreenshot}" @@ -637,26 +700,44 @@ private constructor( companion object { - @JvmStatic fun ofInputText(inputText: InputTextContent) = Content(inputText = inputText) + /** A text input to the model. */ + @JvmStatic + fun ofInputText(inputText: ResponseInputText) = Content(inputText = inputText) + /** A text output from the model. */ @JvmStatic - fun ofOutputText(outputText: OutputTextContent) = Content(outputText = outputText) + fun ofOutputText(outputText: ResponseOutputText) = Content(outputText = outputText) + /** A text content. */ @JvmStatic fun ofText(text: TextContent) = Content(text = text) + /** A summary text from the model. */ @JvmStatic fun ofSummaryText(summaryText: SummaryTextContent) = Content(summaryText = summaryText) - @JvmStatic fun ofRefusal(refusal: RefusalContent) = Content(refusal = refusal) + /** Reasoning text from the model. */ + @JvmStatic + fun ofReasoningText(reasoningText: ReasoningText) = + Content(reasoningText = reasoningText) + + /** A refusal from the model. */ + @JvmStatic fun ofRefusal(refusal: ResponseOutputRefusal) = Content(refusal = refusal) + /** + * An image input to the model. Learn about + * [image inputs](https://platform.openai.com/docs/guides/vision). + */ @JvmStatic - fun ofInputImage(inputImage: InputImageContent) = Content(inputImage = inputImage) + fun ofInputImage(inputImage: ResponseInputImage) = Content(inputImage = inputImage) + /** A screenshot of a computer. */ @JvmStatic fun ofComputerScreenshot(computerScreenshot: ComputerScreenshotContent) = Content(computerScreenshot = computerScreenshot) - @JvmStatic fun ofInputFile(inputFile: InputFileContent) = Content(inputFile = inputFile) + /** A file input to the model. */ + @JvmStatic + fun ofInputFile(inputFile: ResponseInputFile) = Content(inputFile = inputFile) } /** @@ -664,21 +745,35 @@ private constructor( */ interface Visitor { - fun visitInputText(inputText: InputTextContent): T + /** A text input to the model. */ + fun visitInputText(inputText: ResponseInputText): T - fun visitOutputText(outputText: OutputTextContent): T + /** A text output from the model. */ + fun visitOutputText(outputText: ResponseOutputText): T + /** A text content. */ fun visitText(text: TextContent): T + /** A summary text from the model. */ fun visitSummaryText(summaryText: SummaryTextContent): T - fun visitRefusal(refusal: RefusalContent): T + /** Reasoning text from the model. */ + fun visitReasoningText(reasoningText: ReasoningText): T + + /** A refusal from the model. */ + fun visitRefusal(refusal: ResponseOutputRefusal): T - fun visitInputImage(inputImage: InputImageContent): T + /** + * An image input to the model. Learn about + * [image inputs](https://platform.openai.com/docs/guides/vision). + */ + fun visitInputImage(inputImage: ResponseInputImage): T + /** A screenshot of a computer. */ fun visitComputerScreenshot(computerScreenshot: ComputerScreenshotContent): T - fun visitInputFile(inputFile: InputFileContent): T + /** A file input to the model. */ + fun visitInputFile(inputFile: ResponseInputFile): T /** * Maps an unknown variant of [Content] to a value of type [T]. @@ -703,12 +798,12 @@ private constructor( when (type) { "input_text" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { + return tryDeserialize(node, jacksonTypeRef())?.let { Content(inputText = it, _json = json) } ?: Content(_json = json) } "output_text" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { + return tryDeserialize(node, jacksonTypeRef())?.let { Content(outputText = it, _json = json) } ?: Content(_json = json) } @@ -722,13 +817,18 @@ private constructor( Content(summaryText = it, _json = json) } ?: Content(_json = json) } + "reasoning_text" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Content(reasoningText = it, _json = json) + } ?: Content(_json = json) + } "refusal" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { + return tryDeserialize(node, jacksonTypeRef())?.let { Content(refusal = it, _json = json) } ?: Content(_json = json) } "input_image" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { + return tryDeserialize(node, jacksonTypeRef())?.let { Content(inputImage = it, _json = json) } ?: Content(_json = json) } @@ -738,7 +838,7 @@ private constructor( ?: Content(_json = json) } "input_file" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { + return tryDeserialize(node, jacksonTypeRef())?.let { Content(inputFile = it, _json = json) } ?: Content(_json = json) } @@ -760,6 +860,7 @@ private constructor( value.outputText != null -> generator.writeObject(value.outputText) value.text != null -> generator.writeObject(value.text) value.summaryText != null -> generator.writeObject(value.summaryText) + value.reasoningText != null -> generator.writeObject(value.reasoningText) value.refusal != null -> generator.writeObject(value.refusal) value.inputImage != null -> generator.writeObject(value.inputImage) value.computerScreenshot != null -> @@ -770,6 +871,210 @@ private constructor( } } } + + /** Reasoning text from the model. */ + class ReasoningText + private constructor( + private val text: JsonField, + private val type: JsonValue, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("text") @ExcludeMissing text: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + ) : this(text, type, mutableMapOf()) + + /** + * The reasoning text from the model. + * + * @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 the reasoning text. Always `reasoning_text`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("reasoning_text") + * ``` + * + * 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 [text]. + * + * Unlike [text], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text + + @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 [ReasoningText]. + * + * The following fields are required: + * ```java + * .text() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ReasoningText]. */ + class Builder internal constructor() { + + private var text: JsonField? = null + private var type: JsonValue = JsonValue.from("reasoning_text") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(reasoningText: ReasoningText) = apply { + text = reasoningText.text + type = reasoningText.type + additionalProperties = reasoningText.additionalProperties.toMutableMap() + } + + /** The reasoning text from the model. */ + fun text(text: String) = text(JsonField.of(text)) + + /** + * Sets [Builder.text] to an arbitrary JSON value. + * + * You should usually call [Builder.text] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun text(text: JsonField) = apply { this.text = text } + + /** + * 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("reasoning_text") + * ``` + * + * 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 [ReasoningText]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .text() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ReasoningText = + ReasoningText( + checkRequired("text", text), + type, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ReasoningText = apply { + if (validated) { + return@apply + } + + text() + _type().let { + if (it != JsonValue.from("reasoning_text")) { + 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 = + (if (text.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("reasoning_text")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ReasoningText && + text == other.text && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(text, type, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ReasoningText{text=$text, type=$type, additionalProperties=$additionalProperties}" + } } /** diff --git a/openai-java-core/src/main/kotlin/com/openai/models/conversations/OutputTextContent.kt b/openai-java-core/src/main/kotlin/com/openai/models/conversations/OutputTextContent.kt deleted file mode 100644 index 1fe6ccb72..000000000 --- a/openai-java-core/src/main/kotlin/com/openai/models/conversations/OutputTextContent.kt +++ /dev/null @@ -1,558 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.openai.models.conversations - -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.ExcludeMissing -import com.openai.core.JsonField -import com.openai.core.JsonMissing -import com.openai.core.JsonValue -import com.openai.core.checkKnown -import com.openai.core.checkRequired -import com.openai.core.getOrThrow -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 - -class OutputTextContent -private constructor( - private val annotations: JsonField>, - private val text: JsonField, - private val type: JsonValue, - private val logprobs: JsonField>, - private val additionalProperties: MutableMap, -) { - - @JsonCreator - private constructor( - @JsonProperty("annotations") - @ExcludeMissing - annotations: JsonField> = JsonMissing.of(), - @JsonProperty("text") @ExcludeMissing text: JsonField = JsonMissing.of(), - @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), - @JsonProperty("logprobs") - @ExcludeMissing - logprobs: JsonField> = JsonMissing.of(), - ) : this(annotations, text, type, logprobs, mutableMapOf()) - - /** - * The annotations of the text output. - * - * @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 annotations(): List = annotations.getRequired("annotations") - - /** - * The text output from the model. - * - * @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 the output text. Always `output_text`. - * - * Expected to always return the following: - * ```java - * JsonValue.from("output_text") - * ``` - * - * 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 - - /** - * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). - */ - fun logprobs(): Optional> = logprobs.getOptional("logprobs") - - /** - * Returns the raw JSON value of [annotations]. - * - * Unlike [annotations], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("annotations") - @ExcludeMissing - fun _annotations(): JsonField> = annotations - - /** - * 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 [logprobs]. - * - * Unlike [logprobs], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("logprobs") @ExcludeMissing fun _logprobs(): JsonField> = logprobs - - @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 [OutputTextContent]. - * - * The following fields are required: - * ```java - * .annotations() - * .text() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [OutputTextContent]. */ - class Builder internal constructor() { - - private var annotations: JsonField>? = null - private var text: JsonField? = null - private var type: JsonValue = JsonValue.from("output_text") - private var logprobs: JsonField>? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(outputTextContent: OutputTextContent) = apply { - annotations = outputTextContent.annotations.map { it.toMutableList() } - text = outputTextContent.text - type = outputTextContent.type - logprobs = outputTextContent.logprobs.map { it.toMutableList() } - additionalProperties = outputTextContent.additionalProperties.toMutableMap() - } - - /** The annotations of the text output. */ - fun annotations(annotations: List) = annotations(JsonField.of(annotations)) - - /** - * Sets [Builder.annotations] to an arbitrary JSON value. - * - * You should usually call [Builder.annotations] with a well-typed `List` value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun annotations(annotations: JsonField>) = apply { - this.annotations = annotations.map { it.toMutableList() } - } - - /** - * Adds a single [Annotation] to [annotations]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addAnnotation(annotation: Annotation) = apply { - annotations = - (annotations ?: JsonField.of(mutableListOf())).also { - checkKnown("annotations", it).add(annotation) - } - } - - /** Alias for calling [addAnnotation] with `Annotation.ofFileCitation(fileCitation)`. */ - fun addAnnotation(fileCitation: FileCitationBody) = - addAnnotation(Annotation.ofFileCitation(fileCitation)) - - /** Alias for calling [addAnnotation] with `Annotation.ofUrlCitation(urlCitation)`. */ - fun addAnnotation(urlCitation: UrlCitationBody) = - addAnnotation(Annotation.ofUrlCitation(urlCitation)) - - /** - * Alias for calling [addAnnotation] with - * `Annotation.ofContainerFileCitation(containerFileCitation)`. - */ - fun addAnnotation(containerFileCitation: ContainerFileCitationBody) = - addAnnotation(Annotation.ofContainerFileCitation(containerFileCitation)) - - /** The text output from the model. */ - fun text(text: String) = text(JsonField.of(text)) - - /** - * Sets [Builder.text] to an arbitrary JSON value. - * - * You should usually call [Builder.text] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun text(text: JsonField) = apply { this.text = text } - - /** - * 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("output_text") - * ``` - * - * 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 logprobs(logprobs: List) = logprobs(JsonField.of(logprobs)) - - /** - * Sets [Builder.logprobs] to an arbitrary JSON value. - * - * You should usually call [Builder.logprobs] with a well-typed `List` value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun logprobs(logprobs: JsonField>) = apply { - this.logprobs = logprobs.map { it.toMutableList() } - } - - /** - * Adds a single [LobProb] to [logprobs]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addLogprob(logprob: LobProb) = apply { - logprobs = - (logprobs ?: JsonField.of(mutableListOf())).also { - checkKnown("logprobs", it).add(logprob) - } - } - - 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 [OutputTextContent]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .annotations() - * .text() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): OutputTextContent = - OutputTextContent( - checkRequired("annotations", annotations).map { it.toImmutable() }, - checkRequired("text", text), - type, - (logprobs ?: JsonMissing.of()).map { it.toImmutable() }, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): OutputTextContent = apply { - if (validated) { - return@apply - } - - annotations().forEach { it.validate() } - text() - _type().let { - if (it != JsonValue.from("output_text")) { - throw OpenAIInvalidDataException("'type' is invalid, received $it") - } - } - logprobs().ifPresent { it.forEach { 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 = - (annotations.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + - (if (text.asKnown().isPresent) 1 else 0) + - type.let { if (it == JsonValue.from("output_text")) 1 else 0 } + - (logprobs.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) - - @JsonDeserialize(using = Annotation.Deserializer::class) - @JsonSerialize(using = Annotation.Serializer::class) - class Annotation - private constructor( - private val fileCitation: FileCitationBody? = null, - private val urlCitation: UrlCitationBody? = null, - private val containerFileCitation: ContainerFileCitationBody? = null, - private val _json: JsonValue? = null, - ) { - - fun fileCitation(): Optional = Optional.ofNullable(fileCitation) - - fun urlCitation(): Optional = Optional.ofNullable(urlCitation) - - fun containerFileCitation(): Optional = - Optional.ofNullable(containerFileCitation) - - fun isFileCitation(): Boolean = fileCitation != null - - fun isUrlCitation(): Boolean = urlCitation != null - - fun isContainerFileCitation(): Boolean = containerFileCitation != null - - fun asFileCitation(): FileCitationBody = fileCitation.getOrThrow("fileCitation") - - fun asUrlCitation(): UrlCitationBody = urlCitation.getOrThrow("urlCitation") - - fun asContainerFileCitation(): ContainerFileCitationBody = - containerFileCitation.getOrThrow("containerFileCitation") - - fun _json(): Optional = Optional.ofNullable(_json) - - fun accept(visitor: Visitor): T = - when { - fileCitation != null -> visitor.visitFileCitation(fileCitation) - urlCitation != null -> visitor.visitUrlCitation(urlCitation) - containerFileCitation != null -> - visitor.visitContainerFileCitation(containerFileCitation) - else -> visitor.unknown(_json) - } - - private var validated: Boolean = false - - fun validate(): Annotation = apply { - if (validated) { - return@apply - } - - accept( - object : Visitor { - override fun visitFileCitation(fileCitation: FileCitationBody) { - fileCitation.validate() - } - - override fun visitUrlCitation(urlCitation: UrlCitationBody) { - urlCitation.validate() - } - - override fun visitContainerFileCitation( - containerFileCitation: ContainerFileCitationBody - ) { - containerFileCitation.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 visitFileCitation(fileCitation: FileCitationBody) = - fileCitation.validity() - - override fun visitUrlCitation(urlCitation: UrlCitationBody) = - urlCitation.validity() - - override fun visitContainerFileCitation( - containerFileCitation: ContainerFileCitationBody - ) = containerFileCitation.validity() - - override fun unknown(json: JsonValue?) = 0 - } - ) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is Annotation && - fileCitation == other.fileCitation && - urlCitation == other.urlCitation && - containerFileCitation == other.containerFileCitation - } - - override fun hashCode(): Int = - Objects.hash(fileCitation, urlCitation, containerFileCitation) - - override fun toString(): String = - when { - fileCitation != null -> "Annotation{fileCitation=$fileCitation}" - urlCitation != null -> "Annotation{urlCitation=$urlCitation}" - containerFileCitation != null -> - "Annotation{containerFileCitation=$containerFileCitation}" - _json != null -> "Annotation{_unknown=$_json}" - else -> throw IllegalStateException("Invalid Annotation") - } - - companion object { - - @JvmStatic - fun ofFileCitation(fileCitation: FileCitationBody) = - Annotation(fileCitation = fileCitation) - - @JvmStatic - fun ofUrlCitation(urlCitation: UrlCitationBody) = Annotation(urlCitation = urlCitation) - - @JvmStatic - fun ofContainerFileCitation(containerFileCitation: ContainerFileCitationBody) = - Annotation(containerFileCitation = containerFileCitation) - } - - /** - * An interface that defines how to map each variant of [Annotation] to a value of type [T]. - */ - interface Visitor { - - fun visitFileCitation(fileCitation: FileCitationBody): T - - fun visitUrlCitation(urlCitation: UrlCitationBody): T - - fun visitContainerFileCitation(containerFileCitation: ContainerFileCitationBody): T - - /** - * Maps an unknown variant of [Annotation] to a value of type [T]. - * - * An instance of [Annotation] 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 Annotation: $json") - } - } - - internal class Deserializer : BaseDeserializer(Annotation::class) { - - override fun ObjectCodec.deserialize(node: JsonNode): Annotation { - val json = JsonValue.fromJsonNode(node) - val type = json.asObject().getOrNull()?.get("type")?.asString()?.getOrNull() - - when (type) { - "file_citation" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - Annotation(fileCitation = it, _json = json) - } ?: Annotation(_json = json) - } - "url_citation" -> { - return tryDeserialize(node, jacksonTypeRef())?.let { - Annotation(urlCitation = it, _json = json) - } ?: Annotation(_json = json) - } - "container_file_citation" -> { - return tryDeserialize(node, jacksonTypeRef()) - ?.let { Annotation(containerFileCitation = it, _json = json) } - ?: Annotation(_json = json) - } - } - - return Annotation(_json = json) - } - } - - internal class Serializer : BaseSerializer(Annotation::class) { - - override fun serialize( - value: Annotation, - generator: JsonGenerator, - provider: SerializerProvider, - ) { - when { - value.fileCitation != null -> generator.writeObject(value.fileCitation) - value.urlCitation != null -> generator.writeObject(value.urlCitation) - value.containerFileCitation != null -> - generator.writeObject(value.containerFileCitation) - value._json != null -> generator.writeObject(value._json) - else -> throw IllegalStateException("Invalid Annotation") - } - } - } - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is OutputTextContent && - annotations == other.annotations && - text == other.text && - type == other.type && - logprobs == other.logprobs && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(annotations, text, type, logprobs, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "OutputTextContent{annotations=$annotations, text=$text, type=$type, logprobs=$logprobs, additionalProperties=$additionalProperties}" -} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/conversations/RefusalContent.kt b/openai-java-core/src/main/kotlin/com/openai/models/conversations/RefusalContent.kt deleted file mode 100644 index 6cc73948e..000000000 --- a/openai-java-core/src/main/kotlin/com/openai/models/conversations/RefusalContent.kt +++ /dev/null @@ -1,213 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.openai.models.conversations - -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.openai.core.ExcludeMissing -import com.openai.core.JsonField -import com.openai.core.JsonMissing -import com.openai.core.JsonValue -import com.openai.core.checkRequired -import com.openai.errors.OpenAIInvalidDataException -import java.util.Collections -import java.util.Objects - -class RefusalContent -private constructor( - private val refusal: JsonField, - private val type: JsonValue, - private val additionalProperties: MutableMap, -) { - - @JsonCreator - private constructor( - @JsonProperty("refusal") @ExcludeMissing refusal: JsonField = JsonMissing.of(), - @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), - ) : this(refusal, type, mutableMapOf()) - - /** - * The refusal explanation from the model. - * - * @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 refusal(): String = refusal.getRequired("refusal") - - /** - * The type of the refusal. Always `refusal`. - * - * Expected to always return the following: - * ```java - * JsonValue.from("refusal") - * ``` - * - * 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 [refusal]. - * - * Unlike [refusal], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("refusal") @ExcludeMissing fun _refusal(): JsonField = refusal - - @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 [RefusalContent]. - * - * The following fields are required: - * ```java - * .refusal() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [RefusalContent]. */ - class Builder internal constructor() { - - private var refusal: JsonField? = null - private var type: JsonValue = JsonValue.from("refusal") - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(refusalContent: RefusalContent) = apply { - refusal = refusalContent.refusal - type = refusalContent.type - additionalProperties = refusalContent.additionalProperties.toMutableMap() - } - - /** The refusal explanation from the model. */ - fun refusal(refusal: String) = refusal(JsonField.of(refusal)) - - /** - * Sets [Builder.refusal] to an arbitrary JSON value. - * - * You should usually call [Builder.refusal] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun refusal(refusal: JsonField) = apply { this.refusal = refusal } - - /** - * 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("refusal") - * ``` - * - * 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 [RefusalContent]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .refusal() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): RefusalContent = - RefusalContent( - checkRequired("refusal", refusal), - type, - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): RefusalContent = apply { - if (validated) { - return@apply - } - - refusal() - _type().let { - if (it != JsonValue.from("refusal")) { - 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 = - (if (refusal.asKnown().isPresent) 1 else 0) + - type.let { if (it == JsonValue.from("refusal")) 1 else 0 } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is RefusalContent && - refusal == other.refusal && - type == other.type && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { Objects.hash(refusal, type, additionalProperties) } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "RefusalContent{refusal=$refusal, type=$type, additionalProperties=$additionalProperties}" -} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/conversations/SummaryTextContent.kt b/openai-java-core/src/main/kotlin/com/openai/models/conversations/SummaryTextContent.kt index 263a247c3..a00fb944c 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/conversations/SummaryTextContent.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/conversations/SummaryTextContent.kt @@ -15,6 +15,7 @@ import com.openai.errors.OpenAIInvalidDataException import java.util.Collections import java.util.Objects +/** A summary text from the model. */ class SummaryTextContent private constructor( private val text: JsonField, @@ -29,12 +30,16 @@ private constructor( ) : this(text, type, mutableMapOf()) /** + * A summary of the reasoning output from the model so far. + * * @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 the object. Always `summary_text`. + * * Expected to always return the following: * ```java * JsonValue.from("summary_text") @@ -91,6 +96,7 @@ private constructor( additionalProperties = summaryTextContent.additionalProperties.toMutableMap() } + /** A summary of the reasoning output from the model so far. */ fun text(text: String) = text(JsonField.of(text)) /** diff --git a/openai-java-core/src/main/kotlin/com/openai/models/conversations/TextContent.kt b/openai-java-core/src/main/kotlin/com/openai/models/conversations/TextContent.kt index 120f1488b..3f5286528 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/conversations/TextContent.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/conversations/TextContent.kt @@ -15,6 +15,7 @@ import com.openai.errors.OpenAIInvalidDataException import java.util.Collections import java.util.Objects +/** A text content. */ class TextContent private constructor( private val text: JsonField, diff --git a/openai-java-core/src/main/kotlin/com/openai/models/conversations/TopLogProb.kt b/openai-java-core/src/main/kotlin/com/openai/models/conversations/TopLogProb.kt deleted file mode 100644 index c9750659f..000000000 --- a/openai-java-core/src/main/kotlin/com/openai/models/conversations/TopLogProb.kt +++ /dev/null @@ -1,253 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.openai.models.conversations - -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.openai.core.ExcludeMissing -import com.openai.core.JsonField -import com.openai.core.JsonMissing -import com.openai.core.JsonValue -import com.openai.core.checkKnown -import com.openai.core.checkRequired -import com.openai.core.toImmutable -import com.openai.errors.OpenAIInvalidDataException -import java.util.Collections -import java.util.Objects -import kotlin.jvm.optionals.getOrNull - -class TopLogProb -private constructor( - private val token: JsonField, - private val bytes: JsonField>, - private val logprob: JsonField, - private val additionalProperties: MutableMap, -) { - - @JsonCreator - private constructor( - @JsonProperty("token") @ExcludeMissing token: JsonField = JsonMissing.of(), - @JsonProperty("bytes") @ExcludeMissing bytes: JsonField> = JsonMissing.of(), - @JsonProperty("logprob") @ExcludeMissing logprob: JsonField = JsonMissing.of(), - ) : this(token, bytes, logprob, 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 token(): String = token.getRequired("token") - - /** - * @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 bytes(): List = bytes.getRequired("bytes") - - /** - * @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 logprob(): Double = logprob.getRequired("logprob") - - /** - * Returns the raw JSON value of [token]. - * - * Unlike [token], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("token") @ExcludeMissing fun _token(): JsonField = token - - /** - * Returns the raw JSON value of [bytes]. - * - * Unlike [bytes], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("bytes") @ExcludeMissing fun _bytes(): JsonField> = bytes - - /** - * Returns the raw JSON value of [logprob]. - * - * Unlike [logprob], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("logprob") @ExcludeMissing fun _logprob(): JsonField = logprob - - @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 [TopLogProb]. - * - * The following fields are required: - * ```java - * .token() - * .bytes() - * .logprob() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [TopLogProb]. */ - class Builder internal constructor() { - - private var token: JsonField? = null - private var bytes: JsonField>? = null - private var logprob: JsonField? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(topLogProb: TopLogProb) = apply { - token = topLogProb.token - bytes = topLogProb.bytes.map { it.toMutableList() } - logprob = topLogProb.logprob - additionalProperties = topLogProb.additionalProperties.toMutableMap() - } - - fun token(token: String) = token(JsonField.of(token)) - - /** - * Sets [Builder.token] to an arbitrary JSON value. - * - * You should usually call [Builder.token] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun token(token: JsonField) = apply { this.token = token } - - fun bytes(bytes: List) = bytes(JsonField.of(bytes)) - - /** - * Sets [Builder.bytes] to an arbitrary JSON value. - * - * You should usually call [Builder.bytes] with a well-typed `List` value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun bytes(bytes: JsonField>) = apply { - this.bytes = bytes.map { it.toMutableList() } - } - - /** - * Adds a single [Long] to [bytes]. - * - * @throws IllegalStateException if the field was previously set to a non-list. - */ - fun addByte(byte_: Long) = apply { - bytes = - (bytes ?: JsonField.of(mutableListOf())).also { checkKnown("bytes", it).add(byte_) } - } - - fun logprob(logprob: Double) = logprob(JsonField.of(logprob)) - - /** - * Sets [Builder.logprob] to an arbitrary JSON value. - * - * You should usually call [Builder.logprob] with a well-typed [Double] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun logprob(logprob: JsonField) = apply { this.logprob = logprob } - - 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 [TopLogProb]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .token() - * .bytes() - * .logprob() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): TopLogProb = - TopLogProb( - checkRequired("token", token), - checkRequired("bytes", bytes).map { it.toImmutable() }, - checkRequired("logprob", logprob), - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): TopLogProb = apply { - if (validated) { - return@apply - } - - token() - bytes() - logprob() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - /** - * Returns a score indicating how many valid values are contained in this object recursively. - * - * Used for best match union deserialization. - */ - @JvmSynthetic - internal fun validity(): Int = - (if (token.asKnown().isPresent) 1 else 0) + - (bytes.asKnown().getOrNull()?.size ?: 0) + - (if (logprob.asKnown().isPresent) 1 else 0) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is TopLogProb && - token == other.token && - bytes == other.bytes && - logprob == other.logprob && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { Objects.hash(token, bytes, logprob, additionalProperties) } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "TopLogProb{token=$token, bytes=$bytes, logprob=$logprob, additionalProperties=$additionalProperties}" -} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/conversations/UrlCitationBody.kt b/openai-java-core/src/main/kotlin/com/openai/models/conversations/UrlCitationBody.kt deleted file mode 100644 index fec9209ae..000000000 --- a/openai-java-core/src/main/kotlin/com/openai/models/conversations/UrlCitationBody.kt +++ /dev/null @@ -1,323 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.openai.models.conversations - -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.openai.core.ExcludeMissing -import com.openai.core.JsonField -import com.openai.core.JsonMissing -import com.openai.core.JsonValue -import com.openai.core.checkRequired -import com.openai.errors.OpenAIInvalidDataException -import java.util.Collections -import java.util.Objects - -class UrlCitationBody -private constructor( - private val endIndex: JsonField, - private val startIndex: JsonField, - private val title: JsonField, - private val type: JsonValue, - private val url: JsonField, - private val additionalProperties: MutableMap, -) { - - @JsonCreator - private constructor( - @JsonProperty("end_index") @ExcludeMissing endIndex: JsonField = JsonMissing.of(), - @JsonProperty("start_index") @ExcludeMissing startIndex: JsonField = JsonMissing.of(), - @JsonProperty("title") @ExcludeMissing title: JsonField = JsonMissing.of(), - @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), - @JsonProperty("url") @ExcludeMissing url: JsonField = JsonMissing.of(), - ) : this(endIndex, startIndex, title, type, url, mutableMapOf()) - - /** - * The index of the last character of the URL citation in 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 endIndex(): Long = endIndex.getRequired("end_index") - - /** - * The index of the first character of the URL citation in 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 startIndex(): Long = startIndex.getRequired("start_index") - - /** - * The title of the web resource. - * - * @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 title(): String = title.getRequired("title") - - /** - * The type of the URL citation. Always `url_citation`. - * - * Expected to always return the following: - * ```java - * JsonValue.from("url_citation") - * ``` - * - * 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 - - /** - * The URL of the web resource. - * - * @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 url(): String = url.getRequired("url") - - /** - * Returns the raw JSON value of [endIndex]. - * - * Unlike [endIndex], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("end_index") @ExcludeMissing fun _endIndex(): JsonField = endIndex - - /** - * Returns the raw JSON value of [startIndex]. - * - * Unlike [startIndex], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("start_index") @ExcludeMissing fun _startIndex(): JsonField = startIndex - - /** - * Returns the raw JSON value of [title]. - * - * Unlike [title], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("title") @ExcludeMissing fun _title(): JsonField = title - - /** - * Returns the raw JSON value of [url]. - * - * Unlike [url], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("url") @ExcludeMissing fun _url(): JsonField = url - - @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 [UrlCitationBody]. - * - * The following fields are required: - * ```java - * .endIndex() - * .startIndex() - * .title() - * .url() - * ``` - */ - @JvmStatic fun builder() = Builder() - } - - /** A builder for [UrlCitationBody]. */ - class Builder internal constructor() { - - private var endIndex: JsonField? = null - private var startIndex: JsonField? = null - private var title: JsonField? = null - private var type: JsonValue = JsonValue.from("url_citation") - private var url: JsonField? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(urlCitationBody: UrlCitationBody) = apply { - endIndex = urlCitationBody.endIndex - startIndex = urlCitationBody.startIndex - title = urlCitationBody.title - type = urlCitationBody.type - url = urlCitationBody.url - additionalProperties = urlCitationBody.additionalProperties.toMutableMap() - } - - /** The index of the last character of the URL citation in the message. */ - fun endIndex(endIndex: Long) = endIndex(JsonField.of(endIndex)) - - /** - * Sets [Builder.endIndex] to an arbitrary JSON value. - * - * You should usually call [Builder.endIndex] with a well-typed [Long] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun endIndex(endIndex: JsonField) = apply { this.endIndex = endIndex } - - /** The index of the first character of the URL citation in the message. */ - fun startIndex(startIndex: Long) = startIndex(JsonField.of(startIndex)) - - /** - * Sets [Builder.startIndex] to an arbitrary JSON value. - * - * You should usually call [Builder.startIndex] with a well-typed [Long] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun startIndex(startIndex: JsonField) = apply { this.startIndex = startIndex } - - /** The title of the web resource. */ - fun title(title: String) = title(JsonField.of(title)) - - /** - * Sets [Builder.title] to an arbitrary JSON value. - * - * You should usually call [Builder.title] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun title(title: JsonField) = apply { this.title = title } - - /** - * 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("url_citation") - * ``` - * - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun type(type: JsonValue) = apply { this.type = type } - - /** The URL of the web resource. */ - fun url(url: String) = url(JsonField.of(url)) - - /** - * Sets [Builder.url] to an arbitrary JSON value. - * - * You should usually call [Builder.url] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun url(url: JsonField) = apply { this.url = url } - - 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 [UrlCitationBody]. - * - * Further updates to this [Builder] will not mutate the returned instance. - * - * The following fields are required: - * ```java - * .endIndex() - * .startIndex() - * .title() - * .url() - * ``` - * - * @throws IllegalStateException if any required field is unset. - */ - fun build(): UrlCitationBody = - UrlCitationBody( - checkRequired("endIndex", endIndex), - checkRequired("startIndex", startIndex), - checkRequired("title", title), - type, - checkRequired("url", url), - additionalProperties.toMutableMap(), - ) - } - - private var validated: Boolean = false - - fun validate(): UrlCitationBody = apply { - if (validated) { - return@apply - } - - endIndex() - startIndex() - title() - _type().let { - if (it != JsonValue.from("url_citation")) { - throw OpenAIInvalidDataException("'type' is invalid, received $it") - } - } - url() - 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 (endIndex.asKnown().isPresent) 1 else 0) + - (if (startIndex.asKnown().isPresent) 1 else 0) + - (if (title.asKnown().isPresent) 1 else 0) + - type.let { if (it == JsonValue.from("url_citation")) 1 else 0 } + - (if (url.asKnown().isPresent) 1 else 0) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is UrlCitationBody && - endIndex == other.endIndex && - startIndex == other.startIndex && - title == other.title && - type == other.type && - url == other.url && - additionalProperties == other.additionalProperties - } - - private val hashCode: Int by lazy { - Objects.hash(endIndex, startIndex, title, type, url, additionalProperties) - } - - override fun hashCode(): Int = hashCode - - override fun toString() = - "UrlCitationBody{endIndex=$endIndex, startIndex=$startIndex, title=$title, type=$type, url=$url, additionalProperties=$additionalProperties}" -} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/conversations/items/ConversationItem.kt b/openai-java-core/src/main/kotlin/com/openai/models/conversations/items/ConversationItem.kt index c8bd0517d..1343e2b0f 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/conversations/items/ConversationItem.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/conversations/items/ConversationItem.kt @@ -71,6 +71,7 @@ private constructor( private val _json: JsonValue? = null, ) { + /** A message to or from the model. */ fun message(): Optional = Optional.ofNullable(message) /** @@ -186,6 +187,7 @@ private constructor( fun isCustomToolCallOutput(): Boolean = customToolCallOutput != null + /** A message to or from the model. */ fun asMessage(): Message = message.getOrThrow("message") /** @@ -538,6 +540,7 @@ private constructor( companion object { + /** A message to or from the model. */ @JvmStatic fun ofMessage(message: Message) = ConversationItem(message = message) /** @@ -648,6 +651,7 @@ private constructor( */ interface Visitor { + /** A message to or from the model. */ fun visitMessage(message: Message): T /** 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 index 00dfbeaff..b29cf888e 100644 --- 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 @@ -5431,7 +5431,7 @@ private constructor( private val name: JsonField, private val type: JsonValue, private val range: JsonField>, - private val samplingParams: JsonValue, + private val samplingParams: JsonField, private val passThreshold: JsonField, private val additionalProperties: MutableMap, ) { @@ -5449,7 +5449,7 @@ private constructor( range: JsonField> = JsonMissing.of(), @JsonProperty("sampling_params") @ExcludeMissing - samplingParams: JsonValue = JsonMissing.of(), + samplingParams: JsonField = JsonMissing.of(), @JsonProperty("pass_threshold") @ExcludeMissing passThreshold: JsonField = JsonMissing.of(), @@ -5513,10 +5513,14 @@ private constructor( */ fun range(): Optional> = range.getOptional("range") - /** The sampling parameters for the model. */ - @JsonProperty("sampling_params") - @ExcludeMissing - fun _samplingParams(): JsonValue = samplingParams + /** + * The sampling parameters for the model. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun samplingParams(): Optional = + samplingParams.getOptional("sampling_params") /** * The threshold for the score. @@ -5556,6 +5560,16 @@ private constructor( */ @JsonProperty("range") @ExcludeMissing fun _range(): JsonField> = range + /** + * Returns the raw JSON value of [samplingParams]. + * + * Unlike [samplingParams], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("sampling_params") + @ExcludeMissing + fun _samplingParams(): JsonField = samplingParams + /** * Returns the raw JSON value of [passThreshold]. * @@ -5601,7 +5615,8 @@ private constructor( private var name: JsonField? = null private var type: JsonValue = JsonValue.from("score_model") private var range: JsonField>? = null - private var samplingParams: JsonValue = JsonMissing.of() + private var samplingParams: JsonField = + JsonMissing.of() private var passThreshold: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -5708,9 +5723,20 @@ private constructor( } /** The sampling parameters for the model. */ - fun samplingParams(samplingParams: JsonValue) = apply { - this.samplingParams = samplingParams - } + fun samplingParams(samplingParams: ScoreModelGrader.SamplingParams) = + samplingParams(JsonField.of(samplingParams)) + + /** + * Sets [Builder.samplingParams] to an arbitrary JSON value. + * + * You should usually call [Builder.samplingParams] with a well-typed + * [ScoreModelGrader.SamplingParams] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun samplingParams(samplingParams: JsonField) = + apply { + this.samplingParams = samplingParams + } /** The threshold for the score. */ fun passThreshold(passThreshold: Double) = @@ -5792,6 +5818,7 @@ private constructor( } } range() + samplingParams().ifPresent { it.validate() } passThreshold() validated = true } @@ -5817,6 +5844,7 @@ private constructor( (if (name.asKnown().isPresent) 1 else 0) + type.let { if (it == JsonValue.from("score_model")) 1 else 0 } + (range.asKnown().getOrNull()?.size ?: 0) + + (samplingParams.asKnown().getOrNull()?.validity() ?: 0) + (if (passThreshold.asKnown().isPresent) 1 else 0) override fun equals(other: Any?): Boolean { diff --git a/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalCreateResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalCreateResponse.kt index aa442c03d..785849a30 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalCreateResponse.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalCreateResponse.kt @@ -2491,7 +2491,7 @@ private constructor( private val name: JsonField, private val type: JsonValue, private val range: JsonField>, - private val samplingParams: JsonValue, + private val samplingParams: JsonField, private val passThreshold: JsonField, private val additionalProperties: MutableMap, ) { @@ -2509,7 +2509,7 @@ private constructor( range: JsonField> = JsonMissing.of(), @JsonProperty("sampling_params") @ExcludeMissing - samplingParams: JsonValue = JsonMissing.of(), + samplingParams: JsonField = JsonMissing.of(), @JsonProperty("pass_threshold") @ExcludeMissing passThreshold: JsonField = JsonMissing.of(), @@ -2573,10 +2573,14 @@ private constructor( */ fun range(): Optional> = range.getOptional("range") - /** The sampling parameters for the model. */ - @JsonProperty("sampling_params") - @ExcludeMissing - fun _samplingParams(): JsonValue = samplingParams + /** + * The sampling parameters for the model. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun samplingParams(): Optional = + samplingParams.getOptional("sampling_params") /** * The threshold for the score. @@ -2616,6 +2620,16 @@ private constructor( */ @JsonProperty("range") @ExcludeMissing fun _range(): JsonField> = range + /** + * Returns the raw JSON value of [samplingParams]. + * + * Unlike [samplingParams], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("sampling_params") + @ExcludeMissing + fun _samplingParams(): JsonField = samplingParams + /** * Returns the raw JSON value of [passThreshold]. * @@ -2661,7 +2675,8 @@ private constructor( private var name: JsonField? = null private var type: JsonValue = JsonValue.from("score_model") private var range: JsonField>? = null - private var samplingParams: JsonValue = JsonMissing.of() + private var samplingParams: JsonField = + JsonMissing.of() private var passThreshold: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -2768,9 +2783,20 @@ private constructor( } /** The sampling parameters for the model. */ - fun samplingParams(samplingParams: JsonValue) = apply { - this.samplingParams = samplingParams - } + fun samplingParams(samplingParams: ScoreModelGrader.SamplingParams) = + samplingParams(JsonField.of(samplingParams)) + + /** + * Sets [Builder.samplingParams] to an arbitrary JSON value. + * + * You should usually call [Builder.samplingParams] with a well-typed + * [ScoreModelGrader.SamplingParams] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun samplingParams(samplingParams: JsonField) = + apply { + this.samplingParams = samplingParams + } /** The threshold for the score. */ fun passThreshold(passThreshold: Double) = @@ -2852,6 +2878,7 @@ private constructor( } } range() + samplingParams().ifPresent { it.validate() } passThreshold() validated = true } @@ -2877,6 +2904,7 @@ private constructor( (if (name.asKnown().isPresent) 1 else 0) + type.let { if (it == JsonValue.from("score_model")) 1 else 0 } + (range.asKnown().getOrNull()?.size ?: 0) + + (samplingParams.asKnown().getOrNull()?.validity() ?: 0) + (if (passThreshold.asKnown().isPresent) 1 else 0) override fun equals(other: Any?): Boolean { diff --git a/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalListResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalListResponse.kt index f64813fff..1ad539c2c 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalListResponse.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalListResponse.kt @@ -2491,7 +2491,7 @@ private constructor( private val name: JsonField, private val type: JsonValue, private val range: JsonField>, - private val samplingParams: JsonValue, + private val samplingParams: JsonField, private val passThreshold: JsonField, private val additionalProperties: MutableMap, ) { @@ -2509,7 +2509,7 @@ private constructor( range: JsonField> = JsonMissing.of(), @JsonProperty("sampling_params") @ExcludeMissing - samplingParams: JsonValue = JsonMissing.of(), + samplingParams: JsonField = JsonMissing.of(), @JsonProperty("pass_threshold") @ExcludeMissing passThreshold: JsonField = JsonMissing.of(), @@ -2573,10 +2573,14 @@ private constructor( */ fun range(): Optional> = range.getOptional("range") - /** The sampling parameters for the model. */ - @JsonProperty("sampling_params") - @ExcludeMissing - fun _samplingParams(): JsonValue = samplingParams + /** + * The sampling parameters for the model. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun samplingParams(): Optional = + samplingParams.getOptional("sampling_params") /** * The threshold for the score. @@ -2616,6 +2620,16 @@ private constructor( */ @JsonProperty("range") @ExcludeMissing fun _range(): JsonField> = range + /** + * Returns the raw JSON value of [samplingParams]. + * + * Unlike [samplingParams], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("sampling_params") + @ExcludeMissing + fun _samplingParams(): JsonField = samplingParams + /** * Returns the raw JSON value of [passThreshold]. * @@ -2661,7 +2675,8 @@ private constructor( private var name: JsonField? = null private var type: JsonValue = JsonValue.from("score_model") private var range: JsonField>? = null - private var samplingParams: JsonValue = JsonMissing.of() + private var samplingParams: JsonField = + JsonMissing.of() private var passThreshold: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -2768,9 +2783,20 @@ private constructor( } /** The sampling parameters for the model. */ - fun samplingParams(samplingParams: JsonValue) = apply { - this.samplingParams = samplingParams - } + fun samplingParams(samplingParams: ScoreModelGrader.SamplingParams) = + samplingParams(JsonField.of(samplingParams)) + + /** + * Sets [Builder.samplingParams] to an arbitrary JSON value. + * + * You should usually call [Builder.samplingParams] with a well-typed + * [ScoreModelGrader.SamplingParams] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun samplingParams(samplingParams: JsonField) = + apply { + this.samplingParams = samplingParams + } /** The threshold for the score. */ fun passThreshold(passThreshold: Double) = @@ -2852,6 +2878,7 @@ private constructor( } } range() + samplingParams().ifPresent { it.validate() } passThreshold() validated = true } @@ -2877,6 +2904,7 @@ private constructor( (if (name.asKnown().isPresent) 1 else 0) + type.let { if (it == JsonValue.from("score_model")) 1 else 0 } + (range.asKnown().getOrNull()?.size ?: 0) + + (samplingParams.asKnown().getOrNull()?.validity() ?: 0) + (if (passThreshold.asKnown().isPresent) 1 else 0) override fun equals(other: Any?): Boolean { diff --git a/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalRetrieveResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalRetrieveResponse.kt index 291b43f7d..87594f4a7 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalRetrieveResponse.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalRetrieveResponse.kt @@ -2491,7 +2491,7 @@ private constructor( private val name: JsonField, private val type: JsonValue, private val range: JsonField>, - private val samplingParams: JsonValue, + private val samplingParams: JsonField, private val passThreshold: JsonField, private val additionalProperties: MutableMap, ) { @@ -2509,7 +2509,7 @@ private constructor( range: JsonField> = JsonMissing.of(), @JsonProperty("sampling_params") @ExcludeMissing - samplingParams: JsonValue = JsonMissing.of(), + samplingParams: JsonField = JsonMissing.of(), @JsonProperty("pass_threshold") @ExcludeMissing passThreshold: JsonField = JsonMissing.of(), @@ -2573,10 +2573,14 @@ private constructor( */ fun range(): Optional> = range.getOptional("range") - /** The sampling parameters for the model. */ - @JsonProperty("sampling_params") - @ExcludeMissing - fun _samplingParams(): JsonValue = samplingParams + /** + * The sampling parameters for the model. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun samplingParams(): Optional = + samplingParams.getOptional("sampling_params") /** * The threshold for the score. @@ -2616,6 +2620,16 @@ private constructor( */ @JsonProperty("range") @ExcludeMissing fun _range(): JsonField> = range + /** + * Returns the raw JSON value of [samplingParams]. + * + * Unlike [samplingParams], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("sampling_params") + @ExcludeMissing + fun _samplingParams(): JsonField = samplingParams + /** * Returns the raw JSON value of [passThreshold]. * @@ -2661,7 +2675,8 @@ private constructor( private var name: JsonField? = null private var type: JsonValue = JsonValue.from("score_model") private var range: JsonField>? = null - private var samplingParams: JsonValue = JsonMissing.of() + private var samplingParams: JsonField = + JsonMissing.of() private var passThreshold: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -2768,9 +2783,20 @@ private constructor( } /** The sampling parameters for the model. */ - fun samplingParams(samplingParams: JsonValue) = apply { - this.samplingParams = samplingParams - } + fun samplingParams(samplingParams: ScoreModelGrader.SamplingParams) = + samplingParams(JsonField.of(samplingParams)) + + /** + * Sets [Builder.samplingParams] to an arbitrary JSON value. + * + * You should usually call [Builder.samplingParams] with a well-typed + * [ScoreModelGrader.SamplingParams] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun samplingParams(samplingParams: JsonField) = + apply { + this.samplingParams = samplingParams + } /** The threshold for the score. */ fun passThreshold(passThreshold: Double) = @@ -2852,6 +2878,7 @@ private constructor( } } range() + samplingParams().ifPresent { it.validate() } passThreshold() validated = true } @@ -2877,6 +2904,7 @@ private constructor( (if (name.asKnown().isPresent) 1 else 0) + type.let { if (it == JsonValue.from("score_model")) 1 else 0 } + (range.asKnown().getOrNull()?.size ?: 0) + + (samplingParams.asKnown().getOrNull()?.validity() ?: 0) + (if (passThreshold.asKnown().isPresent) 1 else 0) override fun equals(other: Any?): Boolean { diff --git a/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalUpdateResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalUpdateResponse.kt index 177f441e1..f8eff229d 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalUpdateResponse.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalUpdateResponse.kt @@ -2491,7 +2491,7 @@ private constructor( private val name: JsonField, private val type: JsonValue, private val range: JsonField>, - private val samplingParams: JsonValue, + private val samplingParams: JsonField, private val passThreshold: JsonField, private val additionalProperties: MutableMap, ) { @@ -2509,7 +2509,7 @@ private constructor( range: JsonField> = JsonMissing.of(), @JsonProperty("sampling_params") @ExcludeMissing - samplingParams: JsonValue = JsonMissing.of(), + samplingParams: JsonField = JsonMissing.of(), @JsonProperty("pass_threshold") @ExcludeMissing passThreshold: JsonField = JsonMissing.of(), @@ -2573,10 +2573,14 @@ private constructor( */ fun range(): Optional> = range.getOptional("range") - /** The sampling parameters for the model. */ - @JsonProperty("sampling_params") - @ExcludeMissing - fun _samplingParams(): JsonValue = samplingParams + /** + * The sampling parameters for the model. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun samplingParams(): Optional = + samplingParams.getOptional("sampling_params") /** * The threshold for the score. @@ -2616,6 +2620,16 @@ private constructor( */ @JsonProperty("range") @ExcludeMissing fun _range(): JsonField> = range + /** + * Returns the raw JSON value of [samplingParams]. + * + * Unlike [samplingParams], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("sampling_params") + @ExcludeMissing + fun _samplingParams(): JsonField = samplingParams + /** * Returns the raw JSON value of [passThreshold]. * @@ -2661,7 +2675,8 @@ private constructor( private var name: JsonField? = null private var type: JsonValue = JsonValue.from("score_model") private var range: JsonField>? = null - private var samplingParams: JsonValue = JsonMissing.of() + private var samplingParams: JsonField = + JsonMissing.of() private var passThreshold: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -2768,9 +2783,20 @@ private constructor( } /** The sampling parameters for the model. */ - fun samplingParams(samplingParams: JsonValue) = apply { - this.samplingParams = samplingParams - } + fun samplingParams(samplingParams: ScoreModelGrader.SamplingParams) = + samplingParams(JsonField.of(samplingParams)) + + /** + * Sets [Builder.samplingParams] to an arbitrary JSON value. + * + * You should usually call [Builder.samplingParams] with a well-typed + * [ScoreModelGrader.SamplingParams] value instead. This method is primarily for + * setting the field to an undocumented or not yet supported value. + */ + fun samplingParams(samplingParams: JsonField) = + apply { + this.samplingParams = samplingParams + } /** The threshold for the score. */ fun passThreshold(passThreshold: Double) = @@ -2852,6 +2878,7 @@ private constructor( } } range() + samplingParams().ifPresent { it.validate() } passThreshold() validated = true } @@ -2877,6 +2904,7 @@ private constructor( (if (name.asKnown().isPresent) 1 else 0) + type.let { if (it == JsonValue.from("score_model")) 1 else 0 } + (range.asKnown().getOrNull()?.size ?: 0) + + (samplingParams.asKnown().getOrNull()?.validity() ?: 0) + (if (passThreshold.asKnown().isPresent) 1 else 0) override fun equals(other: Any?): Boolean { diff --git a/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/CreateEvalCompletionsRunDataSource.kt b/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/CreateEvalCompletionsRunDataSource.kt index 476c724bb..a8a666cf6 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/CreateEvalCompletionsRunDataSource.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/CreateEvalCompletionsRunDataSource.kt @@ -26,6 +26,7 @@ import com.openai.core.checkRequired import com.openai.core.getOrThrow import com.openai.core.toImmutable import com.openai.errors.OpenAIInvalidDataException +import com.openai.models.ReasoningEffort import com.openai.models.ResponseFormatJsonObject import com.openai.models.ResponseFormatJsonSchema import com.openai.models.ResponseFormatText @@ -4411,6 +4412,7 @@ private constructor( class SamplingParams private constructor( private val maxCompletionTokens: JsonField, + private val reasoningEffort: JsonField, private val responseFormat: JsonField, private val seed: JsonField, private val temperature: JsonField, @@ -4424,6 +4426,9 @@ private constructor( @JsonProperty("max_completion_tokens") @ExcludeMissing maxCompletionTokens: JsonField = JsonMissing.of(), + @JsonProperty("reasoning_effort") + @ExcludeMissing + reasoningEffort: JsonField = JsonMissing.of(), @JsonProperty("response_format") @ExcludeMissing responseFormat: JsonField = JsonMissing.of(), @@ -4437,6 +4442,7 @@ private constructor( @JsonProperty("top_p") @ExcludeMissing topP: JsonField = JsonMissing.of(), ) : this( maxCompletionTokens, + reasoningEffort, responseFormat, seed, temperature, @@ -4454,6 +4460,18 @@ private constructor( fun maxCompletionTokens(): Optional = maxCompletionTokens.getOptional("max_completion_tokens") + /** + * Constrains effort on reasoning for + * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently + * supported values are `minimal`, `low`, `medium`, and `high`. Reducing reasoning effort + * can result in faster responses and fewer tokens used on reasoning in a response. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun reasoningEffort(): Optional = + reasoningEffort.getOptional("reasoning_effort") + /** * An object specifying the format that the model must output. * @@ -4515,6 +4533,16 @@ private constructor( @ExcludeMissing fun _maxCompletionTokens(): JsonField = maxCompletionTokens + /** + * Returns the raw JSON value of [reasoningEffort]. + * + * Unlike [reasoningEffort], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("reasoning_effort") + @ExcludeMissing + fun _reasoningEffort(): JsonField = reasoningEffort + /** * Returns the raw JSON value of [responseFormat]. * @@ -4579,6 +4607,7 @@ private constructor( class Builder internal constructor() { private var maxCompletionTokens: JsonField = JsonMissing.of() + private var reasoningEffort: JsonField = JsonMissing.of() private var responseFormat: JsonField = JsonMissing.of() private var seed: JsonField = JsonMissing.of() private var temperature: JsonField = JsonMissing.of() @@ -4589,6 +4618,7 @@ private constructor( @JvmSynthetic internal fun from(samplingParams: SamplingParams) = apply { maxCompletionTokens = samplingParams.maxCompletionTokens + reasoningEffort = samplingParams.reasoningEffort responseFormat = samplingParams.responseFormat seed = samplingParams.seed temperature = samplingParams.temperature @@ -4612,6 +4642,31 @@ private constructor( this.maxCompletionTokens = maxCompletionTokens } + /** + * Constrains effort on reasoning for + * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently + * supported values are `minimal`, `low`, `medium`, and `high`. Reducing reasoning + * effort can result in faster responses and fewer tokens used on reasoning in a + * response. + */ + fun reasoningEffort(reasoningEffort: ReasoningEffort?) = + reasoningEffort(JsonField.ofNullable(reasoningEffort)) + + /** Alias for calling [Builder.reasoningEffort] with `reasoningEffort.orElse(null)`. */ + fun reasoningEffort(reasoningEffort: Optional) = + reasoningEffort(reasoningEffort.getOrNull()) + + /** + * Sets [Builder.reasoningEffort] to an arbitrary JSON value. + * + * You should usually call [Builder.reasoningEffort] with a well-typed [ReasoningEffort] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun reasoningEffort(reasoningEffort: JsonField) = apply { + this.reasoningEffort = reasoningEffort + } + /** * An object specifying the format that the model must output. * @@ -4749,6 +4804,7 @@ private constructor( fun build(): SamplingParams = SamplingParams( maxCompletionTokens, + reasoningEffort, responseFormat, seed, temperature, @@ -4766,6 +4822,7 @@ private constructor( } maxCompletionTokens() + reasoningEffort().ifPresent { it.validate() } responseFormat().ifPresent { it.validate() } seed() temperature() @@ -4791,6 +4848,7 @@ private constructor( @JvmSynthetic internal fun validity(): Int = (if (maxCompletionTokens.asKnown().isPresent) 1 else 0) + + (reasoningEffort.asKnown().getOrNull()?.validity() ?: 0) + (responseFormat.asKnown().getOrNull()?.validity() ?: 0) + (if (seed.asKnown().isPresent) 1 else 0) + (if (temperature.asKnown().isPresent) 1 else 0) + @@ -5063,6 +5121,7 @@ private constructor( return other is SamplingParams && maxCompletionTokens == other.maxCompletionTokens && + reasoningEffort == other.reasoningEffort && responseFormat == other.responseFormat && seed == other.seed && temperature == other.temperature && @@ -5074,6 +5133,7 @@ private constructor( private val hashCode: Int by lazy { Objects.hash( maxCompletionTokens, + reasoningEffort, responseFormat, seed, temperature, @@ -5086,7 +5146,7 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "SamplingParams{maxCompletionTokens=$maxCompletionTokens, responseFormat=$responseFormat, seed=$seed, temperature=$temperature, tools=$tools, topP=$topP, additionalProperties=$additionalProperties}" + "SamplingParams{maxCompletionTokens=$maxCompletionTokens, reasoningEffort=$reasoningEffort, responseFormat=$responseFormat, seed=$seed, temperature=$temperature, tools=$tools, topP=$topP, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { diff --git a/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/RunCancelResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/RunCancelResponse.kt index 2e81c316d..3d12a0132 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/RunCancelResponse.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/RunCancelResponse.kt @@ -5979,6 +5979,7 @@ private constructor( class SamplingParams private constructor( private val maxCompletionTokens: JsonField, + private val reasoningEffort: JsonField, private val seed: JsonField, private val temperature: JsonField, private val text: JsonField, @@ -5992,6 +5993,9 @@ private constructor( @JsonProperty("max_completion_tokens") @ExcludeMissing maxCompletionTokens: JsonField = JsonMissing.of(), + @JsonProperty("reasoning_effort") + @ExcludeMissing + reasoningEffort: JsonField = JsonMissing.of(), @JsonProperty("seed") @ExcludeMissing seed: JsonField = JsonMissing.of(), @JsonProperty("temperature") @ExcludeMissing @@ -6003,7 +6007,16 @@ private constructor( @JsonProperty("top_p") @ExcludeMissing topP: JsonField = JsonMissing.of(), - ) : this(maxCompletionTokens, seed, temperature, text, tools, topP, mutableMapOf()) + ) : this( + maxCompletionTokens, + reasoningEffort, + seed, + temperature, + text, + tools, + topP, + mutableMapOf(), + ) /** * The maximum number of tokens in the generated output. @@ -6014,6 +6027,19 @@ private constructor( fun maxCompletionTokens(): Optional = maxCompletionTokens.getOptional("max_completion_tokens") + /** + * Constrains effort on reasoning for + * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently + * supported values are `minimal`, `low`, `medium`, and `high`. Reducing reasoning + * effort can result in faster responses and fewer tokens used on reasoning in a + * response. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun reasoningEffort(): Optional = + reasoningEffort.getOptional("reasoning_effort") + /** * A seed value to initialize the randomness, during sampling. * @@ -6079,6 +6105,16 @@ private constructor( @ExcludeMissing fun _maxCompletionTokens(): JsonField = maxCompletionTokens + /** + * Returns the raw JSON value of [reasoningEffort]. + * + * Unlike [reasoningEffort], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reasoning_effort") + @ExcludeMissing + fun _reasoningEffort(): JsonField = reasoningEffort + /** * Returns the raw JSON value of [seed]. * @@ -6145,6 +6181,7 @@ private constructor( class Builder internal constructor() { private var maxCompletionTokens: JsonField = JsonMissing.of() + private var reasoningEffort: JsonField = JsonMissing.of() private var seed: JsonField = JsonMissing.of() private var temperature: JsonField = JsonMissing.of() private var text: JsonField = JsonMissing.of() @@ -6155,6 +6192,7 @@ private constructor( @JvmSynthetic internal fun from(samplingParams: SamplingParams) = apply { maxCompletionTokens = samplingParams.maxCompletionTokens + reasoningEffort = samplingParams.reasoningEffort seed = samplingParams.seed temperature = samplingParams.temperature text = samplingParams.text @@ -6178,6 +6216,34 @@ private constructor( this.maxCompletionTokens = maxCompletionTokens } + /** + * Constrains effort on reasoning for + * [reasoning models](https://platform.openai.com/docs/guides/reasoning). + * Currently supported values are `minimal`, `low`, `medium`, and `high`. + * Reducing reasoning effort can result in faster responses and fewer tokens + * used on reasoning in a response. + */ + fun reasoningEffort(reasoningEffort: ReasoningEffort?) = + reasoningEffort(JsonField.ofNullable(reasoningEffort)) + + /** + * Alias for calling [Builder.reasoningEffort] with + * `reasoningEffort.orElse(null)`. + */ + fun reasoningEffort(reasoningEffort: Optional) = + reasoningEffort(reasoningEffort.getOrNull()) + + /** + * Sets [Builder.reasoningEffort] to an arbitrary JSON value. + * + * You should usually call [Builder.reasoningEffort] with a well-typed + * [ReasoningEffort] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun reasoningEffort(reasoningEffort: JsonField) = apply { + this.reasoningEffort = reasoningEffort + } + /** A seed value to initialize the randomness, during sampling. */ fun seed(seed: Long) = seed(JsonField.of(seed)) @@ -6414,6 +6480,7 @@ private constructor( fun build(): SamplingParams = SamplingParams( maxCompletionTokens, + reasoningEffort, seed, temperature, text, @@ -6431,6 +6498,7 @@ private constructor( } maxCompletionTokens() + reasoningEffort().ifPresent { it.validate() } seed() temperature() text().ifPresent { it.validate() } @@ -6456,6 +6524,7 @@ private constructor( @JvmSynthetic internal fun validity(): Int = (if (maxCompletionTokens.asKnown().isPresent) 1 else 0) + + (reasoningEffort.asKnown().getOrNull()?.validity() ?: 0) + (if (seed.asKnown().isPresent) 1 else 0) + (if (temperature.asKnown().isPresent) 1 else 0) + (text.asKnown().getOrNull()?.validity() ?: 0) + @@ -6674,6 +6743,7 @@ private constructor( return other is SamplingParams && maxCompletionTokens == other.maxCompletionTokens && + reasoningEffort == other.reasoningEffort && seed == other.seed && temperature == other.temperature && text == other.text && @@ -6685,6 +6755,7 @@ private constructor( private val hashCode: Int by lazy { Objects.hash( maxCompletionTokens, + reasoningEffort, seed, temperature, text, @@ -6697,7 +6768,7 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "SamplingParams{maxCompletionTokens=$maxCompletionTokens, seed=$seed, temperature=$temperature, text=$text, tools=$tools, topP=$topP, additionalProperties=$additionalProperties}" + "SamplingParams{maxCompletionTokens=$maxCompletionTokens, reasoningEffort=$reasoningEffort, seed=$seed, temperature=$temperature, text=$text, tools=$tools, topP=$topP, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { diff --git a/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/RunCreateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/RunCreateParams.kt index 64009b762..0ad05a83d 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/RunCreateParams.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/RunCreateParams.kt @@ -5864,6 +5864,7 @@ private constructor( class SamplingParams private constructor( private val maxCompletionTokens: JsonField, + private val reasoningEffort: JsonField, private val seed: JsonField, private val temperature: JsonField, private val text: JsonField, @@ -5877,6 +5878,9 @@ private constructor( @JsonProperty("max_completion_tokens") @ExcludeMissing maxCompletionTokens: JsonField = JsonMissing.of(), + @JsonProperty("reasoning_effort") + @ExcludeMissing + reasoningEffort: JsonField = JsonMissing.of(), @JsonProperty("seed") @ExcludeMissing seed: JsonField = JsonMissing.of(), @JsonProperty("temperature") @ExcludeMissing @@ -5888,7 +5892,16 @@ private constructor( @JsonProperty("top_p") @ExcludeMissing topP: JsonField = JsonMissing.of(), - ) : this(maxCompletionTokens, seed, temperature, text, tools, topP, mutableMapOf()) + ) : this( + maxCompletionTokens, + reasoningEffort, + seed, + temperature, + text, + tools, + topP, + mutableMapOf(), + ) /** * The maximum number of tokens in the generated output. @@ -5899,6 +5912,19 @@ private constructor( fun maxCompletionTokens(): Optional = maxCompletionTokens.getOptional("max_completion_tokens") + /** + * Constrains effort on reasoning for + * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently + * supported values are `minimal`, `low`, `medium`, and `high`. Reducing reasoning + * effort can result in faster responses and fewer tokens used on reasoning in a + * response. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun reasoningEffort(): Optional = + reasoningEffort.getOptional("reasoning_effort") + /** * A seed value to initialize the randomness, during sampling. * @@ -5964,6 +5990,16 @@ private constructor( @ExcludeMissing fun _maxCompletionTokens(): JsonField = maxCompletionTokens + /** + * Returns the raw JSON value of [reasoningEffort]. + * + * Unlike [reasoningEffort], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reasoning_effort") + @ExcludeMissing + fun _reasoningEffort(): JsonField = reasoningEffort + /** * Returns the raw JSON value of [seed]. * @@ -6030,6 +6066,7 @@ private constructor( class Builder internal constructor() { private var maxCompletionTokens: JsonField = JsonMissing.of() + private var reasoningEffort: JsonField = JsonMissing.of() private var seed: JsonField = JsonMissing.of() private var temperature: JsonField = JsonMissing.of() private var text: JsonField = JsonMissing.of() @@ -6040,6 +6077,7 @@ private constructor( @JvmSynthetic internal fun from(samplingParams: SamplingParams) = apply { maxCompletionTokens = samplingParams.maxCompletionTokens + reasoningEffort = samplingParams.reasoningEffort seed = samplingParams.seed temperature = samplingParams.temperature text = samplingParams.text @@ -6063,6 +6101,34 @@ private constructor( this.maxCompletionTokens = maxCompletionTokens } + /** + * Constrains effort on reasoning for + * [reasoning models](https://platform.openai.com/docs/guides/reasoning). + * Currently supported values are `minimal`, `low`, `medium`, and `high`. + * Reducing reasoning effort can result in faster responses and fewer tokens + * used on reasoning in a response. + */ + fun reasoningEffort(reasoningEffort: ReasoningEffort?) = + reasoningEffort(JsonField.ofNullable(reasoningEffort)) + + /** + * Alias for calling [Builder.reasoningEffort] with + * `reasoningEffort.orElse(null)`. + */ + fun reasoningEffort(reasoningEffort: Optional) = + reasoningEffort(reasoningEffort.getOrNull()) + + /** + * Sets [Builder.reasoningEffort] to an arbitrary JSON value. + * + * You should usually call [Builder.reasoningEffort] with a well-typed + * [ReasoningEffort] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun reasoningEffort(reasoningEffort: JsonField) = apply { + this.reasoningEffort = reasoningEffort + } + /** A seed value to initialize the randomness, during sampling. */ fun seed(seed: Long) = seed(JsonField.of(seed)) @@ -6299,6 +6365,7 @@ private constructor( fun build(): SamplingParams = SamplingParams( maxCompletionTokens, + reasoningEffort, seed, temperature, text, @@ -6316,6 +6383,7 @@ private constructor( } maxCompletionTokens() + reasoningEffort().ifPresent { it.validate() } seed() temperature() text().ifPresent { it.validate() } @@ -6341,6 +6409,7 @@ private constructor( @JvmSynthetic internal fun validity(): Int = (if (maxCompletionTokens.asKnown().isPresent) 1 else 0) + + (reasoningEffort.asKnown().getOrNull()?.validity() ?: 0) + (if (seed.asKnown().isPresent) 1 else 0) + (if (temperature.asKnown().isPresent) 1 else 0) + (text.asKnown().getOrNull()?.validity() ?: 0) + @@ -6559,6 +6628,7 @@ private constructor( return other is SamplingParams && maxCompletionTokens == other.maxCompletionTokens && + reasoningEffort == other.reasoningEffort && seed == other.seed && temperature == other.temperature && text == other.text && @@ -6570,6 +6640,7 @@ private constructor( private val hashCode: Int by lazy { Objects.hash( maxCompletionTokens, + reasoningEffort, seed, temperature, text, @@ -6582,7 +6653,7 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "SamplingParams{maxCompletionTokens=$maxCompletionTokens, seed=$seed, temperature=$temperature, text=$text, tools=$tools, topP=$topP, additionalProperties=$additionalProperties}" + "SamplingParams{maxCompletionTokens=$maxCompletionTokens, reasoningEffort=$reasoningEffort, seed=$seed, temperature=$temperature, text=$text, tools=$tools, topP=$topP, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { diff --git a/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/RunCreateResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/RunCreateResponse.kt index a58cbf9a2..f8e3c4ce8 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/RunCreateResponse.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/RunCreateResponse.kt @@ -5979,6 +5979,7 @@ private constructor( class SamplingParams private constructor( private val maxCompletionTokens: JsonField, + private val reasoningEffort: JsonField, private val seed: JsonField, private val temperature: JsonField, private val text: JsonField, @@ -5992,6 +5993,9 @@ private constructor( @JsonProperty("max_completion_tokens") @ExcludeMissing maxCompletionTokens: JsonField = JsonMissing.of(), + @JsonProperty("reasoning_effort") + @ExcludeMissing + reasoningEffort: JsonField = JsonMissing.of(), @JsonProperty("seed") @ExcludeMissing seed: JsonField = JsonMissing.of(), @JsonProperty("temperature") @ExcludeMissing @@ -6003,7 +6007,16 @@ private constructor( @JsonProperty("top_p") @ExcludeMissing topP: JsonField = JsonMissing.of(), - ) : this(maxCompletionTokens, seed, temperature, text, tools, topP, mutableMapOf()) + ) : this( + maxCompletionTokens, + reasoningEffort, + seed, + temperature, + text, + tools, + topP, + mutableMapOf(), + ) /** * The maximum number of tokens in the generated output. @@ -6014,6 +6027,19 @@ private constructor( fun maxCompletionTokens(): Optional = maxCompletionTokens.getOptional("max_completion_tokens") + /** + * Constrains effort on reasoning for + * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently + * supported values are `minimal`, `low`, `medium`, and `high`. Reducing reasoning + * effort can result in faster responses and fewer tokens used on reasoning in a + * response. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun reasoningEffort(): Optional = + reasoningEffort.getOptional("reasoning_effort") + /** * A seed value to initialize the randomness, during sampling. * @@ -6079,6 +6105,16 @@ private constructor( @ExcludeMissing fun _maxCompletionTokens(): JsonField = maxCompletionTokens + /** + * Returns the raw JSON value of [reasoningEffort]. + * + * Unlike [reasoningEffort], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reasoning_effort") + @ExcludeMissing + fun _reasoningEffort(): JsonField = reasoningEffort + /** * Returns the raw JSON value of [seed]. * @@ -6145,6 +6181,7 @@ private constructor( class Builder internal constructor() { private var maxCompletionTokens: JsonField = JsonMissing.of() + private var reasoningEffort: JsonField = JsonMissing.of() private var seed: JsonField = JsonMissing.of() private var temperature: JsonField = JsonMissing.of() private var text: JsonField = JsonMissing.of() @@ -6155,6 +6192,7 @@ private constructor( @JvmSynthetic internal fun from(samplingParams: SamplingParams) = apply { maxCompletionTokens = samplingParams.maxCompletionTokens + reasoningEffort = samplingParams.reasoningEffort seed = samplingParams.seed temperature = samplingParams.temperature text = samplingParams.text @@ -6178,6 +6216,34 @@ private constructor( this.maxCompletionTokens = maxCompletionTokens } + /** + * Constrains effort on reasoning for + * [reasoning models](https://platform.openai.com/docs/guides/reasoning). + * Currently supported values are `minimal`, `low`, `medium`, and `high`. + * Reducing reasoning effort can result in faster responses and fewer tokens + * used on reasoning in a response. + */ + fun reasoningEffort(reasoningEffort: ReasoningEffort?) = + reasoningEffort(JsonField.ofNullable(reasoningEffort)) + + /** + * Alias for calling [Builder.reasoningEffort] with + * `reasoningEffort.orElse(null)`. + */ + fun reasoningEffort(reasoningEffort: Optional) = + reasoningEffort(reasoningEffort.getOrNull()) + + /** + * Sets [Builder.reasoningEffort] to an arbitrary JSON value. + * + * You should usually call [Builder.reasoningEffort] with a well-typed + * [ReasoningEffort] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun reasoningEffort(reasoningEffort: JsonField) = apply { + this.reasoningEffort = reasoningEffort + } + /** A seed value to initialize the randomness, during sampling. */ fun seed(seed: Long) = seed(JsonField.of(seed)) @@ -6414,6 +6480,7 @@ private constructor( fun build(): SamplingParams = SamplingParams( maxCompletionTokens, + reasoningEffort, seed, temperature, text, @@ -6431,6 +6498,7 @@ private constructor( } maxCompletionTokens() + reasoningEffort().ifPresent { it.validate() } seed() temperature() text().ifPresent { it.validate() } @@ -6456,6 +6524,7 @@ private constructor( @JvmSynthetic internal fun validity(): Int = (if (maxCompletionTokens.asKnown().isPresent) 1 else 0) + + (reasoningEffort.asKnown().getOrNull()?.validity() ?: 0) + (if (seed.asKnown().isPresent) 1 else 0) + (if (temperature.asKnown().isPresent) 1 else 0) + (text.asKnown().getOrNull()?.validity() ?: 0) + @@ -6674,6 +6743,7 @@ private constructor( return other is SamplingParams && maxCompletionTokens == other.maxCompletionTokens && + reasoningEffort == other.reasoningEffort && seed == other.seed && temperature == other.temperature && text == other.text && @@ -6685,6 +6755,7 @@ private constructor( private val hashCode: Int by lazy { Objects.hash( maxCompletionTokens, + reasoningEffort, seed, temperature, text, @@ -6697,7 +6768,7 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "SamplingParams{maxCompletionTokens=$maxCompletionTokens, seed=$seed, temperature=$temperature, text=$text, tools=$tools, topP=$topP, additionalProperties=$additionalProperties}" + "SamplingParams{maxCompletionTokens=$maxCompletionTokens, reasoningEffort=$reasoningEffort, seed=$seed, temperature=$temperature, text=$text, tools=$tools, topP=$topP, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { diff --git a/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/RunListResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/RunListResponse.kt index d9c4dbb5e..f68fcadd5 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/RunListResponse.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/RunListResponse.kt @@ -5979,6 +5979,7 @@ private constructor( class SamplingParams private constructor( private val maxCompletionTokens: JsonField, + private val reasoningEffort: JsonField, private val seed: JsonField, private val temperature: JsonField, private val text: JsonField, @@ -5992,6 +5993,9 @@ private constructor( @JsonProperty("max_completion_tokens") @ExcludeMissing maxCompletionTokens: JsonField = JsonMissing.of(), + @JsonProperty("reasoning_effort") + @ExcludeMissing + reasoningEffort: JsonField = JsonMissing.of(), @JsonProperty("seed") @ExcludeMissing seed: JsonField = JsonMissing.of(), @JsonProperty("temperature") @ExcludeMissing @@ -6003,7 +6007,16 @@ private constructor( @JsonProperty("top_p") @ExcludeMissing topP: JsonField = JsonMissing.of(), - ) : this(maxCompletionTokens, seed, temperature, text, tools, topP, mutableMapOf()) + ) : this( + maxCompletionTokens, + reasoningEffort, + seed, + temperature, + text, + tools, + topP, + mutableMapOf(), + ) /** * The maximum number of tokens in the generated output. @@ -6014,6 +6027,19 @@ private constructor( fun maxCompletionTokens(): Optional = maxCompletionTokens.getOptional("max_completion_tokens") + /** + * Constrains effort on reasoning for + * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently + * supported values are `minimal`, `low`, `medium`, and `high`. Reducing reasoning + * effort can result in faster responses and fewer tokens used on reasoning in a + * response. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun reasoningEffort(): Optional = + reasoningEffort.getOptional("reasoning_effort") + /** * A seed value to initialize the randomness, during sampling. * @@ -6079,6 +6105,16 @@ private constructor( @ExcludeMissing fun _maxCompletionTokens(): JsonField = maxCompletionTokens + /** + * Returns the raw JSON value of [reasoningEffort]. + * + * Unlike [reasoningEffort], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reasoning_effort") + @ExcludeMissing + fun _reasoningEffort(): JsonField = reasoningEffort + /** * Returns the raw JSON value of [seed]. * @@ -6145,6 +6181,7 @@ private constructor( class Builder internal constructor() { private var maxCompletionTokens: JsonField = JsonMissing.of() + private var reasoningEffort: JsonField = JsonMissing.of() private var seed: JsonField = JsonMissing.of() private var temperature: JsonField = JsonMissing.of() private var text: JsonField = JsonMissing.of() @@ -6155,6 +6192,7 @@ private constructor( @JvmSynthetic internal fun from(samplingParams: SamplingParams) = apply { maxCompletionTokens = samplingParams.maxCompletionTokens + reasoningEffort = samplingParams.reasoningEffort seed = samplingParams.seed temperature = samplingParams.temperature text = samplingParams.text @@ -6178,6 +6216,34 @@ private constructor( this.maxCompletionTokens = maxCompletionTokens } + /** + * Constrains effort on reasoning for + * [reasoning models](https://platform.openai.com/docs/guides/reasoning). + * Currently supported values are `minimal`, `low`, `medium`, and `high`. + * Reducing reasoning effort can result in faster responses and fewer tokens + * used on reasoning in a response. + */ + fun reasoningEffort(reasoningEffort: ReasoningEffort?) = + reasoningEffort(JsonField.ofNullable(reasoningEffort)) + + /** + * Alias for calling [Builder.reasoningEffort] with + * `reasoningEffort.orElse(null)`. + */ + fun reasoningEffort(reasoningEffort: Optional) = + reasoningEffort(reasoningEffort.getOrNull()) + + /** + * Sets [Builder.reasoningEffort] to an arbitrary JSON value. + * + * You should usually call [Builder.reasoningEffort] with a well-typed + * [ReasoningEffort] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun reasoningEffort(reasoningEffort: JsonField) = apply { + this.reasoningEffort = reasoningEffort + } + /** A seed value to initialize the randomness, during sampling. */ fun seed(seed: Long) = seed(JsonField.of(seed)) @@ -6414,6 +6480,7 @@ private constructor( fun build(): SamplingParams = SamplingParams( maxCompletionTokens, + reasoningEffort, seed, temperature, text, @@ -6431,6 +6498,7 @@ private constructor( } maxCompletionTokens() + reasoningEffort().ifPresent { it.validate() } seed() temperature() text().ifPresent { it.validate() } @@ -6456,6 +6524,7 @@ private constructor( @JvmSynthetic internal fun validity(): Int = (if (maxCompletionTokens.asKnown().isPresent) 1 else 0) + + (reasoningEffort.asKnown().getOrNull()?.validity() ?: 0) + (if (seed.asKnown().isPresent) 1 else 0) + (if (temperature.asKnown().isPresent) 1 else 0) + (text.asKnown().getOrNull()?.validity() ?: 0) + @@ -6674,6 +6743,7 @@ private constructor( return other is SamplingParams && maxCompletionTokens == other.maxCompletionTokens && + reasoningEffort == other.reasoningEffort && seed == other.seed && temperature == other.temperature && text == other.text && @@ -6685,6 +6755,7 @@ private constructor( private val hashCode: Int by lazy { Objects.hash( maxCompletionTokens, + reasoningEffort, seed, temperature, text, @@ -6697,7 +6768,7 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "SamplingParams{maxCompletionTokens=$maxCompletionTokens, seed=$seed, temperature=$temperature, text=$text, tools=$tools, topP=$topP, additionalProperties=$additionalProperties}" + "SamplingParams{maxCompletionTokens=$maxCompletionTokens, reasoningEffort=$reasoningEffort, seed=$seed, temperature=$temperature, text=$text, tools=$tools, topP=$topP, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { diff --git a/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/RunRetrieveResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/RunRetrieveResponse.kt index 41c7aa8d6..78e3bb750 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/RunRetrieveResponse.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/RunRetrieveResponse.kt @@ -5979,6 +5979,7 @@ private constructor( class SamplingParams private constructor( private val maxCompletionTokens: JsonField, + private val reasoningEffort: JsonField, private val seed: JsonField, private val temperature: JsonField, private val text: JsonField, @@ -5992,6 +5993,9 @@ private constructor( @JsonProperty("max_completion_tokens") @ExcludeMissing maxCompletionTokens: JsonField = JsonMissing.of(), + @JsonProperty("reasoning_effort") + @ExcludeMissing + reasoningEffort: JsonField = JsonMissing.of(), @JsonProperty("seed") @ExcludeMissing seed: JsonField = JsonMissing.of(), @JsonProperty("temperature") @ExcludeMissing @@ -6003,7 +6007,16 @@ private constructor( @JsonProperty("top_p") @ExcludeMissing topP: JsonField = JsonMissing.of(), - ) : this(maxCompletionTokens, seed, temperature, text, tools, topP, mutableMapOf()) + ) : this( + maxCompletionTokens, + reasoningEffort, + seed, + temperature, + text, + tools, + topP, + mutableMapOf(), + ) /** * The maximum number of tokens in the generated output. @@ -6014,6 +6027,19 @@ private constructor( fun maxCompletionTokens(): Optional = maxCompletionTokens.getOptional("max_completion_tokens") + /** + * Constrains effort on reasoning for + * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently + * supported values are `minimal`, `low`, `medium`, and `high`. Reducing reasoning + * effort can result in faster responses and fewer tokens used on reasoning in a + * response. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun reasoningEffort(): Optional = + reasoningEffort.getOptional("reasoning_effort") + /** * A seed value to initialize the randomness, during sampling. * @@ -6079,6 +6105,16 @@ private constructor( @ExcludeMissing fun _maxCompletionTokens(): JsonField = maxCompletionTokens + /** + * Returns the raw JSON value of [reasoningEffort]. + * + * Unlike [reasoningEffort], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("reasoning_effort") + @ExcludeMissing + fun _reasoningEffort(): JsonField = reasoningEffort + /** * Returns the raw JSON value of [seed]. * @@ -6145,6 +6181,7 @@ private constructor( class Builder internal constructor() { private var maxCompletionTokens: JsonField = JsonMissing.of() + private var reasoningEffort: JsonField = JsonMissing.of() private var seed: JsonField = JsonMissing.of() private var temperature: JsonField = JsonMissing.of() private var text: JsonField = JsonMissing.of() @@ -6155,6 +6192,7 @@ private constructor( @JvmSynthetic internal fun from(samplingParams: SamplingParams) = apply { maxCompletionTokens = samplingParams.maxCompletionTokens + reasoningEffort = samplingParams.reasoningEffort seed = samplingParams.seed temperature = samplingParams.temperature text = samplingParams.text @@ -6178,6 +6216,34 @@ private constructor( this.maxCompletionTokens = maxCompletionTokens } + /** + * Constrains effort on reasoning for + * [reasoning models](https://platform.openai.com/docs/guides/reasoning). + * Currently supported values are `minimal`, `low`, `medium`, and `high`. + * Reducing reasoning effort can result in faster responses and fewer tokens + * used on reasoning in a response. + */ + fun reasoningEffort(reasoningEffort: ReasoningEffort?) = + reasoningEffort(JsonField.ofNullable(reasoningEffort)) + + /** + * Alias for calling [Builder.reasoningEffort] with + * `reasoningEffort.orElse(null)`. + */ + fun reasoningEffort(reasoningEffort: Optional) = + reasoningEffort(reasoningEffort.getOrNull()) + + /** + * Sets [Builder.reasoningEffort] to an arbitrary JSON value. + * + * You should usually call [Builder.reasoningEffort] with a well-typed + * [ReasoningEffort] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun reasoningEffort(reasoningEffort: JsonField) = apply { + this.reasoningEffort = reasoningEffort + } + /** A seed value to initialize the randomness, during sampling. */ fun seed(seed: Long) = seed(JsonField.of(seed)) @@ -6414,6 +6480,7 @@ private constructor( fun build(): SamplingParams = SamplingParams( maxCompletionTokens, + reasoningEffort, seed, temperature, text, @@ -6431,6 +6498,7 @@ private constructor( } maxCompletionTokens() + reasoningEffort().ifPresent { it.validate() } seed() temperature() text().ifPresent { it.validate() } @@ -6456,6 +6524,7 @@ private constructor( @JvmSynthetic internal fun validity(): Int = (if (maxCompletionTokens.asKnown().isPresent) 1 else 0) + + (reasoningEffort.asKnown().getOrNull()?.validity() ?: 0) + (if (seed.asKnown().isPresent) 1 else 0) + (if (temperature.asKnown().isPresent) 1 else 0) + (text.asKnown().getOrNull()?.validity() ?: 0) + @@ -6674,6 +6743,7 @@ private constructor( return other is SamplingParams && maxCompletionTokens == other.maxCompletionTokens && + reasoningEffort == other.reasoningEffort && seed == other.seed && temperature == other.temperature && text == other.text && @@ -6685,6 +6755,7 @@ private constructor( private val hashCode: Int by lazy { Objects.hash( maxCompletionTokens, + reasoningEffort, seed, temperature, text, @@ -6697,7 +6768,7 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "SamplingParams{maxCompletionTokens=$maxCompletionTokens, seed=$seed, temperature=$temperature, text=$text, tools=$tools, topP=$topP, additionalProperties=$additionalProperties}" + "SamplingParams{maxCompletionTokens=$maxCompletionTokens, reasoningEffort=$reasoningEffort, seed=$seed, temperature=$temperature, text=$text, tools=$tools, topP=$topP, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { diff --git a/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/outputitems/OutputItemListResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/outputitems/OutputItemListResponse.kt index 8080c2fce..e0dd4e0e0 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/outputitems/OutputItemListResponse.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/outputitems/OutputItemListResponse.kt @@ -122,7 +122,7 @@ private constructor( @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ /** - * A list of results from the evaluation run. + * A list of grader results for this output item. * * @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). @@ -361,7 +361,7 @@ private constructor( */ fun object_(object_: JsonValue) = apply { this.object_ = object_ } - /** A list of results from the evaluation run. */ + /** A list of grader results for this output item. */ fun results(results: List) = results(JsonField.of(results)) /** @@ -625,36 +625,211 @@ private constructor( override fun toString() = "DatasourceItem{additionalProperties=$additionalProperties}" } - /** A result object. */ + /** A single grader result for an evaluation run output item. */ class Result - @JsonCreator private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val name: JsonField, + private val passed: JsonField, + private val score: JsonField, + private val sample: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("passed") @ExcludeMissing passed: JsonField = JsonMissing.of(), + @JsonProperty("score") @ExcludeMissing score: JsonField = JsonMissing.of(), + @JsonProperty("sample") @ExcludeMissing sample: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(name, passed, score, sample, type, mutableMapOf()) + + /** + * 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") + + /** + * Whether the grader considered the output a pass. + * + * @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 passed(): Boolean = passed.getRequired("passed") + + /** + * The numeric score produced by 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 score(): Double = score.getRequired("score") + + /** + * Optional sample or intermediate data produced by the grader. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun sample(): Optional = sample.getOptional("sample") + + /** + * The grader type (for example, "string-check-grader"). + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun type(): Optional = type.getOptional("type") + + /** + * 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 [passed]. + * + * Unlike [passed], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("passed") @ExcludeMissing fun _passed(): JsonField = passed + + /** + * Returns the raw JSON value of [score]. + * + * Unlike [score], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("score") @ExcludeMissing fun _score(): JsonField = score + + /** + * Returns the raw JSON value of [sample]. + * + * Unlike [sample], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("sample") @ExcludeMissing fun _sample(): JsonField = sample + + /** + * 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 = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) companion object { - /** Returns a mutable builder for constructing an instance of [Result]. */ + /** + * Returns a mutable builder for constructing an instance of [Result]. + * + * The following fields are required: + * ```java + * .name() + * .passed() + * .score() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [Result]. */ class Builder internal constructor() { + private var name: JsonField? = null + private var passed: JsonField? = null + private var score: JsonField? = null + private var sample: JsonField = JsonMissing.of() + private var type: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(result: Result) = apply { + name = result.name + passed = result.passed + score = result.score + sample = result.sample + type = result.type additionalProperties = result.additionalProperties.toMutableMap() } + /** 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 } + + /** Whether the grader considered the output a pass. */ + fun passed(passed: Boolean) = passed(JsonField.of(passed)) + + /** + * Sets [Builder.passed] to an arbitrary JSON value. + * + * You should usually call [Builder.passed] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun passed(passed: JsonField) = apply { this.passed = passed } + + /** The numeric score produced by the grader. */ + fun score(score: Double) = score(JsonField.of(score)) + + /** + * Sets [Builder.score] to an arbitrary JSON value. + * + * You should usually call [Builder.score] with a well-typed [Double] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun score(score: JsonField) = apply { this.score = score } + + /** Optional sample or intermediate data produced by the grader. */ + fun sample(sample: Sample?) = sample(JsonField.ofNullable(sample)) + + /** Alias for calling [Builder.sample] with `sample.orElse(null)`. */ + fun sample(sample: Optional) = sample(sample.getOrNull()) + + /** + * Sets [Builder.sample] to an arbitrary JSON value. + * + * You should usually call [Builder.sample] with a well-typed [Sample] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun sample(sample: JsonField) = apply { this.sample = sample } + + /** The grader type (for example, "string-check-grader"). */ + fun type(type: String) = type(JsonField.of(type)) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [String] 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) @@ -678,8 +853,25 @@ private constructor( * Returns an immutable instance of [Result]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .name() + * .passed() + * .score() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ - fun build(): Result = Result(additionalProperties.toImmutable()) + fun build(): Result = + Result( + checkRequired("name", name), + checkRequired("passed", passed), + checkRequired("score", score), + sample, + type, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -689,6 +881,11 @@ private constructor( return@apply } + name() + passed() + score() + sample().ifPresent { it.validate() } + type() validated = true } @@ -708,21 +905,137 @@ private constructor( */ @JvmSynthetic internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (name.asKnown().isPresent) 1 else 0) + + (if (passed.asKnown().isPresent) 1 else 0) + + (if (score.asKnown().isPresent) 1 else 0) + + (sample.asKnown().getOrNull()?.validity() ?: 0) + + (if (type.asKnown().isPresent) 1 else 0) + + /** Optional sample or intermediate data produced by the grader. */ + class Sample + @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 [Sample]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Sample]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(sample: Sample) = apply { + additionalProperties = sample.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 [Sample]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Sample = Sample(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Sample = 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 other is Sample && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Sample{additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return other is Result && additionalProperties == other.additionalProperties + return other is Result && + name == other.name && + passed == other.passed && + score == other.score && + sample == other.sample && + type == other.type && + additionalProperties == other.additionalProperties } - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + private val hashCode: Int by lazy { + Objects.hash(name, passed, score, sample, type, additionalProperties) + } override fun hashCode(): Int = hashCode - override fun toString() = "Result{additionalProperties=$additionalProperties}" + override fun toString() = + "Result{name=$name, passed=$passed, score=$score, sample=$sample, type=$type, additionalProperties=$additionalProperties}" } /** A sample containing the input and output of the evaluation run. */ diff --git a/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/outputitems/OutputItemRetrieveResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/outputitems/OutputItemRetrieveResponse.kt index 380c67eb5..195926106 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/outputitems/OutputItemRetrieveResponse.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/outputitems/OutputItemRetrieveResponse.kt @@ -122,7 +122,7 @@ private constructor( @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ /** - * A list of results from the evaluation run. + * A list of grader results for this output item. * * @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). @@ -361,7 +361,7 @@ private constructor( */ fun object_(object_: JsonValue) = apply { this.object_ = object_ } - /** A list of results from the evaluation run. */ + /** A list of grader results for this output item. */ fun results(results: List) = results(JsonField.of(results)) /** @@ -625,36 +625,211 @@ private constructor( override fun toString() = "DatasourceItem{additionalProperties=$additionalProperties}" } - /** A result object. */ + /** A single grader result for an evaluation run output item. */ class Result - @JsonCreator private constructor( - @com.fasterxml.jackson.annotation.JsonValue - private val additionalProperties: Map + private val name: JsonField, + private val passed: JsonField, + private val score: JsonField, + private val sample: JsonField, + private val type: JsonField, + private val additionalProperties: MutableMap, ) { + @JsonCreator + private constructor( + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("passed") @ExcludeMissing passed: JsonField = JsonMissing.of(), + @JsonProperty("score") @ExcludeMissing score: JsonField = JsonMissing.of(), + @JsonProperty("sample") @ExcludeMissing sample: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + ) : this(name, passed, score, sample, type, mutableMapOf()) + + /** + * 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") + + /** + * Whether the grader considered the output a pass. + * + * @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 passed(): Boolean = passed.getRequired("passed") + + /** + * The numeric score produced by 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 score(): Double = score.getRequired("score") + + /** + * Optional sample or intermediate data produced by the grader. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun sample(): Optional = sample.getOptional("sample") + + /** + * The grader type (for example, "string-check-grader"). + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun type(): Optional = type.getOptional("type") + + /** + * 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 [passed]. + * + * Unlike [passed], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("passed") @ExcludeMissing fun _passed(): JsonField = passed + + /** + * Returns the raw JSON value of [score]. + * + * Unlike [score], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("score") @ExcludeMissing fun _score(): JsonField = score + + /** + * Returns the raw JSON value of [sample]. + * + * Unlike [sample], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("sample") @ExcludeMissing fun _sample(): JsonField = sample + + /** + * 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 = additionalProperties + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) fun toBuilder() = Builder().from(this) companion object { - /** Returns a mutable builder for constructing an instance of [Result]. */ + /** + * Returns a mutable builder for constructing an instance of [Result]. + * + * The following fields are required: + * ```java + * .name() + * .passed() + * .score() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [Result]. */ class Builder internal constructor() { + private var name: JsonField? = null + private var passed: JsonField? = null + private var score: JsonField? = null + private var sample: JsonField = JsonMissing.of() + private var type: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(result: Result) = apply { + name = result.name + passed = result.passed + score = result.score + sample = result.sample + type = result.type additionalProperties = result.additionalProperties.toMutableMap() } + /** 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 } + + /** Whether the grader considered the output a pass. */ + fun passed(passed: Boolean) = passed(JsonField.of(passed)) + + /** + * Sets [Builder.passed] to an arbitrary JSON value. + * + * You should usually call [Builder.passed] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun passed(passed: JsonField) = apply { this.passed = passed } + + /** The numeric score produced by the grader. */ + fun score(score: Double) = score(JsonField.of(score)) + + /** + * Sets [Builder.score] to an arbitrary JSON value. + * + * You should usually call [Builder.score] with a well-typed [Double] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun score(score: JsonField) = apply { this.score = score } + + /** Optional sample or intermediate data produced by the grader. */ + fun sample(sample: Sample?) = sample(JsonField.ofNullable(sample)) + + /** Alias for calling [Builder.sample] with `sample.orElse(null)`. */ + fun sample(sample: Optional) = sample(sample.getOrNull()) + + /** + * Sets [Builder.sample] to an arbitrary JSON value. + * + * You should usually call [Builder.sample] with a well-typed [Sample] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun sample(sample: JsonField) = apply { this.sample = sample } + + /** The grader type (for example, "string-check-grader"). */ + fun type(type: String) = type(JsonField.of(type)) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [String] 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) @@ -678,8 +853,25 @@ private constructor( * Returns an immutable instance of [Result]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .name() + * .passed() + * .score() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ - fun build(): Result = Result(additionalProperties.toImmutable()) + fun build(): Result = + Result( + checkRequired("name", name), + checkRequired("passed", passed), + checkRequired("score", score), + sample, + type, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -689,6 +881,11 @@ private constructor( return@apply } + name() + passed() + score() + sample().ifPresent { it.validate() } + type() validated = true } @@ -708,21 +905,137 @@ private constructor( */ @JvmSynthetic internal fun validity(): Int = - additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + (if (name.asKnown().isPresent) 1 else 0) + + (if (passed.asKnown().isPresent) 1 else 0) + + (if (score.asKnown().isPresent) 1 else 0) + + (sample.asKnown().getOrNull()?.validity() ?: 0) + + (if (type.asKnown().isPresent) 1 else 0) + + /** Optional sample or intermediate data produced by the grader. */ + class Sample + @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 [Sample]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Sample]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(sample: Sample) = apply { + additionalProperties = sample.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 [Sample]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Sample = Sample(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Sample = 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 other is Sample && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Sample{additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return other is Result && additionalProperties == other.additionalProperties + return other is Result && + name == other.name && + passed == other.passed && + score == other.score && + sample == other.sample && + type == other.type && + additionalProperties == other.additionalProperties } - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + private val hashCode: Int by lazy { + Objects.hash(name, passed, score, sample, type, additionalProperties) + } override fun hashCode(): Int = hashCode - override fun toString() = "Result{additionalProperties=$additionalProperties}" + override fun toString() = + "Result{name=$name, passed=$passed, score=$score, sample=$sample, type=$type, additionalProperties=$additionalProperties}" } /** A sample containing the input and output of the evaluation run. */ diff --git a/openai-java-core/src/main/kotlin/com/openai/models/graders/gradermodels/ScoreModelGrader.kt b/openai-java-core/src/main/kotlin/com/openai/models/graders/gradermodels/ScoreModelGrader.kt index 74e5b0167..57c509d1f 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/graders/gradermodels/ScoreModelGrader.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/graders/gradermodels/ScoreModelGrader.kt @@ -26,6 +26,7 @@ import com.openai.core.checkRequired import com.openai.core.getOrThrow import com.openai.core.toImmutable import com.openai.errors.OpenAIInvalidDataException +import com.openai.models.ReasoningEffort import com.openai.models.responses.ResponseInputAudio import com.openai.models.responses.ResponseInputText import java.util.Collections @@ -41,7 +42,7 @@ private constructor( private val name: JsonField, private val type: JsonValue, private val range: JsonField>, - private val samplingParams: JsonValue, + private val samplingParams: JsonField, private val additionalProperties: MutableMap, ) { @@ -54,7 +55,7 @@ private constructor( @JsonProperty("range") @ExcludeMissing range: JsonField> = JsonMissing.of(), @JsonProperty("sampling_params") @ExcludeMissing - samplingParams: JsonValue = JsonMissing.of(), + samplingParams: JsonField = JsonMissing.of(), ) : this(input, model, name, type, range, samplingParams, mutableMapOf()) /** @@ -102,10 +103,13 @@ private constructor( */ fun range(): Optional> = range.getOptional("range") - /** The sampling parameters for the model. */ - @JsonProperty("sampling_params") - @ExcludeMissing - fun _samplingParams(): JsonValue = samplingParams + /** + * The sampling parameters for the model. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun samplingParams(): Optional = samplingParams.getOptional("sampling_params") /** * Returns the raw JSON value of [input]. @@ -135,6 +139,15 @@ private constructor( */ @JsonProperty("range") @ExcludeMissing fun _range(): JsonField> = range + /** + * Returns the raw JSON value of [samplingParams]. + * + * Unlike [samplingParams], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("sampling_params") + @ExcludeMissing + fun _samplingParams(): JsonField = samplingParams + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -170,7 +183,7 @@ private constructor( private var name: JsonField? = null private var type: JsonValue = JsonValue.from("score_model") private var range: JsonField>? = null - private var samplingParams: JsonValue = JsonMissing.of() + private var samplingParams: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -273,7 +286,17 @@ private constructor( } /** The sampling parameters for the model. */ - fun samplingParams(samplingParams: JsonValue) = apply { + fun samplingParams(samplingParams: SamplingParams) = + samplingParams(JsonField.of(samplingParams)) + + /** + * Sets [Builder.samplingParams] to an arbitrary JSON value. + * + * You should usually call [Builder.samplingParams] with a well-typed [SamplingParams] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun samplingParams(samplingParams: JsonField) = apply { this.samplingParams = samplingParams } @@ -338,6 +361,7 @@ private constructor( } } range() + samplingParams().ifPresent { it.validate() } validated = true } @@ -360,7 +384,8 @@ private constructor( (if (model.asKnown().isPresent) 1 else 0) + (if (name.asKnown().isPresent) 1 else 0) + type.let { if (it == JsonValue.from("score_model")) 1 else 0 } + - (range.asKnown().getOrNull()?.size ?: 0) + (range.asKnown().getOrNull()?.size ?: 0) + + (samplingParams.asKnown().getOrNull()?.validity() ?: 0) /** * A message input to the model with a role indicating instruction following hierarchy. @@ -1718,6 +1743,384 @@ private constructor( "Input{content=$content, role=$role, type=$type, additionalProperties=$additionalProperties}" } + /** The sampling parameters for the model. */ + class SamplingParams + private constructor( + private val maxCompletionsTokens: JsonField, + private val reasoningEffort: JsonField, + private val seed: JsonField, + private val temperature: JsonField, + private val topP: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("max_completions_tokens") + @ExcludeMissing + maxCompletionsTokens: JsonField = JsonMissing.of(), + @JsonProperty("reasoning_effort") + @ExcludeMissing + reasoningEffort: JsonField = JsonMissing.of(), + @JsonProperty("seed") @ExcludeMissing seed: JsonField = JsonMissing.of(), + @JsonProperty("temperature") + @ExcludeMissing + temperature: JsonField = JsonMissing.of(), + @JsonProperty("top_p") @ExcludeMissing topP: JsonField = JsonMissing.of(), + ) : this(maxCompletionsTokens, reasoningEffort, seed, temperature, topP, mutableMapOf()) + + /** + * The maximum number of tokens the grader model may generate in its response. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun maxCompletionsTokens(): Optional = + maxCompletionsTokens.getOptional("max_completions_tokens") + + /** + * Constrains effort on reasoning for + * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently + * supported values are `minimal`, `low`, `medium`, and `high`. Reducing reasoning effort + * can result in faster responses and fewer tokens used on reasoning in a response. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun reasoningEffort(): Optional = + reasoningEffort.getOptional("reasoning_effort") + + /** + * A seed value to initialize the randomness, during sampling. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun seed(): Optional = seed.getOptional("seed") + + /** + * A higher temperature increases randomness in the outputs. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun temperature(): Optional = temperature.getOptional("temperature") + + /** + * An alternative to temperature for nucleus sampling; 1.0 includes all tokens. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun topP(): Optional = topP.getOptional("top_p") + + /** + * Returns the raw JSON value of [maxCompletionsTokens]. + * + * Unlike [maxCompletionsTokens], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("max_completions_tokens") + @ExcludeMissing + fun _maxCompletionsTokens(): JsonField = maxCompletionsTokens + + /** + * Returns the raw JSON value of [reasoningEffort]. + * + * Unlike [reasoningEffort], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("reasoning_effort") + @ExcludeMissing + fun _reasoningEffort(): JsonField = reasoningEffort + + /** + * Returns the raw JSON value of [seed]. + * + * Unlike [seed], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("seed") @ExcludeMissing fun _seed(): JsonField = seed + + /** + * Returns the raw JSON value of [temperature]. + * + * Unlike [temperature], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("temperature") + @ExcludeMissing + fun _temperature(): JsonField = temperature + + /** + * Returns the raw JSON value of [topP]. + * + * Unlike [topP], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("top_p") @ExcludeMissing fun _topP(): JsonField = topP + + @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 [SamplingParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SamplingParams]. */ + class Builder internal constructor() { + + private var maxCompletionsTokens: JsonField = JsonMissing.of() + private var reasoningEffort: JsonField = JsonMissing.of() + private var seed: JsonField = JsonMissing.of() + private var temperature: JsonField = JsonMissing.of() + private var topP: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(samplingParams: SamplingParams) = apply { + maxCompletionsTokens = samplingParams.maxCompletionsTokens + reasoningEffort = samplingParams.reasoningEffort + seed = samplingParams.seed + temperature = samplingParams.temperature + topP = samplingParams.topP + additionalProperties = samplingParams.additionalProperties.toMutableMap() + } + + /** The maximum number of tokens the grader model may generate in its response. */ + fun maxCompletionsTokens(maxCompletionsTokens: Long?) = + maxCompletionsTokens(JsonField.ofNullable(maxCompletionsTokens)) + + /** + * Alias for [Builder.maxCompletionsTokens]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun maxCompletionsTokens(maxCompletionsTokens: Long) = + maxCompletionsTokens(maxCompletionsTokens as Long?) + + /** + * Alias for calling [Builder.maxCompletionsTokens] with + * `maxCompletionsTokens.orElse(null)`. + */ + fun maxCompletionsTokens(maxCompletionsTokens: Optional) = + maxCompletionsTokens(maxCompletionsTokens.getOrNull()) + + /** + * Sets [Builder.maxCompletionsTokens] to an arbitrary JSON value. + * + * You should usually call [Builder.maxCompletionsTokens] with a well-typed [Long] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun maxCompletionsTokens(maxCompletionsTokens: JsonField) = apply { + this.maxCompletionsTokens = maxCompletionsTokens + } + + /** + * Constrains effort on reasoning for + * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently + * supported values are `minimal`, `low`, `medium`, and `high`. Reducing reasoning + * effort can result in faster responses and fewer tokens used on reasoning in a + * response. + */ + fun reasoningEffort(reasoningEffort: ReasoningEffort?) = + reasoningEffort(JsonField.ofNullable(reasoningEffort)) + + /** Alias for calling [Builder.reasoningEffort] with `reasoningEffort.orElse(null)`. */ + fun reasoningEffort(reasoningEffort: Optional) = + reasoningEffort(reasoningEffort.getOrNull()) + + /** + * Sets [Builder.reasoningEffort] to an arbitrary JSON value. + * + * You should usually call [Builder.reasoningEffort] with a well-typed [ReasoningEffort] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun reasoningEffort(reasoningEffort: JsonField) = apply { + this.reasoningEffort = reasoningEffort + } + + /** A seed value to initialize the randomness, during sampling. */ + fun seed(seed: Long?) = seed(JsonField.ofNullable(seed)) + + /** + * Alias for [Builder.seed]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun seed(seed: Long) = seed(seed as Long?) + + /** Alias for calling [Builder.seed] with `seed.orElse(null)`. */ + fun seed(seed: Optional) = seed(seed.getOrNull()) + + /** + * Sets [Builder.seed] to an arbitrary JSON value. + * + * You should usually call [Builder.seed] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun seed(seed: JsonField) = apply { this.seed = seed } + + /** A higher temperature increases randomness in the outputs. */ + fun temperature(temperature: Double?) = temperature(JsonField.ofNullable(temperature)) + + /** + * Alias for [Builder.temperature]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun temperature(temperature: Double) = temperature(temperature as Double?) + + /** Alias for calling [Builder.temperature] with `temperature.orElse(null)`. */ + fun temperature(temperature: Optional) = temperature(temperature.getOrNull()) + + /** + * Sets [Builder.temperature] to an arbitrary JSON value. + * + * You should usually call [Builder.temperature] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun temperature(temperature: JsonField) = apply { + this.temperature = temperature + } + + /** An alternative to temperature for nucleus sampling; 1.0 includes all tokens. */ + fun topP(topP: Double?) = topP(JsonField.ofNullable(topP)) + + /** + * Alias for [Builder.topP]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun topP(topP: Double) = topP(topP as Double?) + + /** Alias for calling [Builder.topP] with `topP.orElse(null)`. */ + fun topP(topP: Optional) = topP(topP.getOrNull()) + + /** + * Sets [Builder.topP] to an arbitrary JSON value. + * + * You should usually call [Builder.topP] with a well-typed [Double] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun topP(topP: JsonField) = apply { this.topP = topP } + + 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 [SamplingParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): SamplingParams = + SamplingParams( + maxCompletionsTokens, + reasoningEffort, + seed, + temperature, + topP, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): SamplingParams = apply { + if (validated) { + return@apply + } + + maxCompletionsTokens() + reasoningEffort().ifPresent { it.validate() } + seed() + temperature() + topP() + 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 (maxCompletionsTokens.asKnown().isPresent) 1 else 0) + + (reasoningEffort.asKnown().getOrNull()?.validity() ?: 0) + + (if (seed.asKnown().isPresent) 1 else 0) + + (if (temperature.asKnown().isPresent) 1 else 0) + + (if (topP.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is SamplingParams && + maxCompletionsTokens == other.maxCompletionsTokens && + reasoningEffort == other.reasoningEffort && + seed == other.seed && + temperature == other.temperature && + topP == other.topP && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + maxCompletionsTokens, + reasoningEffort, + seed, + temperature, + topP, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SamplingParams{maxCompletionsTokens=$maxCompletionsTokens, reasoningEffort=$reasoningEffort, seed=$seed, temperature=$temperature, topP=$topP, additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseContent.kt b/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseContent.kt index 377e39e24..b1107ec1b 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseContent.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseContent.kt @@ -2,6 +2,10 @@ package com.openai.models.responses +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 @@ -11,10 +15,15 @@ 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.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing import com.openai.core.JsonValue import com.openai.core.allMaxBy +import com.openai.core.checkRequired import com.openai.core.getOrThrow import com.openai.errors.OpenAIInvalidDataException +import java.util.Collections import java.util.Objects import java.util.Optional @@ -29,6 +38,7 @@ private constructor( private val inputAudio: ResponseInputAudio? = null, private val outputText: ResponseOutputText? = null, private val outputRefusal: ResponseOutputRefusal? = null, + private val reasoningText: ReasoningTextContent? = null, private val _json: JsonValue? = null, ) { @@ -53,6 +63,9 @@ private constructor( /** A refusal from the model. */ fun outputRefusal(): Optional = Optional.ofNullable(outputRefusal) + /** Reasoning text from the model. */ + fun reasoningText(): Optional = Optional.ofNullable(reasoningText) + fun isInputText(): Boolean = inputText != null fun isInputImage(): Boolean = inputImage != null @@ -65,6 +78,8 @@ private constructor( fun isOutputRefusal(): Boolean = outputRefusal != null + fun isReasoningText(): Boolean = reasoningText != null + /** A text input to the model. */ fun asInputText(): ResponseInputText = inputText.getOrThrow("inputText") @@ -86,6 +101,9 @@ private constructor( /** A refusal from the model. */ fun asOutputRefusal(): ResponseOutputRefusal = outputRefusal.getOrThrow("outputRefusal") + /** Reasoning text from the model. */ + fun asReasoningText(): ReasoningTextContent = reasoningText.getOrThrow("reasoningText") + fun _json(): Optional = Optional.ofNullable(_json) fun accept(visitor: Visitor): T = @@ -96,6 +114,7 @@ private constructor( inputAudio != null -> visitor.visitInputAudio(inputAudio) outputText != null -> visitor.visitOutputText(outputText) outputRefusal != null -> visitor.visitOutputRefusal(outputRefusal) + reasoningText != null -> visitor.visitReasoningText(reasoningText) else -> visitor.unknown(_json) } @@ -131,6 +150,10 @@ private constructor( override fun visitOutputRefusal(outputRefusal: ResponseOutputRefusal) { outputRefusal.validate() } + + override fun visitReasoningText(reasoningText: ReasoningTextContent) { + reasoningText.validate() + } } ) validated = true @@ -166,6 +189,9 @@ private constructor( override fun visitOutputRefusal(outputRefusal: ResponseOutputRefusal) = outputRefusal.validity() + override fun visitReasoningText(reasoningText: ReasoningTextContent) = + reasoningText.validity() + override fun unknown(json: JsonValue?) = 0 } ) @@ -181,11 +207,20 @@ private constructor( inputFile == other.inputFile && inputAudio == other.inputAudio && outputText == other.outputText && - outputRefusal == other.outputRefusal + outputRefusal == other.outputRefusal && + reasoningText == other.reasoningText } override fun hashCode(): Int = - Objects.hash(inputText, inputImage, inputFile, inputAudio, outputText, outputRefusal) + Objects.hash( + inputText, + inputImage, + inputFile, + inputAudio, + outputText, + outputRefusal, + reasoningText, + ) override fun toString(): String = when { @@ -195,6 +230,7 @@ private constructor( inputAudio != null -> "ResponseContent{inputAudio=$inputAudio}" outputText != null -> "ResponseContent{outputText=$outputText}" outputRefusal != null -> "ResponseContent{outputRefusal=$outputRefusal}" + reasoningText != null -> "ResponseContent{reasoningText=$reasoningText}" _json != null -> "ResponseContent{_unknown=$_json}" else -> throw IllegalStateException("Invalid ResponseContent") } @@ -228,6 +264,11 @@ private constructor( @JvmStatic fun ofOutputRefusal(outputRefusal: ResponseOutputRefusal) = ResponseContent(outputRefusal = outputRefusal) + + /** Reasoning text from the model. */ + @JvmStatic + fun ofReasoningText(reasoningText: ReasoningTextContent) = + ResponseContent(reasoningText = reasoningText) } /** @@ -257,6 +298,9 @@ private constructor( /** A refusal from the model. */ fun visitOutputRefusal(outputRefusal: ResponseOutputRefusal): T + /** Reasoning text from the model. */ + fun visitReasoningText(reasoningText: ReasoningTextContent): T + /** * Maps an unknown variant of [ResponseContent] to a value of type [T]. * @@ -297,6 +341,9 @@ private constructor( tryDeserialize(node, jacksonTypeRef())?.let { ResponseContent(outputRefusal = it, _json = json) }, + tryDeserialize(node, jacksonTypeRef())?.let { + ResponseContent(reasoningText = it, _json = json) + }, ) .filterNotNull() .allMaxBy { it.validity() } @@ -327,9 +374,210 @@ private constructor( value.inputAudio != null -> generator.writeObject(value.inputAudio) value.outputText != null -> generator.writeObject(value.outputText) value.outputRefusal != null -> generator.writeObject(value.outputRefusal) + value.reasoningText != null -> generator.writeObject(value.reasoningText) value._json != null -> generator.writeObject(value._json) else -> throw IllegalStateException("Invalid ResponseContent") } } } + + /** Reasoning text from the model. */ + class ReasoningTextContent + private constructor( + private val text: JsonField, + private val type: JsonValue, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("text") @ExcludeMissing text: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + ) : this(text, type, mutableMapOf()) + + /** + * The reasoning text from the model. + * + * @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 the reasoning text. Always `reasoning_text`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("reasoning_text") + * ``` + * + * 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 [text]. + * + * Unlike [text], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text + + @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 [ReasoningTextContent]. + * + * The following fields are required: + * ```java + * .text() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ReasoningTextContent]. */ + class Builder internal constructor() { + + private var text: JsonField? = null + private var type: JsonValue = JsonValue.from("reasoning_text") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(reasoningTextContent: ReasoningTextContent) = apply { + text = reasoningTextContent.text + type = reasoningTextContent.type + additionalProperties = reasoningTextContent.additionalProperties.toMutableMap() + } + + /** The reasoning text from the model. */ + fun text(text: String) = text(JsonField.of(text)) + + /** + * Sets [Builder.text] to an arbitrary JSON value. + * + * You should usually call [Builder.text] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun text(text: JsonField) = apply { this.text = text } + + /** + * 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("reasoning_text") + * ``` + * + * 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 [ReasoningTextContent]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .text() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ReasoningTextContent = + ReasoningTextContent( + checkRequired("text", text), + type, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ReasoningTextContent = apply { + if (validated) { + return@apply + } + + text() + _type().let { + if (it != JsonValue.from("reasoning_text")) { + 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 = + (if (text.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("reasoning_text")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ReasoningTextContent && + text == other.text && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(text, type, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ReasoningTextContent{text=$text, type=$type, additionalProperties=$additionalProperties}" + } } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseContentPartAddedEvent.kt b/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseContentPartAddedEvent.kt index 6c6dc660f..78b23f229 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseContentPartAddedEvent.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseContentPartAddedEvent.kt @@ -262,6 +262,19 @@ private constructor( fun refusalPart(refusal: String) = part(ResponseOutputRefusal.builder().refusal(refusal).build()) + /** Alias for calling [part] with `Part.ofReasoningText(reasoningText)`. */ + fun part(reasoningText: Part.ReasoningText) = part(Part.ofReasoningText(reasoningText)) + + /** + * Alias for calling [part] with the following: + * ```java + * Part.ReasoningText.builder() + * .text(text) + * .build() + * ``` + */ + fun reasoningTextPart(text: String) = part(Part.ReasoningText.builder().text(text).build()) + /** The sequence number of this event. */ fun sequenceNumber(sequenceNumber: Long) = sequenceNumber(JsonField.of(sequenceNumber)) @@ -386,6 +399,7 @@ private constructor( private constructor( private val outputText: ResponseOutputText? = null, private val refusal: ResponseOutputRefusal? = null, + private val reasoningText: ReasoningText? = null, private val _json: JsonValue? = null, ) { @@ -395,22 +409,31 @@ private constructor( /** A refusal from the model. */ fun refusal(): Optional = Optional.ofNullable(refusal) + /** Reasoning text from the model. */ + fun reasoningText(): Optional = Optional.ofNullable(reasoningText) + fun isOutputText(): Boolean = outputText != null fun isRefusal(): Boolean = refusal != null + fun isReasoningText(): Boolean = reasoningText != null + /** A text output from the model. */ fun asOutputText(): ResponseOutputText = outputText.getOrThrow("outputText") /** A refusal from the model. */ fun asRefusal(): ResponseOutputRefusal = refusal.getOrThrow("refusal") + /** Reasoning text from the model. */ + fun asReasoningText(): ReasoningText = reasoningText.getOrThrow("reasoningText") + fun _json(): Optional = Optional.ofNullable(_json) fun accept(visitor: Visitor): T = when { outputText != null -> visitor.visitOutputText(outputText) refusal != null -> visitor.visitRefusal(refusal) + reasoningText != null -> visitor.visitReasoningText(reasoningText) else -> visitor.unknown(_json) } @@ -430,6 +453,10 @@ private constructor( override fun visitRefusal(refusal: ResponseOutputRefusal) { refusal.validate() } + + override fun visitReasoningText(reasoningText: ReasoningText) { + reasoningText.validate() + } } ) validated = true @@ -458,6 +485,9 @@ private constructor( override fun visitRefusal(refusal: ResponseOutputRefusal) = refusal.validity() + override fun visitReasoningText(reasoningText: ReasoningText) = + reasoningText.validity() + override fun unknown(json: JsonValue?) = 0 } ) @@ -467,15 +497,19 @@ private constructor( return true } - return other is Part && outputText == other.outputText && refusal == other.refusal + return other is Part && + outputText == other.outputText && + refusal == other.refusal && + reasoningText == other.reasoningText } - override fun hashCode(): Int = Objects.hash(outputText, refusal) + override fun hashCode(): Int = Objects.hash(outputText, refusal, reasoningText) override fun toString(): String = when { outputText != null -> "Part{outputText=$outputText}" refusal != null -> "Part{refusal=$refusal}" + reasoningText != null -> "Part{reasoningText=$reasoningText}" _json != null -> "Part{_unknown=$_json}" else -> throw IllegalStateException("Invalid Part") } @@ -488,6 +522,10 @@ private constructor( /** A refusal from the model. */ @JvmStatic fun ofRefusal(refusal: ResponseOutputRefusal) = Part(refusal = refusal) + + /** Reasoning text from the model. */ + @JvmStatic + fun ofReasoningText(reasoningText: ReasoningText) = Part(reasoningText = reasoningText) } /** An interface that defines how to map each variant of [Part] to a value of type [T]. */ @@ -499,6 +537,9 @@ private constructor( /** A refusal from the model. */ fun visitRefusal(refusal: ResponseOutputRefusal): T + /** Reasoning text from the model. */ + fun visitReasoningText(reasoningText: ReasoningText): T + /** * Maps an unknown variant of [Part] to a value of type [T]. * @@ -530,6 +571,11 @@ private constructor( Part(refusal = it, _json = json) } ?: Part(_json = json) } + "reasoning_text" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Part(reasoningText = it, _json = json) + } ?: Part(_json = json) + } } return Part(_json = json) @@ -546,11 +592,216 @@ private constructor( when { value.outputText != null -> generator.writeObject(value.outputText) value.refusal != null -> generator.writeObject(value.refusal) + value.reasoningText != null -> generator.writeObject(value.reasoningText) value._json != null -> generator.writeObject(value._json) else -> throw IllegalStateException("Invalid Part") } } } + + /** Reasoning text from the model. */ + class ReasoningText + private constructor( + private val text: JsonField, + private val type: JsonValue, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("text") @ExcludeMissing text: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + ) : this(text, type, mutableMapOf()) + + /** + * The reasoning text from the model. + * + * @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 the reasoning text. Always `reasoning_text`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("reasoning_text") + * ``` + * + * 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 [text]. + * + * Unlike [text], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text + + @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 [ReasoningText]. + * + * The following fields are required: + * ```java + * .text() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ReasoningText]. */ + class Builder internal constructor() { + + private var text: JsonField? = null + private var type: JsonValue = JsonValue.from("reasoning_text") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(reasoningText: ReasoningText) = apply { + text = reasoningText.text + type = reasoningText.type + additionalProperties = reasoningText.additionalProperties.toMutableMap() + } + + /** The reasoning text from the model. */ + fun text(text: String) = text(JsonField.of(text)) + + /** + * Sets [Builder.text] to an arbitrary JSON value. + * + * You should usually call [Builder.text] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun text(text: JsonField) = apply { this.text = text } + + /** + * 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("reasoning_text") + * ``` + * + * 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 [ReasoningText]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .text() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ReasoningText = + ReasoningText( + checkRequired("text", text), + type, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ReasoningText = apply { + if (validated) { + return@apply + } + + text() + _type().let { + if (it != JsonValue.from("reasoning_text")) { + 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 = + (if (text.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("reasoning_text")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ReasoningText && + text == other.text && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(text, type, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ReasoningText{text=$text, type=$type, additionalProperties=$additionalProperties}" + } } override fun equals(other: Any?): Boolean { diff --git a/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseContentPartDoneEvent.kt b/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseContentPartDoneEvent.kt index e30ffeed2..7eef6eee2 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseContentPartDoneEvent.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseContentPartDoneEvent.kt @@ -261,6 +261,19 @@ private constructor( fun refusalPart(refusal: String) = part(ResponseOutputRefusal.builder().refusal(refusal).build()) + /** Alias for calling [part] with `Part.ofReasoningText(reasoningText)`. */ + fun part(reasoningText: Part.ReasoningText) = part(Part.ofReasoningText(reasoningText)) + + /** + * Alias for calling [part] with the following: + * ```java + * Part.ReasoningText.builder() + * .text(text) + * .build() + * ``` + */ + fun reasoningTextPart(text: String) = part(Part.ReasoningText.builder().text(text).build()) + /** The sequence number of this event. */ fun sequenceNumber(sequenceNumber: Long) = sequenceNumber(JsonField.of(sequenceNumber)) @@ -385,6 +398,7 @@ private constructor( private constructor( private val outputText: ResponseOutputText? = null, private val refusal: ResponseOutputRefusal? = null, + private val reasoningText: ReasoningText? = null, private val _json: JsonValue? = null, ) { @@ -394,22 +408,31 @@ private constructor( /** A refusal from the model. */ fun refusal(): Optional = Optional.ofNullable(refusal) + /** Reasoning text from the model. */ + fun reasoningText(): Optional = Optional.ofNullable(reasoningText) + fun isOutputText(): Boolean = outputText != null fun isRefusal(): Boolean = refusal != null + fun isReasoningText(): Boolean = reasoningText != null + /** A text output from the model. */ fun asOutputText(): ResponseOutputText = outputText.getOrThrow("outputText") /** A refusal from the model. */ fun asRefusal(): ResponseOutputRefusal = refusal.getOrThrow("refusal") + /** Reasoning text from the model. */ + fun asReasoningText(): ReasoningText = reasoningText.getOrThrow("reasoningText") + fun _json(): Optional = Optional.ofNullable(_json) fun accept(visitor: Visitor): T = when { outputText != null -> visitor.visitOutputText(outputText) refusal != null -> visitor.visitRefusal(refusal) + reasoningText != null -> visitor.visitReasoningText(reasoningText) else -> visitor.unknown(_json) } @@ -429,6 +452,10 @@ private constructor( override fun visitRefusal(refusal: ResponseOutputRefusal) { refusal.validate() } + + override fun visitReasoningText(reasoningText: ReasoningText) { + reasoningText.validate() + } } ) validated = true @@ -457,6 +484,9 @@ private constructor( override fun visitRefusal(refusal: ResponseOutputRefusal) = refusal.validity() + override fun visitReasoningText(reasoningText: ReasoningText) = + reasoningText.validity() + override fun unknown(json: JsonValue?) = 0 } ) @@ -466,15 +496,19 @@ private constructor( return true } - return other is Part && outputText == other.outputText && refusal == other.refusal + return other is Part && + outputText == other.outputText && + refusal == other.refusal && + reasoningText == other.reasoningText } - override fun hashCode(): Int = Objects.hash(outputText, refusal) + override fun hashCode(): Int = Objects.hash(outputText, refusal, reasoningText) override fun toString(): String = when { outputText != null -> "Part{outputText=$outputText}" refusal != null -> "Part{refusal=$refusal}" + reasoningText != null -> "Part{reasoningText=$reasoningText}" _json != null -> "Part{_unknown=$_json}" else -> throw IllegalStateException("Invalid Part") } @@ -487,6 +521,10 @@ private constructor( /** A refusal from the model. */ @JvmStatic fun ofRefusal(refusal: ResponseOutputRefusal) = Part(refusal = refusal) + + /** Reasoning text from the model. */ + @JvmStatic + fun ofReasoningText(reasoningText: ReasoningText) = Part(reasoningText = reasoningText) } /** An interface that defines how to map each variant of [Part] to a value of type [T]. */ @@ -498,6 +536,9 @@ private constructor( /** A refusal from the model. */ fun visitRefusal(refusal: ResponseOutputRefusal): T + /** Reasoning text from the model. */ + fun visitReasoningText(reasoningText: ReasoningText): T + /** * Maps an unknown variant of [Part] to a value of type [T]. * @@ -529,6 +570,11 @@ private constructor( Part(refusal = it, _json = json) } ?: Part(_json = json) } + "reasoning_text" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Part(reasoningText = it, _json = json) + } ?: Part(_json = json) + } } return Part(_json = json) @@ -545,11 +591,216 @@ private constructor( when { value.outputText != null -> generator.writeObject(value.outputText) value.refusal != null -> generator.writeObject(value.refusal) + value.reasoningText != null -> generator.writeObject(value.reasoningText) value._json != null -> generator.writeObject(value._json) else -> throw IllegalStateException("Invalid Part") } } } + + /** Reasoning text from the model. */ + class ReasoningText + private constructor( + private val text: JsonField, + private val type: JsonValue, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("text") @ExcludeMissing text: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + ) : this(text, type, mutableMapOf()) + + /** + * The reasoning text from the model. + * + * @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 the reasoning text. Always `reasoning_text`. + * + * Expected to always return the following: + * ```java + * JsonValue.from("reasoning_text") + * ``` + * + * 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 [text]. + * + * Unlike [text], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text + + @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 [ReasoningText]. + * + * The following fields are required: + * ```java + * .text() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ReasoningText]. */ + class Builder internal constructor() { + + private var text: JsonField? = null + private var type: JsonValue = JsonValue.from("reasoning_text") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(reasoningText: ReasoningText) = apply { + text = reasoningText.text + type = reasoningText.type + additionalProperties = reasoningText.additionalProperties.toMutableMap() + } + + /** The reasoning text from the model. */ + fun text(text: String) = text(JsonField.of(text)) + + /** + * Sets [Builder.text] to an arbitrary JSON value. + * + * You should usually call [Builder.text] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun text(text: JsonField) = apply { this.text = text } + + /** + * 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("reasoning_text") + * ``` + * + * 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 [ReasoningText]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .text() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ReasoningText = + ReasoningText( + checkRequired("text", text), + type, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ReasoningText = apply { + if (validated) { + return@apply + } + + text() + _type().let { + if (it != JsonValue.from("reasoning_text")) { + 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 = + (if (text.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("reasoning_text")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ReasoningText && + text == other.text && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(text, type, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ReasoningText{text=$text, type=$type, additionalProperties=$additionalProperties}" + } } override fun equals(other: Any?): Boolean { diff --git a/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseReasoningItem.kt b/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseReasoningItem.kt index 5c2d486b7..98ba86cf1 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseReasoningItem.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseReasoningItem.kt @@ -393,6 +393,7 @@ private constructor( (if (encryptedContent.asKnown().isPresent) 1 else 0) + (status.asKnown().getOrNull()?.validity() ?: 0) + /** A summary text from the model. */ class Summary private constructor( private val text: JsonField, @@ -588,6 +589,7 @@ private constructor( "Summary{text=$text, type=$type, additionalProperties=$additionalProperties}" } + /** Reasoning text from the model. */ class Content private constructor( private val text: JsonField, @@ -602,7 +604,7 @@ private constructor( ) : this(text, type, mutableMapOf()) /** - * Reasoning text output from the model. + * The reasoning text from the model. * * @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). @@ -610,7 +612,7 @@ private constructor( fun text(): String = text.getRequired("text") /** - * The type of the object. Always `reasoning_text`. + * The type of the reasoning text. Always `reasoning_text`. * * Expected to always return the following: * ```java @@ -668,7 +670,7 @@ private constructor( additionalProperties = content.additionalProperties.toMutableMap() } - /** Reasoning text output from the model. */ + /** The reasoning text from the model. */ fun text(text: String) = text(JsonField.of(text)) /** diff --git a/openai-java-core/src/test/kotlin/com/openai/core/http/RetryingHttpClientTest.kt b/openai-java-core/src/test/kotlin/com/openai/core/http/RetryingHttpClientTest.kt index a1967582e..bb562e191 100644 --- a/openai-java-core/src/test/kotlin/com/openai/core/http/RetryingHttpClientTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/core/http/RetryingHttpClientTest.kt @@ -6,6 +6,7 @@ import com.github.tomakehurst.wiremock.junit5.WireMockTest import com.github.tomakehurst.wiremock.stubbing.Scenario import com.openai.client.okhttp.OkHttpClient import com.openai.core.RequestOptions +import com.openai.core.Sleeper import com.openai.errors.OpenAIRetryableException import java.io.InputStream import java.time.Duration @@ -294,12 +295,14 @@ internal class RetryingHttpClientTest { .httpClient(failingHttpClient) .maxRetries(2) .sleeper( - object : RetryingHttpClient.Sleeper { + object : Sleeper { override fun sleep(duration: Duration) {} override fun sleepAsync(duration: Duration): CompletableFuture = CompletableFuture.completedFuture(null) + + override fun close() {} } ) .build() @@ -333,12 +336,14 @@ internal class RetryingHttpClientTest { .httpClient(httpClient) // Use a no-op `Sleeper` to make the test fast. .sleeper( - object : RetryingHttpClient.Sleeper { + object : Sleeper { override fun sleep(duration: Duration) {} override fun sleepAsync(duration: Duration): CompletableFuture = CompletableFuture.completedFuture(null) + + override fun close() {} } ) diff --git a/openai-java-core/src/test/kotlin/com/openai/models/conversations/ContainerFileCitationBodyTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/conversations/ContainerFileCitationBodyTest.kt deleted file mode 100644 index 423f51b4e..000000000 --- a/openai-java-core/src/test/kotlin/com/openai/models/conversations/ContainerFileCitationBodyTest.kt +++ /dev/null @@ -1,50 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.openai.models.conversations - -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.openai.core.jsonMapper -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test - -internal class ContainerFileCitationBodyTest { - - @Test - fun create() { - val containerFileCitationBody = - ContainerFileCitationBody.builder() - .containerId("container_id") - .endIndex(0L) - .fileId("file_id") - .filename("filename") - .startIndex(0L) - .build() - - assertThat(containerFileCitationBody.containerId()).isEqualTo("container_id") - assertThat(containerFileCitationBody.endIndex()).isEqualTo(0L) - assertThat(containerFileCitationBody.fileId()).isEqualTo("file_id") - assertThat(containerFileCitationBody.filename()).isEqualTo("filename") - assertThat(containerFileCitationBody.startIndex()).isEqualTo(0L) - } - - @Test - fun roundtrip() { - val jsonMapper = jsonMapper() - val containerFileCitationBody = - ContainerFileCitationBody.builder() - .containerId("container_id") - .endIndex(0L) - .fileId("file_id") - .filename("filename") - .startIndex(0L) - .build() - - val roundtrippedContainerFileCitationBody = - jsonMapper.readValue( - jsonMapper.writeValueAsString(containerFileCitationBody), - jacksonTypeRef(), - ) - - assertThat(roundtrippedContainerFileCitationBody).isEqualTo(containerFileCitationBody) - } -} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/conversations/FileCitationBodyTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/conversations/FileCitationBodyTest.kt deleted file mode 100644 index 62e90779e..000000000 --- a/openai-java-core/src/test/kotlin/com/openai/models/conversations/FileCitationBodyTest.kt +++ /dev/null @@ -1,36 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.openai.models.conversations - -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.openai.core.jsonMapper -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test - -internal class FileCitationBodyTest { - - @Test - fun create() { - val fileCitationBody = - FileCitationBody.builder().fileId("file_id").filename("filename").index(0L).build() - - assertThat(fileCitationBody.fileId()).isEqualTo("file_id") - assertThat(fileCitationBody.filename()).isEqualTo("filename") - assertThat(fileCitationBody.index()).isEqualTo(0L) - } - - @Test - fun roundtrip() { - val jsonMapper = jsonMapper() - val fileCitationBody = - FileCitationBody.builder().fileId("file_id").filename("filename").index(0L).build() - - val roundtrippedFileCitationBody = - jsonMapper.readValue( - jsonMapper.writeValueAsString(fileCitationBody), - jacksonTypeRef(), - ) - - assertThat(roundtrippedFileCitationBody).isEqualTo(fileCitationBody) - } -} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/conversations/InputFileContentTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/conversations/InputFileContentTest.kt deleted file mode 100644 index 67dc90b3f..000000000 --- a/openai-java-core/src/test/kotlin/com/openai/models/conversations/InputFileContentTest.kt +++ /dev/null @@ -1,44 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.openai.models.conversations - -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.openai.core.jsonMapper -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test - -internal class InputFileContentTest { - - @Test - fun create() { - val inputFileContent = - InputFileContent.builder() - .fileId("file_id") - .fileUrl("file_url") - .filename("filename") - .build() - - assertThat(inputFileContent.fileId()).contains("file_id") - assertThat(inputFileContent.fileUrl()).contains("file_url") - assertThat(inputFileContent.filename()).contains("filename") - } - - @Test - fun roundtrip() { - val jsonMapper = jsonMapper() - val inputFileContent = - InputFileContent.builder() - .fileId("file_id") - .fileUrl("file_url") - .filename("filename") - .build() - - val roundtrippedInputFileContent = - jsonMapper.readValue( - jsonMapper.writeValueAsString(inputFileContent), - jacksonTypeRef(), - ) - - assertThat(roundtrippedInputFileContent).isEqualTo(inputFileContent) - } -} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/conversations/InputImageContentTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/conversations/InputImageContentTest.kt deleted file mode 100644 index 6fb785fd0..000000000 --- a/openai-java-core/src/test/kotlin/com/openai/models/conversations/InputImageContentTest.kt +++ /dev/null @@ -1,44 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.openai.models.conversations - -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.openai.core.jsonMapper -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test - -internal class InputImageContentTest { - - @Test - fun create() { - val inputImageContent = - InputImageContent.builder() - .detail(InputImageContent.Detail.LOW) - .fileId("file_id") - .imageUrl("image_url") - .build() - - assertThat(inputImageContent.detail()).isEqualTo(InputImageContent.Detail.LOW) - assertThat(inputImageContent.fileId()).contains("file_id") - assertThat(inputImageContent.imageUrl()).contains("image_url") - } - - @Test - fun roundtrip() { - val jsonMapper = jsonMapper() - val inputImageContent = - InputImageContent.builder() - .detail(InputImageContent.Detail.LOW) - .fileId("file_id") - .imageUrl("image_url") - .build() - - val roundtrippedInputImageContent = - jsonMapper.readValue( - jsonMapper.writeValueAsString(inputImageContent), - jacksonTypeRef(), - ) - - assertThat(roundtrippedInputImageContent).isEqualTo(inputImageContent) - } -} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/conversations/InputTextContentTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/conversations/InputTextContentTest.kt deleted file mode 100644 index 2e1f8a103..000000000 --- a/openai-java-core/src/test/kotlin/com/openai/models/conversations/InputTextContentTest.kt +++ /dev/null @@ -1,32 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.openai.models.conversations - -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.openai.core.jsonMapper -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test - -internal class InputTextContentTest { - - @Test - fun create() { - val inputTextContent = InputTextContent.builder().text("text").build() - - assertThat(inputTextContent.text()).isEqualTo("text") - } - - @Test - fun roundtrip() { - val jsonMapper = jsonMapper() - val inputTextContent = InputTextContent.builder().text("text").build() - - val roundtrippedInputTextContent = - jsonMapper.readValue( - jsonMapper.writeValueAsString(inputTextContent), - jacksonTypeRef(), - ) - - assertThat(roundtrippedInputTextContent).isEqualTo(inputTextContent) - } -} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/conversations/LobProbTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/conversations/LobProbTest.kt deleted file mode 100644 index 190da5f4b..000000000 --- a/openai-java-core/src/test/kotlin/com/openai/models/conversations/LobProbTest.kt +++ /dev/null @@ -1,45 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.openai.models.conversations - -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.openai.core.jsonMapper -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test - -internal class LobProbTest { - - @Test - fun create() { - val lobProb = - LobProb.builder() - .token("token") - .addByte(0L) - .logprob(0.0) - .addTopLogprob(TopLogProb.builder().token("token").addByte(0L).logprob(0.0).build()) - .build() - - assertThat(lobProb.token()).isEqualTo("token") - assertThat(lobProb.bytes()).containsExactly(0L) - assertThat(lobProb.logprob()).isEqualTo(0.0) - assertThat(lobProb.topLogprobs()) - .containsExactly(TopLogProb.builder().token("token").addByte(0L).logprob(0.0).build()) - } - - @Test - fun roundtrip() { - val jsonMapper = jsonMapper() - val lobProb = - LobProb.builder() - .token("token") - .addByte(0L) - .logprob(0.0) - .addTopLogprob(TopLogProb.builder().token("token").addByte(0L).logprob(0.0).build()) - .build() - - val roundtrippedLobProb = - jsonMapper.readValue(jsonMapper.writeValueAsString(lobProb), jacksonTypeRef()) - - assertThat(roundtrippedLobProb).isEqualTo(lobProb) - } -} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/conversations/MessageTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/conversations/MessageTest.kt index bfeca181f..8de929c5b 100644 --- a/openai-java-core/src/test/kotlin/com/openai/models/conversations/MessageTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/models/conversations/MessageTest.kt @@ -4,6 +4,7 @@ package com.openai.models.conversations import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import com.openai.core.jsonMapper +import com.openai.models.responses.ResponseInputText import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -22,7 +23,7 @@ internal class MessageTest { assertThat(message.id()).isEqualTo("id") assertThat(message.content()) .containsExactly( - Message.Content.ofInputText(InputTextContent.builder().text("text").build()) + Message.Content.ofInputText(ResponseInputText.builder().text("text").build()) ) assertThat(message.role()).isEqualTo(Message.Role.UNKNOWN) assertThat(message.status()).isEqualTo(Message.Status.IN_PROGRESS) diff --git a/openai-java-core/src/test/kotlin/com/openai/models/conversations/OutputTextContentTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/conversations/OutputTextContentTest.kt deleted file mode 100644 index 69c094d35..000000000 --- a/openai-java-core/src/test/kotlin/com/openai/models/conversations/OutputTextContentTest.kt +++ /dev/null @@ -1,94 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.openai.models.conversations - -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.openai.core.jsonMapper -import kotlin.jvm.optionals.getOrNull -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test - -internal class OutputTextContentTest { - - @Test - fun create() { - val outputTextContent = - OutputTextContent.builder() - .addAnnotation( - FileCitationBody.builder() - .fileId("file_id") - .filename("filename") - .index(0L) - .build() - ) - .text("text") - .addLogprob( - LobProb.builder() - .token("token") - .addByte(0L) - .logprob(0.0) - .addTopLogprob( - TopLogProb.builder().token("token").addByte(0L).logprob(0.0).build() - ) - .build() - ) - .build() - - assertThat(outputTextContent.annotations()) - .containsExactly( - OutputTextContent.Annotation.ofFileCitation( - FileCitationBody.builder() - .fileId("file_id") - .filename("filename") - .index(0L) - .build() - ) - ) - assertThat(outputTextContent.text()).isEqualTo("text") - assertThat(outputTextContent.logprobs().getOrNull()) - .containsExactly( - LobProb.builder() - .token("token") - .addByte(0L) - .logprob(0.0) - .addTopLogprob( - TopLogProb.builder().token("token").addByte(0L).logprob(0.0).build() - ) - .build() - ) - } - - @Test - fun roundtrip() { - val jsonMapper = jsonMapper() - val outputTextContent = - OutputTextContent.builder() - .addAnnotation( - FileCitationBody.builder() - .fileId("file_id") - .filename("filename") - .index(0L) - .build() - ) - .text("text") - .addLogprob( - LobProb.builder() - .token("token") - .addByte(0L) - .logprob(0.0) - .addTopLogprob( - TopLogProb.builder().token("token").addByte(0L).logprob(0.0).build() - ) - .build() - ) - .build() - - val roundtrippedOutputTextContent = - jsonMapper.readValue( - jsonMapper.writeValueAsString(outputTextContent), - jacksonTypeRef(), - ) - - assertThat(roundtrippedOutputTextContent).isEqualTo(outputTextContent) - } -} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/conversations/RefusalContentTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/conversations/RefusalContentTest.kt deleted file mode 100644 index b5407f4a1..000000000 --- a/openai-java-core/src/test/kotlin/com/openai/models/conversations/RefusalContentTest.kt +++ /dev/null @@ -1,32 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.openai.models.conversations - -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.openai.core.jsonMapper -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test - -internal class RefusalContentTest { - - @Test - fun create() { - val refusalContent = RefusalContent.builder().refusal("refusal").build() - - assertThat(refusalContent.refusal()).isEqualTo("refusal") - } - - @Test - fun roundtrip() { - val jsonMapper = jsonMapper() - val refusalContent = RefusalContent.builder().refusal("refusal").build() - - val roundtrippedRefusalContent = - jsonMapper.readValue( - jsonMapper.writeValueAsString(refusalContent), - jacksonTypeRef(), - ) - - assertThat(roundtrippedRefusalContent).isEqualTo(refusalContent) - } -} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/conversations/TopLogProbTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/conversations/TopLogProbTest.kt deleted file mode 100644 index 01fb32b4d..000000000 --- a/openai-java-core/src/test/kotlin/com/openai/models/conversations/TopLogProbTest.kt +++ /dev/null @@ -1,34 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.openai.models.conversations - -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.openai.core.jsonMapper -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test - -internal class TopLogProbTest { - - @Test - fun create() { - val topLogProb = TopLogProb.builder().token("token").addByte(0L).logprob(0.0).build() - - assertThat(topLogProb.token()).isEqualTo("token") - assertThat(topLogProb.bytes()).containsExactly(0L) - assertThat(topLogProb.logprob()).isEqualTo(0.0) - } - - @Test - fun roundtrip() { - val jsonMapper = jsonMapper() - val topLogProb = TopLogProb.builder().token("token").addByte(0L).logprob(0.0).build() - - val roundtrippedTopLogProb = - jsonMapper.readValue( - jsonMapper.writeValueAsString(topLogProb), - jacksonTypeRef(), - ) - - assertThat(roundtrippedTopLogProb).isEqualTo(topLogProb) - } -} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/conversations/UrlCitationBodyTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/conversations/UrlCitationBodyTest.kt deleted file mode 100644 index 6d7a1a26e..000000000 --- a/openai-java-core/src/test/kotlin/com/openai/models/conversations/UrlCitationBodyTest.kt +++ /dev/null @@ -1,37 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.openai.models.conversations - -import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.openai.core.jsonMapper -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test - -internal class UrlCitationBodyTest { - - @Test - fun create() { - val urlCitationBody = - UrlCitationBody.builder().endIndex(0L).startIndex(0L).title("title").url("url").build() - - assertThat(urlCitationBody.endIndex()).isEqualTo(0L) - assertThat(urlCitationBody.startIndex()).isEqualTo(0L) - assertThat(urlCitationBody.title()).isEqualTo("title") - assertThat(urlCitationBody.url()).isEqualTo("url") - } - - @Test - fun roundtrip() { - val jsonMapper = jsonMapper() - val urlCitationBody = - UrlCitationBody.builder().endIndex(0L).startIndex(0L).title("title").url("url").build() - - val roundtrippedUrlCitationBody = - jsonMapper.readValue( - jsonMapper.writeValueAsString(urlCitationBody), - jacksonTypeRef(), - ) - - assertThat(roundtrippedUrlCitationBody).isEqualTo(urlCitationBody) - } -} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/evals/runs/CreateEvalCompletionsRunDataSourceTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/evals/runs/CreateEvalCompletionsRunDataSourceTest.kt index 4dd9a84de..387c44357 100644 --- a/openai-java-core/src/test/kotlin/com/openai/models/evals/runs/CreateEvalCompletionsRunDataSourceTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/models/evals/runs/CreateEvalCompletionsRunDataSourceTest.kt @@ -7,6 +7,7 @@ import com.openai.core.JsonValue import com.openai.core.jsonMapper import com.openai.models.FunctionDefinition import com.openai.models.FunctionParameters +import com.openai.models.ReasoningEffort import com.openai.models.ResponseFormatText import com.openai.models.chat.completions.ChatCompletionFunctionTool import com.openai.models.responses.EasyInputMessage @@ -54,6 +55,7 @@ internal class CreateEvalCompletionsRunDataSourceTest { .samplingParams( CreateEvalCompletionsRunDataSource.SamplingParams.builder() .maxCompletionTokens(0L) + .reasoningEffort(ReasoningEffort.MINIMAL) .responseFormat(ResponseFormatText.builder().build()) .seed(0L) .temperature(0.0) @@ -124,6 +126,7 @@ internal class CreateEvalCompletionsRunDataSourceTest { .contains( CreateEvalCompletionsRunDataSource.SamplingParams.builder() .maxCompletionTokens(0L) + .reasoningEffort(ReasoningEffort.MINIMAL) .responseFormat(ResponseFormatText.builder().build()) .seed(0L) .temperature(0.0) @@ -188,6 +191,7 @@ internal class CreateEvalCompletionsRunDataSourceTest { .samplingParams( CreateEvalCompletionsRunDataSource.SamplingParams.builder() .maxCompletionTokens(0L) + .reasoningEffort(ReasoningEffort.MINIMAL) .responseFormat(ResponseFormatText.builder().build()) .seed(0L) .temperature(0.0) diff --git a/openai-java-core/src/test/kotlin/com/openai/models/evals/runs/outputitems/OutputItemListPageResponseTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/evals/runs/outputitems/OutputItemListPageResponseTest.kt index 291a90540..14b6d74f7 100644 --- a/openai-java-core/src/test/kotlin/com/openai/models/evals/runs/outputitems/OutputItemListPageResponseTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/models/evals/runs/outputitems/OutputItemListPageResponseTest.kt @@ -28,7 +28,15 @@ internal class OutputItemListPageResponseTest { .evalId("eval_id") .addResult( OutputItemListResponse.Result.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .name("name") + .passed(true) + .score(0.0) + .sample( + OutputItemListResponse.Result.Sample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .type("type") .build() ) .runId("run_id") @@ -87,7 +95,15 @@ internal class OutputItemListPageResponseTest { .evalId("eval_id") .addResult( OutputItemListResponse.Result.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .name("name") + .passed(true) + .score(0.0) + .sample( + OutputItemListResponse.Result.Sample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .type("type") .build() ) .runId("run_id") @@ -148,7 +164,15 @@ internal class OutputItemListPageResponseTest { .evalId("eval_id") .addResult( OutputItemListResponse.Result.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .name("name") + .passed(true) + .score(0.0) + .sample( + OutputItemListResponse.Result.Sample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .type("type") .build() ) .runId("run_id") diff --git a/openai-java-core/src/test/kotlin/com/openai/models/evals/runs/outputitems/OutputItemListResponseTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/evals/runs/outputitems/OutputItemListResponseTest.kt index 8092f0820..61429b20b 100644 --- a/openai-java-core/src/test/kotlin/com/openai/models/evals/runs/outputitems/OutputItemListResponseTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/models/evals/runs/outputitems/OutputItemListResponseTest.kt @@ -26,7 +26,15 @@ internal class OutputItemListResponseTest { .evalId("eval_id") .addResult( OutputItemListResponse.Result.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .name("name") + .passed(true) + .score(0.0) + .sample( + OutputItemListResponse.Result.Sample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .type("type") .build() ) .runId("run_id") @@ -77,7 +85,15 @@ internal class OutputItemListResponseTest { assertThat(outputItemListResponse.results()) .containsExactly( OutputItemListResponse.Result.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .name("name") + .passed(true) + .score(0.0) + .sample( + OutputItemListResponse.Result.Sample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .type("type") .build() ) assertThat(outputItemListResponse.runId()).isEqualTo("run_id") @@ -132,7 +148,15 @@ internal class OutputItemListResponseTest { .evalId("eval_id") .addResult( OutputItemListResponse.Result.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .name("name") + .passed(true) + .score(0.0) + .sample( + OutputItemListResponse.Result.Sample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .type("type") .build() ) .runId("run_id") diff --git a/openai-java-core/src/test/kotlin/com/openai/models/evals/runs/outputitems/OutputItemRetrieveResponseTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/evals/runs/outputitems/OutputItemRetrieveResponseTest.kt index 430c72429..9b94e6dd7 100644 --- a/openai-java-core/src/test/kotlin/com/openai/models/evals/runs/outputitems/OutputItemRetrieveResponseTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/models/evals/runs/outputitems/OutputItemRetrieveResponseTest.kt @@ -26,7 +26,15 @@ internal class OutputItemRetrieveResponseTest { .evalId("eval_id") .addResult( OutputItemRetrieveResponse.Result.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .name("name") + .passed(true) + .score(0.0) + .sample( + OutputItemRetrieveResponse.Result.Sample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .type("type") .build() ) .runId("run_id") @@ -77,7 +85,15 @@ internal class OutputItemRetrieveResponseTest { assertThat(outputItemRetrieveResponse.results()) .containsExactly( OutputItemRetrieveResponse.Result.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .name("name") + .passed(true) + .score(0.0) + .sample( + OutputItemRetrieveResponse.Result.Sample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .type("type") .build() ) assertThat(outputItemRetrieveResponse.runId()).isEqualTo("run_id") @@ -132,7 +148,15 @@ internal class OutputItemRetrieveResponseTest { .evalId("eval_id") .addResult( OutputItemRetrieveResponse.Result.builder() - .putAdditionalProperty("foo", JsonValue.from("bar")) + .name("name") + .passed(true) + .score(0.0) + .sample( + OutputItemRetrieveResponse.Result.Sample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .type("type") .build() ) .runId("run_id") diff --git a/openai-java-core/src/test/kotlin/com/openai/models/graders/gradermodels/ScoreModelGraderTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/graders/gradermodels/ScoreModelGraderTest.kt index ff2134b6f..3abc21861 100644 --- a/openai-java-core/src/test/kotlin/com/openai/models/graders/gradermodels/ScoreModelGraderTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/models/graders/gradermodels/ScoreModelGraderTest.kt @@ -3,8 +3,8 @@ package com.openai.models.graders.gradermodels import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import com.openai.core.JsonValue import com.openai.core.jsonMapper +import com.openai.models.ReasoningEffort import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -25,7 +25,15 @@ internal class ScoreModelGraderTest { .model("model") .name("name") .addRange(0.0) - .samplingParams(JsonValue.from(mapOf())) + .samplingParams( + ScoreModelGrader.SamplingParams.builder() + .maxCompletionsTokens(1L) + .reasoningEffort(ReasoningEffort.MINIMAL) + .seed(0L) + .temperature(0.0) + .topP(1.0) + .build() + ) .build() assertThat(scoreModelGrader.input()) @@ -39,8 +47,16 @@ internal class ScoreModelGraderTest { assertThat(scoreModelGrader.model()).isEqualTo("model") assertThat(scoreModelGrader.name()).isEqualTo("name") assertThat(scoreModelGrader.range().getOrNull()).containsExactly(0.0) - assertThat(scoreModelGrader._samplingParams()) - .isEqualTo(JsonValue.from(mapOf())) + assertThat(scoreModelGrader.samplingParams()) + .contains( + ScoreModelGrader.SamplingParams.builder() + .maxCompletionsTokens(1L) + .reasoningEffort(ReasoningEffort.MINIMAL) + .seed(0L) + .temperature(0.0) + .topP(1.0) + .build() + ) } @Test @@ -58,7 +74,15 @@ internal class ScoreModelGraderTest { .model("model") .name("name") .addRange(0.0) - .samplingParams(JsonValue.from(mapOf())) + .samplingParams( + ScoreModelGrader.SamplingParams.builder() + .maxCompletionsTokens(1L) + .reasoningEffort(ReasoningEffort.MINIMAL) + .seed(0L) + .temperature(0.0) + .topP(1.0) + .build() + ) .build() val roundtrippedScoreModelGrader = diff --git a/openai-java-core/src/test/kotlin/com/openai/models/responses/ResponseContentTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/responses/ResponseContentTest.kt index a7e30e22c..ef265ed9d 100644 --- a/openai-java-core/src/test/kotlin/com/openai/models/responses/ResponseContentTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/models/responses/ResponseContentTest.kt @@ -26,6 +26,7 @@ internal class ResponseContentTest { assertThat(responseContent.inputAudio()).isEmpty assertThat(responseContent.outputText()).isEmpty assertThat(responseContent.outputRefusal()).isEmpty + assertThat(responseContent.reasoningText()).isEmpty } @Test @@ -60,6 +61,7 @@ internal class ResponseContentTest { assertThat(responseContent.inputAudio()).isEmpty assertThat(responseContent.outputText()).isEmpty assertThat(responseContent.outputRefusal()).isEmpty + assertThat(responseContent.reasoningText()).isEmpty } @Test @@ -101,6 +103,7 @@ internal class ResponseContentTest { assertThat(responseContent.inputAudio()).isEmpty assertThat(responseContent.outputText()).isEmpty assertThat(responseContent.outputRefusal()).isEmpty + assertThat(responseContent.reasoningText()).isEmpty } @Test @@ -145,6 +148,7 @@ internal class ResponseContentTest { assertThat(responseContent.inputAudio()).contains(inputAudio) assertThat(responseContent.outputText()).isEmpty assertThat(responseContent.outputRefusal()).isEmpty + assertThat(responseContent.reasoningText()).isEmpty } @Test @@ -207,6 +211,7 @@ internal class ResponseContentTest { assertThat(responseContent.inputAudio()).isEmpty assertThat(responseContent.outputText()).contains(outputText) assertThat(responseContent.outputRefusal()).isEmpty + assertThat(responseContent.reasoningText()).isEmpty } @Test @@ -261,6 +266,7 @@ internal class ResponseContentTest { assertThat(responseContent.inputAudio()).isEmpty assertThat(responseContent.outputText()).isEmpty assertThat(responseContent.outputRefusal()).contains(outputRefusal) + assertThat(responseContent.reasoningText()).isEmpty } @Test @@ -280,6 +286,38 @@ internal class ResponseContentTest { assertThat(roundtrippedResponseContent).isEqualTo(responseContent) } + @Test + fun ofReasoningText() { + val reasoningText = ResponseContent.ReasoningTextContent.builder().text("text").build() + + val responseContent = ResponseContent.ofReasoningText(reasoningText) + + assertThat(responseContent.inputText()).isEmpty + assertThat(responseContent.inputImage()).isEmpty + assertThat(responseContent.inputFile()).isEmpty + assertThat(responseContent.inputAudio()).isEmpty + assertThat(responseContent.outputText()).isEmpty + assertThat(responseContent.outputRefusal()).isEmpty + assertThat(responseContent.reasoningText()).contains(reasoningText) + } + + @Test + fun ofReasoningTextRoundtrip() { + val jsonMapper = jsonMapper() + val responseContent = + ResponseContent.ofReasoningText( + ResponseContent.ReasoningTextContent.builder().text("text").build() + ) + + val roundtrippedResponseContent = + jsonMapper.readValue( + jsonMapper.writeValueAsString(responseContent), + jacksonTypeRef(), + ) + + assertThat(roundtrippedResponseContent).isEqualTo(responseContent) + } + enum class IncompatibleJsonShapeTestCase(val value: JsonValue) { BOOLEAN(JsonValue.from(false)), STRING(JsonValue.from("invalid")), diff --git a/openai-java-core/src/test/kotlin/com/openai/models/responses/ResponseConversationParamTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/responses/ResponseConversationParamTest.kt index 7d5f69c65..e27ded8b7 100644 --- a/openai-java-core/src/test/kotlin/com/openai/models/responses/ResponseConversationParamTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/models/responses/ResponseConversationParamTest.kt @@ -11,15 +11,15 @@ internal class ResponseConversationParamTest { @Test fun create() { - val responseConversationParam = ResponseConversationParam.builder().id("id").build() + val responseConversationParam = ResponseConversationParam.builder().id("conv_123").build() - assertThat(responseConversationParam.id()).isEqualTo("id") + assertThat(responseConversationParam.id()).isEqualTo("conv_123") } @Test fun roundtrip() { val jsonMapper = jsonMapper() - val responseConversationParam = ResponseConversationParam.builder().id("id").build() + val responseConversationParam = ResponseConversationParam.builder().id("conv_123").build() val roundtrippedResponseConversationParam = jsonMapper.readValue( diff --git a/openai-java-core/src/test/kotlin/com/openai/models/responses/ResponseInputItemTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/responses/ResponseInputItemTest.kt index e50297ce4..ffd484e44 100644 --- a/openai-java-core/src/test/kotlin/com/openai/models/responses/ResponseInputItemTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/models/responses/ResponseInputItemTest.kt @@ -408,7 +408,7 @@ internal class ResponseInputItemTest { .imageUrl("image_url") .build() ) - .id("id") + .id("cuo_123") .addAcknowledgedSafetyCheck( ResponseInputItem.ComputerCallOutput.AcknowledgedSafetyCheck.builder() .id("id") @@ -457,7 +457,7 @@ internal class ResponseInputItemTest { .imageUrl("image_url") .build() ) - .id("id") + .id("cuo_123") .addAcknowledgedSafetyCheck( ResponseInputItem.ComputerCallOutput.AcknowledgedSafetyCheck.builder() .id("id") @@ -616,7 +616,7 @@ internal class ResponseInputItemTest { ResponseInputItem.FunctionCallOutput.builder() .callId("x") .output("output") - .id("id") + .id("fc_123") .status(ResponseInputItem.FunctionCallOutput.Status.IN_PROGRESS) .build() @@ -653,7 +653,7 @@ internal class ResponseInputItemTest { ResponseInputItem.FunctionCallOutput.builder() .callId("x") .output("output") - .id("id") + .id("fc_123") .status(ResponseInputItem.FunctionCallOutput.Status.IN_PROGRESS) .build() )