diff --git a/.release-please-manifest.json b/.release-please-manifest.json index b55c11f0..d0ab6645 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "1.1.1" + ".": "1.2.0" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 57f64447..0422f85e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,24 @@ # Changelog +## 1.2.0 (2025-04-09) + +Full Changelog: [v1.1.1...v1.2.0](https://github.com/openai/openai-java/compare/v1.1.1...v1.2.0) + +### Features + +* **client:** make pagination robust to missing data ([cbccde5](https://github.com/openai/openai-java/commit/cbccde5bbbea40289a7143d40ce5e8c7ac7643ff)) + + +### Documentation + +* add comments for page methods ([cbccde5](https://github.com/openai/openai-java/commit/cbccde5bbbea40289a7143d40ce5e8c7ac7643ff)) + + +### Refactors + +* **client:** deduplicate page response classes ([#433](https://github.com/openai/openai-java/issues/433)) ([cbccde5](https://github.com/openai/openai-java/commit/cbccde5bbbea40289a7143d40ce5e8c7ac7643ff)) +* **client:** migrate pages to builder pattern ([#435](https://github.com/openai/openai-java/issues/435)) ([8cb8878](https://github.com/openai/openai-java/commit/8cb8878becd07e31844f981bafd147c630606c07)) + ## 1.1.1 (2025-04-09) Full Changelog: [v1.1.0...v1.1.1](https://github.com/openai/openai-java/compare/v1.1.0...v1.1.1) diff --git a/README.md b/README.md index 1d10af60..ba9f5121 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/1.1.1) -[![javadoc](https://javadoc.io/badge2/com.openai/openai-java/1.1.1/javadoc.svg)](https://javadoc.io/doc/com.openai/openai-java/1.1.1) +[![Maven Central](https://img.shields.io/maven-central/v/com.openai/openai-java)](https://central.sonatype.com/artifact/com.openai/openai-java/1.2.0) +[![javadoc](https://javadoc.io/badge2/com.openai/openai-java/1.2.0/javadoc.svg)](https://javadoc.io/doc/com.openai/openai-java/1.2.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 also available on [javadoc.io](https://javadoc.io/doc/com.openai/openai-java/1.1.1). +The REST API documentation can be found on [platform.openai.com](https://platform.openai.com/docs). Javadocs are also available on [javadoc.io](https://javadoc.io/doc/com.openai/openai-java/1.2.0). @@ -22,7 +22,7 @@ The REST API documentation can be found on [platform.openai.com](https://platfor ### Gradle ```kotlin -implementation("com.openai:openai-java:1.1.1") +implementation("com.openai:openai-java:1.2.0") ``` ### Maven @@ -31,7 +31,7 @@ implementation("com.openai:openai-java:1.1.1") com.openai openai-java - 1.1.1 + 1.2.0 ``` diff --git a/build.gradle.kts b/build.gradle.kts index 43b1ef16..25e44d39 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ repositories { allprojects { group = "com.openai" - version = "1.1.1" // x-release-please-version + version = "1.2.0" // x-release-please-version } subprojects { diff --git a/openai-java-core/src/main/kotlin/com/openai/models/batches/BatchListPage.kt b/openai-java-core/src/main/kotlin/com/openai/models/batches/BatchListPage.kt index ef32a9c9..35c7aa3f 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/batches/BatchListPage.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/batches/BatchListPage.kt @@ -2,180 +2,115 @@ package com.openai.models.batches -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.errors.OpenAIInvalidDataException +import com.openai.core.checkRequired import com.openai.services.blocking.BatchService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** List your organization's batches. */ +/** @see [BatchService.list] */ class BatchListPage private constructor( - private val batchesService: BatchService, + private val service: BatchService, private val params: BatchListParams, - private val response: Response, + private val response: BatchListPageResponse, ) { - fun response(): Response = response + /** + * Delegates to [BatchListPageResponse], but gracefully handles missing data. + * + * @see [BatchListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() - fun data(): List = response().data() + /** + * Delegates to [BatchListPageResponse], but gracefully handles missing data. + * + * @see [BatchListPageResponse.hasMore] + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") - fun hasMore(): Optional = response().hasMore() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is BatchListPage && batchesService == other.batchesService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(batchesService, params, response) /* spotless:on */ - - override fun toString() = - "BatchListPage{batchesService=$batchesService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - return !data().isEmpty() - } + fun hasNextPage(): Boolean = data().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return Optional.of(params.toBuilder().after(data().last().id()).build()) + return Optional.of(params.toBuilder().after(data().last()._id().getOptional("id")).build()) } - fun getNextPage(): Optional { - return getNextPageParams().map { batchesService.list(it) } - } + fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of(batchesService: BatchService, params: BatchListParams, response: Response) = - BatchListPage(batchesService, params, response) - } - - class Response( - private val data: JsonField>, - private val hasMore: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("has_more") hasMore: JsonField = JsonMissing.of(), - ) : this(data, hasMore, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun hasMore(): Optional = hasMore.getOptional("has_more") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("has_more") - fun _hasMore(): Optional> = Optional.ofNullable(hasMore) + /** The parameters that were used to request this page. */ + fun params(): BatchListParams = params - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + /** The response that this page was parsed from. */ + fun response(): BatchListPageResponse = response - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } + fun toBuilder() = Builder().from(this) - data().map { it.validate() } - hasMore() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && hasMore == other.hasMore && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, hasMore, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [BatchListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, hasMore=$hasMore, additionalProperties=$additionalProperties}" + /** A builder for [BatchListPage]. */ + class Builder internal constructor() { - companion object { + private var service: BatchService? = null + private var params: BatchListParams? = null + private var response: BatchListPageResponse? = null - /** Returns a mutable builder for constructing an instance of [BatchListPage]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(batchListPage: BatchListPage) = apply { + service = batchListPage.service + params = batchListPage.params + response = batchListPage.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var hasMore: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.hasMore = page.hasMore - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) - - fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(data, hasMore, additionalProperties.toMutableMap()) - } + fun service(service: BatchService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: BatchListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: BatchListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [BatchListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BatchListPage = + BatchListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: BatchListPage) : Iterable { @@ -196,4 +131,16 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BatchListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = "BatchListPage{service=$service, params=$params, response=$response}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/batches/BatchListPageAsync.kt b/openai-java-core/src/main/kotlin/com/openai/models/batches/BatchListPageAsync.kt index 239d6082..61612712 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/batches/BatchListPageAsync.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/batches/BatchListPageAsync.kt @@ -2,17 +2,8 @@ package com.openai.models.batches -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.errors.OpenAIInvalidDataException +import com.openai.core.checkRequired import com.openai.services.async.BatchServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -20,165 +11,110 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** List your organization's batches. */ +/** @see [BatchServiceAsync.list] */ class BatchListPageAsync private constructor( - private val batchesService: BatchServiceAsync, + private val service: BatchServiceAsync, private val params: BatchListParams, - private val response: Response, + private val response: BatchListPageResponse, ) { - fun response(): Response = response + /** + * Delegates to [BatchListPageResponse], but gracefully handles missing data. + * + * @see [BatchListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() - fun data(): List = response().data() + /** + * Delegates to [BatchListPageResponse], but gracefully handles missing data. + * + * @see [BatchListPageResponse.hasMore] + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") - fun hasMore(): Optional = response().hasMore() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is BatchListPageAsync && batchesService == other.batchesService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(batchesService, params, response) /* spotless:on */ - - override fun toString() = - "BatchListPageAsync{batchesService=$batchesService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - return !data().isEmpty() - } + fun hasNextPage(): Boolean = data().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return Optional.of(params.toBuilder().after(data().last().id()).build()) + return Optional.of(params.toBuilder().after(data().last()._id().getOptional("id")).build()) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { batchesService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of(batchesService: BatchServiceAsync, params: BatchListParams, response: Response) = - BatchListPageAsync(batchesService, params, response) - } - - class Response( - private val data: JsonField>, - private val hasMore: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("has_more") hasMore: JsonField = JsonMissing.of(), - ) : this(data, hasMore, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun hasMore(): Optional = hasMore.getOptional("has_more") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("has_more") - fun _hasMore(): Optional> = Optional.ofNullable(hasMore) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false + /** The parameters that were used to request this page. */ + fun params(): BatchListParams = params - fun validate(): Response = apply { - if (validated) { - return@apply - } + /** The response that this page was parsed from. */ + fun response(): BatchListPageResponse = response - data().map { it.validate() } - hasMore() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + fun toBuilder() = Builder().from(this) - return /* spotless:off */ other is Response && data == other.data && hasMore == other.hasMore && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, hasMore, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [BatchListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, hasMore=$hasMore, additionalProperties=$additionalProperties}" + /** A builder for [BatchListPageAsync]. */ + class Builder internal constructor() { - companion object { + private var service: BatchServiceAsync? = null + private var params: BatchListParams? = null + private var response: BatchListPageResponse? = null - /** Returns a mutable builder for constructing an instance of [BatchListPageAsync]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(batchListPageAsync: BatchListPageAsync) = apply { + service = batchListPageAsync.service + params = batchListPageAsync.params + response = batchListPageAsync.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var hasMore: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.hasMore = page.hasMore - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) - - fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(data, hasMore, additionalProperties.toMutableMap()) - } + fun service(service: BatchServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: BatchListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: BatchListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [BatchListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BatchListPageAsync = + BatchListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: BatchListPageAsync) { @@ -206,4 +142,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BatchListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "BatchListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/batches/BatchListPageResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/batches/BatchListPageResponse.kt new file mode 100644 index 00000000..47478621 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/batches/BatchListPageResponse.kt @@ -0,0 +1,318 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.batches + +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 java.util.Optional +import kotlin.jvm.optionals.getOrNull + +class BatchListPageResponse +private constructor( + private val data: JsonField>, + private val hasMore: JsonField, + private val object_: JsonValue, + private val firstId: JsonField, + private val lastId: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") @ExcludeMissing data: JsonField> = JsonMissing.of(), + @JsonProperty("has_more") @ExcludeMissing hasMore: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("first_id") @ExcludeMissing firstId: JsonField = JsonMissing.of(), + @JsonProperty("last_id") @ExcludeMissing lastId: JsonField = JsonMissing.of(), + ) : this(data, hasMore, object_, firstId, lastId, 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 data(): List = data.getRequired("data") + + /** + * @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 hasMore(): Boolean = hasMore.getRequired("has_more") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("list") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun firstId(): Optional = firstId.getOptional("first_id") + + /** + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun lastId(): Optional = lastId.getOptional("last_id") + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField> = data + + /** + * Returns the raw JSON value of [hasMore]. + * + * Unlike [hasMore], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("has_more") @ExcludeMissing fun _hasMore(): JsonField = hasMore + + /** + * Returns the raw JSON value of [firstId]. + * + * Unlike [firstId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("first_id") @ExcludeMissing fun _firstId(): JsonField = firstId + + /** + * Returns the raw JSON value of [lastId]. + * + * Unlike [lastId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("last_id") @ExcludeMissing fun _lastId(): JsonField = lastId + + @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 [BatchListPageResponse]. + * + * The following fields are required: + * ```java + * .data() + * .hasMore() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BatchListPageResponse]. */ + class Builder internal constructor() { + + private var data: JsonField>? = null + private var hasMore: JsonField? = null + private var object_: JsonValue = JsonValue.from("list") + private var firstId: JsonField = JsonMissing.of() + private var lastId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(batchListPageResponse: BatchListPageResponse) = apply { + data = batchListPageResponse.data.map { it.toMutableList() } + hasMore = batchListPageResponse.hasMore + object_ = batchListPageResponse.object_ + firstId = batchListPageResponse.firstId + lastId = batchListPageResponse.lastId + additionalProperties = batchListPageResponse.additionalProperties.toMutableMap() + } + + fun data(data: List) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun data(data: JsonField>) = apply { + this.data = data.map { it.toMutableList() } + } + + /** + * Adds a single [Batch] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: Batch) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) + + /** + * Sets [Builder.hasMore] to an arbitrary JSON value. + * + * You should usually call [Builder.hasMore] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } + + /** + * 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("list") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + fun firstId(firstId: String) = firstId(JsonField.of(firstId)) + + /** + * Sets [Builder.firstId] to an arbitrary JSON value. + * + * You should usually call [Builder.firstId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun firstId(firstId: JsonField) = apply { this.firstId = firstId } + + fun lastId(lastId: String) = lastId(JsonField.of(lastId)) + + /** + * Sets [Builder.lastId] to an arbitrary JSON value. + * + * You should usually call [Builder.lastId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun lastId(lastId: JsonField) = apply { this.lastId = lastId } + + 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 [BatchListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .hasMore() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BatchListPageResponse = + BatchListPageResponse( + checkRequired("data", data).map { it.toImmutable() }, + checkRequired("hasMore", hasMore), + object_, + firstId, + lastId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): BatchListPageResponse = apply { + if (validated) { + return@apply + } + + data().forEach { it.validate() } + hasMore() + _object_().let { + if (it != JsonValue.from("list")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + firstId() + lastId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (hasMore.asKnown().isPresent) 1 else 0) + + object_.let { if (it == JsonValue.from("list")) 1 else 0 } + + (if (firstId.asKnown().isPresent) 1 else 0) + + (if (lastId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BatchListPageResponse && data == other.data && hasMore == other.hasMore && object_ == other.object_ && firstId == other.firstId && lastId == other.lastId && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(data, hasMore, object_, firstId, lastId, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BatchListPageResponse{data=$data, hasMore=$hasMore, object_=$object_, firstId=$firstId, lastId=$lastId, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantListPage.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantListPage.kt index 3a3c8446..c852b6fe 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantListPage.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantListPage.kt @@ -2,183 +2,115 @@ package com.openai.models.beta.assistants -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.errors.OpenAIInvalidDataException +import com.openai.core.checkRequired import com.openai.services.blocking.beta.AssistantService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** Returns a list of assistants. */ +/** @see [AssistantService.list] */ class AssistantListPage private constructor( - private val assistantsService: AssistantService, + private val service: AssistantService, private val params: AssistantListParams, - private val response: Response, + private val response: AssistantListPageResponse, ) { - fun response(): Response = response + /** + * Delegates to [AssistantListPageResponse], but gracefully handles missing data. + * + * @see [AssistantListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() - fun data(): List = response().data() + /** + * Delegates to [AssistantListPageResponse], but gracefully handles missing data. + * + * @see [AssistantListPageResponse.hasMore] + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") - fun hasMore(): Optional = response().hasMore() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is AssistantListPage && assistantsService == other.assistantsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(assistantsService, params, response) /* spotless:on */ - - override fun toString() = - "AssistantListPage{assistantsService=$assistantsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - return !data().isEmpty() - } + fun hasNextPage(): Boolean = data().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return Optional.of(params.toBuilder().after(data().last().id()).build()) + return Optional.of(params.toBuilder().after(data().last()._id().getOptional("id")).build()) } - fun getNextPage(): Optional { - return getNextPageParams().map { assistantsService.list(it) } - } + fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) - companion object { + /** The parameters that were used to request this page. */ + fun params(): AssistantListParams = params - @JvmStatic - fun of( - assistantsService: AssistantService, - params: AssistantListParams, - response: Response, - ) = AssistantListPage(assistantsService, params, response) - } + /** The response that this page was parsed from. */ + fun response(): AssistantListPageResponse = response - class Response( - private val data: JsonField>, - private val hasMore: JsonField, - private val additionalProperties: MutableMap, - ) { + fun toBuilder() = Builder().from(this) - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("has_more") hasMore: JsonField = JsonMissing.of(), - ) : this(data, hasMore, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun hasMore(): Optional = hasMore.getOptional("has_more") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("has_more") - fun _hasMore(): Optional> = Optional.ofNullable(hasMore) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - data().map { it.validate() } - hasMore() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && hasMore == other.hasMore && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, hasMore, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [AssistantListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, hasMore=$hasMore, additionalProperties=$additionalProperties}" + /** A builder for [AssistantListPage]. */ + class Builder internal constructor() { - companion object { + private var service: AssistantService? = null + private var params: AssistantListParams? = null + private var response: AssistantListPageResponse? = null - /** Returns a mutable builder for constructing an instance of [AssistantListPage]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(assistantListPage: AssistantListPage) = apply { + service = assistantListPage.service + params = assistantListPage.params + response = assistantListPage.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var hasMore: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.hasMore = page.hasMore - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) - - fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(data, hasMore, additionalProperties.toMutableMap()) - } + fun service(service: AssistantService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: AssistantListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: AssistantListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [AssistantListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AssistantListPage = + AssistantListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: AssistantListPage) : Iterable { @@ -199,4 +131,17 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is AssistantListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "AssistantListPage{service=$service, params=$params, response=$response}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantListPageAsync.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantListPageAsync.kt index abb9ff07..0e90b27c 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantListPageAsync.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantListPageAsync.kt @@ -2,17 +2,8 @@ package com.openai.models.beta.assistants -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.errors.OpenAIInvalidDataException +import com.openai.core.checkRequired import com.openai.services.async.beta.AssistantServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -20,170 +11,110 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** Returns a list of assistants. */ +/** @see [AssistantServiceAsync.list] */ class AssistantListPageAsync private constructor( - private val assistantsService: AssistantServiceAsync, + private val service: AssistantServiceAsync, private val params: AssistantListParams, - private val response: Response, + private val response: AssistantListPageResponse, ) { - fun response(): Response = response + /** + * Delegates to [AssistantListPageResponse], but gracefully handles missing data. + * + * @see [AssistantListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() - fun data(): List = response().data() + /** + * Delegates to [AssistantListPageResponse], but gracefully handles missing data. + * + * @see [AssistantListPageResponse.hasMore] + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") - fun hasMore(): Optional = response().hasMore() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is AssistantListPageAsync && assistantsService == other.assistantsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(assistantsService, params, response) /* spotless:on */ - - override fun toString() = - "AssistantListPageAsync{assistantsService=$assistantsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - return !data().isEmpty() - } + fun hasNextPage(): Boolean = data().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return Optional.of(params.toBuilder().after(data().last().id()).build()) + return Optional.of(params.toBuilder().after(data().last()._id().getOptional("id")).build()) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { assistantsService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of( - assistantsService: AssistantServiceAsync, - params: AssistantListParams, - response: Response, - ) = AssistantListPageAsync(assistantsService, params, response) - } - - class Response( - private val data: JsonField>, - private val hasMore: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("has_more") hasMore: JsonField = JsonMissing.of(), - ) : this(data, hasMore, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun hasMore(): Optional = hasMore.getOptional("has_more") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("has_more") - fun _hasMore(): Optional> = Optional.ofNullable(hasMore) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false + /** The parameters that were used to request this page. */ + fun params(): AssistantListParams = params - fun validate(): Response = apply { - if (validated) { - return@apply - } + /** The response that this page was parsed from. */ + fun response(): AssistantListPageResponse = response - data().map { it.validate() } - hasMore() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + fun toBuilder() = Builder().from(this) - return /* spotless:off */ other is Response && data == other.data && hasMore == other.hasMore && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, hasMore, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [AssistantListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, hasMore=$hasMore, additionalProperties=$additionalProperties}" + /** A builder for [AssistantListPageAsync]. */ + class Builder internal constructor() { - companion object { + private var service: AssistantServiceAsync? = null + private var params: AssistantListParams? = null + private var response: AssistantListPageResponse? = null - /** - * Returns a mutable builder for constructing an instance of [AssistantListPageAsync]. - */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(assistantListPageAsync: AssistantListPageAsync) = apply { + service = assistantListPageAsync.service + params = assistantListPageAsync.params + response = assistantListPageAsync.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var hasMore: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.hasMore = page.hasMore - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) - - fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(data, hasMore, additionalProperties.toMutableMap()) - } + fun service(service: AssistantServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: AssistantListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: AssistantListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [AssistantListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AssistantListPageAsync = + AssistantListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: AssistantListPageAsync) { @@ -211,4 +142,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is AssistantListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "AssistantListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantListPageResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantListPageResponse.kt new file mode 100644 index 00000000..b6cdcf10 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantListPageResponse.kt @@ -0,0 +1,317 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.beta.assistants + +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 AssistantListPageResponse +private constructor( + private val data: JsonField>, + private val firstId: JsonField, + private val hasMore: JsonField, + private val lastId: JsonField, + private val object_: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") @ExcludeMissing data: JsonField> = JsonMissing.of(), + @JsonProperty("first_id") @ExcludeMissing firstId: JsonField = JsonMissing.of(), + @JsonProperty("has_more") @ExcludeMissing hasMore: JsonField = JsonMissing.of(), + @JsonProperty("last_id") @ExcludeMissing lastId: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonField = JsonMissing.of(), + ) : this(data, firstId, hasMore, lastId, object_, 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 data(): List = data.getRequired("data") + + /** + * @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 firstId(): String = firstId.getRequired("first_id") + + /** + * @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 hasMore(): Boolean = hasMore.getRequired("has_more") + + /** + * @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 lastId(): String = lastId.getRequired("last_id") + + /** + * @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 object_(): String = object_.getRequired("object") + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField> = data + + /** + * Returns the raw JSON value of [firstId]. + * + * Unlike [firstId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("first_id") @ExcludeMissing fun _firstId(): JsonField = firstId + + /** + * Returns the raw JSON value of [hasMore]. + * + * Unlike [hasMore], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("has_more") @ExcludeMissing fun _hasMore(): JsonField = hasMore + + /** + * Returns the raw JSON value of [lastId]. + * + * Unlike [lastId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("last_id") @ExcludeMissing fun _lastId(): JsonField = lastId + + /** + * Returns the raw JSON value of [object_]. + * + * Unlike [object_], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonField = object_ + + @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 [AssistantListPageResponse]. + * + * The following fields are required: + * ```java + * .data() + * .firstId() + * .hasMore() + * .lastId() + * .object_() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AssistantListPageResponse]. */ + class Builder internal constructor() { + + private var data: JsonField>? = null + private var firstId: JsonField? = null + private var hasMore: JsonField? = null + private var lastId: JsonField? = null + private var object_: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(assistantListPageResponse: AssistantListPageResponse) = apply { + data = assistantListPageResponse.data.map { it.toMutableList() } + firstId = assistantListPageResponse.firstId + hasMore = assistantListPageResponse.hasMore + lastId = assistantListPageResponse.lastId + object_ = assistantListPageResponse.object_ + additionalProperties = assistantListPageResponse.additionalProperties.toMutableMap() + } + + fun data(data: List) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun data(data: JsonField>) = apply { + this.data = data.map { it.toMutableList() } + } + + /** + * Adds a single [Assistant] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: Assistant) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + fun firstId(firstId: String) = firstId(JsonField.of(firstId)) + + /** + * Sets [Builder.firstId] to an arbitrary JSON value. + * + * You should usually call [Builder.firstId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun firstId(firstId: JsonField) = apply { this.firstId = firstId } + + fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) + + /** + * Sets [Builder.hasMore] to an arbitrary JSON value. + * + * You should usually call [Builder.hasMore] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } + + fun lastId(lastId: String) = lastId(JsonField.of(lastId)) + + /** + * Sets [Builder.lastId] to an arbitrary JSON value. + * + * You should usually call [Builder.lastId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun lastId(lastId: JsonField) = apply { this.lastId = lastId } + + fun object_(object_: String) = object_(JsonField.of(object_)) + + /** + * Sets [Builder.object_] to an arbitrary JSON value. + * + * You should usually call [Builder.object_] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun object_(object_: JsonField) = apply { this.object_ = object_ } + + 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 [AssistantListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .firstId() + * .hasMore() + * .lastId() + * .object_() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AssistantListPageResponse = + AssistantListPageResponse( + checkRequired("data", data).map { it.toImmutable() }, + checkRequired("firstId", firstId), + checkRequired("hasMore", hasMore), + checkRequired("lastId", lastId), + checkRequired("object_", object_), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): AssistantListPageResponse = apply { + if (validated) { + return@apply + } + + data().forEach { it.validate() } + firstId() + hasMore() + lastId() + object_() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (firstId.asKnown().isPresent) 1 else 0) + + (if (hasMore.asKnown().isPresent) 1 else 0) + + (if (lastId.asKnown().isPresent) 1 else 0) + + (if (object_.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is AssistantListPageResponse && data == other.data && firstId == other.firstId && hasMore == other.hasMore && lastId == other.lastId && object_ == other.object_ && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(data, firstId, hasMore, lastId, object_, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AssistantListPageResponse{data=$data, firstId=$firstId, hasMore=$hasMore, lastId=$lastId, object_=$object_, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/messages/MessageListPage.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/messages/MessageListPage.kt index 3f7087fb..14a9a44d 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/messages/MessageListPage.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/messages/MessageListPage.kt @@ -2,180 +2,115 @@ package com.openai.models.beta.threads.messages -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.errors.OpenAIInvalidDataException +import com.openai.core.checkRequired import com.openai.services.blocking.beta.threads.MessageService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** Returns a list of messages for a given thread. */ +/** @see [MessageService.list] */ class MessageListPage private constructor( - private val messagesService: MessageService, + private val service: MessageService, private val params: MessageListParams, - private val response: Response, + private val response: MessageListPageResponse, ) { - fun response(): Response = response + /** + * Delegates to [MessageListPageResponse], but gracefully handles missing data. + * + * @see [MessageListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() - fun data(): List = response().data() + /** + * Delegates to [MessageListPageResponse], but gracefully handles missing data. + * + * @see [MessageListPageResponse.hasMore] + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") - fun hasMore(): Optional = response().hasMore() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is MessageListPage && messagesService == other.messagesService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(messagesService, params, response) /* spotless:on */ - - override fun toString() = - "MessageListPage{messagesService=$messagesService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - return !data().isEmpty() - } + fun hasNextPage(): Boolean = data().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return Optional.of(params.toBuilder().after(data().last().id()).build()) + return Optional.of(params.toBuilder().after(data().last()._id().getOptional("id")).build()) } - fun getNextPage(): Optional { - return getNextPageParams().map { messagesService.list(it) } - } + fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) - companion object { + /** The parameters that were used to request this page. */ + fun params(): MessageListParams = params - @JvmStatic - fun of(messagesService: MessageService, params: MessageListParams, response: Response) = - MessageListPage(messagesService, params, response) - } + /** The response that this page was parsed from. */ + fun response(): MessageListPageResponse = response - class Response( - private val data: JsonField>, - private val hasMore: JsonField, - private val additionalProperties: MutableMap, - ) { + fun toBuilder() = Builder().from(this) - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("has_more") hasMore: JsonField = JsonMissing.of(), - ) : this(data, hasMore, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun hasMore(): Optional = hasMore.getOptional("has_more") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("has_more") - fun _hasMore(): Optional> = Optional.ofNullable(hasMore) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - data().map { it.validate() } - hasMore() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && hasMore == other.hasMore && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, hasMore, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [MessageListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, hasMore=$hasMore, additionalProperties=$additionalProperties}" + /** A builder for [MessageListPage]. */ + class Builder internal constructor() { - companion object { + private var service: MessageService? = null + private var params: MessageListParams? = null + private var response: MessageListPageResponse? = null - /** Returns a mutable builder for constructing an instance of [MessageListPage]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(messageListPage: MessageListPage) = apply { + service = messageListPage.service + params = messageListPage.params + response = messageListPage.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var hasMore: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.hasMore = page.hasMore - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) - - fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(data, hasMore, additionalProperties.toMutableMap()) - } + fun service(service: MessageService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: MessageListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: MessageListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [MessageListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): MessageListPage = + MessageListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: MessageListPage) : Iterable { @@ -196,4 +131,17 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is MessageListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "MessageListPage{service=$service, params=$params, response=$response}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/messages/MessageListPageAsync.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/messages/MessageListPageAsync.kt index 89a7a7cb..fd1595e3 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/messages/MessageListPageAsync.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/messages/MessageListPageAsync.kt @@ -2,17 +2,8 @@ package com.openai.models.beta.threads.messages -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.errors.OpenAIInvalidDataException +import com.openai.core.checkRequired import com.openai.services.async.beta.threads.MessageServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -20,168 +11,110 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** Returns a list of messages for a given thread. */ +/** @see [MessageServiceAsync.list] */ class MessageListPageAsync private constructor( - private val messagesService: MessageServiceAsync, + private val service: MessageServiceAsync, private val params: MessageListParams, - private val response: Response, + private val response: MessageListPageResponse, ) { - fun response(): Response = response + /** + * Delegates to [MessageListPageResponse], but gracefully handles missing data. + * + * @see [MessageListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() - fun data(): List = response().data() + /** + * Delegates to [MessageListPageResponse], but gracefully handles missing data. + * + * @see [MessageListPageResponse.hasMore] + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") - fun hasMore(): Optional = response().hasMore() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is MessageListPageAsync && messagesService == other.messagesService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(messagesService, params, response) /* spotless:on */ - - override fun toString() = - "MessageListPageAsync{messagesService=$messagesService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - return !data().isEmpty() - } + fun hasNextPage(): Boolean = data().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return Optional.of(params.toBuilder().after(data().last().id()).build()) + return Optional.of(params.toBuilder().after(data().last()._id().getOptional("id")).build()) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { messagesService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of( - messagesService: MessageServiceAsync, - params: MessageListParams, - response: Response, - ) = MessageListPageAsync(messagesService, params, response) - } - - class Response( - private val data: JsonField>, - private val hasMore: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("has_more") hasMore: JsonField = JsonMissing.of(), - ) : this(data, hasMore, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun hasMore(): Optional = hasMore.getOptional("has_more") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("has_more") - fun _hasMore(): Optional> = Optional.ofNullable(hasMore) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false + /** The parameters that were used to request this page. */ + fun params(): MessageListParams = params - fun validate(): Response = apply { - if (validated) { - return@apply - } + /** The response that this page was parsed from. */ + fun response(): MessageListPageResponse = response - data().map { it.validate() } - hasMore() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + fun toBuilder() = Builder().from(this) - return /* spotless:off */ other is Response && data == other.data && hasMore == other.hasMore && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, hasMore, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [MessageListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, hasMore=$hasMore, additionalProperties=$additionalProperties}" + /** A builder for [MessageListPageAsync]. */ + class Builder internal constructor() { - companion object { + private var service: MessageServiceAsync? = null + private var params: MessageListParams? = null + private var response: MessageListPageResponse? = null - /** Returns a mutable builder for constructing an instance of [MessageListPageAsync]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(messageListPageAsync: MessageListPageAsync) = apply { + service = messageListPageAsync.service + params = messageListPageAsync.params + response = messageListPageAsync.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var hasMore: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.hasMore = page.hasMore - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) - - fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(data, hasMore, additionalProperties.toMutableMap()) - } + fun service(service: MessageServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: MessageListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: MessageListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [MessageListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): MessageListPageAsync = + MessageListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: MessageListPageAsync) { @@ -209,4 +142,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is MessageListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "MessageListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/messages/MessageListPageResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/messages/MessageListPageResponse.kt new file mode 100644 index 00000000..1f2ebab8 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/messages/MessageListPageResponse.kt @@ -0,0 +1,317 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.beta.threads.messages + +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 MessageListPageResponse +private constructor( + private val data: JsonField>, + private val firstId: JsonField, + private val hasMore: JsonField, + private val lastId: JsonField, + private val object_: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") @ExcludeMissing data: JsonField> = JsonMissing.of(), + @JsonProperty("first_id") @ExcludeMissing firstId: JsonField = JsonMissing.of(), + @JsonProperty("has_more") @ExcludeMissing hasMore: JsonField = JsonMissing.of(), + @JsonProperty("last_id") @ExcludeMissing lastId: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonField = JsonMissing.of(), + ) : this(data, firstId, hasMore, lastId, object_, 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 data(): List = data.getRequired("data") + + /** + * @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 firstId(): String = firstId.getRequired("first_id") + + /** + * @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 hasMore(): Boolean = hasMore.getRequired("has_more") + + /** + * @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 lastId(): String = lastId.getRequired("last_id") + + /** + * @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 object_(): String = object_.getRequired("object") + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField> = data + + /** + * Returns the raw JSON value of [firstId]. + * + * Unlike [firstId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("first_id") @ExcludeMissing fun _firstId(): JsonField = firstId + + /** + * Returns the raw JSON value of [hasMore]. + * + * Unlike [hasMore], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("has_more") @ExcludeMissing fun _hasMore(): JsonField = hasMore + + /** + * Returns the raw JSON value of [lastId]. + * + * Unlike [lastId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("last_id") @ExcludeMissing fun _lastId(): JsonField = lastId + + /** + * Returns the raw JSON value of [object_]. + * + * Unlike [object_], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonField = object_ + + @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 [MessageListPageResponse]. + * + * The following fields are required: + * ```java + * .data() + * .firstId() + * .hasMore() + * .lastId() + * .object_() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [MessageListPageResponse]. */ + class Builder internal constructor() { + + private var data: JsonField>? = null + private var firstId: JsonField? = null + private var hasMore: JsonField? = null + private var lastId: JsonField? = null + private var object_: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(messageListPageResponse: MessageListPageResponse) = apply { + data = messageListPageResponse.data.map { it.toMutableList() } + firstId = messageListPageResponse.firstId + hasMore = messageListPageResponse.hasMore + lastId = messageListPageResponse.lastId + object_ = messageListPageResponse.object_ + additionalProperties = messageListPageResponse.additionalProperties.toMutableMap() + } + + fun data(data: List) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun data(data: JsonField>) = apply { + this.data = data.map { it.toMutableList() } + } + + /** + * Adds a single [Message] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: Message) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + fun firstId(firstId: String) = firstId(JsonField.of(firstId)) + + /** + * Sets [Builder.firstId] to an arbitrary JSON value. + * + * You should usually call [Builder.firstId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun firstId(firstId: JsonField) = apply { this.firstId = firstId } + + fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) + + /** + * Sets [Builder.hasMore] to an arbitrary JSON value. + * + * You should usually call [Builder.hasMore] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } + + fun lastId(lastId: String) = lastId(JsonField.of(lastId)) + + /** + * Sets [Builder.lastId] to an arbitrary JSON value. + * + * You should usually call [Builder.lastId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun lastId(lastId: JsonField) = apply { this.lastId = lastId } + + fun object_(object_: String) = object_(JsonField.of(object_)) + + /** + * Sets [Builder.object_] to an arbitrary JSON value. + * + * You should usually call [Builder.object_] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun object_(object_: JsonField) = apply { this.object_ = object_ } + + 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 [MessageListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .firstId() + * .hasMore() + * .lastId() + * .object_() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): MessageListPageResponse = + MessageListPageResponse( + checkRequired("data", data).map { it.toImmutable() }, + checkRequired("firstId", firstId), + checkRequired("hasMore", hasMore), + checkRequired("lastId", lastId), + checkRequired("object_", object_), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): MessageListPageResponse = apply { + if (validated) { + return@apply + } + + data().forEach { it.validate() } + firstId() + hasMore() + lastId() + object_() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (firstId.asKnown().isPresent) 1 else 0) + + (if (hasMore.asKnown().isPresent) 1 else 0) + + (if (lastId.asKnown().isPresent) 1 else 0) + + (if (object_.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is MessageListPageResponse && data == other.data && firstId == other.firstId && hasMore == other.hasMore && lastId == other.lastId && object_ == other.object_ && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(data, firstId, hasMore, lastId, object_, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "MessageListPageResponse{data=$data, firstId=$firstId, hasMore=$hasMore, lastId=$lastId, object_=$object_, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/runs/RunListPage.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/runs/RunListPage.kt index cbab224d..108f1287 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/runs/RunListPage.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/runs/RunListPage.kt @@ -2,180 +2,115 @@ package com.openai.models.beta.threads.runs -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.errors.OpenAIInvalidDataException +import com.openai.core.checkRequired import com.openai.services.blocking.beta.threads.RunService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** Returns a list of runs belonging to a thread. */ +/** @see [RunService.list] */ class RunListPage private constructor( - private val runsService: RunService, + private val service: RunService, private val params: RunListParams, - private val response: Response, + private val response: RunListPageResponse, ) { - fun response(): Response = response + /** + * Delegates to [RunListPageResponse], but gracefully handles missing data. + * + * @see [RunListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() - fun data(): List = response().data() + /** + * Delegates to [RunListPageResponse], but gracefully handles missing data. + * + * @see [RunListPageResponse.hasMore] + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") - fun hasMore(): Optional = response().hasMore() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is RunListPage && runsService == other.runsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(runsService, params, response) /* spotless:on */ - - override fun toString() = - "RunListPage{runsService=$runsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - return !data().isEmpty() - } + fun hasNextPage(): Boolean = data().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return Optional.of(params.toBuilder().after(data().last().id()).build()) + return Optional.of(params.toBuilder().after(data().last()._id().getOptional("id")).build()) } - fun getNextPage(): Optional { - return getNextPageParams().map { runsService.list(it) } - } + fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of(runsService: RunService, params: RunListParams, response: Response) = - RunListPage(runsService, params, response) - } - - class Response( - private val data: JsonField>, - private val hasMore: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("has_more") hasMore: JsonField = JsonMissing.of(), - ) : this(data, hasMore, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun hasMore(): Optional = hasMore.getOptional("has_more") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("has_more") - fun _hasMore(): Optional> = Optional.ofNullable(hasMore) + /** The parameters that were used to request this page. */ + fun params(): RunListParams = params - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + /** The response that this page was parsed from. */ + fun response(): RunListPageResponse = response - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } + fun toBuilder() = Builder().from(this) - data().map { it.validate() } - hasMore() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && hasMore == other.hasMore && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, hasMore, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [RunListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, hasMore=$hasMore, additionalProperties=$additionalProperties}" + /** A builder for [RunListPage]. */ + class Builder internal constructor() { - companion object { + private var service: RunService? = null + private var params: RunListParams? = null + private var response: RunListPageResponse? = null - /** Returns a mutable builder for constructing an instance of [RunListPage]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(runListPage: RunListPage) = apply { + service = runListPage.service + params = runListPage.params + response = runListPage.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var hasMore: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.hasMore = page.hasMore - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) - - fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(data, hasMore, additionalProperties.toMutableMap()) - } + fun service(service: RunService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: RunListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: RunListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [RunListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RunListPage = + RunListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: RunListPage) : Iterable { @@ -196,4 +131,16 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is RunListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = "RunListPage{service=$service, params=$params, response=$response}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/runs/RunListPageAsync.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/runs/RunListPageAsync.kt index 40ac6d96..ca329d17 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/runs/RunListPageAsync.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/runs/RunListPageAsync.kt @@ -2,17 +2,8 @@ package com.openai.models.beta.threads.runs -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.errors.OpenAIInvalidDataException +import com.openai.core.checkRequired import com.openai.services.async.beta.threads.RunServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -20,165 +11,110 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** Returns a list of runs belonging to a thread. */ +/** @see [RunServiceAsync.list] */ class RunListPageAsync private constructor( - private val runsService: RunServiceAsync, + private val service: RunServiceAsync, private val params: RunListParams, - private val response: Response, + private val response: RunListPageResponse, ) { - fun response(): Response = response + /** + * Delegates to [RunListPageResponse], but gracefully handles missing data. + * + * @see [RunListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() - fun data(): List = response().data() + /** + * Delegates to [RunListPageResponse], but gracefully handles missing data. + * + * @see [RunListPageResponse.hasMore] + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") - fun hasMore(): Optional = response().hasMore() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is RunListPageAsync && runsService == other.runsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(runsService, params, response) /* spotless:on */ - - override fun toString() = - "RunListPageAsync{runsService=$runsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - return !data().isEmpty() - } + fun hasNextPage(): Boolean = data().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return Optional.of(params.toBuilder().after(data().last().id()).build()) + return Optional.of(params.toBuilder().after(data().last()._id().getOptional("id")).build()) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { runsService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of(runsService: RunServiceAsync, params: RunListParams, response: Response) = - RunListPageAsync(runsService, params, response) - } - - class Response( - private val data: JsonField>, - private val hasMore: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("has_more") hasMore: JsonField = JsonMissing.of(), - ) : this(data, hasMore, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun hasMore(): Optional = hasMore.getOptional("has_more") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("has_more") - fun _hasMore(): Optional> = Optional.ofNullable(hasMore) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false + /** The parameters that were used to request this page. */ + fun params(): RunListParams = params - fun validate(): Response = apply { - if (validated) { - return@apply - } + /** The response that this page was parsed from. */ + fun response(): RunListPageResponse = response - data().map { it.validate() } - hasMore() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + fun toBuilder() = Builder().from(this) - return /* spotless:off */ other is Response && data == other.data && hasMore == other.hasMore && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, hasMore, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [RunListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, hasMore=$hasMore, additionalProperties=$additionalProperties}" + /** A builder for [RunListPageAsync]. */ + class Builder internal constructor() { - companion object { + private var service: RunServiceAsync? = null + private var params: RunListParams? = null + private var response: RunListPageResponse? = null - /** Returns a mutable builder for constructing an instance of [RunListPageAsync]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(runListPageAsync: RunListPageAsync) = apply { + service = runListPageAsync.service + params = runListPageAsync.params + response = runListPageAsync.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var hasMore: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.hasMore = page.hasMore - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) - - fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(data, hasMore, additionalProperties.toMutableMap()) - } + fun service(service: RunServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: RunListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: RunListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [RunListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RunListPageAsync = + RunListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: RunListPageAsync) { @@ -206,4 +142,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is RunListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "RunListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/runs/RunListPageResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/runs/RunListPageResponse.kt new file mode 100644 index 00000000..8c6df2cc --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/runs/RunListPageResponse.kt @@ -0,0 +1,314 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.beta.threads.runs + +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 RunListPageResponse +private constructor( + private val data: JsonField>, + private val firstId: JsonField, + private val hasMore: JsonField, + private val lastId: JsonField, + private val object_: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") @ExcludeMissing data: JsonField> = JsonMissing.of(), + @JsonProperty("first_id") @ExcludeMissing firstId: JsonField = JsonMissing.of(), + @JsonProperty("has_more") @ExcludeMissing hasMore: JsonField = JsonMissing.of(), + @JsonProperty("last_id") @ExcludeMissing lastId: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonField = JsonMissing.of(), + ) : this(data, firstId, hasMore, lastId, object_, 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 data(): List = data.getRequired("data") + + /** + * @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 firstId(): String = firstId.getRequired("first_id") + + /** + * @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 hasMore(): Boolean = hasMore.getRequired("has_more") + + /** + * @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 lastId(): String = lastId.getRequired("last_id") + + /** + * @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 object_(): String = object_.getRequired("object") + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField> = data + + /** + * Returns the raw JSON value of [firstId]. + * + * Unlike [firstId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("first_id") @ExcludeMissing fun _firstId(): JsonField = firstId + + /** + * Returns the raw JSON value of [hasMore]. + * + * Unlike [hasMore], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("has_more") @ExcludeMissing fun _hasMore(): JsonField = hasMore + + /** + * Returns the raw JSON value of [lastId]. + * + * Unlike [lastId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("last_id") @ExcludeMissing fun _lastId(): JsonField = lastId + + /** + * Returns the raw JSON value of [object_]. + * + * Unlike [object_], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonField = object_ + + @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 [RunListPageResponse]. + * + * The following fields are required: + * ```java + * .data() + * .firstId() + * .hasMore() + * .lastId() + * .object_() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RunListPageResponse]. */ + class Builder internal constructor() { + + private var data: JsonField>? = null + private var firstId: JsonField? = null + private var hasMore: JsonField? = null + private var lastId: JsonField? = null + private var object_: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(runListPageResponse: RunListPageResponse) = apply { + data = runListPageResponse.data.map { it.toMutableList() } + firstId = runListPageResponse.firstId + hasMore = runListPageResponse.hasMore + lastId = runListPageResponse.lastId + object_ = runListPageResponse.object_ + additionalProperties = runListPageResponse.additionalProperties.toMutableMap() + } + + fun data(data: List) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed `List` value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun data(data: JsonField>) = apply { this.data = data.map { it.toMutableList() } } + + /** + * Adds a single [Run] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: Run) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + fun firstId(firstId: String) = firstId(JsonField.of(firstId)) + + /** + * Sets [Builder.firstId] to an arbitrary JSON value. + * + * You should usually call [Builder.firstId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun firstId(firstId: JsonField) = apply { this.firstId = firstId } + + fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) + + /** + * Sets [Builder.hasMore] to an arbitrary JSON value. + * + * You should usually call [Builder.hasMore] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } + + fun lastId(lastId: String) = lastId(JsonField.of(lastId)) + + /** + * Sets [Builder.lastId] to an arbitrary JSON value. + * + * You should usually call [Builder.lastId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun lastId(lastId: JsonField) = apply { this.lastId = lastId } + + fun object_(object_: String) = object_(JsonField.of(object_)) + + /** + * Sets [Builder.object_] to an arbitrary JSON value. + * + * You should usually call [Builder.object_] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun object_(object_: JsonField) = apply { this.object_ = object_ } + + 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 [RunListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .firstId() + * .hasMore() + * .lastId() + * .object_() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RunListPageResponse = + RunListPageResponse( + checkRequired("data", data).map { it.toImmutable() }, + checkRequired("firstId", firstId), + checkRequired("hasMore", hasMore), + checkRequired("lastId", lastId), + checkRequired("object_", object_), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): RunListPageResponse = apply { + if (validated) { + return@apply + } + + data().forEach { it.validate() } + firstId() + hasMore() + lastId() + object_() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (firstId.asKnown().isPresent) 1 else 0) + + (if (hasMore.asKnown().isPresent) 1 else 0) + + (if (lastId.asKnown().isPresent) 1 else 0) + + (if (object_.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is RunListPageResponse && data == other.data && firstId == other.firstId && hasMore == other.hasMore && lastId == other.lastId && object_ == other.object_ && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(data, firstId, hasMore, lastId, object_, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "RunListPageResponse{data=$data, firstId=$firstId, hasMore=$hasMore, lastId=$lastId, object_=$object_, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/runs/steps/StepListPage.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/runs/steps/StepListPage.kt index 49dcd8cd..b9740fab 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/runs/steps/StepListPage.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/runs/steps/StepListPage.kt @@ -2,180 +2,115 @@ package com.openai.models.beta.threads.runs.steps -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.errors.OpenAIInvalidDataException +import com.openai.core.checkRequired import com.openai.services.blocking.beta.threads.runs.StepService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** Returns a list of run steps belonging to a run. */ +/** @see [StepService.list] */ class StepListPage private constructor( - private val stepsService: StepService, + private val service: StepService, private val params: StepListParams, - private val response: Response, + private val response: StepListPageResponse, ) { - fun response(): Response = response + /** + * Delegates to [StepListPageResponse], but gracefully handles missing data. + * + * @see [StepListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() - fun data(): List = response().data() + /** + * Delegates to [StepListPageResponse], but gracefully handles missing data. + * + * @see [StepListPageResponse.hasMore] + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") - fun hasMore(): Optional = response().hasMore() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is StepListPage && stepsService == other.stepsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(stepsService, params, response) /* spotless:on */ - - override fun toString() = - "StepListPage{stepsService=$stepsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - return !data().isEmpty() - } + fun hasNextPage(): Boolean = data().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return Optional.of(params.toBuilder().after(data().last().id()).build()) + return Optional.of(params.toBuilder().after(data().last()._id().getOptional("id")).build()) } - fun getNextPage(): Optional { - return getNextPageParams().map { stepsService.list(it) } - } + fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of(stepsService: StepService, params: StepListParams, response: Response) = - StepListPage(stepsService, params, response) - } - - class Response( - private val data: JsonField>, - private val hasMore: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("has_more") hasMore: JsonField = JsonMissing.of(), - ) : this(data, hasMore, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun hasMore(): Optional = hasMore.getOptional("has_more") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("has_more") - fun _hasMore(): Optional> = Optional.ofNullable(hasMore) + /** The parameters that were used to request this page. */ + fun params(): StepListParams = params - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + /** The response that this page was parsed from. */ + fun response(): StepListPageResponse = response - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } + fun toBuilder() = Builder().from(this) - data().map { it.validate() } - hasMore() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && hasMore == other.hasMore && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, hasMore, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [StepListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, hasMore=$hasMore, additionalProperties=$additionalProperties}" + /** A builder for [StepListPage]. */ + class Builder internal constructor() { - companion object { + private var service: StepService? = null + private var params: StepListParams? = null + private var response: StepListPageResponse? = null - /** Returns a mutable builder for constructing an instance of [StepListPage]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(stepListPage: StepListPage) = apply { + service = stepListPage.service + params = stepListPage.params + response = stepListPage.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var hasMore: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.hasMore = page.hasMore - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) - - fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(data, hasMore, additionalProperties.toMutableMap()) - } + fun service(service: StepService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: StepListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: StepListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [StepListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): StepListPage = + StepListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: StepListPage) : Iterable { @@ -196,4 +131,16 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is StepListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = "StepListPage{service=$service, params=$params, response=$response}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/runs/steps/StepListPageAsync.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/runs/steps/StepListPageAsync.kt index e4b252c6..a753633e 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/runs/steps/StepListPageAsync.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/runs/steps/StepListPageAsync.kt @@ -2,17 +2,8 @@ package com.openai.models.beta.threads.runs.steps -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.errors.OpenAIInvalidDataException +import com.openai.core.checkRequired import com.openai.services.async.beta.threads.runs.StepServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -20,165 +11,110 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** Returns a list of run steps belonging to a run. */ +/** @see [StepServiceAsync.list] */ class StepListPageAsync private constructor( - private val stepsService: StepServiceAsync, + private val service: StepServiceAsync, private val params: StepListParams, - private val response: Response, + private val response: StepListPageResponse, ) { - fun response(): Response = response + /** + * Delegates to [StepListPageResponse], but gracefully handles missing data. + * + * @see [StepListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() - fun data(): List = response().data() + /** + * Delegates to [StepListPageResponse], but gracefully handles missing data. + * + * @see [StepListPageResponse.hasMore] + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") - fun hasMore(): Optional = response().hasMore() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is StepListPageAsync && stepsService == other.stepsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(stepsService, params, response) /* spotless:on */ - - override fun toString() = - "StepListPageAsync{stepsService=$stepsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - return !data().isEmpty() - } + fun hasNextPage(): Boolean = data().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return Optional.of(params.toBuilder().after(data().last().id()).build()) + return Optional.of(params.toBuilder().after(data().last()._id().getOptional("id")).build()) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { stepsService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of(stepsService: StepServiceAsync, params: StepListParams, response: Response) = - StepListPageAsync(stepsService, params, response) - } - - class Response( - private val data: JsonField>, - private val hasMore: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("has_more") hasMore: JsonField = JsonMissing.of(), - ) : this(data, hasMore, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun hasMore(): Optional = hasMore.getOptional("has_more") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("has_more") - fun _hasMore(): Optional> = Optional.ofNullable(hasMore) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false + /** The parameters that were used to request this page. */ + fun params(): StepListParams = params - fun validate(): Response = apply { - if (validated) { - return@apply - } + /** The response that this page was parsed from. */ + fun response(): StepListPageResponse = response - data().map { it.validate() } - hasMore() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + fun toBuilder() = Builder().from(this) - return /* spotless:off */ other is Response && data == other.data && hasMore == other.hasMore && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, hasMore, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [StepListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, hasMore=$hasMore, additionalProperties=$additionalProperties}" + /** A builder for [StepListPageAsync]. */ + class Builder internal constructor() { - companion object { + private var service: StepServiceAsync? = null + private var params: StepListParams? = null + private var response: StepListPageResponse? = null - /** Returns a mutable builder for constructing an instance of [StepListPageAsync]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(stepListPageAsync: StepListPageAsync) = apply { + service = stepListPageAsync.service + params = stepListPageAsync.params + response = stepListPageAsync.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var hasMore: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.hasMore = page.hasMore - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) - - fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(data, hasMore, additionalProperties.toMutableMap()) - } + fun service(service: StepServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: StepListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: StepListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [StepListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): StepListPageAsync = + StepListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: StepListPageAsync) { @@ -206,4 +142,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is StepListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "StepListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/runs/steps/StepListPageResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/runs/steps/StepListPageResponse.kt new file mode 100644 index 00000000..cfceed93 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/runs/steps/StepListPageResponse.kt @@ -0,0 +1,317 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.beta.threads.runs.steps + +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 StepListPageResponse +private constructor( + private val data: JsonField>, + private val firstId: JsonField, + private val hasMore: JsonField, + private val lastId: JsonField, + private val object_: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") @ExcludeMissing data: JsonField> = JsonMissing.of(), + @JsonProperty("first_id") @ExcludeMissing firstId: JsonField = JsonMissing.of(), + @JsonProperty("has_more") @ExcludeMissing hasMore: JsonField = JsonMissing.of(), + @JsonProperty("last_id") @ExcludeMissing lastId: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonField = JsonMissing.of(), + ) : this(data, firstId, hasMore, lastId, object_, 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 data(): List = data.getRequired("data") + + /** + * @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 firstId(): String = firstId.getRequired("first_id") + + /** + * @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 hasMore(): Boolean = hasMore.getRequired("has_more") + + /** + * @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 lastId(): String = lastId.getRequired("last_id") + + /** + * @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 object_(): String = object_.getRequired("object") + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField> = data + + /** + * Returns the raw JSON value of [firstId]. + * + * Unlike [firstId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("first_id") @ExcludeMissing fun _firstId(): JsonField = firstId + + /** + * Returns the raw JSON value of [hasMore]. + * + * Unlike [hasMore], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("has_more") @ExcludeMissing fun _hasMore(): JsonField = hasMore + + /** + * Returns the raw JSON value of [lastId]. + * + * Unlike [lastId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("last_id") @ExcludeMissing fun _lastId(): JsonField = lastId + + /** + * Returns the raw JSON value of [object_]. + * + * Unlike [object_], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonField = object_ + + @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 [StepListPageResponse]. + * + * The following fields are required: + * ```java + * .data() + * .firstId() + * .hasMore() + * .lastId() + * .object_() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [StepListPageResponse]. */ + class Builder internal constructor() { + + private var data: JsonField>? = null + private var firstId: JsonField? = null + private var hasMore: JsonField? = null + private var lastId: JsonField? = null + private var object_: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(stepListPageResponse: StepListPageResponse) = apply { + data = stepListPageResponse.data.map { it.toMutableList() } + firstId = stepListPageResponse.firstId + hasMore = stepListPageResponse.hasMore + lastId = stepListPageResponse.lastId + object_ = stepListPageResponse.object_ + additionalProperties = stepListPageResponse.additionalProperties.toMutableMap() + } + + fun data(data: List) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun data(data: JsonField>) = apply { + this.data = data.map { it.toMutableList() } + } + + /** + * Adds a single [RunStep] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: RunStep) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + fun firstId(firstId: String) = firstId(JsonField.of(firstId)) + + /** + * Sets [Builder.firstId] to an arbitrary JSON value. + * + * You should usually call [Builder.firstId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun firstId(firstId: JsonField) = apply { this.firstId = firstId } + + fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) + + /** + * Sets [Builder.hasMore] to an arbitrary JSON value. + * + * You should usually call [Builder.hasMore] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } + + fun lastId(lastId: String) = lastId(JsonField.of(lastId)) + + /** + * Sets [Builder.lastId] to an arbitrary JSON value. + * + * You should usually call [Builder.lastId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun lastId(lastId: JsonField) = apply { this.lastId = lastId } + + fun object_(object_: String) = object_(JsonField.of(object_)) + + /** + * Sets [Builder.object_] to an arbitrary JSON value. + * + * You should usually call [Builder.object_] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun object_(object_: JsonField) = apply { this.object_ = object_ } + + 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 [StepListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .firstId() + * .hasMore() + * .lastId() + * .object_() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): StepListPageResponse = + StepListPageResponse( + checkRequired("data", data).map { it.toImmutable() }, + checkRequired("firstId", firstId), + checkRequired("hasMore", hasMore), + checkRequired("lastId", lastId), + checkRequired("object_", object_), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): StepListPageResponse = apply { + if (validated) { + return@apply + } + + data().forEach { it.validate() } + firstId() + hasMore() + lastId() + object_() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (firstId.asKnown().isPresent) 1 else 0) + + (if (hasMore.asKnown().isPresent) 1 else 0) + + (if (lastId.asKnown().isPresent) 1 else 0) + + (if (object_.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is StepListPageResponse && data == other.data && firstId == other.firstId && hasMore == other.hasMore && lastId == other.lastId && object_ == other.object_ && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(data, firstId, hasMore, lastId, object_, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "StepListPageResponse{data=$data, firstId=$firstId, hasMore=$hasMore, lastId=$lastId, object_=$object_, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/chat/completions/ChatCompletionListPage.kt b/openai-java-core/src/main/kotlin/com/openai/models/chat/completions/ChatCompletionListPage.kt index 147688a3..6c807633 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/chat/completions/ChatCompletionListPage.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/chat/completions/ChatCompletionListPage.kt @@ -2,188 +2,117 @@ package com.openai.models.chat.completions -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.errors.OpenAIInvalidDataException +import com.openai.core.checkRequired import com.openai.services.blocking.chat.ChatCompletionService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** - * List stored Chat Completions. Only Chat Completions that have been stored with the `store` - * parameter set to `true` will be returned. - */ +/** @see [ChatCompletionService.list] */ class ChatCompletionListPage private constructor( - private val completionsService: ChatCompletionService, + private val service: ChatCompletionService, private val params: ChatCompletionListParams, - private val response: Response, + private val response: ChatCompletionListPageResponse, ) { - fun response(): Response = response + /** + * Delegates to [ChatCompletionListPageResponse], but gracefully handles missing data. + * + * @see [ChatCompletionListPageResponse.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() - fun data(): List = response().data() + /** + * Delegates to [ChatCompletionListPageResponse], but gracefully handles missing data. + * + * @see [ChatCompletionListPageResponse.hasMore] + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") - fun hasMore(): Optional = response().hasMore() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ChatCompletionListPage && completionsService == other.completionsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(completionsService, params, response) /* spotless:on */ - - override fun toString() = - "ChatCompletionListPage{completionsService=$completionsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - return !data().isEmpty() - } + fun hasNextPage(): Boolean = data().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return Optional.of(params.toBuilder().after(data().last().id()).build()) + return Optional.of(params.toBuilder().after(data().last()._id().getOptional("id")).build()) } - fun getNextPage(): Optional { - return getNextPageParams().map { completionsService.list(it) } - } + fun getNextPage(): Optional = + getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) - companion object { + /** The parameters that were used to request this page. */ + fun params(): ChatCompletionListParams = params - @JvmStatic - fun of( - completionsService: ChatCompletionService, - params: ChatCompletionListParams, - response: Response, - ) = ChatCompletionListPage(completionsService, params, response) - } + /** The response that this page was parsed from. */ + fun response(): ChatCompletionListPageResponse = response - class Response( - private val data: JsonField>, - private val hasMore: JsonField, - private val additionalProperties: MutableMap, - ) { + fun toBuilder() = Builder().from(this) - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("has_more") hasMore: JsonField = JsonMissing.of(), - ) : this(data, hasMore, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun hasMore(): Optional = hasMore.getOptional("has_more") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("has_more") - fun _hasMore(): Optional> = Optional.ofNullable(hasMore) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - data().map { it.validate() } - hasMore() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && hasMore == other.hasMore && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, hasMore, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [ChatCompletionListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, hasMore=$hasMore, additionalProperties=$additionalProperties}" + /** A builder for [ChatCompletionListPage]. */ + class Builder internal constructor() { - companion object { + private var service: ChatCompletionService? = null + private var params: ChatCompletionListParams? = null + private var response: ChatCompletionListPageResponse? = null - /** - * Returns a mutable builder for constructing an instance of [ChatCompletionListPage]. - */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(chatCompletionListPage: ChatCompletionListPage) = apply { + service = chatCompletionListPage.service + params = chatCompletionListPage.params + response = chatCompletionListPage.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var hasMore: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.hasMore = page.hasMore - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) - - fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(data, hasMore, additionalProperties.toMutableMap()) - } + fun service(service: ChatCompletionService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: ChatCompletionListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: ChatCompletionListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [ChatCompletionListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ChatCompletionListPage = + ChatCompletionListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: ChatCompletionListPage) : Iterable { @@ -204,4 +133,17 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ChatCompletionListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "ChatCompletionListPage{service=$service, params=$params, response=$response}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/chat/completions/ChatCompletionListPageAsync.kt b/openai-java-core/src/main/kotlin/com/openai/models/chat/completions/ChatCompletionListPageAsync.kt index 12da0d80..87bef9ed 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/chat/completions/ChatCompletionListPageAsync.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/chat/completions/ChatCompletionListPageAsync.kt @@ -2,17 +2,8 @@ package com.openai.models.chat.completions -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.errors.OpenAIInvalidDataException +import com.openai.core.checkRequired import com.openai.services.async.chat.ChatCompletionServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -20,174 +11,111 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** - * List stored Chat Completions. Only Chat Completions that have been stored with the `store` - * parameter set to `true` will be returned. - */ +/** @see [ChatCompletionServiceAsync.list] */ class ChatCompletionListPageAsync private constructor( - private val completionsService: ChatCompletionServiceAsync, + private val service: ChatCompletionServiceAsync, private val params: ChatCompletionListParams, - private val response: Response, + private val response: ChatCompletionListPageResponse, ) { - fun response(): Response = response + /** + * Delegates to [ChatCompletionListPageResponse], but gracefully handles missing data. + * + * @see [ChatCompletionListPageResponse.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() - fun data(): List = response().data() + /** + * Delegates to [ChatCompletionListPageResponse], but gracefully handles missing data. + * + * @see [ChatCompletionListPageResponse.hasMore] + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") - fun hasMore(): Optional = response().hasMore() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ChatCompletionListPageAsync && completionsService == other.completionsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(completionsService, params, response) /* spotless:on */ - - override fun toString() = - "ChatCompletionListPageAsync{completionsService=$completionsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - return !data().isEmpty() - } + fun hasNextPage(): Boolean = data().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return Optional.of(params.toBuilder().after(data().last().id()).build()) + return Optional.of(params.toBuilder().after(data().last()._id().getOptional("id")).build()) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { completionsService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of( - completionsService: ChatCompletionServiceAsync, - params: ChatCompletionListParams, - response: Response, - ) = ChatCompletionListPageAsync(completionsService, params, response) - } - - class Response( - private val data: JsonField>, - private val hasMore: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("has_more") hasMore: JsonField = JsonMissing.of(), - ) : this(data, hasMore, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun hasMore(): Optional = hasMore.getOptional("has_more") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("has_more") - fun _hasMore(): Optional> = Optional.ofNullable(hasMore) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false + /** The parameters that were used to request this page. */ + fun params(): ChatCompletionListParams = params - fun validate(): Response = apply { - if (validated) { - return@apply - } + /** The response that this page was parsed from. */ + fun response(): ChatCompletionListPageResponse = response - data().map { it.validate() } - hasMore() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + fun toBuilder() = Builder().from(this) - return /* spotless:off */ other is Response && data == other.data && hasMore == other.hasMore && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, hasMore, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [ChatCompletionListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, hasMore=$hasMore, additionalProperties=$additionalProperties}" + /** A builder for [ChatCompletionListPageAsync]. */ + class Builder internal constructor() { - companion object { + private var service: ChatCompletionServiceAsync? = null + private var params: ChatCompletionListParams? = null + private var response: ChatCompletionListPageResponse? = null - /** - * Returns a mutable builder for constructing an instance of - * [ChatCompletionListPageAsync]. - */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(chatCompletionListPageAsync: ChatCompletionListPageAsync) = apply { + service = chatCompletionListPageAsync.service + params = chatCompletionListPageAsync.params + response = chatCompletionListPageAsync.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var hasMore: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.hasMore = page.hasMore - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) - - fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(data, hasMore, additionalProperties.toMutableMap()) - } + fun service(service: ChatCompletionServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: ChatCompletionListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: ChatCompletionListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [ChatCompletionListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ChatCompletionListPageAsync = + ChatCompletionListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: ChatCompletionListPageAsync) { @@ -218,4 +146,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ChatCompletionListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "ChatCompletionListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/chat/completions/ChatCompletionListPageResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/chat/completions/ChatCompletionListPageResponse.kt new file mode 100644 index 00000000..4db9bd69 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/chat/completions/ChatCompletionListPageResponse.kt @@ -0,0 +1,340 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.chat.completions + +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 + +/** An object representing a list of Chat Completions. */ +class ChatCompletionListPageResponse +private constructor( + private val data: JsonField>, + private val firstId: JsonField, + private val hasMore: JsonField, + private val lastId: JsonField, + private val object_: JsonValue, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") + @ExcludeMissing + data: JsonField> = JsonMissing.of(), + @JsonProperty("first_id") @ExcludeMissing firstId: JsonField = JsonMissing.of(), + @JsonProperty("has_more") @ExcludeMissing hasMore: JsonField = JsonMissing.of(), + @JsonProperty("last_id") @ExcludeMissing lastId: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + ) : this(data, firstId, hasMore, lastId, object_, mutableMapOf()) + + /** + * An array of chat completion objects. + * + * @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 data(): List = data.getRequired("data") + + /** + * The identifier of the first chat completion in the data array. + * + * @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 firstId(): String = firstId.getRequired("first_id") + + /** + * Indicates whether there are more Chat Completions available. + * + * @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 hasMore(): Boolean = hasMore.getRequired("has_more") + + /** + * The identifier of the last chat completion in the data array. + * + * @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 lastId(): String = lastId.getRequired("last_id") + + /** + * The type of this object. It is always set to "list". + * + * Expected to always return the following: + * ```java + * JsonValue.from("list") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField> = data + + /** + * Returns the raw JSON value of [firstId]. + * + * Unlike [firstId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("first_id") @ExcludeMissing fun _firstId(): JsonField = firstId + + /** + * Returns the raw JSON value of [hasMore]. + * + * Unlike [hasMore], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("has_more") @ExcludeMissing fun _hasMore(): JsonField = hasMore + + /** + * Returns the raw JSON value of [lastId]. + * + * Unlike [lastId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("last_id") @ExcludeMissing fun _lastId(): JsonField = lastId + + @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 + * [ChatCompletionListPageResponse]. + * + * The following fields are required: + * ```java + * .data() + * .firstId() + * .hasMore() + * .lastId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ChatCompletionListPageResponse]. */ + class Builder internal constructor() { + + private var data: JsonField>? = null + private var firstId: JsonField? = null + private var hasMore: JsonField? = null + private var lastId: JsonField? = null + private var object_: JsonValue = JsonValue.from("list") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(chatCompletionListPageResponse: ChatCompletionListPageResponse) = apply { + data = chatCompletionListPageResponse.data.map { it.toMutableList() } + firstId = chatCompletionListPageResponse.firstId + hasMore = chatCompletionListPageResponse.hasMore + lastId = chatCompletionListPageResponse.lastId + object_ = chatCompletionListPageResponse.object_ + additionalProperties = + chatCompletionListPageResponse.additionalProperties.toMutableMap() + } + + /** An array of chat completion objects. */ + fun data(data: List) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun data(data: JsonField>) = apply { + this.data = data.map { it.toMutableList() } + } + + /** + * Adds a single [ChatCompletion] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: ChatCompletion) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + /** The identifier of the first chat completion in the data array. */ + fun firstId(firstId: String) = firstId(JsonField.of(firstId)) + + /** + * Sets [Builder.firstId] to an arbitrary JSON value. + * + * You should usually call [Builder.firstId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun firstId(firstId: JsonField) = apply { this.firstId = firstId } + + /** Indicates whether there are more Chat Completions available. */ + fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) + + /** + * Sets [Builder.hasMore] to an arbitrary JSON value. + * + * You should usually call [Builder.hasMore] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } + + /** The identifier of the last chat completion in the data array. */ + fun lastId(lastId: String) = lastId(JsonField.of(lastId)) + + /** + * Sets [Builder.lastId] to an arbitrary JSON value. + * + * You should usually call [Builder.lastId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun lastId(lastId: JsonField) = apply { this.lastId = lastId } + + /** + * 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("list") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + 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 [ChatCompletionListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .firstId() + * .hasMore() + * .lastId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ChatCompletionListPageResponse = + ChatCompletionListPageResponse( + checkRequired("data", data).map { it.toImmutable() }, + checkRequired("firstId", firstId), + checkRequired("hasMore", hasMore), + checkRequired("lastId", lastId), + object_, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ChatCompletionListPageResponse = apply { + if (validated) { + return@apply + } + + data().forEach { it.validate() } + firstId() + hasMore() + lastId() + _object_().let { + if (it != JsonValue.from("list")) { + throw OpenAIInvalidDataException("'object_' 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 = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (firstId.asKnown().isPresent) 1 else 0) + + (if (hasMore.asKnown().isPresent) 1 else 0) + + (if (lastId.asKnown().isPresent) 1 else 0) + + object_.let { if (it == JsonValue.from("list")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ChatCompletionListPageResponse && data == other.data && firstId == other.firstId && hasMore == other.hasMore && lastId == other.lastId && object_ == other.object_ && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(data, firstId, hasMore, lastId, object_, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ChatCompletionListPageResponse{data=$data, firstId=$firstId, hasMore=$hasMore, lastId=$lastId, object_=$object_, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/chat/completions/messages/MessageListPage.kt b/openai-java-core/src/main/kotlin/com/openai/models/chat/completions/messages/MessageListPage.kt index 448d533b..4088b3ef 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/chat/completions/messages/MessageListPage.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/chat/completions/messages/MessageListPage.kt @@ -2,187 +2,117 @@ package com.openai.models.chat.completions.messages -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.errors.OpenAIInvalidDataException +import com.openai.core.checkRequired import com.openai.models.chat.completions.ChatCompletionStoreMessage import com.openai.services.blocking.chat.completions.MessageService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** - * Get the messages in a stored chat completion. Only Chat Completions that have been created with - * the `store` parameter set to `true` will be returned. - */ +/** @see [MessageService.list] */ class MessageListPage private constructor( - private val messagesService: MessageService, + private val service: MessageService, private val params: MessageListParams, - private val response: Response, + private val response: MessageListPageResponse, ) { - fun response(): Response = response + /** + * Delegates to [MessageListPageResponse], but gracefully handles missing data. + * + * @see [MessageListPageResponse.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() - fun data(): List = response().data() + /** + * Delegates to [MessageListPageResponse], but gracefully handles missing data. + * + * @see [MessageListPageResponse.hasMore] + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") - fun hasMore(): Optional = response().hasMore() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is MessageListPage && messagesService == other.messagesService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(messagesService, params, response) /* spotless:on */ - - override fun toString() = - "MessageListPage{messagesService=$messagesService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - return !data().isEmpty() - } + fun hasNextPage(): Boolean = data().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return Optional.of(params.toBuilder().after(data().last().id()).build()) + return Optional.of(params.toBuilder().after(data().last()._id().getOptional("id")).build()) } - fun getNextPage(): Optional { - return getNextPageParams().map { messagesService.list(it) } - } + fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) - companion object { + /** The parameters that were used to request this page. */ + fun params(): MessageListParams = params - @JvmStatic - fun of(messagesService: MessageService, params: MessageListParams, response: Response) = - MessageListPage(messagesService, params, response) - } + /** The response that this page was parsed from. */ + fun response(): MessageListPageResponse = response - class Response( - private val data: JsonField>, - private val hasMore: JsonField, - private val additionalProperties: MutableMap, - ) { + fun toBuilder() = Builder().from(this) - @JsonCreator - private constructor( - @JsonProperty("data") - data: JsonField> = JsonMissing.of(), - @JsonProperty("has_more") hasMore: JsonField = JsonMissing.of(), - ) : this(data, hasMore, mutableMapOf()) - - fun data(): List = - data.getOptional("data").getOrNull() ?: listOf() - - fun hasMore(): Optional = hasMore.getOptional("has_more") - - @JsonProperty("data") - fun _data(): Optional>> = - Optional.ofNullable(data) - - @JsonProperty("has_more") - fun _hasMore(): Optional> = Optional.ofNullable(hasMore) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - data().map { it.validate() } - hasMore() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && hasMore == other.hasMore && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, hasMore, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [MessageListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, hasMore=$hasMore, additionalProperties=$additionalProperties}" + /** A builder for [MessageListPage]. */ + class Builder internal constructor() { - companion object { + private var service: MessageService? = null + private var params: MessageListParams? = null + private var response: MessageListPageResponse? = null - /** Returns a mutable builder for constructing an instance of [MessageListPage]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(messageListPage: MessageListPage) = apply { + service = messageListPage.service + params = messageListPage.params + response = messageListPage.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var hasMore: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.hasMore = page.hasMore - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) - - fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(data, hasMore, additionalProperties.toMutableMap()) - } + fun service(service: MessageService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: MessageListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: MessageListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [MessageListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): MessageListPage = + MessageListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: MessageListPage) : Iterable { @@ -203,4 +133,17 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is MessageListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "MessageListPage{service=$service, params=$params, response=$response}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/chat/completions/messages/MessageListPageAsync.kt b/openai-java-core/src/main/kotlin/com/openai/models/chat/completions/messages/MessageListPageAsync.kt index 55f6e486..d013eff2 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/chat/completions/messages/MessageListPageAsync.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/chat/completions/messages/MessageListPageAsync.kt @@ -2,18 +2,9 @@ package com.openai.models.chat.completions.messages -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.errors.OpenAIInvalidDataException +import com.openai.core.checkRequired import com.openai.models.chat.completions.ChatCompletionStoreMessage import com.openai.services.async.chat.completions.MessageServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -21,174 +12,111 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** - * Get the messages in a stored chat completion. Only Chat Completions that have been created with - * the `store` parameter set to `true` will be returned. - */ +/** @see [MessageServiceAsync.list] */ class MessageListPageAsync private constructor( - private val messagesService: MessageServiceAsync, + private val service: MessageServiceAsync, private val params: MessageListParams, - private val response: Response, + private val response: MessageListPageResponse, ) { - fun response(): Response = response + /** + * Delegates to [MessageListPageResponse], but gracefully handles missing data. + * + * @see [MessageListPageResponse.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() - fun data(): List = response().data() + /** + * Delegates to [MessageListPageResponse], but gracefully handles missing data. + * + * @see [MessageListPageResponse.hasMore] + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") - fun hasMore(): Optional = response().hasMore() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is MessageListPageAsync && messagesService == other.messagesService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(messagesService, params, response) /* spotless:on */ - - override fun toString() = - "MessageListPageAsync{messagesService=$messagesService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - return !data().isEmpty() - } + fun hasNextPage(): Boolean = data().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return Optional.of(params.toBuilder().after(data().last().id()).build()) + return Optional.of(params.toBuilder().after(data().last()._id().getOptional("id")).build()) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { messagesService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of( - messagesService: MessageServiceAsync, - params: MessageListParams, - response: Response, - ) = MessageListPageAsync(messagesService, params, response) - } - - class Response( - private val data: JsonField>, - private val hasMore: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") - data: JsonField> = JsonMissing.of(), - @JsonProperty("has_more") hasMore: JsonField = JsonMissing.of(), - ) : this(data, hasMore, mutableMapOf()) - - fun data(): List = - data.getOptional("data").getOrNull() ?: listOf() - - fun hasMore(): Optional = hasMore.getOptional("has_more") - - @JsonProperty("data") - fun _data(): Optional>> = - Optional.ofNullable(data) - - @JsonProperty("has_more") - fun _hasMore(): Optional> = Optional.ofNullable(hasMore) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false + /** The parameters that were used to request this page. */ + fun params(): MessageListParams = params - fun validate(): Response = apply { - if (validated) { - return@apply - } + /** The response that this page was parsed from. */ + fun response(): MessageListPageResponse = response - data().map { it.validate() } - hasMore() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + fun toBuilder() = Builder().from(this) - return /* spotless:off */ other is Response && data == other.data && hasMore == other.hasMore && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, hasMore, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [MessageListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, hasMore=$hasMore, additionalProperties=$additionalProperties}" + /** A builder for [MessageListPageAsync]. */ + class Builder internal constructor() { - companion object { + private var service: MessageServiceAsync? = null + private var params: MessageListParams? = null + private var response: MessageListPageResponse? = null - /** Returns a mutable builder for constructing an instance of [MessageListPageAsync]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(messageListPageAsync: MessageListPageAsync) = apply { + service = messageListPageAsync.service + params = messageListPageAsync.params + response = messageListPageAsync.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var hasMore: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.hasMore = page.hasMore - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) - - fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(data, hasMore, additionalProperties.toMutableMap()) - } + fun service(service: MessageServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: MessageListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: MessageListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [MessageListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): MessageListPageAsync = + MessageListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: MessageListPageAsync) { @@ -219,4 +147,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is MessageListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "MessageListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/chat/completions/messages/MessageListPageResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/chat/completions/messages/MessageListPageResponse.kt new file mode 100644 index 00000000..33667398 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/chat/completions/messages/MessageListPageResponse.kt @@ -0,0 +1,341 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.chat.completions.messages + +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 com.openai.models.chat.completions.ChatCompletionStoreMessage +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +/** An object representing a list of chat completion messages. */ +class MessageListPageResponse +private constructor( + private val data: JsonField>, + private val firstId: JsonField, + private val hasMore: JsonField, + private val lastId: JsonField, + private val object_: JsonValue, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") + @ExcludeMissing + data: JsonField> = JsonMissing.of(), + @JsonProperty("first_id") @ExcludeMissing firstId: JsonField = JsonMissing.of(), + @JsonProperty("has_more") @ExcludeMissing hasMore: JsonField = JsonMissing.of(), + @JsonProperty("last_id") @ExcludeMissing lastId: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + ) : this(data, firstId, hasMore, lastId, object_, mutableMapOf()) + + /** + * An array of chat completion message objects. + * + * @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 data(): List = data.getRequired("data") + + /** + * The identifier of the first chat message in the data array. + * + * @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 firstId(): String = firstId.getRequired("first_id") + + /** + * Indicates whether there are more chat messages available. + * + * @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 hasMore(): Boolean = hasMore.getRequired("has_more") + + /** + * The identifier of the last chat message in the data array. + * + * @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 lastId(): String = lastId.getRequired("last_id") + + /** + * The type of this object. It is always set to "list". + * + * Expected to always return the following: + * ```java + * JsonValue.from("list") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") + @ExcludeMissing + fun _data(): JsonField> = data + + /** + * Returns the raw JSON value of [firstId]. + * + * Unlike [firstId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("first_id") @ExcludeMissing fun _firstId(): JsonField = firstId + + /** + * Returns the raw JSON value of [hasMore]. + * + * Unlike [hasMore], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("has_more") @ExcludeMissing fun _hasMore(): JsonField = hasMore + + /** + * Returns the raw JSON value of [lastId]. + * + * Unlike [lastId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("last_id") @ExcludeMissing fun _lastId(): JsonField = lastId + + @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 [MessageListPageResponse]. + * + * The following fields are required: + * ```java + * .data() + * .firstId() + * .hasMore() + * .lastId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [MessageListPageResponse]. */ + class Builder internal constructor() { + + private var data: JsonField>? = null + private var firstId: JsonField? = null + private var hasMore: JsonField? = null + private var lastId: JsonField? = null + private var object_: JsonValue = JsonValue.from("list") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(messageListPageResponse: MessageListPageResponse) = apply { + data = messageListPageResponse.data.map { it.toMutableList() } + firstId = messageListPageResponse.firstId + hasMore = messageListPageResponse.hasMore + lastId = messageListPageResponse.lastId + object_ = messageListPageResponse.object_ + additionalProperties = messageListPageResponse.additionalProperties.toMutableMap() + } + + /** An array of chat completion message objects. */ + fun data(data: List) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun data(data: JsonField>) = apply { + this.data = data.map { it.toMutableList() } + } + + /** + * Adds a single [ChatCompletionStoreMessage] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: ChatCompletionStoreMessage) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + /** The identifier of the first chat message in the data array. */ + fun firstId(firstId: String) = firstId(JsonField.of(firstId)) + + /** + * Sets [Builder.firstId] to an arbitrary JSON value. + * + * You should usually call [Builder.firstId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun firstId(firstId: JsonField) = apply { this.firstId = firstId } + + /** Indicates whether there are more chat messages available. */ + fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) + + /** + * Sets [Builder.hasMore] to an arbitrary JSON value. + * + * You should usually call [Builder.hasMore] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } + + /** The identifier of the last chat message in the data array. */ + fun lastId(lastId: String) = lastId(JsonField.of(lastId)) + + /** + * Sets [Builder.lastId] to an arbitrary JSON value. + * + * You should usually call [Builder.lastId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun lastId(lastId: JsonField) = apply { this.lastId = lastId } + + /** + * 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("list") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + 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 [MessageListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .firstId() + * .hasMore() + * .lastId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): MessageListPageResponse = + MessageListPageResponse( + checkRequired("data", data).map { it.toImmutable() }, + checkRequired("firstId", firstId), + checkRequired("hasMore", hasMore), + checkRequired("lastId", lastId), + object_, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): MessageListPageResponse = apply { + if (validated) { + return@apply + } + + data().forEach { it.validate() } + firstId() + hasMore() + lastId() + _object_().let { + if (it != JsonValue.from("list")) { + throw OpenAIInvalidDataException("'object_' 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 = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (firstId.asKnown().isPresent) 1 else 0) + + (if (hasMore.asKnown().isPresent) 1 else 0) + + (if (lastId.asKnown().isPresent) 1 else 0) + + object_.let { if (it == JsonValue.from("list")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is MessageListPageResponse && data == other.data && firstId == other.firstId && hasMore == other.hasMore && lastId == other.lastId && object_ == other.object_ && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(data, firstId, hasMore, lastId, object_, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "MessageListPageResponse{data=$data, firstId=$firstId, hasMore=$hasMore, lastId=$lastId, object_=$object_, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalListPage.kt b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalListPage.kt index 01acf382..aa65e3f9 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalListPage.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalListPage.kt @@ -2,180 +2,116 @@ package com.openai.models.evals -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import com.openai.core.ExcludeMissing -import com.openai.core.JsonField -import com.openai.core.JsonMissing -import com.openai.core.JsonValue -import com.openai.errors.OpenAIInvalidDataException +import com.openai.core.checkRequired import com.openai.services.blocking.EvalService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** List evaluations for a project. */ +/** @see [EvalService.list] */ class EvalListPage private constructor( - private val evalsService: EvalService, + private val service: EvalService, private val params: EvalListParams, - private val response: Response, + private val response: EvalListPageResponse, ) { - fun response(): Response = response + /** + * Delegates to [EvalListPageResponse], but gracefully handles missing data. + * + * @see [EvalListPageResponse.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() - fun data(): List = response().data() + /** + * Delegates to [EvalListPageResponse], but gracefully handles missing data. + * + * @see [EvalListPageResponse.hasMore] + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") - fun hasMore(): Optional = response().hasMore() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is EvalListPage && evalsService == other.evalsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(evalsService, params, response) /* spotless:on */ - - override fun toString() = - "EvalListPage{evalsService=$evalsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - return !data().isEmpty() - } + fun hasNextPage(): Boolean = data().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return Optional.of(params.toBuilder().after(data().last().id()).build()) + return Optional.of(params.toBuilder().after(data().last()._id().getOptional("id")).build()) } - fun getNextPage(): Optional { - return getNextPageParams().map { evalsService.list(it) } - } + fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of(evalsService: EvalService, params: EvalListParams, response: Response) = - EvalListPage(evalsService, params, response) - } - - class Response( - private val data: JsonField>, - private val hasMore: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("has_more") hasMore: JsonField = JsonMissing.of(), - ) : this(data, hasMore, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun hasMore(): Optional = hasMore.getOptional("has_more") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("has_more") - fun _hasMore(): Optional> = Optional.ofNullable(hasMore) + /** The parameters that were used to request this page. */ + fun params(): EvalListParams = params - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + /** The response that this page was parsed from. */ + fun response(): EvalListPageResponse = response - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } + fun toBuilder() = Builder().from(this) - data().map { it.validate() } - hasMore() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && hasMore == other.hasMore && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, hasMore, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [EvalListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, hasMore=$hasMore, additionalProperties=$additionalProperties}" + /** A builder for [EvalListPage]. */ + class Builder internal constructor() { - companion object { + private var service: EvalService? = null + private var params: EvalListParams? = null + private var response: EvalListPageResponse? = null - /** Returns a mutable builder for constructing an instance of [EvalListPage]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(evalListPage: EvalListPage) = apply { + service = evalListPage.service + params = evalListPage.params + response = evalListPage.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var hasMore: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.hasMore = page.hasMore - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) - - fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(data, hasMore, additionalProperties.toMutableMap()) - } + fun service(service: EvalService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: EvalListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: EvalListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [EvalListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EvalListPage = + EvalListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: EvalListPage) : Iterable { @@ -196,4 +132,16 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is EvalListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = "EvalListPage{service=$service, params=$params, response=$response}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalListPageAsync.kt b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalListPageAsync.kt index 8a38784d..d23299f4 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalListPageAsync.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalListPageAsync.kt @@ -2,17 +2,8 @@ package com.openai.models.evals -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonProperty -import com.openai.core.ExcludeMissing -import com.openai.core.JsonField -import com.openai.core.JsonMissing -import com.openai.core.JsonValue -import com.openai.errors.OpenAIInvalidDataException +import com.openai.core.checkRequired import com.openai.services.async.EvalServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -20,165 +11,111 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** List evaluations for a project. */ +/** @see [EvalServiceAsync.list] */ class EvalListPageAsync private constructor( - private val evalsService: EvalServiceAsync, + private val service: EvalServiceAsync, private val params: EvalListParams, - private val response: Response, + private val response: EvalListPageResponse, ) { - fun response(): Response = response + /** + * Delegates to [EvalListPageResponse], but gracefully handles missing data. + * + * @see [EvalListPageResponse.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() - fun data(): List = response().data() + /** + * Delegates to [EvalListPageResponse], but gracefully handles missing data. + * + * @see [EvalListPageResponse.hasMore] + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") - fun hasMore(): Optional = response().hasMore() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is EvalListPageAsync && evalsService == other.evalsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(evalsService, params, response) /* spotless:on */ - - override fun toString() = - "EvalListPageAsync{evalsService=$evalsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - return !data().isEmpty() - } + fun hasNextPage(): Boolean = data().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return Optional.of(params.toBuilder().after(data().last().id()).build()) + return Optional.of(params.toBuilder().after(data().last()._id().getOptional("id")).build()) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { evalsService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of(evalsService: EvalServiceAsync, params: EvalListParams, response: Response) = - EvalListPageAsync(evalsService, params, response) - } - - class Response( - private val data: JsonField>, - private val hasMore: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("has_more") hasMore: JsonField = JsonMissing.of(), - ) : this(data, hasMore, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun hasMore(): Optional = hasMore.getOptional("has_more") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("has_more") - fun _hasMore(): Optional> = Optional.ofNullable(hasMore) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false + /** The parameters that were used to request this page. */ + fun params(): EvalListParams = params - fun validate(): Response = apply { - if (validated) { - return@apply - } + /** The response that this page was parsed from. */ + fun response(): EvalListPageResponse = response - data().map { it.validate() } - hasMore() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + fun toBuilder() = Builder().from(this) - return /* spotless:off */ other is Response && data == other.data && hasMore == other.hasMore && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, hasMore, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [EvalListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, hasMore=$hasMore, additionalProperties=$additionalProperties}" + /** A builder for [EvalListPageAsync]. */ + class Builder internal constructor() { - companion object { + private var service: EvalServiceAsync? = null + private var params: EvalListParams? = null + private var response: EvalListPageResponse? = null - /** Returns a mutable builder for constructing an instance of [EvalListPageAsync]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(evalListPageAsync: EvalListPageAsync) = apply { + service = evalListPageAsync.service + params = evalListPageAsync.params + response = evalListPageAsync.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var hasMore: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.hasMore = page.hasMore - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) - - fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(data, hasMore, additionalProperties.toMutableMap()) - } + fun service(service: EvalServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: EvalListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: EvalListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [EvalListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EvalListPageAsync = + EvalListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: EvalListPageAsync) { @@ -209,4 +146,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is EvalListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "EvalListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalListPageResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalListPageResponse.kt new file mode 100644 index 00000000..727faaf4 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/evals/EvalListPageResponse.kt @@ -0,0 +1,338 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.evals + +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import com.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 + +/** An object representing a list of evals. */ +class EvalListPageResponse +private constructor( + private val data: JsonField>, + private val firstId: JsonField, + private val hasMore: JsonField, + private val lastId: JsonField, + private val object_: JsonValue, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") + @ExcludeMissing + data: JsonField> = JsonMissing.of(), + @JsonProperty("first_id") @ExcludeMissing firstId: JsonField = JsonMissing.of(), + @JsonProperty("has_more") @ExcludeMissing hasMore: JsonField = JsonMissing.of(), + @JsonProperty("last_id") @ExcludeMissing lastId: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + ) : this(data, firstId, hasMore, lastId, object_, mutableMapOf()) + + /** + * An array of eval objects. + * + * @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 data(): List = data.getRequired("data") + + /** + * The identifier of the first eval in the data array. + * + * @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 firstId(): String = firstId.getRequired("first_id") + + /** + * Indicates whether there are more evals available. + * + * @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 hasMore(): Boolean = hasMore.getRequired("has_more") + + /** + * The identifier of the last eval in the data array. + * + * @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 lastId(): String = lastId.getRequired("last_id") + + /** + * The type of this object. It is always set to "list". + * + * Expected to always return the following: + * ```java + * JsonValue.from("list") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField> = data + + /** + * Returns the raw JSON value of [firstId]. + * + * Unlike [firstId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("first_id") @ExcludeMissing fun _firstId(): JsonField = firstId + + /** + * Returns the raw JSON value of [hasMore]. + * + * Unlike [hasMore], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("has_more") @ExcludeMissing fun _hasMore(): JsonField = hasMore + + /** + * Returns the raw JSON value of [lastId]. + * + * Unlike [lastId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("last_id") @ExcludeMissing fun _lastId(): JsonField = lastId + + @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 [EvalListPageResponse]. + * + * The following fields are required: + * ```java + * .data() + * .firstId() + * .hasMore() + * .lastId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [EvalListPageResponse]. */ + class Builder internal constructor() { + + private var data: JsonField>? = null + private var firstId: JsonField? = null + private var hasMore: JsonField? = null + private var lastId: JsonField? = null + private var object_: JsonValue = JsonValue.from("list") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(evalListPageResponse: EvalListPageResponse) = apply { + data = evalListPageResponse.data.map { it.toMutableList() } + firstId = evalListPageResponse.firstId + hasMore = evalListPageResponse.hasMore + lastId = evalListPageResponse.lastId + object_ = evalListPageResponse.object_ + additionalProperties = evalListPageResponse.additionalProperties.toMutableMap() + } + + /** An array of eval objects. */ + fun data(data: List) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun data(data: JsonField>) = apply { + this.data = data.map { it.toMutableList() } + } + + /** + * Adds a single [EvalListResponse] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: EvalListResponse) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + /** The identifier of the first eval in the data array. */ + fun firstId(firstId: String) = firstId(JsonField.of(firstId)) + + /** + * Sets [Builder.firstId] to an arbitrary JSON value. + * + * You should usually call [Builder.firstId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun firstId(firstId: JsonField) = apply { this.firstId = firstId } + + /** Indicates whether there are more evals available. */ + fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) + + /** + * Sets [Builder.hasMore] to an arbitrary JSON value. + * + * You should usually call [Builder.hasMore] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } + + /** The identifier of the last eval in the data array. */ + fun lastId(lastId: String) = lastId(JsonField.of(lastId)) + + /** + * Sets [Builder.lastId] to an arbitrary JSON value. + * + * You should usually call [Builder.lastId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun lastId(lastId: JsonField) = apply { this.lastId = lastId } + + /** + * 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("list") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + 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 [EvalListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .firstId() + * .hasMore() + * .lastId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): EvalListPageResponse = + EvalListPageResponse( + checkRequired("data", data).map { it.toImmutable() }, + checkRequired("firstId", firstId), + checkRequired("hasMore", hasMore), + checkRequired("lastId", lastId), + object_, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): EvalListPageResponse = apply { + if (validated) { + return@apply + } + + data().forEach { it.validate() } + firstId() + hasMore() + lastId() + _object_().let { + if (it != JsonValue.from("list")) { + throw OpenAIInvalidDataException("'object_' 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 = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (firstId.asKnown().isPresent) 1 else 0) + + (if (hasMore.asKnown().isPresent) 1 else 0) + + (if (lastId.asKnown().isPresent) 1 else 0) + + object_.let { if (it == JsonValue.from("list")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is EvalListPageResponse && data == other.data && firstId == other.firstId && hasMore == other.hasMore && lastId == other.lastId && object_ == other.object_ && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(data, firstId, hasMore, lastId, object_, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "EvalListPageResponse{data=$data, firstId=$firstId, hasMore=$hasMore, lastId=$lastId, object_=$object_, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/RunListPage.kt b/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/RunListPage.kt index 117a771a..ca22d061 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/RunListPage.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/RunListPage.kt @@ -2,180 +2,116 @@ package com.openai.models.evals.runs -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.errors.OpenAIInvalidDataException +import com.openai.core.checkRequired import com.openai.services.blocking.evals.RunService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** Get a list of runs for an evaluation. */ +/** @see [RunService.list] */ class RunListPage private constructor( - private val runsService: RunService, + private val service: RunService, private val params: RunListParams, - private val response: Response, + private val response: RunListPageResponse, ) { - fun response(): Response = response + /** + * Delegates to [RunListPageResponse], but gracefully handles missing data. + * + * @see [RunListPageResponse.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() - fun data(): List = response().data() + /** + * Delegates to [RunListPageResponse], but gracefully handles missing data. + * + * @see [RunListPageResponse.hasMore] + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") - fun hasMore(): Optional = response().hasMore() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is RunListPage && runsService == other.runsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(runsService, params, response) /* spotless:on */ - - override fun toString() = - "RunListPage{runsService=$runsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - return !data().isEmpty() - } + fun hasNextPage(): Boolean = data().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return Optional.of(params.toBuilder().after(data().last().id()).build()) + return Optional.of(params.toBuilder().after(data().last()._id().getOptional("id")).build()) } - fun getNextPage(): Optional { - return getNextPageParams().map { runsService.list(it) } - } + fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of(runsService: RunService, params: RunListParams, response: Response) = - RunListPage(runsService, params, response) - } - - class Response( - private val data: JsonField>, - private val hasMore: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("has_more") hasMore: JsonField = JsonMissing.of(), - ) : this(data, hasMore, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun hasMore(): Optional = hasMore.getOptional("has_more") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("has_more") - fun _hasMore(): Optional> = Optional.ofNullable(hasMore) + /** The parameters that were used to request this page. */ + fun params(): RunListParams = params - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + /** The response that this page was parsed from. */ + fun response(): RunListPageResponse = response - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } + fun toBuilder() = Builder().from(this) - data().map { it.validate() } - hasMore() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && hasMore == other.hasMore && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, hasMore, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [RunListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, hasMore=$hasMore, additionalProperties=$additionalProperties}" + /** A builder for [RunListPage]. */ + class Builder internal constructor() { - companion object { + private var service: RunService? = null + private var params: RunListParams? = null + private var response: RunListPageResponse? = null - /** Returns a mutable builder for constructing an instance of [RunListPage]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(runListPage: RunListPage) = apply { + service = runListPage.service + params = runListPage.params + response = runListPage.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var hasMore: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.hasMore = page.hasMore - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) - - fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(data, hasMore, additionalProperties.toMutableMap()) - } + fun service(service: RunService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: RunListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: RunListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [RunListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RunListPage = + RunListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: RunListPage) : Iterable { @@ -196,4 +132,16 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is RunListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = "RunListPage{service=$service, params=$params, response=$response}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/RunListPageAsync.kt b/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/RunListPageAsync.kt index 21b08007..f159f392 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/RunListPageAsync.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/RunListPageAsync.kt @@ -2,17 +2,8 @@ package com.openai.models.evals.runs -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.errors.OpenAIInvalidDataException +import com.openai.core.checkRequired import com.openai.services.async.evals.RunServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -20,165 +11,111 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** Get a list of runs for an evaluation. */ +/** @see [RunServiceAsync.list] */ class RunListPageAsync private constructor( - private val runsService: RunServiceAsync, + private val service: RunServiceAsync, private val params: RunListParams, - private val response: Response, + private val response: RunListPageResponse, ) { - fun response(): Response = response + /** + * Delegates to [RunListPageResponse], but gracefully handles missing data. + * + * @see [RunListPageResponse.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() - fun data(): List = response().data() + /** + * Delegates to [RunListPageResponse], but gracefully handles missing data. + * + * @see [RunListPageResponse.hasMore] + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") - fun hasMore(): Optional = response().hasMore() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is RunListPageAsync && runsService == other.runsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(runsService, params, response) /* spotless:on */ - - override fun toString() = - "RunListPageAsync{runsService=$runsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - return !data().isEmpty() - } + fun hasNextPage(): Boolean = data().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return Optional.of(params.toBuilder().after(data().last().id()).build()) + return Optional.of(params.toBuilder().after(data().last()._id().getOptional("id")).build()) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { runsService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of(runsService: RunServiceAsync, params: RunListParams, response: Response) = - RunListPageAsync(runsService, params, response) - } - - class Response( - private val data: JsonField>, - private val hasMore: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("has_more") hasMore: JsonField = JsonMissing.of(), - ) : this(data, hasMore, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun hasMore(): Optional = hasMore.getOptional("has_more") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("has_more") - fun _hasMore(): Optional> = Optional.ofNullable(hasMore) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false + /** The parameters that were used to request this page. */ + fun params(): RunListParams = params - fun validate(): Response = apply { - if (validated) { - return@apply - } + /** The response that this page was parsed from. */ + fun response(): RunListPageResponse = response - data().map { it.validate() } - hasMore() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + fun toBuilder() = Builder().from(this) - return /* spotless:off */ other is Response && data == other.data && hasMore == other.hasMore && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, hasMore, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [RunListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, hasMore=$hasMore, additionalProperties=$additionalProperties}" + /** A builder for [RunListPageAsync]. */ + class Builder internal constructor() { - companion object { + private var service: RunServiceAsync? = null + private var params: RunListParams? = null + private var response: RunListPageResponse? = null - /** Returns a mutable builder for constructing an instance of [RunListPageAsync]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(runListPageAsync: RunListPageAsync) = apply { + service = runListPageAsync.service + params = runListPageAsync.params + response = runListPageAsync.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var hasMore: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.hasMore = page.hasMore - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) - - fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(data, hasMore, additionalProperties.toMutableMap()) - } + fun service(service: RunServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: RunListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: RunListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [RunListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RunListPageAsync = + RunListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: RunListPageAsync) { @@ -209,4 +146,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is RunListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "RunListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/RunListPageResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/RunListPageResponse.kt new file mode 100644 index 00000000..555bbfa7 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/RunListPageResponse.kt @@ -0,0 +1,338 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.evals.runs + +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 + +/** An object representing a list of runs for an evaluation. */ +class RunListPageResponse +private constructor( + private val data: JsonField>, + private val firstId: JsonField, + private val hasMore: JsonField, + private val lastId: JsonField, + private val object_: JsonValue, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") + @ExcludeMissing + data: JsonField> = JsonMissing.of(), + @JsonProperty("first_id") @ExcludeMissing firstId: JsonField = JsonMissing.of(), + @JsonProperty("has_more") @ExcludeMissing hasMore: JsonField = JsonMissing.of(), + @JsonProperty("last_id") @ExcludeMissing lastId: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + ) : this(data, firstId, hasMore, lastId, object_, mutableMapOf()) + + /** + * An array of eval run objects. + * + * @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 data(): List = data.getRequired("data") + + /** + * The identifier of the first eval run in the data array. + * + * @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 firstId(): String = firstId.getRequired("first_id") + + /** + * Indicates whether there are more evals available. + * + * @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 hasMore(): Boolean = hasMore.getRequired("has_more") + + /** + * The identifier of the last eval run in the data array. + * + * @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 lastId(): String = lastId.getRequired("last_id") + + /** + * The type of this object. It is always set to "list". + * + * Expected to always return the following: + * ```java + * JsonValue.from("list") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField> = data + + /** + * Returns the raw JSON value of [firstId]. + * + * Unlike [firstId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("first_id") @ExcludeMissing fun _firstId(): JsonField = firstId + + /** + * Returns the raw JSON value of [hasMore]. + * + * Unlike [hasMore], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("has_more") @ExcludeMissing fun _hasMore(): JsonField = hasMore + + /** + * Returns the raw JSON value of [lastId]. + * + * Unlike [lastId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("last_id") @ExcludeMissing fun _lastId(): JsonField = lastId + + @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 [RunListPageResponse]. + * + * The following fields are required: + * ```java + * .data() + * .firstId() + * .hasMore() + * .lastId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RunListPageResponse]. */ + class Builder internal constructor() { + + private var data: JsonField>? = null + private var firstId: JsonField? = null + private var hasMore: JsonField? = null + private var lastId: JsonField? = null + private var object_: JsonValue = JsonValue.from("list") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(runListPageResponse: RunListPageResponse) = apply { + data = runListPageResponse.data.map { it.toMutableList() } + firstId = runListPageResponse.firstId + hasMore = runListPageResponse.hasMore + lastId = runListPageResponse.lastId + object_ = runListPageResponse.object_ + additionalProperties = runListPageResponse.additionalProperties.toMutableMap() + } + + /** An array of eval run objects. */ + fun data(data: List) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun data(data: JsonField>) = apply { + this.data = data.map { it.toMutableList() } + } + + /** + * Adds a single [RunListResponse] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: RunListResponse) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + /** The identifier of the first eval run in the data array. */ + fun firstId(firstId: String) = firstId(JsonField.of(firstId)) + + /** + * Sets [Builder.firstId] to an arbitrary JSON value. + * + * You should usually call [Builder.firstId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun firstId(firstId: JsonField) = apply { this.firstId = firstId } + + /** Indicates whether there are more evals available. */ + fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) + + /** + * Sets [Builder.hasMore] to an arbitrary JSON value. + * + * You should usually call [Builder.hasMore] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } + + /** The identifier of the last eval run in the data array. */ + fun lastId(lastId: String) = lastId(JsonField.of(lastId)) + + /** + * Sets [Builder.lastId] to an arbitrary JSON value. + * + * You should usually call [Builder.lastId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun lastId(lastId: JsonField) = apply { this.lastId = lastId } + + /** + * 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("list") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + 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 [RunListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .firstId() + * .hasMore() + * .lastId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RunListPageResponse = + RunListPageResponse( + checkRequired("data", data).map { it.toImmutable() }, + checkRequired("firstId", firstId), + checkRequired("hasMore", hasMore), + checkRequired("lastId", lastId), + object_, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): RunListPageResponse = apply { + if (validated) { + return@apply + } + + data().forEach { it.validate() } + firstId() + hasMore() + lastId() + _object_().let { + if (it != JsonValue.from("list")) { + throw OpenAIInvalidDataException("'object_' 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 = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (firstId.asKnown().isPresent) 1 else 0) + + (if (hasMore.asKnown().isPresent) 1 else 0) + + (if (lastId.asKnown().isPresent) 1 else 0) + + object_.let { if (it == JsonValue.from("list")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is RunListPageResponse && data == other.data && firstId == other.firstId && hasMore == other.hasMore && lastId == other.lastId && object_ == other.object_ && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(data, firstId, hasMore, lastId, object_, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "RunListPageResponse{data=$data, firstId=$firstId, hasMore=$hasMore, lastId=$lastId, object_=$object_, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/outputitems/OutputItemListPage.kt b/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/outputitems/OutputItemListPage.kt index 1b8d9101..e24395a2 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/outputitems/OutputItemListPage.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/outputitems/OutputItemListPage.kt @@ -2,183 +2,116 @@ package com.openai.models.evals.runs.outputitems -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.errors.OpenAIInvalidDataException +import com.openai.core.checkRequired import com.openai.services.blocking.evals.runs.OutputItemService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** Get a list of output items for an evaluation run. */ +/** @see [OutputItemService.list] */ class OutputItemListPage private constructor( - private val outputItemsService: OutputItemService, + private val service: OutputItemService, private val params: OutputItemListParams, - private val response: Response, + private val response: OutputItemListPageResponse, ) { - fun response(): Response = response + /** + * Delegates to [OutputItemListPageResponse], but gracefully handles missing data. + * + * @see [OutputItemListPageResponse.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() - fun data(): List = response().data() + /** + * Delegates to [OutputItemListPageResponse], but gracefully handles missing data. + * + * @see [OutputItemListPageResponse.hasMore] + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") - fun hasMore(): Optional = response().hasMore() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is OutputItemListPage && outputItemsService == other.outputItemsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(outputItemsService, params, response) /* spotless:on */ - - override fun toString() = - "OutputItemListPage{outputItemsService=$outputItemsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - return !data().isEmpty() - } + fun hasNextPage(): Boolean = data().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return Optional.of(params.toBuilder().after(data().last().id()).build()) + return Optional.of(params.toBuilder().after(data().last()._id().getOptional("id")).build()) } - fun getNextPage(): Optional { - return getNextPageParams().map { outputItemsService.list(it) } - } + fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) - companion object { + /** The parameters that were used to request this page. */ + fun params(): OutputItemListParams = params - @JvmStatic - fun of( - outputItemsService: OutputItemService, - params: OutputItemListParams, - response: Response, - ) = OutputItemListPage(outputItemsService, params, response) - } + /** The response that this page was parsed from. */ + fun response(): OutputItemListPageResponse = response - class Response( - private val data: JsonField>, - private val hasMore: JsonField, - private val additionalProperties: MutableMap, - ) { + fun toBuilder() = Builder().from(this) - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("has_more") hasMore: JsonField = JsonMissing.of(), - ) : this(data, hasMore, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun hasMore(): Optional = hasMore.getOptional("has_more") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("has_more") - fun _hasMore(): Optional> = Optional.ofNullable(hasMore) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - data().map { it.validate() } - hasMore() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && hasMore == other.hasMore && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, hasMore, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [OutputItemListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, hasMore=$hasMore, additionalProperties=$additionalProperties}" + /** A builder for [OutputItemListPage]. */ + class Builder internal constructor() { - companion object { + private var service: OutputItemService? = null + private var params: OutputItemListParams? = null + private var response: OutputItemListPageResponse? = null - /** Returns a mutable builder for constructing an instance of [OutputItemListPage]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(outputItemListPage: OutputItemListPage) = apply { + service = outputItemListPage.service + params = outputItemListPage.params + response = outputItemListPage.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var hasMore: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.hasMore = page.hasMore - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) - - fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(data, hasMore, additionalProperties.toMutableMap()) - } + fun service(service: OutputItemService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: OutputItemListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: OutputItemListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [OutputItemListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OutputItemListPage = + OutputItemListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: OutputItemListPage) : Iterable { @@ -199,4 +132,17 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is OutputItemListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "OutputItemListPage{service=$service, params=$params, response=$response}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/outputitems/OutputItemListPageAsync.kt b/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/outputitems/OutputItemListPageAsync.kt index eee73e54..9e5c9635 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/outputitems/OutputItemListPageAsync.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/outputitems/OutputItemListPageAsync.kt @@ -2,17 +2,8 @@ package com.openai.models.evals.runs.outputitems -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.errors.OpenAIInvalidDataException +import com.openai.core.checkRequired import com.openai.services.async.evals.runs.OutputItemServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -20,170 +11,111 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** Get a list of output items for an evaluation run. */ +/** @see [OutputItemServiceAsync.list] */ class OutputItemListPageAsync private constructor( - private val outputItemsService: OutputItemServiceAsync, + private val service: OutputItemServiceAsync, private val params: OutputItemListParams, - private val response: Response, + private val response: OutputItemListPageResponse, ) { - fun response(): Response = response + /** + * Delegates to [OutputItemListPageResponse], but gracefully handles missing data. + * + * @see [OutputItemListPageResponse.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() - fun data(): List = response().data() + /** + * Delegates to [OutputItemListPageResponse], but gracefully handles missing data. + * + * @see [OutputItemListPageResponse.hasMore] + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") - fun hasMore(): Optional = response().hasMore() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is OutputItemListPageAsync && outputItemsService == other.outputItemsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(outputItemsService, params, response) /* spotless:on */ - - override fun toString() = - "OutputItemListPageAsync{outputItemsService=$outputItemsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - return !data().isEmpty() - } + fun hasNextPage(): Boolean = data().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return Optional.of(params.toBuilder().after(data().last().id()).build()) + return Optional.of(params.toBuilder().after(data().last()._id().getOptional("id")).build()) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { outputItemsService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of( - outputItemsService: OutputItemServiceAsync, - params: OutputItemListParams, - response: Response, - ) = OutputItemListPageAsync(outputItemsService, params, response) - } - - class Response( - private val data: JsonField>, - private val hasMore: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("has_more") hasMore: JsonField = JsonMissing.of(), - ) : this(data, hasMore, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun hasMore(): Optional = hasMore.getOptional("has_more") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("has_more") - fun _hasMore(): Optional> = Optional.ofNullable(hasMore) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false + /** The parameters that were used to request this page. */ + fun params(): OutputItemListParams = params - fun validate(): Response = apply { - if (validated) { - return@apply - } + /** The response that this page was parsed from. */ + fun response(): OutputItemListPageResponse = response - data().map { it.validate() } - hasMore() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + fun toBuilder() = Builder().from(this) - return /* spotless:off */ other is Response && data == other.data && hasMore == other.hasMore && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, hasMore, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [OutputItemListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, hasMore=$hasMore, additionalProperties=$additionalProperties}" + /** A builder for [OutputItemListPageAsync]. */ + class Builder internal constructor() { - companion object { + private var service: OutputItemServiceAsync? = null + private var params: OutputItemListParams? = null + private var response: OutputItemListPageResponse? = null - /** - * Returns a mutable builder for constructing an instance of [OutputItemListPageAsync]. - */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(outputItemListPageAsync: OutputItemListPageAsync) = apply { + service = outputItemListPageAsync.service + params = outputItemListPageAsync.params + response = outputItemListPageAsync.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var hasMore: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.hasMore = page.hasMore - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) - - fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(data, hasMore, additionalProperties.toMutableMap()) - } + fun service(service: OutputItemServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: OutputItemListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: OutputItemListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [OutputItemListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OutputItemListPageAsync = + OutputItemListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: OutputItemListPageAsync) { @@ -214,4 +146,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is OutputItemListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "OutputItemListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/outputitems/OutputItemListPageResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/outputitems/OutputItemListPageResponse.kt new file mode 100644 index 00000000..6d09b3c8 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/evals/runs/outputitems/OutputItemListPageResponse.kt @@ -0,0 +1,340 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.evals.runs.outputitems + +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 + +/** An object representing a list of output items for an evaluation run. */ +class OutputItemListPageResponse +private constructor( + private val data: JsonField>, + private val firstId: JsonField, + private val hasMore: JsonField, + private val lastId: JsonField, + private val object_: JsonValue, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") + @ExcludeMissing + data: JsonField> = JsonMissing.of(), + @JsonProperty("first_id") @ExcludeMissing firstId: JsonField = JsonMissing.of(), + @JsonProperty("has_more") @ExcludeMissing hasMore: JsonField = JsonMissing.of(), + @JsonProperty("last_id") @ExcludeMissing lastId: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + ) : this(data, firstId, hasMore, lastId, object_, mutableMapOf()) + + /** + * An array of eval run output item objects. + * + * @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 data(): List = data.getRequired("data") + + /** + * The identifier of the first eval run output item in the data array. + * + * @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 firstId(): String = firstId.getRequired("first_id") + + /** + * Indicates whether there are more eval run output items available. + * + * @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 hasMore(): Boolean = hasMore.getRequired("has_more") + + /** + * The identifier of the last eval run output item in the data array. + * + * @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 lastId(): String = lastId.getRequired("last_id") + + /** + * The type of this object. It is always set to "list". + * + * Expected to always return the following: + * ```java + * JsonValue.from("list") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") + @ExcludeMissing + fun _data(): JsonField> = data + + /** + * Returns the raw JSON value of [firstId]. + * + * Unlike [firstId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("first_id") @ExcludeMissing fun _firstId(): JsonField = firstId + + /** + * Returns the raw JSON value of [hasMore]. + * + * Unlike [hasMore], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("has_more") @ExcludeMissing fun _hasMore(): JsonField = hasMore + + /** + * Returns the raw JSON value of [lastId]. + * + * Unlike [lastId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("last_id") @ExcludeMissing fun _lastId(): JsonField = lastId + + @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 [OutputItemListPageResponse]. + * + * The following fields are required: + * ```java + * .data() + * .firstId() + * .hasMore() + * .lastId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [OutputItemListPageResponse]. */ + class Builder internal constructor() { + + private var data: JsonField>? = null + private var firstId: JsonField? = null + private var hasMore: JsonField? = null + private var lastId: JsonField? = null + private var object_: JsonValue = JsonValue.from("list") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(outputItemListPageResponse: OutputItemListPageResponse) = apply { + data = outputItemListPageResponse.data.map { it.toMutableList() } + firstId = outputItemListPageResponse.firstId + hasMore = outputItemListPageResponse.hasMore + lastId = outputItemListPageResponse.lastId + object_ = outputItemListPageResponse.object_ + additionalProperties = outputItemListPageResponse.additionalProperties.toMutableMap() + } + + /** An array of eval run output item objects. */ + fun data(data: List) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun data(data: JsonField>) = apply { + this.data = data.map { it.toMutableList() } + } + + /** + * Adds a single [OutputItemListResponse] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: OutputItemListResponse) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + /** The identifier of the first eval run output item in the data array. */ + fun firstId(firstId: String) = firstId(JsonField.of(firstId)) + + /** + * Sets [Builder.firstId] to an arbitrary JSON value. + * + * You should usually call [Builder.firstId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun firstId(firstId: JsonField) = apply { this.firstId = firstId } + + /** Indicates whether there are more eval run output items available. */ + fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) + + /** + * Sets [Builder.hasMore] to an arbitrary JSON value. + * + * You should usually call [Builder.hasMore] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } + + /** The identifier of the last eval run output item in the data array. */ + fun lastId(lastId: String) = lastId(JsonField.of(lastId)) + + /** + * Sets [Builder.lastId] to an arbitrary JSON value. + * + * You should usually call [Builder.lastId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun lastId(lastId: JsonField) = apply { this.lastId = lastId } + + /** + * 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("list") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + 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 [OutputItemListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .firstId() + * .hasMore() + * .lastId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): OutputItemListPageResponse = + OutputItemListPageResponse( + checkRequired("data", data).map { it.toImmutable() }, + checkRequired("firstId", firstId), + checkRequired("hasMore", hasMore), + checkRequired("lastId", lastId), + object_, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): OutputItemListPageResponse = apply { + if (validated) { + return@apply + } + + data().forEach { it.validate() } + firstId() + hasMore() + lastId() + _object_().let { + if (it != JsonValue.from("list")) { + throw OpenAIInvalidDataException("'object_' 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 = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (firstId.asKnown().isPresent) 1 else 0) + + (if (hasMore.asKnown().isPresent) 1 else 0) + + (if (lastId.asKnown().isPresent) 1 else 0) + + object_.let { if (it == JsonValue.from("list")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is OutputItemListPageResponse && data == other.data && firstId == other.firstId && hasMore == other.hasMore && lastId == other.lastId && object_ == other.object_ && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(data, firstId, hasMore, lastId, object_, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "OutputItemListPageResponse{data=$data, firstId=$firstId, hasMore=$hasMore, lastId=$lastId, object_=$object_, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/files/FileListPage.kt b/openai-java-core/src/main/kotlin/com/openai/models/files/FileListPage.kt index b0dde91d..2aa16da3 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/files/FileListPage.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/files/FileListPage.kt @@ -2,180 +2,115 @@ package com.openai.models.files -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.errors.OpenAIInvalidDataException +import com.openai.core.checkRequired import com.openai.services.blocking.FileService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** Returns a list of files. */ +/** @see [FileService.list] */ class FileListPage private constructor( - private val filesService: FileService, + private val service: FileService, private val params: FileListParams, - private val response: Response, + private val response: FileListPageResponse, ) { - fun response(): Response = response + /** + * Delegates to [FileListPageResponse], but gracefully handles missing data. + * + * @see [FileListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() - fun data(): List = response().data() + /** + * Delegates to [FileListPageResponse], but gracefully handles missing data. + * + * @see [FileListPageResponse.hasMore] + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") - fun hasMore(): Optional = response().hasMore() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is FileListPage && filesService == other.filesService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(filesService, params, response) /* spotless:on */ - - override fun toString() = - "FileListPage{filesService=$filesService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - return !data().isEmpty() - } + fun hasNextPage(): Boolean = data().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return Optional.of(params.toBuilder().after(data().last().id()).build()) + return Optional.of(params.toBuilder().after(data().last()._id().getOptional("id")).build()) } - fun getNextPage(): Optional { - return getNextPageParams().map { filesService.list(it) } - } + fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of(filesService: FileService, params: FileListParams, response: Response) = - FileListPage(filesService, params, response) - } - - class Response( - private val data: JsonField>, - private val hasMore: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("has_more") hasMore: JsonField = JsonMissing.of(), - ) : this(data, hasMore, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun hasMore(): Optional = hasMore.getOptional("has_more") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("has_more") - fun _hasMore(): Optional> = Optional.ofNullable(hasMore) + /** The parameters that were used to request this page. */ + fun params(): FileListParams = params - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + /** The response that this page was parsed from. */ + fun response(): FileListPageResponse = response - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } + fun toBuilder() = Builder().from(this) - data().map { it.validate() } - hasMore() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && hasMore == other.hasMore && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, hasMore, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [FileListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, hasMore=$hasMore, additionalProperties=$additionalProperties}" + /** A builder for [FileListPage]. */ + class Builder internal constructor() { - companion object { + private var service: FileService? = null + private var params: FileListParams? = null + private var response: FileListPageResponse? = null - /** Returns a mutable builder for constructing an instance of [FileListPage]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(fileListPage: FileListPage) = apply { + service = fileListPage.service + params = fileListPage.params + response = fileListPage.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var hasMore: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.hasMore = page.hasMore - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) - - fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(data, hasMore, additionalProperties.toMutableMap()) - } + fun service(service: FileService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: FileListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: FileListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [FileListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): FileListPage = + FileListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: FileListPage) : Iterable { @@ -196,4 +131,16 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is FileListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = "FileListPage{service=$service, params=$params, response=$response}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/files/FileListPageAsync.kt b/openai-java-core/src/main/kotlin/com/openai/models/files/FileListPageAsync.kt index fd7c0f3d..ec8e2d6c 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/files/FileListPageAsync.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/files/FileListPageAsync.kt @@ -2,17 +2,8 @@ package com.openai.models.files -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.errors.OpenAIInvalidDataException +import com.openai.core.checkRequired import com.openai.services.async.FileServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -20,165 +11,110 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** Returns a list of files. */ +/** @see [FileServiceAsync.list] */ class FileListPageAsync private constructor( - private val filesService: FileServiceAsync, + private val service: FileServiceAsync, private val params: FileListParams, - private val response: Response, + private val response: FileListPageResponse, ) { - fun response(): Response = response + /** + * Delegates to [FileListPageResponse], but gracefully handles missing data. + * + * @see [FileListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() - fun data(): List = response().data() + /** + * Delegates to [FileListPageResponse], but gracefully handles missing data. + * + * @see [FileListPageResponse.hasMore] + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") - fun hasMore(): Optional = response().hasMore() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is FileListPageAsync && filesService == other.filesService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(filesService, params, response) /* spotless:on */ - - override fun toString() = - "FileListPageAsync{filesService=$filesService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - return !data().isEmpty() - } + fun hasNextPage(): Boolean = data().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return Optional.of(params.toBuilder().after(data().last().id()).build()) + return Optional.of(params.toBuilder().after(data().last()._id().getOptional("id")).build()) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { filesService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of(filesService: FileServiceAsync, params: FileListParams, response: Response) = - FileListPageAsync(filesService, params, response) - } - - class Response( - private val data: JsonField>, - private val hasMore: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("has_more") hasMore: JsonField = JsonMissing.of(), - ) : this(data, hasMore, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun hasMore(): Optional = hasMore.getOptional("has_more") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("has_more") - fun _hasMore(): Optional> = Optional.ofNullable(hasMore) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false + /** The parameters that were used to request this page. */ + fun params(): FileListParams = params - fun validate(): Response = apply { - if (validated) { - return@apply - } + /** The response that this page was parsed from. */ + fun response(): FileListPageResponse = response - data().map { it.validate() } - hasMore() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + fun toBuilder() = Builder().from(this) - return /* spotless:off */ other is Response && data == other.data && hasMore == other.hasMore && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, hasMore, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [FileListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, hasMore=$hasMore, additionalProperties=$additionalProperties}" + /** A builder for [FileListPageAsync]. */ + class Builder internal constructor() { - companion object { + private var service: FileServiceAsync? = null + private var params: FileListParams? = null + private var response: FileListPageResponse? = null - /** Returns a mutable builder for constructing an instance of [FileListPageAsync]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(fileListPageAsync: FileListPageAsync) = apply { + service = fileListPageAsync.service + params = fileListPageAsync.params + response = fileListPageAsync.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var hasMore: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.hasMore = page.hasMore - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) - - fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(data, hasMore, additionalProperties.toMutableMap()) - } + fun service(service: FileServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: FileListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: FileListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [FileListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): FileListPageAsync = + FileListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: FileListPageAsync) { @@ -206,4 +142,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is FileListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "FileListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/files/FileListPageResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/files/FileListPageResponse.kt new file mode 100644 index 00000000..7cf59160 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/files/FileListPageResponse.kt @@ -0,0 +1,317 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.files + +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 FileListPageResponse +private constructor( + private val data: JsonField>, + private val firstId: JsonField, + private val hasMore: JsonField, + private val lastId: JsonField, + private val object_: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") @ExcludeMissing data: JsonField> = JsonMissing.of(), + @JsonProperty("first_id") @ExcludeMissing firstId: JsonField = JsonMissing.of(), + @JsonProperty("has_more") @ExcludeMissing hasMore: JsonField = JsonMissing.of(), + @JsonProperty("last_id") @ExcludeMissing lastId: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonField = JsonMissing.of(), + ) : this(data, firstId, hasMore, lastId, object_, 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 data(): List = data.getRequired("data") + + /** + * @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 firstId(): String = firstId.getRequired("first_id") + + /** + * @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 hasMore(): Boolean = hasMore.getRequired("has_more") + + /** + * @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 lastId(): String = lastId.getRequired("last_id") + + /** + * @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 object_(): String = object_.getRequired("object") + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField> = data + + /** + * Returns the raw JSON value of [firstId]. + * + * Unlike [firstId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("first_id") @ExcludeMissing fun _firstId(): JsonField = firstId + + /** + * Returns the raw JSON value of [hasMore]. + * + * Unlike [hasMore], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("has_more") @ExcludeMissing fun _hasMore(): JsonField = hasMore + + /** + * Returns the raw JSON value of [lastId]. + * + * Unlike [lastId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("last_id") @ExcludeMissing fun _lastId(): JsonField = lastId + + /** + * Returns the raw JSON value of [object_]. + * + * Unlike [object_], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonField = object_ + + @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 [FileListPageResponse]. + * + * The following fields are required: + * ```java + * .data() + * .firstId() + * .hasMore() + * .lastId() + * .object_() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [FileListPageResponse]. */ + class Builder internal constructor() { + + private var data: JsonField>? = null + private var firstId: JsonField? = null + private var hasMore: JsonField? = null + private var lastId: JsonField? = null + private var object_: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(fileListPageResponse: FileListPageResponse) = apply { + data = fileListPageResponse.data.map { it.toMutableList() } + firstId = fileListPageResponse.firstId + hasMore = fileListPageResponse.hasMore + lastId = fileListPageResponse.lastId + object_ = fileListPageResponse.object_ + additionalProperties = fileListPageResponse.additionalProperties.toMutableMap() + } + + fun data(data: List) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun data(data: JsonField>) = apply { + this.data = data.map { it.toMutableList() } + } + + /** + * Adds a single [FileObject] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: FileObject) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + fun firstId(firstId: String) = firstId(JsonField.of(firstId)) + + /** + * Sets [Builder.firstId] to an arbitrary JSON value. + * + * You should usually call [Builder.firstId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun firstId(firstId: JsonField) = apply { this.firstId = firstId } + + fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) + + /** + * Sets [Builder.hasMore] to an arbitrary JSON value. + * + * You should usually call [Builder.hasMore] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } + + fun lastId(lastId: String) = lastId(JsonField.of(lastId)) + + /** + * Sets [Builder.lastId] to an arbitrary JSON value. + * + * You should usually call [Builder.lastId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun lastId(lastId: JsonField) = apply { this.lastId = lastId } + + fun object_(object_: String) = object_(JsonField.of(object_)) + + /** + * Sets [Builder.object_] to an arbitrary JSON value. + * + * You should usually call [Builder.object_] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun object_(object_: JsonField) = apply { this.object_ = object_ } + + 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 [FileListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .firstId() + * .hasMore() + * .lastId() + * .object_() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): FileListPageResponse = + FileListPageResponse( + checkRequired("data", data).map { it.toImmutable() }, + checkRequired("firstId", firstId), + checkRequired("hasMore", hasMore), + checkRequired("lastId", lastId), + checkRequired("object_", object_), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): FileListPageResponse = apply { + if (validated) { + return@apply + } + + data().forEach { it.validate() } + firstId() + hasMore() + lastId() + object_() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (firstId.asKnown().isPresent) 1 else 0) + + (if (hasMore.asKnown().isPresent) 1 else 0) + + (if (lastId.asKnown().isPresent) 1 else 0) + + (if (object_.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is FileListPageResponse && data == other.data && firstId == other.firstId && hasMore == other.hasMore && lastId == other.lastId && object_ == other.object_ && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(data, firstId, hasMore, lastId, object_, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "FileListPageResponse{data=$data, firstId=$firstId, hasMore=$hasMore, lastId=$lastId, object_=$object_, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/finetuning/checkpoints/permissions/PermissionCreatePage.kt b/openai-java-core/src/main/kotlin/com/openai/models/finetuning/checkpoints/permissions/PermissionCreatePage.kt index ca6a054b..ea6aeac9 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/finetuning/checkpoints/permissions/PermissionCreatePage.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/finetuning/checkpoints/permissions/PermissionCreatePage.kt @@ -2,186 +2,108 @@ package com.openai.models.finetuning.checkpoints.permissions -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.errors.OpenAIInvalidDataException +import com.openai.core.checkRequired import com.openai.services.blocking.finetuning.checkpoints.PermissionService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** - * **NOTE:** Calling this endpoint requires an [admin API key](../admin-api-keys). - * - * This enables organization owners to share fine-tuned models with other projects in their - * organization. - */ +/** @see [PermissionService.create] */ class PermissionCreatePage private constructor( - private val permissionsService: PermissionService, + private val service: PermissionService, private val params: PermissionCreateParams, - private val response: Response, + private val response: PermissionCreatePageResponse, ) { - fun response(): Response = response + /** + * Delegates to [PermissionCreatePageResponse], but gracefully handles missing data. + * + * @see [PermissionCreatePageResponse.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() - fun data(): List = response().data() + /** @see [PermissionCreatePageResponse.object_] */ + fun object_(): JsonValue = response._object_() - fun object_(): String = response().object_() + fun hasNextPage(): Boolean = data().isNotEmpty() - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is PermissionCreatePage && permissionsService == other.permissionsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(permissionsService, params, response) /* spotless:on */ + fun getNextPageParams(): Optional = Optional.empty() - override fun toString() = - "PermissionCreatePage{permissionsService=$permissionsService, params=$params, response=$response}" + fun getNextPage(): Optional = + getNextPageParams().map { service.create(it) } - fun hasNextPage(): Boolean { - return !data().isEmpty() - } + fun autoPager(): AutoPager = AutoPager(this) - fun getNextPageParams(): Optional { - return Optional.empty() - } + /** The parameters that were used to request this page. */ + fun params(): PermissionCreateParams = params - fun getNextPage(): Optional { - return getNextPageParams().map { permissionsService.create(it) } - } + /** The response that this page was parsed from. */ + fun response(): PermissionCreatePageResponse = response - fun autoPager(): AutoPager = AutoPager(this) + fun toBuilder() = Builder().from(this) companion object { - @JvmStatic - fun of( - permissionsService: PermissionService, - params: PermissionCreateParams, - response: Response, - ) = PermissionCreatePage(permissionsService, params, response) + /** + * Returns a mutable builder for constructing an instance of [PermissionCreatePage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() } - class Response( - private val data: JsonField>, - private val object_: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") - data: JsonField> = JsonMissing.of(), - @JsonProperty("object") object_: JsonField = JsonMissing.of(), - ) : this(data, object_, mutableMapOf()) - - fun data(): List = - data.getOptional("data").getOrNull() ?: listOf() - - fun object_(): String = object_.getRequired("object") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("object") - fun _object_(): Optional> = Optional.ofNullable(object_) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - data().map { it.validate() } - object_() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && object_ == other.object_ && additionalProperties == other.additionalProperties /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, object_, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{data=$data, object_=$object_, additionalProperties=$additionalProperties}" + /** A builder for [PermissionCreatePage]. */ + class Builder internal constructor() { - companion object { + private var service: PermissionService? = null + private var params: PermissionCreateParams? = null + private var response: PermissionCreatePageResponse? = null - /** Returns a mutable builder for constructing an instance of [PermissionCreatePage]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(permissionCreatePage: PermissionCreatePage) = apply { + service = permissionCreatePage.service + params = permissionCreatePage.params + response = permissionCreatePage.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var object_: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.object_ = page.object_ - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun object_(object_: String) = object_(JsonField.of(object_)) - - fun object_(object_: JsonField) = apply { this.object_ = object_ } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(data, object_, additionalProperties.toMutableMap()) - } + fun service(service: PermissionService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: PermissionCreateParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: PermissionCreatePageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [PermissionCreatePage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PermissionCreatePage = + PermissionCreatePage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: PermissionCreatePage) : @@ -203,4 +125,17 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is PermissionCreatePage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "PermissionCreatePage{service=$service, params=$params, response=$response}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/finetuning/checkpoints/permissions/PermissionCreatePageAsync.kt b/openai-java-core/src/main/kotlin/com/openai/models/finetuning/checkpoints/permissions/PermissionCreatePageAsync.kt index b6f74e5d..174dc4c7 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/finetuning/checkpoints/permissions/PermissionCreatePageAsync.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/finetuning/checkpoints/permissions/PermissionCreatePageAsync.kt @@ -2,17 +2,9 @@ package com.openai.models.finetuning.checkpoints.permissions -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.errors.OpenAIInvalidDataException +import com.openai.core.checkRequired import com.openai.services.async.finetuning.checkpoints.PermissionServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -20,174 +12,101 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** - * **NOTE:** Calling this endpoint requires an [admin API key](../admin-api-keys). - * - * This enables organization owners to share fine-tuned models with other projects in their - * organization. - */ +/** @see [PermissionServiceAsync.create] */ class PermissionCreatePageAsync private constructor( - private val permissionsService: PermissionServiceAsync, + private val service: PermissionServiceAsync, private val params: PermissionCreateParams, - private val response: Response, + private val response: PermissionCreatePageResponse, ) { - fun response(): Response = response + /** + * Delegates to [PermissionCreatePageResponse], but gracefully handles missing data. + * + * @see [PermissionCreatePageResponse.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() - fun data(): List = response().data() + /** @see [PermissionCreatePageResponse.object_] */ + fun object_(): JsonValue = response._object_() - fun object_(): String = response().object_() + fun hasNextPage(): Boolean = data().isNotEmpty() - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is PermissionCreatePageAsync && permissionsService == other.permissionsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(permissionsService, params, response) /* spotless:on */ + fun getNextPageParams(): Optional = Optional.empty() - override fun toString() = - "PermissionCreatePageAsync{permissionsService=$permissionsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - return !data().isEmpty() - } - - fun getNextPageParams(): Optional { - return Optional.empty() - } - - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { permissionsService.create(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.create(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of( - permissionsService: PermissionServiceAsync, - params: PermissionCreateParams, - response: Response, - ) = PermissionCreatePageAsync(permissionsService, params, response) - } - - class Response( - private val data: JsonField>, - private val object_: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") - data: JsonField> = JsonMissing.of(), - @JsonProperty("object") object_: JsonField = JsonMissing.of(), - ) : this(data, object_, mutableMapOf()) - - fun data(): List = - data.getOptional("data").getOrNull() ?: listOf() - - fun object_(): String = object_.getRequired("object") + /** The parameters that were used to request this page. */ + fun params(): PermissionCreateParams = params - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) + /** The response that this page was parsed from. */ + fun response(): PermissionCreatePageResponse = response - @JsonProperty("object") - fun _object_(): Optional> = Optional.ofNullable(object_) + fun toBuilder() = Builder().from(this) - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - data().map { it.validate() } - object_() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && object_ == other.object_ && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, object_, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [PermissionCreatePageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, object_=$object_, additionalProperties=$additionalProperties}" + /** A builder for [PermissionCreatePageAsync]. */ + class Builder internal constructor() { - companion object { + private var service: PermissionServiceAsync? = null + private var params: PermissionCreateParams? = null + private var response: PermissionCreatePageResponse? = null - /** - * Returns a mutable builder for constructing an instance of - * [PermissionCreatePageAsync]. - */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(permissionCreatePageAsync: PermissionCreatePageAsync) = apply { + service = permissionCreatePageAsync.service + params = permissionCreatePageAsync.params + response = permissionCreatePageAsync.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var object_: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.object_ = page.object_ - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun object_(object_: String) = object_(JsonField.of(object_)) - - fun object_(object_: JsonField) = apply { this.object_ = object_ } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(data, object_, additionalProperties.toMutableMap()) - } + fun service(service: PermissionServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: PermissionCreateParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: PermissionCreatePageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [PermissionCreatePageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PermissionCreatePageAsync = + PermissionCreatePageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: PermissionCreatePageAsync) { @@ -218,4 +137,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is PermissionCreatePageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "PermissionCreatePageAsync{service=$service, params=$params, response=$response}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/finetuning/checkpoints/permissions/PermissionCreatePageResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/finetuning/checkpoints/permissions/PermissionCreatePageResponse.kt new file mode 100644 index 00000000..1357914d --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/finetuning/checkpoints/permissions/PermissionCreatePageResponse.kt @@ -0,0 +1,328 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.finetuning.checkpoints.permissions + +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 java.util.Optional +import kotlin.jvm.optionals.getOrNull + +class PermissionCreatePageResponse +private constructor( + private val data: JsonField>, + private val hasMore: JsonField, + private val object_: JsonValue, + private val firstId: JsonField, + private val lastId: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") + @ExcludeMissing + data: JsonField> = JsonMissing.of(), + @JsonProperty("has_more") @ExcludeMissing hasMore: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("first_id") @ExcludeMissing firstId: JsonField = JsonMissing.of(), + @JsonProperty("last_id") @ExcludeMissing lastId: JsonField = JsonMissing.of(), + ) : this(data, hasMore, object_, firstId, lastId, 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 data(): List = data.getRequired("data") + + /** + * @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 hasMore(): Boolean = hasMore.getRequired("has_more") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("list") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun firstId(): Optional = firstId.getOptional("first_id") + + /** + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun lastId(): Optional = lastId.getOptional("last_id") + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") + @ExcludeMissing + fun _data(): JsonField> = data + + /** + * Returns the raw JSON value of [hasMore]. + * + * Unlike [hasMore], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("has_more") @ExcludeMissing fun _hasMore(): JsonField = hasMore + + /** + * Returns the raw JSON value of [firstId]. + * + * Unlike [firstId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("first_id") @ExcludeMissing fun _firstId(): JsonField = firstId + + /** + * Returns the raw JSON value of [lastId]. + * + * Unlike [lastId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("last_id") @ExcludeMissing fun _lastId(): JsonField = lastId + + @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 [PermissionCreatePageResponse]. + * + * The following fields are required: + * ```java + * .data() + * .hasMore() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [PermissionCreatePageResponse]. */ + class Builder internal constructor() { + + private var data: JsonField>? = null + private var hasMore: JsonField? = null + private var object_: JsonValue = JsonValue.from("list") + private var firstId: JsonField = JsonMissing.of() + private var lastId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(permissionCreatePageResponse: PermissionCreatePageResponse) = apply { + data = permissionCreatePageResponse.data.map { it.toMutableList() } + hasMore = permissionCreatePageResponse.hasMore + object_ = permissionCreatePageResponse.object_ + firstId = permissionCreatePageResponse.firstId + lastId = permissionCreatePageResponse.lastId + additionalProperties = permissionCreatePageResponse.additionalProperties.toMutableMap() + } + + fun data(data: List) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun data(data: JsonField>) = apply { + this.data = data.map { it.toMutableList() } + } + + /** + * Adds a single [PermissionCreateResponse] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: PermissionCreateResponse) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) + + /** + * Sets [Builder.hasMore] to an arbitrary JSON value. + * + * You should usually call [Builder.hasMore] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } + + /** + * 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("list") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + fun firstId(firstId: String?) = firstId(JsonField.ofNullable(firstId)) + + /** Alias for calling [Builder.firstId] with `firstId.orElse(null)`. */ + fun firstId(firstId: Optional) = firstId(firstId.getOrNull()) + + /** + * Sets [Builder.firstId] to an arbitrary JSON value. + * + * You should usually call [Builder.firstId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun firstId(firstId: JsonField) = apply { this.firstId = firstId } + + fun lastId(lastId: String?) = lastId(JsonField.ofNullable(lastId)) + + /** Alias for calling [Builder.lastId] with `lastId.orElse(null)`. */ + fun lastId(lastId: Optional) = lastId(lastId.getOrNull()) + + /** + * Sets [Builder.lastId] to an arbitrary JSON value. + * + * You should usually call [Builder.lastId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun lastId(lastId: JsonField) = apply { this.lastId = lastId } + + 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 [PermissionCreatePageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .hasMore() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PermissionCreatePageResponse = + PermissionCreatePageResponse( + checkRequired("data", data).map { it.toImmutable() }, + checkRequired("hasMore", hasMore), + object_, + firstId, + lastId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): PermissionCreatePageResponse = apply { + if (validated) { + return@apply + } + + data().forEach { it.validate() } + hasMore() + _object_().let { + if (it != JsonValue.from("list")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + firstId() + lastId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (hasMore.asKnown().isPresent) 1 else 0) + + object_.let { if (it == JsonValue.from("list")) 1 else 0 } + + (if (firstId.asKnown().isPresent) 1 else 0) + + (if (lastId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is PermissionCreatePageResponse && data == other.data && hasMore == other.hasMore && object_ == other.object_ && firstId == other.firstId && lastId == other.lastId && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(data, hasMore, object_, firstId, lastId, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PermissionCreatePageResponse{data=$data, hasMore=$hasMore, object_=$object_, firstId=$firstId, lastId=$lastId, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/finetuning/jobs/JobListEventsPage.kt b/openai-java-core/src/main/kotlin/com/openai/models/finetuning/jobs/JobListEventsPage.kt index 5a9cd1cc..7acc932f 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/finetuning/jobs/JobListEventsPage.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/finetuning/jobs/JobListEventsPage.kt @@ -2,180 +2,117 @@ package com.openai.models.finetuning.jobs -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.errors.OpenAIInvalidDataException +import com.openai.core.checkRequired import com.openai.services.blocking.finetuning.JobService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** Get status updates for a fine-tuning job. */ +/** @see [JobService.listEvents] */ class JobListEventsPage private constructor( - private val jobsService: JobService, + private val service: JobService, private val params: JobListEventsParams, - private val response: Response, + private val response: JobListEventsPageResponse, ) { - fun response(): Response = response + /** + * Delegates to [JobListEventsPageResponse], but gracefully handles missing data. + * + * @see [JobListEventsPageResponse.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() - fun data(): List = response().data() + /** + * Delegates to [JobListEventsPageResponse], but gracefully handles missing data. + * + * @see [JobListEventsPageResponse.hasMore] + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") - fun hasMore(): Optional = response().hasMore() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is JobListEventsPage && jobsService == other.jobsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(jobsService, params, response) /* spotless:on */ - - override fun toString() = - "JobListEventsPage{jobsService=$jobsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - return !data().isEmpty() - } + fun hasNextPage(): Boolean = data().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return Optional.of(params.toBuilder().after(data().last().id()).build()) + return Optional.of(params.toBuilder().after(data().last()._id().getOptional("id")).build()) } - fun getNextPage(): Optional { - return getNextPageParams().map { jobsService.listEvents(it) } - } + fun getNextPage(): Optional = + getNextPageParams().map { service.listEvents(it) } fun autoPager(): AutoPager = AutoPager(this) - companion object { + /** The parameters that were used to request this page. */ + fun params(): JobListEventsParams = params - @JvmStatic - fun of(jobsService: JobService, params: JobListEventsParams, response: Response) = - JobListEventsPage(jobsService, params, response) - } + /** The response that this page was parsed from. */ + fun response(): JobListEventsPageResponse = response - class Response( - private val data: JsonField>, - private val hasMore: JsonField, - private val additionalProperties: MutableMap, - ) { + fun toBuilder() = Builder().from(this) - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("has_more") hasMore: JsonField = JsonMissing.of(), - ) : this(data, hasMore, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun hasMore(): Optional = hasMore.getOptional("has_more") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("has_more") - fun _hasMore(): Optional> = Optional.ofNullable(hasMore) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - data().map { it.validate() } - hasMore() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && hasMore == other.hasMore && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, hasMore, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [JobListEventsPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, hasMore=$hasMore, additionalProperties=$additionalProperties}" + /** A builder for [JobListEventsPage]. */ + class Builder internal constructor() { - companion object { + private var service: JobService? = null + private var params: JobListEventsParams? = null + private var response: JobListEventsPageResponse? = null - /** Returns a mutable builder for constructing an instance of [JobListEventsPage]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(jobListEventsPage: JobListEventsPage) = apply { + service = jobListEventsPage.service + params = jobListEventsPage.params + response = jobListEventsPage.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var hasMore: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.hasMore = page.hasMore - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) - - fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(data, hasMore, additionalProperties.toMutableMap()) - } + fun service(service: JobService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: JobListEventsParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: JobListEventsPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [JobListEventsPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): JobListEventsPage = + JobListEventsPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: JobListEventsPage) : Iterable { @@ -196,4 +133,17 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is JobListEventsPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "JobListEventsPage{service=$service, params=$params, response=$response}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/finetuning/jobs/JobListEventsPageAsync.kt b/openai-java-core/src/main/kotlin/com/openai/models/finetuning/jobs/JobListEventsPageAsync.kt index 38cc5b45..eceb1568 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/finetuning/jobs/JobListEventsPageAsync.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/finetuning/jobs/JobListEventsPageAsync.kt @@ -2,17 +2,8 @@ package com.openai.models.finetuning.jobs -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.errors.OpenAIInvalidDataException +import com.openai.core.checkRequired import com.openai.services.async.finetuning.JobServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -20,167 +11,111 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** Get status updates for a fine-tuning job. */ +/** @see [JobServiceAsync.listEvents] */ class JobListEventsPageAsync private constructor( - private val jobsService: JobServiceAsync, + private val service: JobServiceAsync, private val params: JobListEventsParams, - private val response: Response, + private val response: JobListEventsPageResponse, ) { - fun response(): Response = response + /** + * Delegates to [JobListEventsPageResponse], but gracefully handles missing data. + * + * @see [JobListEventsPageResponse.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() - fun data(): List = response().data() + /** + * Delegates to [JobListEventsPageResponse], but gracefully handles missing data. + * + * @see [JobListEventsPageResponse.hasMore] + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") - fun hasMore(): Optional = response().hasMore() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is JobListEventsPageAsync && jobsService == other.jobsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(jobsService, params, response) /* spotless:on */ - - override fun toString() = - "JobListEventsPageAsync{jobsService=$jobsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - return !data().isEmpty() - } + fun hasNextPage(): Boolean = data().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return Optional.of(params.toBuilder().after(data().last().id()).build()) + return Optional.of(params.toBuilder().after(data().last()._id().getOptional("id")).build()) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { jobsService.listEvents(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.listEvents(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of(jobsService: JobServiceAsync, params: JobListEventsParams, response: Response) = - JobListEventsPageAsync(jobsService, params, response) - } - - class Response( - private val data: JsonField>, - private val hasMore: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("has_more") hasMore: JsonField = JsonMissing.of(), - ) : this(data, hasMore, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun hasMore(): Optional = hasMore.getOptional("has_more") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("has_more") - fun _hasMore(): Optional> = Optional.ofNullable(hasMore) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false + /** The parameters that were used to request this page. */ + fun params(): JobListEventsParams = params - fun validate(): Response = apply { - if (validated) { - return@apply - } + /** The response that this page was parsed from. */ + fun response(): JobListEventsPageResponse = response - data().map { it.validate() } - hasMore() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + fun toBuilder() = Builder().from(this) - return /* spotless:off */ other is Response && data == other.data && hasMore == other.hasMore && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, hasMore, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [JobListEventsPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, hasMore=$hasMore, additionalProperties=$additionalProperties}" + /** A builder for [JobListEventsPageAsync]. */ + class Builder internal constructor() { - companion object { + private var service: JobServiceAsync? = null + private var params: JobListEventsParams? = null + private var response: JobListEventsPageResponse? = null - /** - * Returns a mutable builder for constructing an instance of [JobListEventsPageAsync]. - */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(jobListEventsPageAsync: JobListEventsPageAsync) = apply { + service = jobListEventsPageAsync.service + params = jobListEventsPageAsync.params + response = jobListEventsPageAsync.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var hasMore: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.hasMore = page.hasMore - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) - - fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(data, hasMore, additionalProperties.toMutableMap()) - } + fun service(service: JobServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: JobListEventsParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: JobListEventsPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [JobListEventsPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): JobListEventsPageAsync = + JobListEventsPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: JobListEventsPageAsync) { @@ -211,4 +146,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is JobListEventsPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "JobListEventsPageAsync{service=$service, params=$params, response=$response}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/finetuning/jobs/JobListEventsPageResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/finetuning/jobs/JobListEventsPageResponse.kt new file mode 100644 index 00000000..ae126d94 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/finetuning/jobs/JobListEventsPageResponse.kt @@ -0,0 +1,259 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.finetuning.jobs + +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 JobListEventsPageResponse +private constructor( + private val data: JsonField>, + private val hasMore: JsonField, + private val object_: JsonValue, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") + @ExcludeMissing + data: JsonField> = JsonMissing.of(), + @JsonProperty("has_more") @ExcludeMissing hasMore: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + ) : this(data, hasMore, object_, 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 data(): List = data.getRequired("data") + + /** + * @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 hasMore(): Boolean = hasMore.getRequired("has_more") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("list") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField> = data + + /** + * Returns the raw JSON value of [hasMore]. + * + * Unlike [hasMore], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("has_more") @ExcludeMissing fun _hasMore(): JsonField = hasMore + + @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 [JobListEventsPageResponse]. + * + * The following fields are required: + * ```java + * .data() + * .hasMore() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [JobListEventsPageResponse]. */ + class Builder internal constructor() { + + private var data: JsonField>? = null + private var hasMore: JsonField? = null + private var object_: JsonValue = JsonValue.from("list") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(jobListEventsPageResponse: JobListEventsPageResponse) = apply { + data = jobListEventsPageResponse.data.map { it.toMutableList() } + hasMore = jobListEventsPageResponse.hasMore + object_ = jobListEventsPageResponse.object_ + additionalProperties = jobListEventsPageResponse.additionalProperties.toMutableMap() + } + + fun data(data: List) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun data(data: JsonField>) = apply { + this.data = data.map { it.toMutableList() } + } + + /** + * Adds a single [FineTuningJobEvent] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: FineTuningJobEvent) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) + + /** + * Sets [Builder.hasMore] to an arbitrary JSON value. + * + * You should usually call [Builder.hasMore] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } + + /** + * 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("list") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + 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 [JobListEventsPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .hasMore() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): JobListEventsPageResponse = + JobListEventsPageResponse( + checkRequired("data", data).map { it.toImmutable() }, + checkRequired("hasMore", hasMore), + object_, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): JobListEventsPageResponse = apply { + if (validated) { + return@apply + } + + data().forEach { it.validate() } + hasMore() + _object_().let { + if (it != JsonValue.from("list")) { + throw OpenAIInvalidDataException("'object_' 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 = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (hasMore.asKnown().isPresent) 1 else 0) + + object_.let { if (it == JsonValue.from("list")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is JobListEventsPageResponse && data == other.data && hasMore == other.hasMore && object_ == other.object_ && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(data, hasMore, object_, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "JobListEventsPageResponse{data=$data, hasMore=$hasMore, object_=$object_, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/finetuning/jobs/JobListPage.kt b/openai-java-core/src/main/kotlin/com/openai/models/finetuning/jobs/JobListPage.kt index a2e5e955..db6bcab0 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/finetuning/jobs/JobListPage.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/finetuning/jobs/JobListPage.kt @@ -2,180 +2,116 @@ package com.openai.models.finetuning.jobs -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.errors.OpenAIInvalidDataException +import com.openai.core.checkRequired import com.openai.services.blocking.finetuning.JobService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** List your organization's fine-tuning jobs */ +/** @see [JobService.list] */ class JobListPage private constructor( - private val jobsService: JobService, + private val service: JobService, private val params: JobListParams, - private val response: Response, + private val response: JobListPageResponse, ) { - fun response(): Response = response + /** + * Delegates to [JobListPageResponse], but gracefully handles missing data. + * + * @see [JobListPageResponse.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() - fun data(): List = response().data() + /** + * Delegates to [JobListPageResponse], but gracefully handles missing data. + * + * @see [JobListPageResponse.hasMore] + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") - fun hasMore(): Optional = response().hasMore() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is JobListPage && jobsService == other.jobsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(jobsService, params, response) /* spotless:on */ - - override fun toString() = - "JobListPage{jobsService=$jobsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - return !data().isEmpty() - } + fun hasNextPage(): Boolean = data().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return Optional.of(params.toBuilder().after(data().last().id()).build()) + return Optional.of(params.toBuilder().after(data().last()._id().getOptional("id")).build()) } - fun getNextPage(): Optional { - return getNextPageParams().map { jobsService.list(it) } - } + fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of(jobsService: JobService, params: JobListParams, response: Response) = - JobListPage(jobsService, params, response) - } - - class Response( - private val data: JsonField>, - private val hasMore: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("has_more") hasMore: JsonField = JsonMissing.of(), - ) : this(data, hasMore, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun hasMore(): Optional = hasMore.getOptional("has_more") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("has_more") - fun _hasMore(): Optional> = Optional.ofNullable(hasMore) + /** The parameters that were used to request this page. */ + fun params(): JobListParams = params - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + /** The response that this page was parsed from. */ + fun response(): JobListPageResponse = response - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } + fun toBuilder() = Builder().from(this) - data().map { it.validate() } - hasMore() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && hasMore == other.hasMore && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, hasMore, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [JobListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, hasMore=$hasMore, additionalProperties=$additionalProperties}" + /** A builder for [JobListPage]. */ + class Builder internal constructor() { - companion object { + private var service: JobService? = null + private var params: JobListParams? = null + private var response: JobListPageResponse? = null - /** Returns a mutable builder for constructing an instance of [JobListPage]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(jobListPage: JobListPage) = apply { + service = jobListPage.service + params = jobListPage.params + response = jobListPage.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var hasMore: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.hasMore = page.hasMore - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) - - fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(data, hasMore, additionalProperties.toMutableMap()) - } + fun service(service: JobService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: JobListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: JobListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [JobListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): JobListPage = + JobListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: JobListPage) : Iterable { @@ -196,4 +132,16 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is JobListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = "JobListPage{service=$service, params=$params, response=$response}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/finetuning/jobs/JobListPageAsync.kt b/openai-java-core/src/main/kotlin/com/openai/models/finetuning/jobs/JobListPageAsync.kt index 0bddbe51..7730d220 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/finetuning/jobs/JobListPageAsync.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/finetuning/jobs/JobListPageAsync.kt @@ -2,17 +2,8 @@ package com.openai.models.finetuning.jobs -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.errors.OpenAIInvalidDataException +import com.openai.core.checkRequired import com.openai.services.async.finetuning.JobServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -20,165 +11,111 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** List your organization's fine-tuning jobs */ +/** @see [JobServiceAsync.list] */ class JobListPageAsync private constructor( - private val jobsService: JobServiceAsync, + private val service: JobServiceAsync, private val params: JobListParams, - private val response: Response, + private val response: JobListPageResponse, ) { - fun response(): Response = response + /** + * Delegates to [JobListPageResponse], but gracefully handles missing data. + * + * @see [JobListPageResponse.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() - fun data(): List = response().data() + /** + * Delegates to [JobListPageResponse], but gracefully handles missing data. + * + * @see [JobListPageResponse.hasMore] + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") - fun hasMore(): Optional = response().hasMore() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is JobListPageAsync && jobsService == other.jobsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(jobsService, params, response) /* spotless:on */ - - override fun toString() = - "JobListPageAsync{jobsService=$jobsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - return !data().isEmpty() - } + fun hasNextPage(): Boolean = data().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return Optional.of(params.toBuilder().after(data().last().id()).build()) + return Optional.of(params.toBuilder().after(data().last()._id().getOptional("id")).build()) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { jobsService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of(jobsService: JobServiceAsync, params: JobListParams, response: Response) = - JobListPageAsync(jobsService, params, response) - } - - class Response( - private val data: JsonField>, - private val hasMore: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("has_more") hasMore: JsonField = JsonMissing.of(), - ) : this(data, hasMore, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun hasMore(): Optional = hasMore.getOptional("has_more") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("has_more") - fun _hasMore(): Optional> = Optional.ofNullable(hasMore) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false + /** The parameters that were used to request this page. */ + fun params(): JobListParams = params - fun validate(): Response = apply { - if (validated) { - return@apply - } + /** The response that this page was parsed from. */ + fun response(): JobListPageResponse = response - data().map { it.validate() } - hasMore() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + fun toBuilder() = Builder().from(this) - return /* spotless:off */ other is Response && data == other.data && hasMore == other.hasMore && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, hasMore, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [JobListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, hasMore=$hasMore, additionalProperties=$additionalProperties}" + /** A builder for [JobListPageAsync]. */ + class Builder internal constructor() { - companion object { + private var service: JobServiceAsync? = null + private var params: JobListParams? = null + private var response: JobListPageResponse? = null - /** Returns a mutable builder for constructing an instance of [JobListPageAsync]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(jobListPageAsync: JobListPageAsync) = apply { + service = jobListPageAsync.service + params = jobListPageAsync.params + response = jobListPageAsync.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var hasMore: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.hasMore = page.hasMore - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) - - fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(data, hasMore, additionalProperties.toMutableMap()) - } + fun service(service: JobServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: JobListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: JobListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [JobListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): JobListPageAsync = + JobListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: JobListPageAsync) { @@ -206,4 +143,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is JobListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "JobListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/finetuning/jobs/JobListPageResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/finetuning/jobs/JobListPageResponse.kt new file mode 100644 index 00000000..1e2dd1f5 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/finetuning/jobs/JobListPageResponse.kt @@ -0,0 +1,259 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.finetuning.jobs + +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 JobListPageResponse +private constructor( + private val data: JsonField>, + private val hasMore: JsonField, + private val object_: JsonValue, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") + @ExcludeMissing + data: JsonField> = JsonMissing.of(), + @JsonProperty("has_more") @ExcludeMissing hasMore: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + ) : this(data, hasMore, object_, 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 data(): List = data.getRequired("data") + + /** + * @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 hasMore(): Boolean = hasMore.getRequired("has_more") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("list") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField> = data + + /** + * Returns the raw JSON value of [hasMore]. + * + * Unlike [hasMore], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("has_more") @ExcludeMissing fun _hasMore(): JsonField = hasMore + + @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 [JobListPageResponse]. + * + * The following fields are required: + * ```java + * .data() + * .hasMore() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [JobListPageResponse]. */ + class Builder internal constructor() { + + private var data: JsonField>? = null + private var hasMore: JsonField? = null + private var object_: JsonValue = JsonValue.from("list") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(jobListPageResponse: JobListPageResponse) = apply { + data = jobListPageResponse.data.map { it.toMutableList() } + hasMore = jobListPageResponse.hasMore + object_ = jobListPageResponse.object_ + additionalProperties = jobListPageResponse.additionalProperties.toMutableMap() + } + + fun data(data: List) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun data(data: JsonField>) = apply { + this.data = data.map { it.toMutableList() } + } + + /** + * Adds a single [FineTuningJob] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: FineTuningJob) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) + + /** + * Sets [Builder.hasMore] to an arbitrary JSON value. + * + * You should usually call [Builder.hasMore] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } + + /** + * 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("list") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + 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 [JobListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .hasMore() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): JobListPageResponse = + JobListPageResponse( + checkRequired("data", data).map { it.toImmutable() }, + checkRequired("hasMore", hasMore), + object_, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): JobListPageResponse = apply { + if (validated) { + return@apply + } + + data().forEach { it.validate() } + hasMore() + _object_().let { + if (it != JsonValue.from("list")) { + throw OpenAIInvalidDataException("'object_' 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 = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (hasMore.asKnown().isPresent) 1 else 0) + + object_.let { if (it == JsonValue.from("list")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is JobListPageResponse && data == other.data && hasMore == other.hasMore && object_ == other.object_ && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(data, hasMore, object_, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "JobListPageResponse{data=$data, hasMore=$hasMore, object_=$object_, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/finetuning/jobs/checkpoints/CheckpointListPage.kt b/openai-java-core/src/main/kotlin/com/openai/models/finetuning/jobs/checkpoints/CheckpointListPage.kt index 27fa2e8a..64c6ce8b 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/finetuning/jobs/checkpoints/CheckpointListPage.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/finetuning/jobs/checkpoints/CheckpointListPage.kt @@ -2,183 +2,116 @@ package com.openai.models.finetuning.jobs.checkpoints -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.errors.OpenAIInvalidDataException +import com.openai.core.checkRequired import com.openai.services.blocking.finetuning.jobs.CheckpointService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** List checkpoints for a fine-tuning job. */ +/** @see [CheckpointService.list] */ class CheckpointListPage private constructor( - private val checkpointsService: CheckpointService, + private val service: CheckpointService, private val params: CheckpointListParams, - private val response: Response, + private val response: CheckpointListPageResponse, ) { - fun response(): Response = response + /** + * Delegates to [CheckpointListPageResponse], but gracefully handles missing data. + * + * @see [CheckpointListPageResponse.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() - fun data(): List = response().data() + /** + * Delegates to [CheckpointListPageResponse], but gracefully handles missing data. + * + * @see [CheckpointListPageResponse.hasMore] + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") - fun hasMore(): Optional = response().hasMore() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is CheckpointListPage && checkpointsService == other.checkpointsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(checkpointsService, params, response) /* spotless:on */ - - override fun toString() = - "CheckpointListPage{checkpointsService=$checkpointsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - return !data().isEmpty() - } + fun hasNextPage(): Boolean = data().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return Optional.of(params.toBuilder().after(data().last().id()).build()) + return Optional.of(params.toBuilder().after(data().last()._id().getOptional("id")).build()) } - fun getNextPage(): Optional { - return getNextPageParams().map { checkpointsService.list(it) } - } + fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) - companion object { + /** The parameters that were used to request this page. */ + fun params(): CheckpointListParams = params - @JvmStatic - fun of( - checkpointsService: CheckpointService, - params: CheckpointListParams, - response: Response, - ) = CheckpointListPage(checkpointsService, params, response) - } + /** The response that this page was parsed from. */ + fun response(): CheckpointListPageResponse = response - class Response( - private val data: JsonField>, - private val hasMore: JsonField, - private val additionalProperties: MutableMap, - ) { + fun toBuilder() = Builder().from(this) - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("has_more") hasMore: JsonField = JsonMissing.of(), - ) : this(data, hasMore, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun hasMore(): Optional = hasMore.getOptional("has_more") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("has_more") - fun _hasMore(): Optional> = Optional.ofNullable(hasMore) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - data().map { it.validate() } - hasMore() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && hasMore == other.hasMore && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, hasMore, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [CheckpointListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, hasMore=$hasMore, additionalProperties=$additionalProperties}" + /** A builder for [CheckpointListPage]. */ + class Builder internal constructor() { - companion object { + private var service: CheckpointService? = null + private var params: CheckpointListParams? = null + private var response: CheckpointListPageResponse? = null - /** Returns a mutable builder for constructing an instance of [CheckpointListPage]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(checkpointListPage: CheckpointListPage) = apply { + service = checkpointListPage.service + params = checkpointListPage.params + response = checkpointListPage.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var hasMore: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.hasMore = page.hasMore - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) - - fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(data, hasMore, additionalProperties.toMutableMap()) - } + fun service(service: CheckpointService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: CheckpointListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: CheckpointListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [CheckpointListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CheckpointListPage = + CheckpointListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: CheckpointListPage) : Iterable { @@ -199,4 +132,17 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is CheckpointListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "CheckpointListPage{service=$service, params=$params, response=$response}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/finetuning/jobs/checkpoints/CheckpointListPageAsync.kt b/openai-java-core/src/main/kotlin/com/openai/models/finetuning/jobs/checkpoints/CheckpointListPageAsync.kt index 2081d0b9..b5812ee7 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/finetuning/jobs/checkpoints/CheckpointListPageAsync.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/finetuning/jobs/checkpoints/CheckpointListPageAsync.kt @@ -2,17 +2,8 @@ package com.openai.models.finetuning.jobs.checkpoints -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.errors.OpenAIInvalidDataException +import com.openai.core.checkRequired import com.openai.services.async.finetuning.jobs.CheckpointServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -20,170 +11,111 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** List checkpoints for a fine-tuning job. */ +/** @see [CheckpointServiceAsync.list] */ class CheckpointListPageAsync private constructor( - private val checkpointsService: CheckpointServiceAsync, + private val service: CheckpointServiceAsync, private val params: CheckpointListParams, - private val response: Response, + private val response: CheckpointListPageResponse, ) { - fun response(): Response = response + /** + * Delegates to [CheckpointListPageResponse], but gracefully handles missing data. + * + * @see [CheckpointListPageResponse.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() - fun data(): List = response().data() + /** + * Delegates to [CheckpointListPageResponse], but gracefully handles missing data. + * + * @see [CheckpointListPageResponse.hasMore] + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") - fun hasMore(): Optional = response().hasMore() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is CheckpointListPageAsync && checkpointsService == other.checkpointsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(checkpointsService, params, response) /* spotless:on */ - - override fun toString() = - "CheckpointListPageAsync{checkpointsService=$checkpointsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - return !data().isEmpty() - } + fun hasNextPage(): Boolean = data().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return Optional.of(params.toBuilder().after(data().last().id()).build()) + return Optional.of(params.toBuilder().after(data().last()._id().getOptional("id")).build()) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { checkpointsService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of( - checkpointsService: CheckpointServiceAsync, - params: CheckpointListParams, - response: Response, - ) = CheckpointListPageAsync(checkpointsService, params, response) - } - - class Response( - private val data: JsonField>, - private val hasMore: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("has_more") hasMore: JsonField = JsonMissing.of(), - ) : this(data, hasMore, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun hasMore(): Optional = hasMore.getOptional("has_more") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("has_more") - fun _hasMore(): Optional> = Optional.ofNullable(hasMore) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false + /** The parameters that were used to request this page. */ + fun params(): CheckpointListParams = params - fun validate(): Response = apply { - if (validated) { - return@apply - } + /** The response that this page was parsed from. */ + fun response(): CheckpointListPageResponse = response - data().map { it.validate() } - hasMore() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + fun toBuilder() = Builder().from(this) - return /* spotless:off */ other is Response && data == other.data && hasMore == other.hasMore && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, hasMore, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [CheckpointListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, hasMore=$hasMore, additionalProperties=$additionalProperties}" + /** A builder for [CheckpointListPageAsync]. */ + class Builder internal constructor() { - companion object { + private var service: CheckpointServiceAsync? = null + private var params: CheckpointListParams? = null + private var response: CheckpointListPageResponse? = null - /** - * Returns a mutable builder for constructing an instance of [CheckpointListPageAsync]. - */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(checkpointListPageAsync: CheckpointListPageAsync) = apply { + service = checkpointListPageAsync.service + params = checkpointListPageAsync.params + response = checkpointListPageAsync.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var hasMore: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.hasMore = page.hasMore - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) - - fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(data, hasMore, additionalProperties.toMutableMap()) - } + fun service(service: CheckpointServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: CheckpointListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: CheckpointListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [CheckpointListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CheckpointListPageAsync = + CheckpointListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: CheckpointListPageAsync) { @@ -214,4 +146,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is CheckpointListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "CheckpointListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/finetuning/jobs/checkpoints/CheckpointListPageResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/finetuning/jobs/checkpoints/CheckpointListPageResponse.kt new file mode 100644 index 00000000..a2cd3def --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/finetuning/jobs/checkpoints/CheckpointListPageResponse.kt @@ -0,0 +1,328 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.finetuning.jobs.checkpoints + +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 java.util.Optional +import kotlin.jvm.optionals.getOrNull + +class CheckpointListPageResponse +private constructor( + private val data: JsonField>, + private val hasMore: JsonField, + private val object_: JsonValue, + private val firstId: JsonField, + private val lastId: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") + @ExcludeMissing + data: JsonField> = JsonMissing.of(), + @JsonProperty("has_more") @ExcludeMissing hasMore: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("first_id") @ExcludeMissing firstId: JsonField = JsonMissing.of(), + @JsonProperty("last_id") @ExcludeMissing lastId: JsonField = JsonMissing.of(), + ) : this(data, hasMore, object_, firstId, lastId, 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 data(): List = data.getRequired("data") + + /** + * @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 hasMore(): Boolean = hasMore.getRequired("has_more") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("list") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun firstId(): Optional = firstId.getOptional("first_id") + + /** + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun lastId(): Optional = lastId.getOptional("last_id") + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") + @ExcludeMissing + fun _data(): JsonField> = data + + /** + * Returns the raw JSON value of [hasMore]. + * + * Unlike [hasMore], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("has_more") @ExcludeMissing fun _hasMore(): JsonField = hasMore + + /** + * Returns the raw JSON value of [firstId]. + * + * Unlike [firstId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("first_id") @ExcludeMissing fun _firstId(): JsonField = firstId + + /** + * Returns the raw JSON value of [lastId]. + * + * Unlike [lastId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("last_id") @ExcludeMissing fun _lastId(): JsonField = lastId + + @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 [CheckpointListPageResponse]. + * + * The following fields are required: + * ```java + * .data() + * .hasMore() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CheckpointListPageResponse]. */ + class Builder internal constructor() { + + private var data: JsonField>? = null + private var hasMore: JsonField? = null + private var object_: JsonValue = JsonValue.from("list") + private var firstId: JsonField = JsonMissing.of() + private var lastId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(checkpointListPageResponse: CheckpointListPageResponse) = apply { + data = checkpointListPageResponse.data.map { it.toMutableList() } + hasMore = checkpointListPageResponse.hasMore + object_ = checkpointListPageResponse.object_ + firstId = checkpointListPageResponse.firstId + lastId = checkpointListPageResponse.lastId + additionalProperties = checkpointListPageResponse.additionalProperties.toMutableMap() + } + + fun data(data: List) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun data(data: JsonField>) = apply { + this.data = data.map { it.toMutableList() } + } + + /** + * Adds a single [FineTuningJobCheckpoint] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: FineTuningJobCheckpoint) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) + + /** + * Sets [Builder.hasMore] to an arbitrary JSON value. + * + * You should usually call [Builder.hasMore] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } + + /** + * 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("list") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + fun firstId(firstId: String?) = firstId(JsonField.ofNullable(firstId)) + + /** Alias for calling [Builder.firstId] with `firstId.orElse(null)`. */ + fun firstId(firstId: Optional) = firstId(firstId.getOrNull()) + + /** + * Sets [Builder.firstId] to an arbitrary JSON value. + * + * You should usually call [Builder.firstId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun firstId(firstId: JsonField) = apply { this.firstId = firstId } + + fun lastId(lastId: String?) = lastId(JsonField.ofNullable(lastId)) + + /** Alias for calling [Builder.lastId] with `lastId.orElse(null)`. */ + fun lastId(lastId: Optional) = lastId(lastId.getOrNull()) + + /** + * Sets [Builder.lastId] to an arbitrary JSON value. + * + * You should usually call [Builder.lastId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun lastId(lastId: JsonField) = apply { this.lastId = lastId } + + 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 [CheckpointListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .hasMore() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CheckpointListPageResponse = + CheckpointListPageResponse( + checkRequired("data", data).map { it.toImmutable() }, + checkRequired("hasMore", hasMore), + object_, + firstId, + lastId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): CheckpointListPageResponse = apply { + if (validated) { + return@apply + } + + data().forEach { it.validate() } + hasMore() + _object_().let { + if (it != JsonValue.from("list")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + firstId() + lastId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (hasMore.asKnown().isPresent) 1 else 0) + + object_.let { if (it == JsonValue.from("list")) 1 else 0 } + + (if (firstId.asKnown().isPresent) 1 else 0) + + (if (lastId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is CheckpointListPageResponse && data == other.data && hasMore == other.hasMore && object_ == other.object_ && firstId == other.firstId && lastId == other.lastId && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(data, hasMore, object_, firstId, lastId, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CheckpointListPageResponse{data=$data, hasMore=$hasMore, object_=$object_, firstId=$firstId, lastId=$lastId, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/models/ModelListPage.kt b/openai-java-core/src/main/kotlin/com/openai/models/models/ModelListPage.kt index 3f0902ec..2da80544 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/models/ModelListPage.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/models/ModelListPage.kt @@ -2,179 +2,106 @@ package com.openai.models.models -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.errors.OpenAIInvalidDataException +import com.openai.core.checkRequired import com.openai.services.blocking.ModelService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** - * Lists the currently available models, and provides basic information about each one such as the - * owner and availability. - */ +/** @see [ModelService.list] */ class ModelListPage private constructor( - private val modelsService: ModelService, + private val service: ModelService, private val params: ModelListParams, - private val response: Response, + private val response: ModelListPageResponse, ) { - fun response(): Response = response + /** + * Delegates to [ModelListPageResponse], but gracefully handles missing data. + * + * @see [ModelListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() - fun data(): List = response().data() + /** @see [ModelListPageResponse.object_] */ + fun object_(): JsonValue = response._object_() - fun object_(): String = response().object_() + fun hasNextPage(): Boolean = data().isNotEmpty() - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ModelListPage && modelsService == other.modelsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(modelsService, params, response) /* spotless:on */ + fun getNextPageParams(): Optional = Optional.empty() - override fun toString() = - "ModelListPage{modelsService=$modelsService, params=$params, response=$response}" + fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } - fun hasNextPage(): Boolean { - return !data().isEmpty() - } + fun autoPager(): AutoPager = AutoPager(this) - fun getNextPageParams(): Optional { - return Optional.empty() - } + /** The parameters that were used to request this page. */ + fun params(): ModelListParams = params - fun getNextPage(): Optional { - return getNextPageParams().map { modelsService.list(it) } - } + /** The response that this page was parsed from. */ + fun response(): ModelListPageResponse = response - fun autoPager(): AutoPager = AutoPager(this) + fun toBuilder() = Builder().from(this) companion object { - @JvmStatic - fun of(modelsService: ModelService, params: ModelListParams, response: Response) = - ModelListPage(modelsService, params, response) + /** + * Returns a mutable builder for constructing an instance of [ModelListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() } - class Response( - private val data: JsonField>, - private val object_: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("object") object_: JsonField = JsonMissing.of(), - ) : this(data, object_, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun object_(): String = object_.getRequired("object") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("object") - fun _object_(): Optional> = Optional.ofNullable(object_) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - data().map { it.validate() } - object_() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && object_ == other.object_ && additionalProperties == other.additionalProperties /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, object_, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{data=$data, object_=$object_, additionalProperties=$additionalProperties}" + /** A builder for [ModelListPage]. */ + class Builder internal constructor() { - companion object { + private var service: ModelService? = null + private var params: ModelListParams? = null + private var response: ModelListPageResponse? = null - /** Returns a mutable builder for constructing an instance of [ModelListPage]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(modelListPage: ModelListPage) = apply { + service = modelListPage.service + params = modelListPage.params + response = modelListPage.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var object_: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.object_ = page.object_ - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun object_(object_: String) = object_(JsonField.of(object_)) - - fun object_(object_: JsonField) = apply { this.object_ = object_ } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(data, object_, additionalProperties.toMutableMap()) - } + fun service(service: ModelService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: ModelListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: ModelListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [ModelListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ModelListPage = + ModelListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: ModelListPage) : Iterable { @@ -195,4 +122,16 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ModelListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = "ModelListPage{service=$service, params=$params, response=$response}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/models/ModelListPageAsync.kt b/openai-java-core/src/main/kotlin/com/openai/models/models/ModelListPageAsync.kt index ffd731af..653a08f5 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/models/ModelListPageAsync.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/models/ModelListPageAsync.kt @@ -2,17 +2,9 @@ package com.openai.models.models -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.errors.OpenAIInvalidDataException +import com.openai.core.checkRequired import com.openai.services.async.ModelServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -20,164 +12,100 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** - * Lists the currently available models, and provides basic information about each one such as the - * owner and availability. - */ +/** @see [ModelServiceAsync.list] */ class ModelListPageAsync private constructor( - private val modelsService: ModelServiceAsync, + private val service: ModelServiceAsync, private val params: ModelListParams, - private val response: Response, + private val response: ModelListPageResponse, ) { - fun response(): Response = response + /** + * Delegates to [ModelListPageResponse], but gracefully handles missing data. + * + * @see [ModelListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() - fun data(): List = response().data() + /** @see [ModelListPageResponse.object_] */ + fun object_(): JsonValue = response._object_() - fun object_(): String = response().object_() + fun hasNextPage(): Boolean = data().isNotEmpty() - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ModelListPageAsync && modelsService == other.modelsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(modelsService, params, response) /* spotless:on */ + fun getNextPageParams(): Optional = Optional.empty() - override fun toString() = - "ModelListPageAsync{modelsService=$modelsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - return !data().isEmpty() - } - - fun getNextPageParams(): Optional { - return Optional.empty() - } - - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { modelsService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of(modelsService: ModelServiceAsync, params: ModelListParams, response: Response) = - ModelListPageAsync(modelsService, params, response) - } - - class Response( - private val data: JsonField>, - private val object_: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("object") object_: JsonField = JsonMissing.of(), - ) : this(data, object_, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun object_(): String = object_.getRequired("object") + /** The parameters that were used to request this page. */ + fun params(): ModelListParams = params - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) + /** The response that this page was parsed from. */ + fun response(): ModelListPageResponse = response - @JsonProperty("object") - fun _object_(): Optional> = Optional.ofNullable(object_) + fun toBuilder() = Builder().from(this) - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - data().map { it.validate() } - object_() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && object_ == other.object_ && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, object_, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [ModelListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, object_=$object_, additionalProperties=$additionalProperties}" + /** A builder for [ModelListPageAsync]. */ + class Builder internal constructor() { - companion object { + private var service: ModelServiceAsync? = null + private var params: ModelListParams? = null + private var response: ModelListPageResponse? = null - /** Returns a mutable builder for constructing an instance of [ModelListPageAsync]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(modelListPageAsync: ModelListPageAsync) = apply { + service = modelListPageAsync.service + params = modelListPageAsync.params + response = modelListPageAsync.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var object_: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.object_ = page.object_ - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun object_(object_: String) = object_(JsonField.of(object_)) - - fun object_(object_: JsonField) = apply { this.object_ = object_ } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(data, object_, additionalProperties.toMutableMap()) - } + fun service(service: ModelServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: ModelListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: ModelListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [ModelListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ModelListPageAsync = + ModelListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: ModelListPageAsync) { @@ -205,4 +133,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ModelListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "ModelListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/models/ModelListPageResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/models/ModelListPageResponse.kt new file mode 100644 index 00000000..63c2c106 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/models/ModelListPageResponse.kt @@ -0,0 +1,225 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.models + +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 ModelListPageResponse +private constructor( + private val data: JsonField>, + private val object_: JsonValue, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") @ExcludeMissing data: JsonField> = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + ) : this(data, object_, 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 data(): List = data.getRequired("data") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("list") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField> = data + + @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 [ModelListPageResponse]. + * + * The following fields are required: + * ```java + * .data() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ModelListPageResponse]. */ + class Builder internal constructor() { + + private var data: JsonField>? = null + private var object_: JsonValue = JsonValue.from("list") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(modelListPageResponse: ModelListPageResponse) = apply { + data = modelListPageResponse.data.map { it.toMutableList() } + object_ = modelListPageResponse.object_ + additionalProperties = modelListPageResponse.additionalProperties.toMutableMap() + } + + fun data(data: List) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun data(data: JsonField>) = apply { + this.data = data.map { it.toMutableList() } + } + + /** + * Adds a single [Model] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: Model) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + /** + * 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("list") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + 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 [ModelListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ModelListPageResponse = + ModelListPageResponse( + checkRequired("data", data).map { it.toImmutable() }, + object_, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): ModelListPageResponse = apply { + if (validated) { + return@apply + } + + data().forEach { it.validate() } + _object_().let { + if (it != JsonValue.from("list")) { + throw OpenAIInvalidDataException("'object_' 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 = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + object_.let { if (it == JsonValue.from("list")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ModelListPageResponse && data == other.data && object_ == other.object_ && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(data, object_, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ModelListPageResponse{data=$data, object_=$object_, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/responses/inputitems/InputItemListPage.kt b/openai-java-core/src/main/kotlin/com/openai/models/responses/inputitems/InputItemListPage.kt index cf78f47d..1fbb02ef 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/responses/inputitems/InputItemListPage.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/responses/inputitems/InputItemListPage.kt @@ -2,15 +2,7 @@ package com.openai.models.responses.inputitems -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.errors.OpenAIInvalidDataException +import com.openai.core.checkRequired import com.openai.models.responses.ResponseComputerToolCall import com.openai.models.responses.ResponseComputerToolCallOutputItem import com.openai.models.responses.ResponseFileSearchToolCall @@ -21,43 +13,35 @@ import com.openai.models.responses.ResponseInputMessageItem import com.openai.models.responses.ResponseItem import com.openai.models.responses.ResponseOutputMessage import com.openai.services.blocking.responses.InputItemService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** Returns a list of input items for a given response. */ +/** @see [InputItemService.list] */ class InputItemListPage private constructor( - private val inputItemsService: InputItemService, + private val service: InputItemService, private val params: InputItemListParams, - private val response: Response, + private val response: ResponseItemList, ) { - fun response(): Response = response + /** + * Delegates to [ResponseItemList], but gracefully handles missing data. + * + * @see [ResponseItemList.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() - fun data(): List = response().data() + /** + * Delegates to [ResponseItemList], but gracefully handles missing data. + * + * @see [ResponseItemList.hasMore] + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") - fun hasMore(): Optional = response().hasMore() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is InputItemListPage && inputItemsService == other.inputItemsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(inputItemsService, params, response) /* spotless:on */ - - override fun toString() = - "InputItemListPage{inputItemsService=$inputItemsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - return !data().isEmpty() - } + fun hasNextPage(): Boolean = data().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -74,35 +58,36 @@ private constructor( object : ResponseItem.Visitor> { override fun visitResponseInputMessageItem( responseInputMessageItem: ResponseInputMessageItem - ): Optional = Optional.of(responseInputMessageItem.id()) + ): Optional = + responseInputMessageItem._id().getOptional("id") override fun visitResponseOutputMessage( responseOutputMessage: ResponseOutputMessage - ): Optional = Optional.of(responseOutputMessage.id()) + ): Optional = responseOutputMessage._id().getOptional("id") override fun visitFileSearchCall( fileSearchCall: ResponseFileSearchToolCall - ): Optional = Optional.of(fileSearchCall.id()) + ): Optional = fileSearchCall._id().getOptional("id") override fun visitComputerCall( computerCall: ResponseComputerToolCall - ): Optional = Optional.of(computerCall.id()) + ): Optional = computerCall._id().getOptional("id") override fun visitComputerCallOutput( computerCallOutput: ResponseComputerToolCallOutputItem - ): Optional = Optional.of(computerCallOutput.id()) + ): Optional = computerCallOutput._id().getOptional("id") override fun visitWebSearchCall( webSearchCall: ResponseFunctionWebSearch - ): Optional = Optional.of(webSearchCall.id()) + ): Optional = webSearchCall._id().getOptional("id") override fun visitFunctionCall( functionCall: ResponseFunctionToolCallItem - ): Optional = functionCall.id() + ): Optional = functionCall._id().getOptional("id") override fun visitFunctionCallOutput( functionCallOutput: ResponseFunctionToolCallOutputItem - ): Optional = Optional.of(functionCallOutput.id()) + ): Optional = functionCallOutput._id().getOptional("id") } ) ) @@ -110,127 +95,75 @@ private constructor( ) } - fun getNextPage(): Optional { - return getNextPageParams().map { inputItemsService.list(it) } - } + fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) - companion object { + /** The parameters that were used to request this page. */ + fun params(): InputItemListParams = params - @JvmStatic - fun of( - inputItemsService: InputItemService, - params: InputItemListParams, - response: Response, - ) = InputItemListPage(inputItemsService, params, response) - } + /** The response that this page was parsed from. */ + fun response(): ResponseItemList = response - class Response( - private val data: JsonField>, - private val hasMore: JsonField, - private val additionalProperties: MutableMap, - ) { + fun toBuilder() = Builder().from(this) - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("has_more") hasMore: JsonField = JsonMissing.of(), - ) : this(data, hasMore, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun hasMore(): Optional = hasMore.getOptional("has_more") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("has_more") - fun _hasMore(): Optional> = Optional.ofNullable(hasMore) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - data().map { it.validate() } - hasMore() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && hasMore == other.hasMore && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, hasMore, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [InputItemListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, hasMore=$hasMore, additionalProperties=$additionalProperties}" + /** A builder for [InputItemListPage]. */ + class Builder internal constructor() { - companion object { + private var service: InputItemService? = null + private var params: InputItemListParams? = null + private var response: ResponseItemList? = null - /** Returns a mutable builder for constructing an instance of [InputItemListPage]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(inputItemListPage: InputItemListPage) = apply { + service = inputItemListPage.service + params = inputItemListPage.params + response = inputItemListPage.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var hasMore: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.hasMore = page.hasMore - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) - - fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(data, hasMore, additionalProperties.toMutableMap()) - } + fun service(service: InputItemService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: InputItemListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: ResponseItemList) = apply { this.response = response } + + /** + * Returns an immutable instance of [InputItemListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): InputItemListPage = + InputItemListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: InputItemListPage) : Iterable { @@ -251,4 +184,17 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is InputItemListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "InputItemListPage{service=$service, params=$params, response=$response}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/responses/inputitems/InputItemListPageAsync.kt b/openai-java-core/src/main/kotlin/com/openai/models/responses/inputitems/InputItemListPageAsync.kt index ded30345..ddde7ff4 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/responses/inputitems/InputItemListPageAsync.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/responses/inputitems/InputItemListPageAsync.kt @@ -2,15 +2,7 @@ package com.openai.models.responses.inputitems -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.errors.OpenAIInvalidDataException +import com.openai.core.checkRequired import com.openai.models.responses.ResponseComputerToolCall import com.openai.models.responses.ResponseComputerToolCallOutputItem import com.openai.models.responses.ResponseFileSearchToolCall @@ -21,7 +13,6 @@ import com.openai.models.responses.ResponseInputMessageItem import com.openai.models.responses.ResponseItem import com.openai.models.responses.ResponseOutputMessage import com.openai.services.async.responses.InputItemServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -29,36 +20,29 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** Returns a list of input items for a given response. */ +/** @see [InputItemServiceAsync.list] */ class InputItemListPageAsync private constructor( - private val inputItemsService: InputItemServiceAsync, + private val service: InputItemServiceAsync, private val params: InputItemListParams, - private val response: Response, + private val response: ResponseItemList, ) { - fun response(): Response = response + /** + * Delegates to [ResponseItemList], but gracefully handles missing data. + * + * @see [ResponseItemList.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() - fun data(): List = response().data() + /** + * Delegates to [ResponseItemList], but gracefully handles missing data. + * + * @see [ResponseItemList.hasMore] + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") - fun hasMore(): Optional = response().hasMore() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is InputItemListPageAsync && inputItemsService == other.inputItemsService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(inputItemsService, params, response) /* spotless:on */ - - override fun toString() = - "InputItemListPageAsync{inputItemsService=$inputItemsService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - return !data().isEmpty() - } + fun hasNextPage(): Boolean = data().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { @@ -75,35 +59,36 @@ private constructor( object : ResponseItem.Visitor> { override fun visitResponseInputMessageItem( responseInputMessageItem: ResponseInputMessageItem - ): Optional = Optional.of(responseInputMessageItem.id()) + ): Optional = + responseInputMessageItem._id().getOptional("id") override fun visitResponseOutputMessage( responseOutputMessage: ResponseOutputMessage - ): Optional = Optional.of(responseOutputMessage.id()) + ): Optional = responseOutputMessage._id().getOptional("id") override fun visitFileSearchCall( fileSearchCall: ResponseFileSearchToolCall - ): Optional = Optional.of(fileSearchCall.id()) + ): Optional = fileSearchCall._id().getOptional("id") override fun visitComputerCall( computerCall: ResponseComputerToolCall - ): Optional = Optional.of(computerCall.id()) + ): Optional = computerCall._id().getOptional("id") override fun visitComputerCallOutput( computerCallOutput: ResponseComputerToolCallOutputItem - ): Optional = Optional.of(computerCallOutput.id()) + ): Optional = computerCallOutput._id().getOptional("id") override fun visitWebSearchCall( webSearchCall: ResponseFunctionWebSearch - ): Optional = Optional.of(webSearchCall.id()) + ): Optional = webSearchCall._id().getOptional("id") override fun visitFunctionCall( functionCall: ResponseFunctionToolCallItem - ): Optional = functionCall.id() + ): Optional = functionCall._id().getOptional("id") override fun visitFunctionCallOutput( functionCallOutput: ResponseFunctionToolCallOutputItem - ): Optional = Optional.of(functionCallOutput.id()) + ): Optional = functionCallOutput._id().getOptional("id") } ) ) @@ -111,131 +96,78 @@ private constructor( ) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { inputItemsService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of( - inputItemsService: InputItemServiceAsync, - params: InputItemListParams, - response: Response, - ) = InputItemListPageAsync(inputItemsService, params, response) - } - - class Response( - private val data: JsonField>, - private val hasMore: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("has_more") hasMore: JsonField = JsonMissing.of(), - ) : this(data, hasMore, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun hasMore(): Optional = hasMore.getOptional("has_more") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("has_more") - fun _hasMore(): Optional> = Optional.ofNullable(hasMore) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false + /** The parameters that were used to request this page. */ + fun params(): InputItemListParams = params - fun validate(): Response = apply { - if (validated) { - return@apply - } + /** The response that this page was parsed from. */ + fun response(): ResponseItemList = response - data().map { it.validate() } - hasMore() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + fun toBuilder() = Builder().from(this) - return /* spotless:off */ other is Response && data == other.data && hasMore == other.hasMore && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, hasMore, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [InputItemListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, hasMore=$hasMore, additionalProperties=$additionalProperties}" + /** A builder for [InputItemListPageAsync]. */ + class Builder internal constructor() { - companion object { + private var service: InputItemServiceAsync? = null + private var params: InputItemListParams? = null + private var response: ResponseItemList? = null - /** - * Returns a mutable builder for constructing an instance of [InputItemListPageAsync]. - */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(inputItemListPageAsync: InputItemListPageAsync) = apply { + service = inputItemListPageAsync.service + params = inputItemListPageAsync.params + response = inputItemListPageAsync.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var hasMore: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.hasMore = page.hasMore - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) - - fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(data, hasMore, additionalProperties.toMutableMap()) - } + fun service(service: InputItemServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: InputItemListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: ResponseItemList) = apply { this.response = response } + + /** + * Returns an immutable instance of [InputItemListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): InputItemListPageAsync = + InputItemListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: InputItemListPageAsync) { @@ -263,4 +195,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is InputItemListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "InputItemListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/VectorStoreListPage.kt b/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/VectorStoreListPage.kt index 7a1c3c8a..fcb7958e 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/VectorStoreListPage.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/VectorStoreListPage.kt @@ -2,183 +2,115 @@ package com.openai.models.vectorstores -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.errors.OpenAIInvalidDataException +import com.openai.core.checkRequired import com.openai.services.blocking.VectorStoreService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** Returns a list of vector stores. */ +/** @see [VectorStoreService.list] */ class VectorStoreListPage private constructor( - private val vectorStoresService: VectorStoreService, + private val service: VectorStoreService, private val params: VectorStoreListParams, - private val response: Response, + private val response: VectorStoreListPageResponse, ) { - fun response(): Response = response + /** + * Delegates to [VectorStoreListPageResponse], but gracefully handles missing data. + * + * @see [VectorStoreListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() - fun data(): List = response().data() + /** + * Delegates to [VectorStoreListPageResponse], but gracefully handles missing data. + * + * @see [VectorStoreListPageResponse.hasMore] + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") - fun hasMore(): Optional = response().hasMore() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is VectorStoreListPage && vectorStoresService == other.vectorStoresService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(vectorStoresService, params, response) /* spotless:on */ - - override fun toString() = - "VectorStoreListPage{vectorStoresService=$vectorStoresService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - return !data().isEmpty() - } + fun hasNextPage(): Boolean = data().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return Optional.of(params.toBuilder().after(data().last().id()).build()) + return Optional.of(params.toBuilder().after(data().last()._id().getOptional("id")).build()) } - fun getNextPage(): Optional { - return getNextPageParams().map { vectorStoresService.list(it) } - } + fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) - companion object { + /** The parameters that were used to request this page. */ + fun params(): VectorStoreListParams = params - @JvmStatic - fun of( - vectorStoresService: VectorStoreService, - params: VectorStoreListParams, - response: Response, - ) = VectorStoreListPage(vectorStoresService, params, response) - } + /** The response that this page was parsed from. */ + fun response(): VectorStoreListPageResponse = response - class Response( - private val data: JsonField>, - private val hasMore: JsonField, - private val additionalProperties: MutableMap, - ) { + fun toBuilder() = Builder().from(this) - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("has_more") hasMore: JsonField = JsonMissing.of(), - ) : this(data, hasMore, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun hasMore(): Optional = hasMore.getOptional("has_more") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("has_more") - fun _hasMore(): Optional> = Optional.ofNullable(hasMore) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - data().map { it.validate() } - hasMore() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && hasMore == other.hasMore && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, hasMore, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [VectorStoreListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, hasMore=$hasMore, additionalProperties=$additionalProperties}" + /** A builder for [VectorStoreListPage]. */ + class Builder internal constructor() { - companion object { + private var service: VectorStoreService? = null + private var params: VectorStoreListParams? = null + private var response: VectorStoreListPageResponse? = null - /** Returns a mutable builder for constructing an instance of [VectorStoreListPage]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(vectorStoreListPage: VectorStoreListPage) = apply { + service = vectorStoreListPage.service + params = vectorStoreListPage.params + response = vectorStoreListPage.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var hasMore: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.hasMore = page.hasMore - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) - - fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(data, hasMore, additionalProperties.toMutableMap()) - } + fun service(service: VectorStoreService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: VectorStoreListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: VectorStoreListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [VectorStoreListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): VectorStoreListPage = + VectorStoreListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: VectorStoreListPage) : Iterable { @@ -199,4 +131,17 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is VectorStoreListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "VectorStoreListPage{service=$service, params=$params, response=$response}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/VectorStoreListPageAsync.kt b/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/VectorStoreListPageAsync.kt index 6623139e..1e2daf96 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/VectorStoreListPageAsync.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/VectorStoreListPageAsync.kt @@ -2,17 +2,8 @@ package com.openai.models.vectorstores -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.errors.OpenAIInvalidDataException +import com.openai.core.checkRequired import com.openai.services.async.VectorStoreServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -20,170 +11,110 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** Returns a list of vector stores. */ +/** @see [VectorStoreServiceAsync.list] */ class VectorStoreListPageAsync private constructor( - private val vectorStoresService: VectorStoreServiceAsync, + private val service: VectorStoreServiceAsync, private val params: VectorStoreListParams, - private val response: Response, + private val response: VectorStoreListPageResponse, ) { - fun response(): Response = response + /** + * Delegates to [VectorStoreListPageResponse], but gracefully handles missing data. + * + * @see [VectorStoreListPageResponse.data] + */ + fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList() - fun data(): List = response().data() + /** + * Delegates to [VectorStoreListPageResponse], but gracefully handles missing data. + * + * @see [VectorStoreListPageResponse.hasMore] + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") - fun hasMore(): Optional = response().hasMore() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is VectorStoreListPageAsync && vectorStoresService == other.vectorStoresService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(vectorStoresService, params, response) /* spotless:on */ - - override fun toString() = - "VectorStoreListPageAsync{vectorStoresService=$vectorStoresService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - return !data().isEmpty() - } + fun hasNextPage(): Boolean = data().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return Optional.of(params.toBuilder().after(data().last().id()).build()) + return Optional.of(params.toBuilder().after(data().last()._id().getOptional("id")).build()) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { vectorStoresService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of( - vectorStoresService: VectorStoreServiceAsync, - params: VectorStoreListParams, - response: Response, - ) = VectorStoreListPageAsync(vectorStoresService, params, response) - } - - class Response( - private val data: JsonField>, - private val hasMore: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("has_more") hasMore: JsonField = JsonMissing.of(), - ) : this(data, hasMore, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun hasMore(): Optional = hasMore.getOptional("has_more") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("has_more") - fun _hasMore(): Optional> = Optional.ofNullable(hasMore) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false + /** The parameters that were used to request this page. */ + fun params(): VectorStoreListParams = params - fun validate(): Response = apply { - if (validated) { - return@apply - } + /** The response that this page was parsed from. */ + fun response(): VectorStoreListPageResponse = response - data().map { it.validate() } - hasMore() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + fun toBuilder() = Builder().from(this) - return /* spotless:off */ other is Response && data == other.data && hasMore == other.hasMore && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, hasMore, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [VectorStoreListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, hasMore=$hasMore, additionalProperties=$additionalProperties}" + /** A builder for [VectorStoreListPageAsync]. */ + class Builder internal constructor() { - companion object { + private var service: VectorStoreServiceAsync? = null + private var params: VectorStoreListParams? = null + private var response: VectorStoreListPageResponse? = null - /** - * Returns a mutable builder for constructing an instance of [VectorStoreListPageAsync]. - */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(vectorStoreListPageAsync: VectorStoreListPageAsync) = apply { + service = vectorStoreListPageAsync.service + params = vectorStoreListPageAsync.params + response = vectorStoreListPageAsync.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var hasMore: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.hasMore = page.hasMore - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) - - fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(data, hasMore, additionalProperties.toMutableMap()) - } + fun service(service: VectorStoreServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: VectorStoreListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: VectorStoreListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [VectorStoreListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): VectorStoreListPageAsync = + VectorStoreListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: VectorStoreListPageAsync) { @@ -211,4 +142,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is VectorStoreListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "VectorStoreListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/VectorStoreListPageResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/VectorStoreListPageResponse.kt new file mode 100644 index 00000000..c51536c6 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/VectorStoreListPageResponse.kt @@ -0,0 +1,317 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.vectorstores + +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 VectorStoreListPageResponse +private constructor( + private val data: JsonField>, + private val firstId: JsonField, + private val hasMore: JsonField, + private val lastId: JsonField, + private val object_: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") @ExcludeMissing data: JsonField> = JsonMissing.of(), + @JsonProperty("first_id") @ExcludeMissing firstId: JsonField = JsonMissing.of(), + @JsonProperty("has_more") @ExcludeMissing hasMore: JsonField = JsonMissing.of(), + @JsonProperty("last_id") @ExcludeMissing lastId: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonField = JsonMissing.of(), + ) : this(data, firstId, hasMore, lastId, object_, 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 data(): List = data.getRequired("data") + + /** + * @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 firstId(): String = firstId.getRequired("first_id") + + /** + * @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 hasMore(): Boolean = hasMore.getRequired("has_more") + + /** + * @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 lastId(): String = lastId.getRequired("last_id") + + /** + * @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 object_(): String = object_.getRequired("object") + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField> = data + + /** + * Returns the raw JSON value of [firstId]. + * + * Unlike [firstId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("first_id") @ExcludeMissing fun _firstId(): JsonField = firstId + + /** + * Returns the raw JSON value of [hasMore]. + * + * Unlike [hasMore], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("has_more") @ExcludeMissing fun _hasMore(): JsonField = hasMore + + /** + * Returns the raw JSON value of [lastId]. + * + * Unlike [lastId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("last_id") @ExcludeMissing fun _lastId(): JsonField = lastId + + /** + * Returns the raw JSON value of [object_]. + * + * Unlike [object_], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonField = object_ + + @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 [VectorStoreListPageResponse]. + * + * The following fields are required: + * ```java + * .data() + * .firstId() + * .hasMore() + * .lastId() + * .object_() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [VectorStoreListPageResponse]. */ + class Builder internal constructor() { + + private var data: JsonField>? = null + private var firstId: JsonField? = null + private var hasMore: JsonField? = null + private var lastId: JsonField? = null + private var object_: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(vectorStoreListPageResponse: VectorStoreListPageResponse) = apply { + data = vectorStoreListPageResponse.data.map { it.toMutableList() } + firstId = vectorStoreListPageResponse.firstId + hasMore = vectorStoreListPageResponse.hasMore + lastId = vectorStoreListPageResponse.lastId + object_ = vectorStoreListPageResponse.object_ + additionalProperties = vectorStoreListPageResponse.additionalProperties.toMutableMap() + } + + fun data(data: List) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun data(data: JsonField>) = apply { + this.data = data.map { it.toMutableList() } + } + + /** + * Adds a single [VectorStore] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: VectorStore) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + fun firstId(firstId: String) = firstId(JsonField.of(firstId)) + + /** + * Sets [Builder.firstId] to an arbitrary JSON value. + * + * You should usually call [Builder.firstId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun firstId(firstId: JsonField) = apply { this.firstId = firstId } + + fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) + + /** + * Sets [Builder.hasMore] to an arbitrary JSON value. + * + * You should usually call [Builder.hasMore] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } + + fun lastId(lastId: String) = lastId(JsonField.of(lastId)) + + /** + * Sets [Builder.lastId] to an arbitrary JSON value. + * + * You should usually call [Builder.lastId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun lastId(lastId: JsonField) = apply { this.lastId = lastId } + + fun object_(object_: String) = object_(JsonField.of(object_)) + + /** + * Sets [Builder.object_] to an arbitrary JSON value. + * + * You should usually call [Builder.object_] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun object_(object_: JsonField) = apply { this.object_ = object_ } + + 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 [VectorStoreListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .firstId() + * .hasMore() + * .lastId() + * .object_() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): VectorStoreListPageResponse = + VectorStoreListPageResponse( + checkRequired("data", data).map { it.toImmutable() }, + checkRequired("firstId", firstId), + checkRequired("hasMore", hasMore), + checkRequired("lastId", lastId), + checkRequired("object_", object_), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): VectorStoreListPageResponse = apply { + if (validated) { + return@apply + } + + data().forEach { it.validate() } + firstId() + hasMore() + lastId() + object_() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (firstId.asKnown().isPresent) 1 else 0) + + (if (hasMore.asKnown().isPresent) 1 else 0) + + (if (lastId.asKnown().isPresent) 1 else 0) + + (if (object_.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is VectorStoreListPageResponse && data == other.data && firstId == other.firstId && hasMore == other.hasMore && lastId == other.lastId && object_ == other.object_ && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(data, firstId, hasMore, lastId, object_, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "VectorStoreListPageResponse{data=$data, firstId=$firstId, hasMore=$hasMore, lastId=$lastId, object_=$object_, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/VectorStoreSearchPage.kt b/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/VectorStoreSearchPage.kt index 064a144f..fcdefb6c 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/VectorStoreSearchPage.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/VectorStoreSearchPage.kt @@ -2,184 +2,108 @@ package com.openai.models.vectorstores -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.errors.OpenAIInvalidDataException +import com.openai.core.checkRequired import com.openai.services.blocking.VectorStoreService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** Search a vector store for relevant chunks based on a query and file attributes filter. */ +/** @see [VectorStoreService.search] */ class VectorStoreSearchPage private constructor( - private val vectorStoresService: VectorStoreService, + private val service: VectorStoreService, private val params: VectorStoreSearchParams, - private val response: Response, + private val response: VectorStoreSearchPageResponse, ) { - fun response(): Response = response + /** + * Delegates to [VectorStoreSearchPageResponse], but gracefully handles missing data. + * + * @see [VectorStoreSearchPageResponse.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() - fun data(): List = response().data() + /** @see [VectorStoreSearchPageResponse.object_] */ + fun object_(): JsonValue = response._object_() - fun object_(): String = response().object_() + fun hasNextPage(): Boolean = data().isNotEmpty() - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is VectorStoreSearchPage && vectorStoresService == other.vectorStoresService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(vectorStoresService, params, response) /* spotless:on */ + fun getNextPageParams(): Optional = Optional.empty() - override fun toString() = - "VectorStoreSearchPage{vectorStoresService=$vectorStoresService, params=$params, response=$response}" + fun getNextPage(): Optional = + getNextPageParams().map { service.search(it) } - fun hasNextPage(): Boolean { - return !data().isEmpty() - } + fun autoPager(): AutoPager = AutoPager(this) - fun getNextPageParams(): Optional { - return Optional.empty() - } + /** The parameters that were used to request this page. */ + fun params(): VectorStoreSearchParams = params - fun getNextPage(): Optional { - return getNextPageParams().map { vectorStoresService.search(it) } - } + /** The response that this page was parsed from. */ + fun response(): VectorStoreSearchPageResponse = response - fun autoPager(): AutoPager = AutoPager(this) + fun toBuilder() = Builder().from(this) companion object { - @JvmStatic - fun of( - vectorStoresService: VectorStoreService, - params: VectorStoreSearchParams, - response: Response, - ) = VectorStoreSearchPage(vectorStoresService, params, response) + /** + * Returns a mutable builder for constructing an instance of [VectorStoreSearchPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() } - class Response( - private val data: JsonField>, - private val object_: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") - data: JsonField> = JsonMissing.of(), - @JsonProperty("object") object_: JsonField = JsonMissing.of(), - ) : this(data, object_, mutableMapOf()) - - fun data(): List = - data.getOptional("data").getOrNull() ?: listOf() - - fun object_(): String = object_.getRequired("object") - - @JsonProperty("data") - fun _data(): Optional>> = - Optional.ofNullable(data) - - @JsonProperty("object") - fun _object_(): Optional> = Optional.ofNullable(object_) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - data().map { it.validate() } - object_() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && object_ == other.object_ && additionalProperties == other.additionalProperties /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, object_, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{data=$data, object_=$object_, additionalProperties=$additionalProperties}" + /** A builder for [VectorStoreSearchPage]. */ + class Builder internal constructor() { - companion object { + private var service: VectorStoreService? = null + private var params: VectorStoreSearchParams? = null + private var response: VectorStoreSearchPageResponse? = null - /** - * Returns a mutable builder for constructing an instance of [VectorStoreSearchPage]. - */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(vectorStoreSearchPage: VectorStoreSearchPage) = apply { + service = vectorStoreSearchPage.service + params = vectorStoreSearchPage.params + response = vectorStoreSearchPage.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var object_: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.object_ = page.object_ - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun object_(object_: String) = object_(JsonField.of(object_)) - - fun object_(object_: JsonField) = apply { this.object_ = object_ } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(data, object_, additionalProperties.toMutableMap()) - } + fun service(service: VectorStoreService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: VectorStoreSearchParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: VectorStoreSearchPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [VectorStoreSearchPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): VectorStoreSearchPage = + VectorStoreSearchPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: VectorStoreSearchPage) : @@ -201,4 +125,17 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is VectorStoreSearchPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "VectorStoreSearchPage{service=$service, params=$params, response=$response}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/VectorStoreSearchPageAsync.kt b/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/VectorStoreSearchPageAsync.kt index cc8ac7ed..0b7c1d85 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/VectorStoreSearchPageAsync.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/VectorStoreSearchPageAsync.kt @@ -2,17 +2,9 @@ package com.openai.models.vectorstores -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.errors.OpenAIInvalidDataException +import com.openai.core.checkRequired import com.openai.services.async.VectorStoreServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -20,170 +12,101 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** Search a vector store for relevant chunks based on a query and file attributes filter. */ +/** @see [VectorStoreServiceAsync.search] */ class VectorStoreSearchPageAsync private constructor( - private val vectorStoresService: VectorStoreServiceAsync, + private val service: VectorStoreServiceAsync, private val params: VectorStoreSearchParams, - private val response: Response, + private val response: VectorStoreSearchPageResponse, ) { - fun response(): Response = response + /** + * Delegates to [VectorStoreSearchPageResponse], but gracefully handles missing data. + * + * @see [VectorStoreSearchPageResponse.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() - fun data(): List = response().data() + /** @see [VectorStoreSearchPageResponse.object_] */ + fun object_(): JsonValue = response._object_() - fun object_(): String = response().object_() + fun hasNextPage(): Boolean = data().isNotEmpty() - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is VectorStoreSearchPageAsync && vectorStoresService == other.vectorStoresService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(vectorStoresService, params, response) /* spotless:on */ + fun getNextPageParams(): Optional = Optional.empty() - override fun toString() = - "VectorStoreSearchPageAsync{vectorStoresService=$vectorStoresService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - return !data().isEmpty() - } - - fun getNextPageParams(): Optional { - return Optional.empty() - } - - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { vectorStoresService.search(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.search(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of( - vectorStoresService: VectorStoreServiceAsync, - params: VectorStoreSearchParams, - response: Response, - ) = VectorStoreSearchPageAsync(vectorStoresService, params, response) - } - - class Response( - private val data: JsonField>, - private val object_: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") - data: JsonField> = JsonMissing.of(), - @JsonProperty("object") object_: JsonField = JsonMissing.of(), - ) : this(data, object_, mutableMapOf()) - - fun data(): List = - data.getOptional("data").getOrNull() ?: listOf() - - fun object_(): String = object_.getRequired("object") + /** The parameters that were used to request this page. */ + fun params(): VectorStoreSearchParams = params - @JsonProperty("data") - fun _data(): Optional>> = - Optional.ofNullable(data) + /** The response that this page was parsed from. */ + fun response(): VectorStoreSearchPageResponse = response - @JsonProperty("object") - fun _object_(): Optional> = Optional.ofNullable(object_) + fun toBuilder() = Builder().from(this) - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - data().map { it.validate() } - object_() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && object_ == other.object_ && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, object_, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [VectorStoreSearchPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, object_=$object_, additionalProperties=$additionalProperties}" + /** A builder for [VectorStoreSearchPageAsync]. */ + class Builder internal constructor() { - companion object { + private var service: VectorStoreServiceAsync? = null + private var params: VectorStoreSearchParams? = null + private var response: VectorStoreSearchPageResponse? = null - /** - * Returns a mutable builder for constructing an instance of - * [VectorStoreSearchPageAsync]. - */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(vectorStoreSearchPageAsync: VectorStoreSearchPageAsync) = apply { + service = vectorStoreSearchPageAsync.service + params = vectorStoreSearchPageAsync.params + response = vectorStoreSearchPageAsync.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var object_: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.object_ = page.object_ - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun object_(object_: String) = object_(JsonField.of(object_)) - - fun object_(object_: JsonField) = apply { this.object_ = object_ } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(data, object_, additionalProperties.toMutableMap()) - } + fun service(service: VectorStoreServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: VectorStoreSearchParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: VectorStoreSearchPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [VectorStoreSearchPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): VectorStoreSearchPageAsync = + VectorStoreSearchPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: VectorStoreSearchPageAsync) { @@ -214,4 +137,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is VectorStoreSearchPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "VectorStoreSearchPageAsync{service=$service, params=$params, response=$response}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/VectorStoreSearchPageResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/VectorStoreSearchPageResponse.kt new file mode 100644 index 00000000..3830da7c --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/VectorStoreSearchPageResponse.kt @@ -0,0 +1,360 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.vectorstores + +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 java.util.Optional +import kotlin.jvm.optionals.getOrNull + +class VectorStoreSearchPageResponse +private constructor( + private val data: JsonField>, + private val hasMore: JsonField, + private val nextPage: JsonField, + private val object_: JsonValue, + private val searchQuery: JsonField>, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") + @ExcludeMissing + data: JsonField> = JsonMissing.of(), + @JsonProperty("has_more") @ExcludeMissing hasMore: JsonField = JsonMissing.of(), + @JsonProperty("next_page") @ExcludeMissing nextPage: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + @JsonProperty("search_query") + @ExcludeMissing + searchQuery: JsonField> = JsonMissing.of(), + ) : this(data, hasMore, nextPage, object_, searchQuery, mutableMapOf()) + + /** + * The list of search result items. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun data(): List = data.getRequired("data") + + /** + * Indicates if there are more results to fetch. + * + * @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 hasMore(): Boolean = hasMore.getRequired("has_more") + + /** + * The token for the next page, if any. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun nextPage(): Optional = nextPage.getOptional("next_page") + + /** + * The object type, which is always `vector_store.search_results.page` + * + * Expected to always return the following: + * ```java + * JsonValue.from("vector_store.search_results.page") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * @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 searchQuery(): List = searchQuery.getRequired("search_query") + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") + @ExcludeMissing + fun _data(): JsonField> = data + + /** + * Returns the raw JSON value of [hasMore]. + * + * Unlike [hasMore], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("has_more") @ExcludeMissing fun _hasMore(): JsonField = hasMore + + /** + * Returns the raw JSON value of [nextPage]. + * + * Unlike [nextPage], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("next_page") @ExcludeMissing fun _nextPage(): JsonField = nextPage + + /** + * Returns the raw JSON value of [searchQuery]. + * + * Unlike [searchQuery], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("search_query") + @ExcludeMissing + fun _searchQuery(): JsonField> = searchQuery + + @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 + * [VectorStoreSearchPageResponse]. + * + * The following fields are required: + * ```java + * .data() + * .hasMore() + * .nextPage() + * .searchQuery() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [VectorStoreSearchPageResponse]. */ + class Builder internal constructor() { + + private var data: JsonField>? = null + private var hasMore: JsonField? = null + private var nextPage: JsonField? = null + private var object_: JsonValue = JsonValue.from("vector_store.search_results.page") + private var searchQuery: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(vectorStoreSearchPageResponse: VectorStoreSearchPageResponse) = apply { + data = vectorStoreSearchPageResponse.data.map { it.toMutableList() } + hasMore = vectorStoreSearchPageResponse.hasMore + nextPage = vectorStoreSearchPageResponse.nextPage + object_ = vectorStoreSearchPageResponse.object_ + searchQuery = vectorStoreSearchPageResponse.searchQuery.map { it.toMutableList() } + additionalProperties = vectorStoreSearchPageResponse.additionalProperties.toMutableMap() + } + + /** The list of search result items. */ + fun data(data: List) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun data(data: JsonField>) = apply { + this.data = data.map { it.toMutableList() } + } + + /** + * Adds a single [VectorStoreSearchResponse] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: VectorStoreSearchResponse) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + /** Indicates if there are more results to fetch. */ + fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) + + /** + * Sets [Builder.hasMore] to an arbitrary JSON value. + * + * You should usually call [Builder.hasMore] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } + + /** The token for the next page, if any. */ + fun nextPage(nextPage: String?) = nextPage(JsonField.ofNullable(nextPage)) + + /** Alias for calling [Builder.nextPage] with `nextPage.orElse(null)`. */ + fun nextPage(nextPage: Optional) = nextPage(nextPage.getOrNull()) + + /** + * Sets [Builder.nextPage] to an arbitrary JSON value. + * + * You should usually call [Builder.nextPage] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun nextPage(nextPage: JsonField) = apply { this.nextPage = nextPage } + + /** + * 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("vector_store.search_results.page") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + fun searchQuery(searchQuery: List) = searchQuery(JsonField.of(searchQuery)) + + /** + * Sets [Builder.searchQuery] to an arbitrary JSON value. + * + * You should usually call [Builder.searchQuery] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun searchQuery(searchQuery: JsonField>) = apply { + this.searchQuery = searchQuery.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [Builder.searchQuery]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSearchQuery(searchQuery: String) = apply { + this.searchQuery = + (this.searchQuery ?: JsonField.of(mutableListOf())).also { + checkKnown("searchQuery", it).add(searchQuery) + } + } + + 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 [VectorStoreSearchPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .hasMore() + * .nextPage() + * .searchQuery() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): VectorStoreSearchPageResponse = + VectorStoreSearchPageResponse( + checkRequired("data", data).map { it.toImmutable() }, + checkRequired("hasMore", hasMore), + checkRequired("nextPage", nextPage), + object_, + checkRequired("searchQuery", searchQuery).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): VectorStoreSearchPageResponse = apply { + if (validated) { + return@apply + } + + data().forEach { it.validate() } + hasMore() + nextPage() + _object_().let { + if (it != JsonValue.from("vector_store.search_results.page")) { + throw OpenAIInvalidDataException("'object_' is invalid, received $it") + } + } + searchQuery() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (hasMore.asKnown().isPresent) 1 else 0) + + (if (nextPage.asKnown().isPresent) 1 else 0) + + object_.let { if (it == JsonValue.from("vector_store.search_results.page")) 1 else 0 } + + (searchQuery.asKnown().getOrNull()?.size ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is VectorStoreSearchPageResponse && data == other.data && hasMore == other.hasMore && nextPage == other.nextPage && object_ == other.object_ && searchQuery == other.searchQuery && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(data, hasMore, nextPage, object_, searchQuery, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "VectorStoreSearchPageResponse{data=$data, hasMore=$hasMore, nextPage=$nextPage, object_=$object_, searchQuery=$searchQuery, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/filebatches/FileBatchListFilesPage.kt b/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/filebatches/FileBatchListFilesPage.kt index e8296fc3..42d724d5 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/filebatches/FileBatchListFilesPage.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/filebatches/FileBatchListFilesPage.kt @@ -2,186 +2,118 @@ package com.openai.models.vectorstores.filebatches -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.errors.OpenAIInvalidDataException +import com.openai.core.checkRequired import com.openai.models.vectorstores.files.VectorStoreFile import com.openai.services.blocking.vectorstores.FileBatchService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** Returns a list of vector store files in a batch. */ +/** @see [FileBatchService.listFiles] */ class FileBatchListFilesPage private constructor( - private val fileBatchesService: FileBatchService, + private val service: FileBatchService, private val params: FileBatchListFilesParams, - private val response: Response, + private val response: FileBatchListFilesPageResponse, ) { - fun response(): Response = response + /** + * Delegates to [FileBatchListFilesPageResponse], but gracefully handles missing data. + * + * @see [FileBatchListFilesPageResponse.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() - fun data(): List = response().data() + /** + * Delegates to [FileBatchListFilesPageResponse], but gracefully handles missing data. + * + * @see [FileBatchListFilesPageResponse.hasMore] + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") - fun hasMore(): Optional = response().hasMore() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is FileBatchListFilesPage && fileBatchesService == other.fileBatchesService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(fileBatchesService, params, response) /* spotless:on */ - - override fun toString() = - "FileBatchListFilesPage{fileBatchesService=$fileBatchesService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - return !data().isEmpty() - } + fun hasNextPage(): Boolean = data().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return Optional.of(params.toBuilder().after(data().last().id()).build()) + return Optional.of(params.toBuilder().after(data().last()._id().getOptional("id")).build()) } - fun getNextPage(): Optional { - return getNextPageParams().map { fileBatchesService.listFiles(it) } - } + fun getNextPage(): Optional = + getNextPageParams().map { service.listFiles(it) } fun autoPager(): AutoPager = AutoPager(this) - companion object { + /** The parameters that were used to request this page. */ + fun params(): FileBatchListFilesParams = params - @JvmStatic - fun of( - fileBatchesService: FileBatchService, - params: FileBatchListFilesParams, - response: Response, - ) = FileBatchListFilesPage(fileBatchesService, params, response) - } + /** The response that this page was parsed from. */ + fun response(): FileBatchListFilesPageResponse = response - class Response( - private val data: JsonField>, - private val hasMore: JsonField, - private val additionalProperties: MutableMap, - ) { + fun toBuilder() = Builder().from(this) - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("has_more") hasMore: JsonField = JsonMissing.of(), - ) : this(data, hasMore, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun hasMore(): Optional = hasMore.getOptional("has_more") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("has_more") - fun _hasMore(): Optional> = Optional.ofNullable(hasMore) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - data().map { it.validate() } - hasMore() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && hasMore == other.hasMore && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, hasMore, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [FileBatchListFilesPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, hasMore=$hasMore, additionalProperties=$additionalProperties}" + /** A builder for [FileBatchListFilesPage]. */ + class Builder internal constructor() { - companion object { + private var service: FileBatchService? = null + private var params: FileBatchListFilesParams? = null + private var response: FileBatchListFilesPageResponse? = null - /** - * Returns a mutable builder for constructing an instance of [FileBatchListFilesPage]. - */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(fileBatchListFilesPage: FileBatchListFilesPage) = apply { + service = fileBatchListFilesPage.service + params = fileBatchListFilesPage.params + response = fileBatchListFilesPage.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var hasMore: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.hasMore = page.hasMore - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) - - fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(data, hasMore, additionalProperties.toMutableMap()) - } + fun service(service: FileBatchService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: FileBatchListFilesParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: FileBatchListFilesPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [FileBatchListFilesPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): FileBatchListFilesPage = + FileBatchListFilesPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: FileBatchListFilesPage) : Iterable { @@ -202,4 +134,17 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is FileBatchListFilesPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "FileBatchListFilesPage{service=$service, params=$params, response=$response}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/filebatches/FileBatchListFilesPageAsync.kt b/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/filebatches/FileBatchListFilesPageAsync.kt index 96c5946f..7c52c45b 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/filebatches/FileBatchListFilesPageAsync.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/filebatches/FileBatchListFilesPageAsync.kt @@ -2,18 +2,9 @@ package com.openai.models.vectorstores.filebatches -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.errors.OpenAIInvalidDataException +import com.openai.core.checkRequired import com.openai.models.vectorstores.files.VectorStoreFile import com.openai.services.async.vectorstores.FileBatchServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -21,171 +12,111 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** Returns a list of vector store files in a batch. */ +/** @see [FileBatchServiceAsync.listFiles] */ class FileBatchListFilesPageAsync private constructor( - private val fileBatchesService: FileBatchServiceAsync, + private val service: FileBatchServiceAsync, private val params: FileBatchListFilesParams, - private val response: Response, + private val response: FileBatchListFilesPageResponse, ) { - fun response(): Response = response + /** + * Delegates to [FileBatchListFilesPageResponse], but gracefully handles missing data. + * + * @see [FileBatchListFilesPageResponse.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() - fun data(): List = response().data() + /** + * Delegates to [FileBatchListFilesPageResponse], but gracefully handles missing data. + * + * @see [FileBatchListFilesPageResponse.hasMore] + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") - fun hasMore(): Optional = response().hasMore() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is FileBatchListFilesPageAsync && fileBatchesService == other.fileBatchesService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(fileBatchesService, params, response) /* spotless:on */ - - override fun toString() = - "FileBatchListFilesPageAsync{fileBatchesService=$fileBatchesService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - return !data().isEmpty() - } + fun hasNextPage(): Boolean = data().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return Optional.of(params.toBuilder().after(data().last().id()).build()) + return Optional.of(params.toBuilder().after(data().last()._id().getOptional("id")).build()) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { fileBatchesService.listFiles(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.listFiles(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of( - fileBatchesService: FileBatchServiceAsync, - params: FileBatchListFilesParams, - response: Response, - ) = FileBatchListFilesPageAsync(fileBatchesService, params, response) - } - - class Response( - private val data: JsonField>, - private val hasMore: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("has_more") hasMore: JsonField = JsonMissing.of(), - ) : this(data, hasMore, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun hasMore(): Optional = hasMore.getOptional("has_more") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("has_more") - fun _hasMore(): Optional> = Optional.ofNullable(hasMore) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false + /** The parameters that were used to request this page. */ + fun params(): FileBatchListFilesParams = params - fun validate(): Response = apply { - if (validated) { - return@apply - } + /** The response that this page was parsed from. */ + fun response(): FileBatchListFilesPageResponse = response - data().map { it.validate() } - hasMore() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + fun toBuilder() = Builder().from(this) - return /* spotless:off */ other is Response && data == other.data && hasMore == other.hasMore && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, hasMore, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [FileBatchListFilesPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, hasMore=$hasMore, additionalProperties=$additionalProperties}" + /** A builder for [FileBatchListFilesPageAsync]. */ + class Builder internal constructor() { - companion object { + private var service: FileBatchServiceAsync? = null + private var params: FileBatchListFilesParams? = null + private var response: FileBatchListFilesPageResponse? = null - /** - * Returns a mutable builder for constructing an instance of - * [FileBatchListFilesPageAsync]. - */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(fileBatchListFilesPageAsync: FileBatchListFilesPageAsync) = apply { + service = fileBatchListFilesPageAsync.service + params = fileBatchListFilesPageAsync.params + response = fileBatchListFilesPageAsync.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var hasMore: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.hasMore = page.hasMore - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) - - fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(data, hasMore, additionalProperties.toMutableMap()) - } + fun service(service: FileBatchServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: FileBatchListFilesParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: FileBatchListFilesPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [FileBatchListFilesPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): FileBatchListFilesPageAsync = + FileBatchListFilesPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: FileBatchListFilesPageAsync) { @@ -216,4 +147,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is FileBatchListFilesPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "FileBatchListFilesPageAsync{service=$service, params=$params, response=$response}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/filebatches/FileBatchListFilesPageResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/filebatches/FileBatchListFilesPageResponse.kt new file mode 100644 index 00000000..ae3e0a70 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/filebatches/FileBatchListFilesPageResponse.kt @@ -0,0 +1,322 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.vectorstores.filebatches + +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 com.openai.models.vectorstores.files.VectorStoreFile +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +class FileBatchListFilesPageResponse +private constructor( + private val data: JsonField>, + private val firstId: JsonField, + private val hasMore: JsonField, + private val lastId: JsonField, + private val object_: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") + @ExcludeMissing + data: JsonField> = JsonMissing.of(), + @JsonProperty("first_id") @ExcludeMissing firstId: JsonField = JsonMissing.of(), + @JsonProperty("has_more") @ExcludeMissing hasMore: JsonField = JsonMissing.of(), + @JsonProperty("last_id") @ExcludeMissing lastId: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonField = JsonMissing.of(), + ) : this(data, firstId, hasMore, lastId, object_, 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 data(): List = data.getRequired("data") + + /** + * @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 firstId(): String = firstId.getRequired("first_id") + + /** + * @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 hasMore(): Boolean = hasMore.getRequired("has_more") + + /** + * @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 lastId(): String = lastId.getRequired("last_id") + + /** + * @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 object_(): String = object_.getRequired("object") + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField> = data + + /** + * Returns the raw JSON value of [firstId]. + * + * Unlike [firstId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("first_id") @ExcludeMissing fun _firstId(): JsonField = firstId + + /** + * Returns the raw JSON value of [hasMore]. + * + * Unlike [hasMore], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("has_more") @ExcludeMissing fun _hasMore(): JsonField = hasMore + + /** + * Returns the raw JSON value of [lastId]. + * + * Unlike [lastId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("last_id") @ExcludeMissing fun _lastId(): JsonField = lastId + + /** + * Returns the raw JSON value of [object_]. + * + * Unlike [object_], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonField = object_ + + @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 + * [FileBatchListFilesPageResponse]. + * + * The following fields are required: + * ```java + * .data() + * .firstId() + * .hasMore() + * .lastId() + * .object_() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [FileBatchListFilesPageResponse]. */ + class Builder internal constructor() { + + private var data: JsonField>? = null + private var firstId: JsonField? = null + private var hasMore: JsonField? = null + private var lastId: JsonField? = null + private var object_: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(fileBatchListFilesPageResponse: FileBatchListFilesPageResponse) = apply { + data = fileBatchListFilesPageResponse.data.map { it.toMutableList() } + firstId = fileBatchListFilesPageResponse.firstId + hasMore = fileBatchListFilesPageResponse.hasMore + lastId = fileBatchListFilesPageResponse.lastId + object_ = fileBatchListFilesPageResponse.object_ + additionalProperties = + fileBatchListFilesPageResponse.additionalProperties.toMutableMap() + } + + fun data(data: List) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun data(data: JsonField>) = apply { + this.data = data.map { it.toMutableList() } + } + + /** + * Adds a single [VectorStoreFile] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: VectorStoreFile) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + fun firstId(firstId: String) = firstId(JsonField.of(firstId)) + + /** + * Sets [Builder.firstId] to an arbitrary JSON value. + * + * You should usually call [Builder.firstId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun firstId(firstId: JsonField) = apply { this.firstId = firstId } + + fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) + + /** + * Sets [Builder.hasMore] to an arbitrary JSON value. + * + * You should usually call [Builder.hasMore] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } + + fun lastId(lastId: String) = lastId(JsonField.of(lastId)) + + /** + * Sets [Builder.lastId] to an arbitrary JSON value. + * + * You should usually call [Builder.lastId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun lastId(lastId: JsonField) = apply { this.lastId = lastId } + + fun object_(object_: String) = object_(JsonField.of(object_)) + + /** + * Sets [Builder.object_] to an arbitrary JSON value. + * + * You should usually call [Builder.object_] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun object_(object_: JsonField) = apply { this.object_ = object_ } + + 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 [FileBatchListFilesPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .firstId() + * .hasMore() + * .lastId() + * .object_() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): FileBatchListFilesPageResponse = + FileBatchListFilesPageResponse( + checkRequired("data", data).map { it.toImmutable() }, + checkRequired("firstId", firstId), + checkRequired("hasMore", hasMore), + checkRequired("lastId", lastId), + checkRequired("object_", object_), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): FileBatchListFilesPageResponse = apply { + if (validated) { + return@apply + } + + data().forEach { it.validate() } + firstId() + hasMore() + lastId() + object_() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (firstId.asKnown().isPresent) 1 else 0) + + (if (hasMore.asKnown().isPresent) 1 else 0) + + (if (lastId.asKnown().isPresent) 1 else 0) + + (if (object_.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is FileBatchListFilesPageResponse && data == other.data && firstId == other.firstId && hasMore == other.hasMore && lastId == other.lastId && object_ == other.object_ && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(data, firstId, hasMore, lastId, object_, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "FileBatchListFilesPageResponse{data=$data, firstId=$firstId, hasMore=$hasMore, lastId=$lastId, object_=$object_, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/files/FileContentPage.kt b/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/files/FileContentPage.kt index a291365b..6bbd3084 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/files/FileContentPage.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/files/FileContentPage.kt @@ -2,176 +2,107 @@ package com.openai.models.vectorstores.files -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.errors.OpenAIInvalidDataException +import com.openai.core.checkRequired import com.openai.services.blocking.vectorstores.FileService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** Retrieve the parsed contents of a vector store file. */ +/** @see [FileService.content] */ class FileContentPage private constructor( - private val filesService: FileService, + private val service: FileService, private val params: FileContentParams, - private val response: Response, + private val response: FileContentPageResponse, ) { - fun response(): Response = response + /** + * Delegates to [FileContentPageResponse], but gracefully handles missing data. + * + * @see [FileContentPageResponse.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() - fun data(): List = response().data() + /** @see [FileContentPageResponse.object_] */ + fun object_(): JsonValue = response._object_() - fun object_(): String = response().object_() + fun hasNextPage(): Boolean = data().isNotEmpty() - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is FileContentPage && filesService == other.filesService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(filesService, params, response) /* spotless:on */ + fun getNextPageParams(): Optional = Optional.empty() - override fun toString() = - "FileContentPage{filesService=$filesService, params=$params, response=$response}" + fun getNextPage(): Optional = getNextPageParams().map { service.content(it) } - fun hasNextPage(): Boolean { - return !data().isEmpty() - } + fun autoPager(): AutoPager = AutoPager(this) - fun getNextPageParams(): Optional { - return Optional.empty() - } + /** The parameters that were used to request this page. */ + fun params(): FileContentParams = params - fun getNextPage(): Optional { - return getNextPageParams().map { filesService.content(it) } - } + /** The response that this page was parsed from. */ + fun response(): FileContentPageResponse = response - fun autoPager(): AutoPager = AutoPager(this) + fun toBuilder() = Builder().from(this) companion object { - @JvmStatic - fun of(filesService: FileService, params: FileContentParams, response: Response) = - FileContentPage(filesService, params, response) + /** + * Returns a mutable builder for constructing an instance of [FileContentPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() } - class Response( - private val data: JsonField>, - private val object_: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("object") object_: JsonField = JsonMissing.of(), - ) : this(data, object_, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun object_(): String = object_.getRequired("object") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("object") - fun _object_(): Optional> = Optional.ofNullable(object_) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - data().map { it.validate() } - object_() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && object_ == other.object_ && additionalProperties == other.additionalProperties /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, object_, additionalProperties) /* spotless:on */ - - override fun toString() = - "Response{data=$data, object_=$object_, additionalProperties=$additionalProperties}" + /** A builder for [FileContentPage]. */ + class Builder internal constructor() { - companion object { + private var service: FileService? = null + private var params: FileContentParams? = null + private var response: FileContentPageResponse? = null - /** Returns a mutable builder for constructing an instance of [FileContentPage]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(fileContentPage: FileContentPage) = apply { + service = fileContentPage.service + params = fileContentPage.params + response = fileContentPage.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var object_: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.object_ = page.object_ - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun object_(object_: String) = object_(JsonField.of(object_)) - - fun object_(object_: JsonField) = apply { this.object_ = object_ } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(data, object_, additionalProperties.toMutableMap()) - } + fun service(service: FileService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: FileContentParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: FileContentPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [FileContentPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): FileContentPage = + FileContentPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: FileContentPage) : Iterable { @@ -192,4 +123,17 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is FileContentPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "FileContentPage{service=$service, params=$params, response=$response}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/files/FileContentPageAsync.kt b/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/files/FileContentPageAsync.kt index f6866736..a55657f1 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/files/FileContentPageAsync.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/files/FileContentPageAsync.kt @@ -2,17 +2,9 @@ package com.openai.models.vectorstores.files -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.errors.OpenAIInvalidDataException +import com.openai.core.checkRequired import com.openai.services.async.vectorstores.FileServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -20,161 +12,101 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** Retrieve the parsed contents of a vector store file. */ +/** @see [FileServiceAsync.content] */ class FileContentPageAsync private constructor( - private val filesService: FileServiceAsync, + private val service: FileServiceAsync, private val params: FileContentParams, - private val response: Response, + private val response: FileContentPageResponse, ) { - fun response(): Response = response + /** + * Delegates to [FileContentPageResponse], but gracefully handles missing data. + * + * @see [FileContentPageResponse.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() - fun data(): List = response().data() + /** @see [FileContentPageResponse.object_] */ + fun object_(): JsonValue = response._object_() - fun object_(): String = response().object_() + fun hasNextPage(): Boolean = data().isNotEmpty() - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is FileContentPageAsync && filesService == other.filesService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(filesService, params, response) /* spotless:on */ + fun getNextPageParams(): Optional = Optional.empty() - override fun toString() = - "FileContentPageAsync{filesService=$filesService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - return !data().isEmpty() - } - - fun getNextPageParams(): Optional { - return Optional.empty() - } - - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { filesService.content(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.content(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of(filesService: FileServiceAsync, params: FileContentParams, response: Response) = - FileContentPageAsync(filesService, params, response) - } - - class Response( - private val data: JsonField>, - private val object_: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("object") object_: JsonField = JsonMissing.of(), - ) : this(data, object_, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun object_(): String = object_.getRequired("object") + /** The parameters that were used to request this page. */ + fun params(): FileContentParams = params - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) + /** The response that this page was parsed from. */ + fun response(): FileContentPageResponse = response - @JsonProperty("object") - fun _object_(): Optional> = Optional.ofNullable(object_) + fun toBuilder() = Builder().from(this) - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } - - data().map { it.validate() } - object_() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && object_ == other.object_ && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, object_, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [FileContentPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, object_=$object_, additionalProperties=$additionalProperties}" + /** A builder for [FileContentPageAsync]. */ + class Builder internal constructor() { - companion object { + private var service: FileServiceAsync? = null + private var params: FileContentParams? = null + private var response: FileContentPageResponse? = null - /** Returns a mutable builder for constructing an instance of [FileContentPageAsync]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(fileContentPageAsync: FileContentPageAsync) = apply { + service = fileContentPageAsync.service + params = fileContentPageAsync.params + response = fileContentPageAsync.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var object_: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.object_ = page.object_ - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun object_(object_: String) = object_(JsonField.of(object_)) - - fun object_(object_: JsonField) = apply { this.object_ = object_ } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(data, object_, additionalProperties.toMutableMap()) - } + fun service(service: FileServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: FileContentParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: FileContentPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [FileContentPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): FileContentPageAsync = + FileContentPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: FileContentPageAsync) { @@ -205,4 +137,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is FileContentPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "FileContentPageAsync{service=$service, params=$params, response=$response}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/files/FileContentPageResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/files/FileContentPageResponse.kt new file mode 100644 index 00000000..22f7a2c6 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/files/FileContentPageResponse.kt @@ -0,0 +1,307 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.vectorstores.files + +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 java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Represents the parsed content of a vector store file. */ +class FileContentPageResponse +private constructor( + private val data: JsonField>, + private val hasMore: JsonField, + private val nextPage: JsonField, + private val object_: JsonValue, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") + @ExcludeMissing + data: JsonField> = JsonMissing.of(), + @JsonProperty("has_more") @ExcludeMissing hasMore: JsonField = JsonMissing.of(), + @JsonProperty("next_page") @ExcludeMissing nextPage: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), + ) : this(data, hasMore, nextPage, object_, mutableMapOf()) + + /** + * Parsed content 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 data(): List = data.getRequired("data") + + /** + * Indicates if there are more content pages to fetch. + * + * @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 hasMore(): Boolean = hasMore.getRequired("has_more") + + /** + * The token for the next page, if any. + * + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun nextPage(): Optional = nextPage.getOptional("next_page") + + /** + * The object type, which is always `vector_store.file_content.page` + * + * Expected to always return the following: + * ```java + * JsonValue.from("vector_store.file_content.page") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField> = data + + /** + * Returns the raw JSON value of [hasMore]. + * + * Unlike [hasMore], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("has_more") @ExcludeMissing fun _hasMore(): JsonField = hasMore + + /** + * Returns the raw JSON value of [nextPage]. + * + * Unlike [nextPage], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("next_page") @ExcludeMissing fun _nextPage(): JsonField = nextPage + + @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 [FileContentPageResponse]. + * + * The following fields are required: + * ```java + * .data() + * .hasMore() + * .nextPage() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [FileContentPageResponse]. */ + class Builder internal constructor() { + + private var data: JsonField>? = null + private var hasMore: JsonField? = null + private var nextPage: JsonField? = null + private var object_: JsonValue = JsonValue.from("vector_store.file_content.page") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(fileContentPageResponse: FileContentPageResponse) = apply { + data = fileContentPageResponse.data.map { it.toMutableList() } + hasMore = fileContentPageResponse.hasMore + nextPage = fileContentPageResponse.nextPage + object_ = fileContentPageResponse.object_ + additionalProperties = fileContentPageResponse.additionalProperties.toMutableMap() + } + + /** Parsed content of the file. */ + fun data(data: List) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun data(data: JsonField>) = apply { + this.data = data.map { it.toMutableList() } + } + + /** + * Adds a single [FileContentResponse] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: FileContentResponse) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + /** Indicates if there are more content pages to fetch. */ + fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) + + /** + * Sets [Builder.hasMore] to an arbitrary JSON value. + * + * You should usually call [Builder.hasMore] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } + + /** The token for the next page, if any. */ + fun nextPage(nextPage: String?) = nextPage(JsonField.ofNullable(nextPage)) + + /** Alias for calling [Builder.nextPage] with `nextPage.orElse(null)`. */ + fun nextPage(nextPage: Optional) = nextPage(nextPage.getOrNull()) + + /** + * Sets [Builder.nextPage] to an arbitrary JSON value. + * + * You should usually call [Builder.nextPage] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun nextPage(nextPage: JsonField) = apply { this.nextPage = nextPage } + + /** + * 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("vector_store.file_content.page") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun object_(object_: JsonValue) = apply { this.object_ = object_ } + + 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 [FileContentPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .hasMore() + * .nextPage() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): FileContentPageResponse = + FileContentPageResponse( + checkRequired("data", data).map { it.toImmutable() }, + checkRequired("hasMore", hasMore), + checkRequired("nextPage", nextPage), + object_, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): FileContentPageResponse = apply { + if (validated) { + return@apply + } + + data().forEach { it.validate() } + hasMore() + nextPage() + _object_().let { + if (it != JsonValue.from("vector_store.file_content.page")) { + throw OpenAIInvalidDataException("'object_' 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 = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (hasMore.asKnown().isPresent) 1 else 0) + + (if (nextPage.asKnown().isPresent) 1 else 0) + + object_.let { if (it == JsonValue.from("vector_store.file_content.page")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is FileContentPageResponse && data == other.data && hasMore == other.hasMore && nextPage == other.nextPage && object_ == other.object_ && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(data, hasMore, nextPage, object_, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "FileContentPageResponse{data=$data, hasMore=$hasMore, nextPage=$nextPage, object_=$object_, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/files/FileListPage.kt b/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/files/FileListPage.kt index fc93a2f5..51c03261 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/files/FileListPage.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/files/FileListPage.kt @@ -2,180 +2,116 @@ package com.openai.models.vectorstores.files -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.errors.OpenAIInvalidDataException +import com.openai.core.checkRequired import com.openai.services.blocking.vectorstores.FileService -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.stream.Stream import java.util.stream.StreamSupport import kotlin.jvm.optionals.getOrNull -/** Returns a list of vector store files. */ +/** @see [FileService.list] */ class FileListPage private constructor( - private val filesService: FileService, + private val service: FileService, private val params: FileListParams, - private val response: Response, + private val response: FileListPageResponse, ) { - fun response(): Response = response + /** + * Delegates to [FileListPageResponse], but gracefully handles missing data. + * + * @see [FileListPageResponse.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() - fun data(): List = response().data() + /** + * Delegates to [FileListPageResponse], but gracefully handles missing data. + * + * @see [FileListPageResponse.hasMore] + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") - fun hasMore(): Optional = response().hasMore() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is FileListPage && filesService == other.filesService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(filesService, params, response) /* spotless:on */ - - override fun toString() = - "FileListPage{filesService=$filesService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - return !data().isEmpty() - } + fun hasNextPage(): Boolean = data().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return Optional.of(params.toBuilder().after(data().last().id()).build()) + return Optional.of(params.toBuilder().after(data().last()._id().getOptional("id")).build()) } - fun getNextPage(): Optional { - return getNextPageParams().map { filesService.list(it) } - } + fun getNextPage(): Optional = getNextPageParams().map { service.list(it) } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of(filesService: FileService, params: FileListParams, response: Response) = - FileListPage(filesService, params, response) - } - - class Response( - private val data: JsonField>, - private val hasMore: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("has_more") hasMore: JsonField = JsonMissing.of(), - ) : this(data, hasMore, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun hasMore(): Optional = hasMore.getOptional("has_more") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("has_more") - fun _hasMore(): Optional> = Optional.ofNullable(hasMore) + /** The parameters that were used to request this page. */ + fun params(): FileListParams = params - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) + /** The response that this page was parsed from. */ + fun response(): FileListPageResponse = response - private var validated: Boolean = false - - fun validate(): Response = apply { - if (validated) { - return@apply - } + fun toBuilder() = Builder().from(this) - data().map { it.validate() } - hasMore() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Response && data == other.data && hasMore == other.hasMore && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, hasMore, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [FileListPage]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, hasMore=$hasMore, additionalProperties=$additionalProperties}" + /** A builder for [FileListPage]. */ + class Builder internal constructor() { - companion object { + private var service: FileService? = null + private var params: FileListParams? = null + private var response: FileListPageResponse? = null - /** Returns a mutable builder for constructing an instance of [FileListPage]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(fileListPage: FileListPage) = apply { + service = fileListPage.service + params = fileListPage.params + response = fileListPage.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var hasMore: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.hasMore = page.hasMore - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) - - fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(data, hasMore, additionalProperties.toMutableMap()) - } + fun service(service: FileService) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: FileListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: FileListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [FileListPage]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): FileListPage = + FileListPage( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: FileListPage) : Iterable { @@ -196,4 +132,16 @@ private constructor( return StreamSupport.stream(spliterator(), false) } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is FileListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = "FileListPage{service=$service, params=$params, response=$response}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/files/FileListPageAsync.kt b/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/files/FileListPageAsync.kt index f4ba3765..ace12328 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/files/FileListPageAsync.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/files/FileListPageAsync.kt @@ -2,17 +2,8 @@ package com.openai.models.vectorstores.files -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.errors.OpenAIInvalidDataException +import com.openai.core.checkRequired import com.openai.services.async.vectorstores.FileServiceAsync -import java.util.Collections import java.util.Objects import java.util.Optional import java.util.concurrent.CompletableFuture @@ -20,165 +11,111 @@ import java.util.concurrent.Executor import java.util.function.Predicate import kotlin.jvm.optionals.getOrNull -/** Returns a list of vector store files. */ +/** @see [FileServiceAsync.list] */ class FileListPageAsync private constructor( - private val filesService: FileServiceAsync, + private val service: FileServiceAsync, private val params: FileListParams, - private val response: Response, + private val response: FileListPageResponse, ) { - fun response(): Response = response + /** + * Delegates to [FileListPageResponse], but gracefully handles missing data. + * + * @see [FileListPageResponse.data] + */ + fun data(): List = + response._data().getOptional("data").getOrNull() ?: emptyList() - fun data(): List = response().data() + /** + * Delegates to [FileListPageResponse], but gracefully handles missing data. + * + * @see [FileListPageResponse.hasMore] + */ + fun hasMore(): Optional = response._hasMore().getOptional("has_more") - fun hasMore(): Optional = response().hasMore() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is FileListPageAsync && filesService == other.filesService && params == other.params && response == other.response /* spotless:on */ - } - - override fun hashCode(): Int = /* spotless:off */ Objects.hash(filesService, params, response) /* spotless:on */ - - override fun toString() = - "FileListPageAsync{filesService=$filesService, params=$params, response=$response}" - - fun hasNextPage(): Boolean { - return !data().isEmpty() - } + fun hasNextPage(): Boolean = data().isNotEmpty() fun getNextPageParams(): Optional { if (!hasNextPage()) { return Optional.empty() } - return Optional.of(params.toBuilder().after(data().last().id()).build()) + return Optional.of(params.toBuilder().after(data().last()._id().getOptional("id")).build()) } - fun getNextPage(): CompletableFuture> { - return getNextPageParams() - .map { filesService.list(it).thenApply { Optional.of(it) } } + fun getNextPage(): CompletableFuture> = + getNextPageParams() + .map { service.list(it).thenApply { Optional.of(it) } } .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } - } fun autoPager(): AutoPager = AutoPager(this) - companion object { - - @JvmStatic - fun of(filesService: FileServiceAsync, params: FileListParams, response: Response) = - FileListPageAsync(filesService, params, response) - } - - class Response( - private val data: JsonField>, - private val hasMore: JsonField, - private val additionalProperties: MutableMap, - ) { - - @JsonCreator - private constructor( - @JsonProperty("data") data: JsonField> = JsonMissing.of(), - @JsonProperty("has_more") hasMore: JsonField = JsonMissing.of(), - ) : this(data, hasMore, mutableMapOf()) - - fun data(): List = data.getOptional("data").getOrNull() ?: listOf() - - fun hasMore(): Optional = hasMore.getOptional("has_more") - - @JsonProperty("data") - fun _data(): Optional>> = Optional.ofNullable(data) - - @JsonProperty("has_more") - fun _hasMore(): Optional> = Optional.ofNullable(hasMore) - - @JsonAnySetter - private fun putAdditionalProperty(key: String, value: JsonValue) { - additionalProperties.put(key, value) - } - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = - Collections.unmodifiableMap(additionalProperties) - - private var validated: Boolean = false + /** The parameters that were used to request this page. */ + fun params(): FileListParams = params - fun validate(): Response = apply { - if (validated) { - return@apply - } + /** The response that this page was parsed from. */ + fun response(): FileListPageResponse = response - data().map { it.validate() } - hasMore() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: OpenAIInvalidDataException) { - false - } - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + fun toBuilder() = Builder().from(this) - return /* spotless:off */ other is Response && data == other.data && hasMore == other.hasMore && additionalProperties == other.additionalProperties /* spotless:on */ - } + companion object { - override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, hasMore, additionalProperties) /* spotless:on */ + /** + * Returns a mutable builder for constructing an instance of [FileListPageAsync]. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + */ + @JvmStatic fun builder() = Builder() + } - override fun toString() = - "Response{data=$data, hasMore=$hasMore, additionalProperties=$additionalProperties}" + /** A builder for [FileListPageAsync]. */ + class Builder internal constructor() { - companion object { + private var service: FileServiceAsync? = null + private var params: FileListParams? = null + private var response: FileListPageResponse? = null - /** Returns a mutable builder for constructing an instance of [FileListPageAsync]. */ - @JvmStatic fun builder() = Builder() + @JvmSynthetic + internal fun from(fileListPageAsync: FileListPageAsync) = apply { + service = fileListPageAsync.service + params = fileListPageAsync.params + response = fileListPageAsync.response } - class Builder { - - private var data: JsonField> = JsonMissing.of() - private var hasMore: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(page: Response) = apply { - this.data = page.data - this.hasMore = page.hasMore - this.additionalProperties.putAll(page.additionalProperties) - } - - fun data(data: List) = data(JsonField.of(data)) - - fun data(data: JsonField>) = apply { this.data = data } - - fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) - - fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } - - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - /** - * Returns an immutable instance of [Response]. - * - * Further updates to this [Builder] will not mutate the returned instance. - */ - fun build(): Response = Response(data, hasMore, additionalProperties.toMutableMap()) - } + fun service(service: FileServiceAsync) = apply { this.service = service } + + /** The parameters that were used to request this page. */ + fun params(params: FileListParams) = apply { this.params = params } + + /** The response that this page was parsed from. */ + fun response(response: FileListPageResponse) = apply { this.response = response } + + /** + * Returns an immutable instance of [FileListPageAsync]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .service() + * .params() + * .response() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): FileListPageAsync = + FileListPageAsync( + checkRequired("service", service), + checkRequired("params", params), + checkRequired("response", response), + ) } class AutoPager(private val firstPage: FileListPageAsync) { @@ -209,4 +146,17 @@ private constructor( return forEach(values::add, executor).thenApply { values } } } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is FileListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ + + override fun toString() = + "FileListPageAsync{service=$service, params=$params, response=$response}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/files/FileListPageResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/files/FileListPageResponse.kt new file mode 100644 index 00000000..ea4d08e5 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/vectorstores/files/FileListPageResponse.kt @@ -0,0 +1,319 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.vectorstores.files + +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 FileListPageResponse +private constructor( + private val data: JsonField>, + private val firstId: JsonField, + private val hasMore: JsonField, + private val lastId: JsonField, + private val object_: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") + @ExcludeMissing + data: JsonField> = JsonMissing.of(), + @JsonProperty("first_id") @ExcludeMissing firstId: JsonField = JsonMissing.of(), + @JsonProperty("has_more") @ExcludeMissing hasMore: JsonField = JsonMissing.of(), + @JsonProperty("last_id") @ExcludeMissing lastId: JsonField = JsonMissing.of(), + @JsonProperty("object") @ExcludeMissing object_: JsonField = JsonMissing.of(), + ) : this(data, firstId, hasMore, lastId, object_, 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 data(): List = data.getRequired("data") + + /** + * @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 firstId(): String = firstId.getRequired("first_id") + + /** + * @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 hasMore(): Boolean = hasMore.getRequired("has_more") + + /** + * @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 lastId(): String = lastId.getRequired("last_id") + + /** + * @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 object_(): String = object_.getRequired("object") + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField> = data + + /** + * Returns the raw JSON value of [firstId]. + * + * Unlike [firstId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("first_id") @ExcludeMissing fun _firstId(): JsonField = firstId + + /** + * Returns the raw JSON value of [hasMore]. + * + * Unlike [hasMore], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("has_more") @ExcludeMissing fun _hasMore(): JsonField = hasMore + + /** + * Returns the raw JSON value of [lastId]. + * + * Unlike [lastId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("last_id") @ExcludeMissing fun _lastId(): JsonField = lastId + + /** + * Returns the raw JSON value of [object_]. + * + * Unlike [object_], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonField = object_ + + @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 [FileListPageResponse]. + * + * The following fields are required: + * ```java + * .data() + * .firstId() + * .hasMore() + * .lastId() + * .object_() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [FileListPageResponse]. */ + class Builder internal constructor() { + + private var data: JsonField>? = null + private var firstId: JsonField? = null + private var hasMore: JsonField? = null + private var lastId: JsonField? = null + private var object_: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(fileListPageResponse: FileListPageResponse) = apply { + data = fileListPageResponse.data.map { it.toMutableList() } + firstId = fileListPageResponse.firstId + hasMore = fileListPageResponse.hasMore + lastId = fileListPageResponse.lastId + object_ = fileListPageResponse.object_ + additionalProperties = fileListPageResponse.additionalProperties.toMutableMap() + } + + fun data(data: List) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun data(data: JsonField>) = apply { + this.data = data.map { it.toMutableList() } + } + + /** + * Adds a single [VectorStoreFile] to [Builder.data]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addData(data: VectorStoreFile) = apply { + this.data = + (this.data ?: JsonField.of(mutableListOf())).also { + checkKnown("data", it).add(data) + } + } + + fun firstId(firstId: String) = firstId(JsonField.of(firstId)) + + /** + * Sets [Builder.firstId] to an arbitrary JSON value. + * + * You should usually call [Builder.firstId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun firstId(firstId: JsonField) = apply { this.firstId = firstId } + + fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore)) + + /** + * Sets [Builder.hasMore] to an arbitrary JSON value. + * + * You should usually call [Builder.hasMore] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun hasMore(hasMore: JsonField) = apply { this.hasMore = hasMore } + + fun lastId(lastId: String) = lastId(JsonField.of(lastId)) + + /** + * Sets [Builder.lastId] to an arbitrary JSON value. + * + * You should usually call [Builder.lastId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun lastId(lastId: JsonField) = apply { this.lastId = lastId } + + fun object_(object_: String) = object_(JsonField.of(object_)) + + /** + * Sets [Builder.object_] to an arbitrary JSON value. + * + * You should usually call [Builder.object_] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun object_(object_: JsonField) = apply { this.object_ = object_ } + + 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 [FileListPageResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * .firstId() + * .hasMore() + * .lastId() + * .object_() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): FileListPageResponse = + FileListPageResponse( + checkRequired("data", data).map { it.toImmutable() }, + checkRequired("firstId", firstId), + checkRequired("hasMore", hasMore), + checkRequired("lastId", lastId), + checkRequired("object_", object_), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): FileListPageResponse = apply { + if (validated) { + return@apply + } + + data().forEach { it.validate() } + firstId() + hasMore() + lastId() + object_() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: OpenAIInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (firstId.asKnown().isPresent) 1 else 0) + + (if (hasMore.asKnown().isPresent) 1 else 0) + + (if (lastId.asKnown().isPresent) 1 else 0) + + (if (object_.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is FileListPageResponse && data == other.data && firstId == other.firstId && hasMore == other.hasMore && lastId == other.lastId && object_ == other.object_ && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(data, firstId, hasMore, lastId, object_, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "FileListPageResponse{data=$data, firstId=$firstId, hasMore=$hasMore, lastId=$lastId, object_=$object_, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/BatchServiceAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/BatchServiceAsyncImpl.kt index 38ffdb95..82fbc507 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/BatchServiceAsyncImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/BatchServiceAsyncImpl.kt @@ -19,6 +19,7 @@ import com.openai.models.batches.Batch import com.openai.models.batches.BatchCancelParams import com.openai.models.batches.BatchCreateParams import com.openai.models.batches.BatchListPageAsync +import com.openai.models.batches.BatchListPageResponse import com.openai.models.batches.BatchListParams import com.openai.models.batches.BatchRetrieveParams import java.util.concurrent.CompletableFuture @@ -124,8 +125,8 @@ class BatchServiceAsyncImpl internal constructor(private val clientOptions: Clie } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -151,11 +152,11 @@ class BatchServiceAsyncImpl internal constructor(private val clientOptions: Clie } } .let { - BatchListPageAsync.of( - BatchServiceAsyncImpl(clientOptions), - params, - it, - ) + BatchListPageAsync.builder() + .service(BatchServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/EvalServiceAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/EvalServiceAsyncImpl.kt index 91aef3f7..46b90a99 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/EvalServiceAsyncImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/EvalServiceAsyncImpl.kt @@ -20,6 +20,7 @@ import com.openai.models.evals.EvalCreateResponse import com.openai.models.evals.EvalDeleteParams import com.openai.models.evals.EvalDeleteResponse import com.openai.models.evals.EvalListPageAsync +import com.openai.models.evals.EvalListPageResponse import com.openai.models.evals.EvalListParams import com.openai.models.evals.EvalRetrieveParams import com.openai.models.evals.EvalRetrieveResponse @@ -178,8 +179,8 @@ class EvalServiceAsyncImpl internal constructor(private val clientOptions: Clien } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -205,11 +206,11 @@ class EvalServiceAsyncImpl internal constructor(private val clientOptions: Clien } } .let { - EvalListPageAsync.of( - EvalServiceAsyncImpl(clientOptions), - params, - it, - ) + EvalListPageAsync.builder() + .service(EvalServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/FileServiceAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/FileServiceAsyncImpl.kt index 265711d6..a60ded87 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/FileServiceAsyncImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/FileServiceAsyncImpl.kt @@ -22,6 +22,7 @@ import com.openai.models.files.FileCreateParams import com.openai.models.files.FileDeleteParams import com.openai.models.files.FileDeleted import com.openai.models.files.FileListPageAsync +import com.openai.models.files.FileListPageResponse import com.openai.models.files.FileListParams import com.openai.models.files.FileObject import com.openai.models.files.FileRetrieveParams @@ -135,8 +136,8 @@ class FileServiceAsyncImpl internal constructor(private val clientOptions: Clien } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -162,11 +163,11 @@ class FileServiceAsyncImpl internal constructor(private val clientOptions: Clien } } .let { - FileListPageAsync.of( - FileServiceAsyncImpl(clientOptions), - params, - it, - ) + FileListPageAsync.builder() + .service(FileServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/ModelServiceAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/ModelServiceAsyncImpl.kt index 758a2198..7973eaa3 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/ModelServiceAsyncImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/ModelServiceAsyncImpl.kt @@ -19,6 +19,7 @@ import com.openai.models.models.Model import com.openai.models.models.ModelDeleteParams import com.openai.models.models.ModelDeleted import com.openai.models.models.ModelListPageAsync +import com.openai.models.models.ModelListPageResponse import com.openai.models.models.ModelListParams import com.openai.models.models.ModelRetrieveParams import java.util.concurrent.CompletableFuture @@ -87,8 +88,8 @@ class ModelServiceAsyncImpl internal constructor(private val clientOptions: Clie } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -114,11 +115,11 @@ class ModelServiceAsyncImpl internal constructor(private val clientOptions: Clie } } .let { - ModelListPageAsync.of( - ModelServiceAsyncImpl(clientOptions), - params, - it, - ) + ModelListPageAsync.builder() + .service(ModelServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/VectorStoreServiceAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/VectorStoreServiceAsyncImpl.kt index 7d9f07e4..da248f22 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/VectorStoreServiceAsyncImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/VectorStoreServiceAsyncImpl.kt @@ -21,9 +21,11 @@ import com.openai.models.vectorstores.VectorStoreCreateParams import com.openai.models.vectorstores.VectorStoreDeleteParams import com.openai.models.vectorstores.VectorStoreDeleted import com.openai.models.vectorstores.VectorStoreListPageAsync +import com.openai.models.vectorstores.VectorStoreListPageResponse import com.openai.models.vectorstores.VectorStoreListParams import com.openai.models.vectorstores.VectorStoreRetrieveParams import com.openai.models.vectorstores.VectorStoreSearchPageAsync +import com.openai.models.vectorstores.VectorStoreSearchPageResponse import com.openai.models.vectorstores.VectorStoreSearchParams import com.openai.models.vectorstores.VectorStoreUpdateParams import com.openai.services.async.vectorstores.FileBatchServiceAsync @@ -207,8 +209,8 @@ class VectorStoreServiceAsyncImpl internal constructor(private val clientOptions } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -235,11 +237,11 @@ class VectorStoreServiceAsyncImpl internal constructor(private val clientOptions } } .let { - VectorStoreListPageAsync.of( - VectorStoreServiceAsyncImpl(clientOptions), - params, - it, - ) + VectorStoreListPageAsync.builder() + .service(VectorStoreServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } @@ -276,8 +278,8 @@ class VectorStoreServiceAsyncImpl internal constructor(private val clientOptions } } - private val searchHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val searchHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun search( @@ -305,11 +307,11 @@ class VectorStoreServiceAsyncImpl internal constructor(private val clientOptions } } .let { - VectorStoreSearchPageAsync.of( - VectorStoreServiceAsyncImpl(clientOptions), - params, - it, - ) + VectorStoreSearchPageAsync.builder() + .service(VectorStoreServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/beta/AssistantServiceAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/beta/AssistantServiceAsyncImpl.kt index 9a3beec2..7eb20393 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/beta/AssistantServiceAsyncImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/beta/AssistantServiceAsyncImpl.kt @@ -21,6 +21,7 @@ import com.openai.models.beta.assistants.AssistantCreateParams import com.openai.models.beta.assistants.AssistantDeleteParams import com.openai.models.beta.assistants.AssistantDeleted import com.openai.models.beta.assistants.AssistantListPageAsync +import com.openai.models.beta.assistants.AssistantListPageResponse import com.openai.models.beta.assistants.AssistantListParams import com.openai.models.beta.assistants.AssistantRetrieveParams import com.openai.models.beta.assistants.AssistantUpdateParams @@ -176,8 +177,8 @@ class AssistantServiceAsyncImpl internal constructor(private val clientOptions: } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -204,11 +205,11 @@ class AssistantServiceAsyncImpl internal constructor(private val clientOptions: } } .let { - AssistantListPageAsync.of( - AssistantServiceAsyncImpl(clientOptions), - params, - it, - ) + AssistantListPageAsync.builder() + .service(AssistantServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/beta/threads/MessageServiceAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/beta/threads/MessageServiceAsyncImpl.kt index 28859976..9753c5f6 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/beta/threads/MessageServiceAsyncImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/beta/threads/MessageServiceAsyncImpl.kt @@ -21,6 +21,7 @@ import com.openai.models.beta.threads.messages.MessageCreateParams import com.openai.models.beta.threads.messages.MessageDeleteParams import com.openai.models.beta.threads.messages.MessageDeleted import com.openai.models.beta.threads.messages.MessageListPageAsync +import com.openai.models.beta.threads.messages.MessageListPageResponse import com.openai.models.beta.threads.messages.MessageListParams import com.openai.models.beta.threads.messages.MessageRetrieveParams import com.openai.models.beta.threads.messages.MessageUpdateParams @@ -182,8 +183,8 @@ class MessageServiceAsyncImpl internal constructor(private val clientOptions: Cl } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -210,11 +211,11 @@ class MessageServiceAsyncImpl internal constructor(private val clientOptions: Cl } } .let { - MessageListPageAsync.of( - MessageServiceAsyncImpl(clientOptions), - params, - it, - ) + MessageListPageAsync.builder() + .service(MessageServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/beta/threads/RunServiceAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/beta/threads/RunServiceAsyncImpl.kt index ea7027ca..9a15dc34 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/beta/threads/RunServiceAsyncImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/beta/threads/RunServiceAsyncImpl.kt @@ -28,6 +28,7 @@ import com.openai.models.beta.threads.runs.Run import com.openai.models.beta.threads.runs.RunCancelParams import com.openai.models.beta.threads.runs.RunCreateParams import com.openai.models.beta.threads.runs.RunListPageAsync +import com.openai.models.beta.threads.runs.RunListPageResponse import com.openai.models.beta.threads.runs.RunListParams import com.openai.models.beta.threads.runs.RunRetrieveParams import com.openai.models.beta.threads.runs.RunSubmitToolOutputsParams @@ -271,8 +272,8 @@ class RunServiceAsyncImpl internal constructor(private val clientOptions: Client } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -299,7 +300,11 @@ class RunServiceAsyncImpl internal constructor(private val clientOptions: Client } } .let { - RunListPageAsync.of(RunServiceAsyncImpl(clientOptions), params, it) + RunListPageAsync.builder() + .service(RunServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/beta/threads/runs/StepServiceAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/beta/threads/runs/StepServiceAsyncImpl.kt index 787b583f..9f3f8350 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/beta/threads/runs/StepServiceAsyncImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/beta/threads/runs/StepServiceAsyncImpl.kt @@ -17,6 +17,7 @@ import com.openai.core.prepareAsync import com.openai.models.ErrorObject import com.openai.models.beta.threads.runs.steps.RunStep import com.openai.models.beta.threads.runs.steps.StepListPageAsync +import com.openai.models.beta.threads.runs.steps.StepListPageResponse import com.openai.models.beta.threads.runs.steps.StepListParams import com.openai.models.beta.threads.runs.steps.StepRetrieveParams import java.util.concurrent.CompletableFuture @@ -91,8 +92,8 @@ class StepServiceAsyncImpl internal constructor(private val clientOptions: Clien } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -125,11 +126,11 @@ class StepServiceAsyncImpl internal constructor(private val clientOptions: Clien } } .let { - StepListPageAsync.of( - StepServiceAsyncImpl(clientOptions), - params, - it, - ) + StepListPageAsync.builder() + .service(StepServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/chat/ChatCompletionServiceAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/chat/ChatCompletionServiceAsyncImpl.kt index 1d1c892e..783a608d 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/chat/ChatCompletionServiceAsyncImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/chat/ChatCompletionServiceAsyncImpl.kt @@ -28,6 +28,7 @@ import com.openai.models.chat.completions.ChatCompletionCreateParams import com.openai.models.chat.completions.ChatCompletionDeleteParams import com.openai.models.chat.completions.ChatCompletionDeleted import com.openai.models.chat.completions.ChatCompletionListPageAsync +import com.openai.models.chat.completions.ChatCompletionListPageResponse import com.openai.models.chat.completions.ChatCompletionListParams import com.openai.models.chat.completions.ChatCompletionRetrieveParams import com.openai.models.chat.completions.ChatCompletionUpdateParams @@ -237,8 +238,8 @@ internal constructor(private val clientOptions: ClientOptions) : ChatCompletionS } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -268,11 +269,11 @@ internal constructor(private val clientOptions: ClientOptions) : ChatCompletionS } } .let { - ChatCompletionListPageAsync.of( - ChatCompletionServiceAsyncImpl(clientOptions), - params, - it, - ) + ChatCompletionListPageAsync.builder() + .service(ChatCompletionServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/chat/completions/MessageServiceAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/chat/completions/MessageServiceAsyncImpl.kt index 94cc873e..c66410b5 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/chat/completions/MessageServiceAsyncImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/chat/completions/MessageServiceAsyncImpl.kt @@ -15,6 +15,7 @@ import com.openai.core.http.parseable import com.openai.core.prepareAsync import com.openai.models.ErrorObject import com.openai.models.chat.completions.messages.MessageListPageAsync +import com.openai.models.chat.completions.messages.MessageListPageResponse import com.openai.models.chat.completions.messages.MessageListParams import java.util.concurrent.CompletableFuture @@ -39,8 +40,8 @@ class MessageServiceAsyncImpl internal constructor(private val clientOptions: Cl private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -66,11 +67,11 @@ class MessageServiceAsyncImpl internal constructor(private val clientOptions: Cl } } .let { - MessageListPageAsync.of( - MessageServiceAsyncImpl(clientOptions), - params, - it, - ) + MessageListPageAsync.builder() + .service(MessageServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/evals/RunServiceAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/evals/RunServiceAsyncImpl.kt index 2eb915d7..b39590a1 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/evals/RunServiceAsyncImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/evals/RunServiceAsyncImpl.kt @@ -22,6 +22,7 @@ import com.openai.models.evals.runs.RunCreateResponse import com.openai.models.evals.runs.RunDeleteParams import com.openai.models.evals.runs.RunDeleteResponse import com.openai.models.evals.runs.RunListPageAsync +import com.openai.models.evals.runs.RunListPageResponse import com.openai.models.evals.runs.RunListParams import com.openai.models.evals.runs.RunRetrieveParams import com.openai.models.evals.runs.RunRetrieveResponse @@ -150,8 +151,8 @@ class RunServiceAsyncImpl internal constructor(private val clientOptions: Client } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -177,7 +178,11 @@ class RunServiceAsyncImpl internal constructor(private val clientOptions: Client } } .let { - RunListPageAsync.of(RunServiceAsyncImpl(clientOptions), params, it) + RunListPageAsync.builder() + .service(RunServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/evals/runs/OutputItemServiceAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/evals/runs/OutputItemServiceAsyncImpl.kt index 37ee920c..05537bed 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/evals/runs/OutputItemServiceAsyncImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/evals/runs/OutputItemServiceAsyncImpl.kt @@ -15,6 +15,7 @@ import com.openai.core.http.parseable import com.openai.core.prepareAsync import com.openai.models.ErrorObject import com.openai.models.evals.runs.outputitems.OutputItemListPageAsync +import com.openai.models.evals.runs.outputitems.OutputItemListPageResponse import com.openai.models.evals.runs.outputitems.OutputItemListParams import com.openai.models.evals.runs.outputitems.OutputItemRetrieveParams import com.openai.models.evals.runs.outputitems.OutputItemRetrieveResponse @@ -85,8 +86,8 @@ class OutputItemServiceAsyncImpl internal constructor(private val clientOptions: } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -118,11 +119,11 @@ class OutputItemServiceAsyncImpl internal constructor(private val clientOptions: } } .let { - OutputItemListPageAsync.of( - OutputItemServiceAsyncImpl(clientOptions), - params, - it, - ) + OutputItemListPageAsync.builder() + .service(OutputItemServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/finetuning/JobServiceAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/finetuning/JobServiceAsyncImpl.kt index 3b95596c..5ebe2d42 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/finetuning/JobServiceAsyncImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/finetuning/JobServiceAsyncImpl.kt @@ -19,8 +19,10 @@ import com.openai.models.finetuning.jobs.FineTuningJob import com.openai.models.finetuning.jobs.JobCancelParams import com.openai.models.finetuning.jobs.JobCreateParams import com.openai.models.finetuning.jobs.JobListEventsPageAsync +import com.openai.models.finetuning.jobs.JobListEventsPageResponse import com.openai.models.finetuning.jobs.JobListEventsParams import com.openai.models.finetuning.jobs.JobListPageAsync +import com.openai.models.finetuning.jobs.JobListPageResponse import com.openai.models.finetuning.jobs.JobListParams import com.openai.models.finetuning.jobs.JobRetrieveParams import com.openai.services.async.finetuning.jobs.CheckpointServiceAsync @@ -147,8 +149,8 @@ class JobServiceAsyncImpl internal constructor(private val clientOptions: Client } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -174,7 +176,11 @@ class JobServiceAsyncImpl internal constructor(private val clientOptions: Client } } .let { - JobListPageAsync.of(JobServiceAsyncImpl(clientOptions), params, it) + JobListPageAsync.builder() + .service(JobServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } @@ -210,8 +216,8 @@ class JobServiceAsyncImpl internal constructor(private val clientOptions: Client } } - private val listEventsHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listEventsHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun listEvents( @@ -237,11 +243,11 @@ class JobServiceAsyncImpl internal constructor(private val clientOptions: Client } } .let { - JobListEventsPageAsync.of( - JobServiceAsyncImpl(clientOptions), - params, - it, - ) + JobListEventsPageAsync.builder() + .service(JobServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/finetuning/checkpoints/PermissionServiceAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/finetuning/checkpoints/PermissionServiceAsyncImpl.kt index be8c9457..18a4bd2b 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/finetuning/checkpoints/PermissionServiceAsyncImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/finetuning/checkpoints/PermissionServiceAsyncImpl.kt @@ -16,6 +16,7 @@ import com.openai.core.http.parseable import com.openai.core.prepareAsync import com.openai.models.ErrorObject import com.openai.models.finetuning.checkpoints.permissions.PermissionCreatePageAsync +import com.openai.models.finetuning.checkpoints.permissions.PermissionCreatePageResponse import com.openai.models.finetuning.checkpoints.permissions.PermissionCreateParams import com.openai.models.finetuning.checkpoints.permissions.PermissionDeleteParams import com.openai.models.finetuning.checkpoints.permissions.PermissionDeleteResponse @@ -58,8 +59,8 @@ class PermissionServiceAsyncImpl internal constructor(private val clientOptions: private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) - private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val createHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun create( @@ -91,11 +92,11 @@ class PermissionServiceAsyncImpl internal constructor(private val clientOptions: } } .let { - PermissionCreatePageAsync.of( - PermissionServiceAsyncImpl(clientOptions), - params, - it, - ) + PermissionCreatePageAsync.builder() + .service(PermissionServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/finetuning/jobs/CheckpointServiceAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/finetuning/jobs/CheckpointServiceAsyncImpl.kt index ecfa89da..61014509 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/finetuning/jobs/CheckpointServiceAsyncImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/finetuning/jobs/CheckpointServiceAsyncImpl.kt @@ -15,6 +15,7 @@ import com.openai.core.http.parseable import com.openai.core.prepareAsync import com.openai.models.ErrorObject import com.openai.models.finetuning.jobs.checkpoints.CheckpointListPageAsync +import com.openai.models.finetuning.jobs.checkpoints.CheckpointListPageResponse import com.openai.models.finetuning.jobs.checkpoints.CheckpointListParams import java.util.concurrent.CompletableFuture @@ -39,8 +40,8 @@ class CheckpointServiceAsyncImpl internal constructor(private val clientOptions: private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -66,11 +67,11 @@ class CheckpointServiceAsyncImpl internal constructor(private val clientOptions: } } .let { - CheckpointListPageAsync.of( - CheckpointServiceAsyncImpl(clientOptions), - params, - it, - ) + CheckpointListPageAsync.builder() + .service(CheckpointServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/responses/InputItemServiceAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/responses/InputItemServiceAsyncImpl.kt index 0bad8a4f..32f8112e 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/responses/InputItemServiceAsyncImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/responses/InputItemServiceAsyncImpl.kt @@ -16,6 +16,7 @@ import com.openai.core.prepareAsync import com.openai.models.ErrorObject import com.openai.models.responses.inputitems.InputItemListPageAsync import com.openai.models.responses.inputitems.InputItemListParams +import com.openai.models.responses.inputitems.ResponseItemList import java.util.concurrent.CompletableFuture class InputItemServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : @@ -39,9 +40,8 @@ class InputItemServiceAsyncImpl internal constructor(private val clientOptions: private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) override fun list( params: InputItemListParams, @@ -66,11 +66,11 @@ class InputItemServiceAsyncImpl internal constructor(private val clientOptions: } } .let { - InputItemListPageAsync.of( - InputItemServiceAsyncImpl(clientOptions), - params, - it, - ) + InputItemListPageAsync.builder() + .service(InputItemServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/vectorstores/FileBatchServiceAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/vectorstores/FileBatchServiceAsyncImpl.kt index 5eb1399b..e9d7625a 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/vectorstores/FileBatchServiceAsyncImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/vectorstores/FileBatchServiceAsyncImpl.kt @@ -19,6 +19,7 @@ import com.openai.models.ErrorObject import com.openai.models.vectorstores.filebatches.FileBatchCancelParams import com.openai.models.vectorstores.filebatches.FileBatchCreateParams import com.openai.models.vectorstores.filebatches.FileBatchListFilesPageAsync +import com.openai.models.vectorstores.filebatches.FileBatchListFilesPageResponse import com.openai.models.vectorstores.filebatches.FileBatchListFilesParams import com.openai.models.vectorstores.filebatches.FileBatchRetrieveParams import com.openai.models.vectorstores.filebatches.VectorStoreFileBatch @@ -177,8 +178,8 @@ class FileBatchServiceAsyncImpl internal constructor(private val clientOptions: } } - private val listFilesHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listFilesHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun listFiles( @@ -211,11 +212,11 @@ class FileBatchServiceAsyncImpl internal constructor(private val clientOptions: } } .let { - FileBatchListFilesPageAsync.of( - FileBatchServiceAsyncImpl(clientOptions), - params, - it, - ) + FileBatchListFilesPageAsync.builder() + .service(FileBatchServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/openai-java-core/src/main/kotlin/com/openai/services/async/vectorstores/FileServiceAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/async/vectorstores/FileServiceAsyncImpl.kt index 6b2bb7e5..a03202c6 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/async/vectorstores/FileServiceAsyncImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/async/vectorstores/FileServiceAsyncImpl.kt @@ -17,10 +17,12 @@ import com.openai.core.http.parseable import com.openai.core.prepareAsync import com.openai.models.ErrorObject import com.openai.models.vectorstores.files.FileContentPageAsync +import com.openai.models.vectorstores.files.FileContentPageResponse import com.openai.models.vectorstores.files.FileContentParams import com.openai.models.vectorstores.files.FileCreateParams import com.openai.models.vectorstores.files.FileDeleteParams import com.openai.models.vectorstores.files.FileListPageAsync +import com.openai.models.vectorstores.files.FileListPageResponse import com.openai.models.vectorstores.files.FileListParams import com.openai.models.vectorstores.files.FileRetrieveParams import com.openai.models.vectorstores.files.FileUpdateParams @@ -191,8 +193,8 @@ class FileServiceAsyncImpl internal constructor(private val clientOptions: Clien } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -219,11 +221,11 @@ class FileServiceAsyncImpl internal constructor(private val clientOptions: Clien } } .let { - FileListPageAsync.of( - FileServiceAsyncImpl(clientOptions), - params, - it, - ) + FileListPageAsync.builder() + .service(FileServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } @@ -266,8 +268,8 @@ class FileServiceAsyncImpl internal constructor(private val clientOptions: Clien } } - private val contentHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val contentHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun content( @@ -300,11 +302,11 @@ class FileServiceAsyncImpl internal constructor(private val clientOptions: Clien } } .let { - FileContentPageAsync.of( - FileServiceAsyncImpl(clientOptions), - params, - it, - ) + FileContentPageAsync.builder() + .service(FileServiceAsyncImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/BatchServiceImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/BatchServiceImpl.kt index 0695bbf3..7a1a929c 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/BatchServiceImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/BatchServiceImpl.kt @@ -19,6 +19,7 @@ import com.openai.models.batches.Batch import com.openai.models.batches.BatchCancelParams import com.openai.models.batches.BatchCreateParams import com.openai.models.batches.BatchListPage +import com.openai.models.batches.BatchListPageResponse import com.openai.models.batches.BatchListParams import com.openai.models.batches.BatchRetrieveParams @@ -105,8 +106,8 @@ class BatchServiceImpl internal constructor(private val clientOptions: ClientOpt } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -129,7 +130,13 @@ class BatchServiceImpl internal constructor(private val clientOptions: ClientOpt it.validate() } } - .let { BatchListPage.of(BatchServiceImpl(clientOptions), params, it) } + .let { + BatchListPage.builder() + .service(BatchServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } } } diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/EvalServiceImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/EvalServiceImpl.kt index fa8962f2..faa4cc5f 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/EvalServiceImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/EvalServiceImpl.kt @@ -20,6 +20,7 @@ import com.openai.models.evals.EvalCreateResponse import com.openai.models.evals.EvalDeleteParams import com.openai.models.evals.EvalDeleteResponse import com.openai.models.evals.EvalListPage +import com.openai.models.evals.EvalListPageResponse import com.openai.models.evals.EvalListParams import com.openai.models.evals.EvalRetrieveParams import com.openai.models.evals.EvalRetrieveResponse @@ -164,8 +165,8 @@ class EvalServiceImpl internal constructor(private val clientOptions: ClientOpti } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -188,7 +189,13 @@ class EvalServiceImpl internal constructor(private val clientOptions: ClientOpti it.validate() } } - .let { EvalListPage.of(EvalServiceImpl(clientOptions), params, it) } + .let { + EvalListPage.builder() + .service(EvalServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } } } diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/FileServiceImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/FileServiceImpl.kt index 73cbbac2..c9b1f1f7 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/FileServiceImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/FileServiceImpl.kt @@ -22,6 +22,7 @@ import com.openai.models.files.FileCreateParams import com.openai.models.files.FileDeleteParams import com.openai.models.files.FileDeleted import com.openai.models.files.FileListPage +import com.openai.models.files.FileListPageResponse import com.openai.models.files.FileListParams import com.openai.models.files.FileObject import com.openai.models.files.FileRetrieveParams @@ -112,8 +113,8 @@ class FileServiceImpl internal constructor(private val clientOptions: ClientOpti } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -136,7 +137,13 @@ class FileServiceImpl internal constructor(private val clientOptions: ClientOpti it.validate() } } - .let { FileListPage.of(FileServiceImpl(clientOptions), params, it) } + .let { + FileListPage.builder() + .service(FileServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } } } diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/ModelServiceImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/ModelServiceImpl.kt index 65cfeb4c..6e7a023e 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/ModelServiceImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/ModelServiceImpl.kt @@ -19,6 +19,7 @@ import com.openai.models.models.Model import com.openai.models.models.ModelDeleteParams import com.openai.models.models.ModelDeleted import com.openai.models.models.ModelListPage +import com.openai.models.models.ModelListPageResponse import com.openai.models.models.ModelListParams import com.openai.models.models.ModelRetrieveParams @@ -74,8 +75,8 @@ class ModelServiceImpl internal constructor(private val clientOptions: ClientOpt } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -98,7 +99,13 @@ class ModelServiceImpl internal constructor(private val clientOptions: ClientOpt it.validate() } } - .let { ModelListPage.of(ModelServiceImpl(clientOptions), params, it) } + .let { + ModelListPage.builder() + .service(ModelServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } } } diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/VectorStoreServiceImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/VectorStoreServiceImpl.kt index e2e45800..5a077091 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/VectorStoreServiceImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/VectorStoreServiceImpl.kt @@ -21,9 +21,11 @@ import com.openai.models.vectorstores.VectorStoreCreateParams import com.openai.models.vectorstores.VectorStoreDeleteParams import com.openai.models.vectorstores.VectorStoreDeleted import com.openai.models.vectorstores.VectorStoreListPage +import com.openai.models.vectorstores.VectorStoreListPageResponse import com.openai.models.vectorstores.VectorStoreListParams import com.openai.models.vectorstores.VectorStoreRetrieveParams import com.openai.models.vectorstores.VectorStoreSearchPage +import com.openai.models.vectorstores.VectorStoreSearchPageResponse import com.openai.models.vectorstores.VectorStoreSearchParams import com.openai.models.vectorstores.VectorStoreUpdateParams import com.openai.services.blocking.vectorstores.FileBatchService @@ -195,8 +197,8 @@ class VectorStoreServiceImpl internal constructor(private val clientOptions: Cli } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -221,7 +223,11 @@ class VectorStoreServiceImpl internal constructor(private val clientOptions: Cli } } .let { - VectorStoreListPage.of(VectorStoreServiceImpl(clientOptions), params, it) + VectorStoreListPage.builder() + .service(VectorStoreServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } @@ -254,8 +260,8 @@ class VectorStoreServiceImpl internal constructor(private val clientOptions: Cli } } - private val searchHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val searchHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun search( @@ -281,7 +287,11 @@ class VectorStoreServiceImpl internal constructor(private val clientOptions: Cli } } .let { - VectorStoreSearchPage.of(VectorStoreServiceImpl(clientOptions), params, it) + VectorStoreSearchPage.builder() + .service(VectorStoreServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/beta/AssistantServiceImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/beta/AssistantServiceImpl.kt index 148b6344..521543aa 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/beta/AssistantServiceImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/beta/AssistantServiceImpl.kt @@ -21,6 +21,7 @@ import com.openai.models.beta.assistants.AssistantCreateParams import com.openai.models.beta.assistants.AssistantDeleteParams import com.openai.models.beta.assistants.AssistantDeleted import com.openai.models.beta.assistants.AssistantListPage +import com.openai.models.beta.assistants.AssistantListPageResponse import com.openai.models.beta.assistants.AssistantListParams import com.openai.models.beta.assistants.AssistantRetrieveParams import com.openai.models.beta.assistants.AssistantUpdateParams @@ -160,8 +161,8 @@ class AssistantServiceImpl internal constructor(private val clientOptions: Clien } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -185,7 +186,13 @@ class AssistantServiceImpl internal constructor(private val clientOptions: Clien it.validate() } } - .let { AssistantListPage.of(AssistantServiceImpl(clientOptions), params, it) } + .let { + AssistantListPage.builder() + .service(AssistantServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } } } diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/beta/threads/MessageServiceImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/beta/threads/MessageServiceImpl.kt index 87eb8f2d..fddd1451 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/beta/threads/MessageServiceImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/beta/threads/MessageServiceImpl.kt @@ -21,6 +21,7 @@ import com.openai.models.beta.threads.messages.MessageCreateParams import com.openai.models.beta.threads.messages.MessageDeleteParams import com.openai.models.beta.threads.messages.MessageDeleted import com.openai.models.beta.threads.messages.MessageListPage +import com.openai.models.beta.threads.messages.MessageListPageResponse import com.openai.models.beta.threads.messages.MessageListParams import com.openai.models.beta.threads.messages.MessageRetrieveParams import com.openai.models.beta.threads.messages.MessageUpdateParams @@ -160,8 +161,8 @@ class MessageServiceImpl internal constructor(private val clientOptions: ClientO } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -185,7 +186,13 @@ class MessageServiceImpl internal constructor(private val clientOptions: ClientO it.validate() } } - .let { MessageListPage.of(MessageServiceImpl(clientOptions), params, it) } + .let { + MessageListPage.builder() + .service(MessageServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } } } diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/beta/threads/RunServiceImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/beta/threads/RunServiceImpl.kt index 2bfe4387..0d7f999d 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/beta/threads/RunServiceImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/beta/threads/RunServiceImpl.kt @@ -26,6 +26,7 @@ import com.openai.models.beta.threads.runs.Run import com.openai.models.beta.threads.runs.RunCancelParams import com.openai.models.beta.threads.runs.RunCreateParams import com.openai.models.beta.threads.runs.RunListPage +import com.openai.models.beta.threads.runs.RunListPageResponse import com.openai.models.beta.threads.runs.RunListParams import com.openai.models.beta.threads.runs.RunRetrieveParams import com.openai.models.beta.threads.runs.RunSubmitToolOutputsParams @@ -234,8 +235,8 @@ class RunServiceImpl internal constructor(private val clientOptions: ClientOptio } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -259,7 +260,13 @@ class RunServiceImpl internal constructor(private val clientOptions: ClientOptio it.validate() } } - .let { RunListPage.of(RunServiceImpl(clientOptions), params, it) } + .let { + RunListPage.builder() + .service(RunServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } } } diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/beta/threads/runs/StepServiceImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/beta/threads/runs/StepServiceImpl.kt index 9816761d..e4d41faf 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/beta/threads/runs/StepServiceImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/beta/threads/runs/StepServiceImpl.kt @@ -17,6 +17,7 @@ import com.openai.core.prepare import com.openai.models.ErrorObject import com.openai.models.beta.threads.runs.steps.RunStep import com.openai.models.beta.threads.runs.steps.StepListPage +import com.openai.models.beta.threads.runs.steps.StepListPageResponse import com.openai.models.beta.threads.runs.steps.StepListParams import com.openai.models.beta.threads.runs.steps.StepRetrieveParams @@ -80,8 +81,8 @@ class StepServiceImpl internal constructor(private val clientOptions: ClientOpti } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -111,7 +112,13 @@ class StepServiceImpl internal constructor(private val clientOptions: ClientOpti it.validate() } } - .let { StepListPage.of(StepServiceImpl(clientOptions), params, it) } + .let { + StepListPage.builder() + .service(StepServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } } } } diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/chat/ChatCompletionServiceImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/chat/ChatCompletionServiceImpl.kt index ed63767c..0bffd8df 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/chat/ChatCompletionServiceImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/chat/ChatCompletionServiceImpl.kt @@ -26,6 +26,7 @@ import com.openai.models.chat.completions.ChatCompletionCreateParams import com.openai.models.chat.completions.ChatCompletionDeleteParams import com.openai.models.chat.completions.ChatCompletionDeleted import com.openai.models.chat.completions.ChatCompletionListPage +import com.openai.models.chat.completions.ChatCompletionListPageResponse import com.openai.models.chat.completions.ChatCompletionListParams import com.openai.models.chat.completions.ChatCompletionRetrieveParams import com.openai.models.chat.completions.ChatCompletionUpdateParams @@ -219,8 +220,8 @@ class ChatCompletionServiceImpl internal constructor(private val clientOptions: } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -248,11 +249,11 @@ class ChatCompletionServiceImpl internal constructor(private val clientOptions: } } .let { - ChatCompletionListPage.of( - ChatCompletionServiceImpl(clientOptions), - params, - it, - ) + ChatCompletionListPage.builder() + .service(ChatCompletionServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/chat/completions/MessageServiceImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/chat/completions/MessageServiceImpl.kt index dd5261aa..c87f53ee 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/chat/completions/MessageServiceImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/chat/completions/MessageServiceImpl.kt @@ -15,6 +15,7 @@ import com.openai.core.http.parseable import com.openai.core.prepare import com.openai.models.ErrorObject import com.openai.models.chat.completions.messages.MessageListPage +import com.openai.models.chat.completions.messages.MessageListPageResponse import com.openai.models.chat.completions.messages.MessageListParams class MessageServiceImpl internal constructor(private val clientOptions: ClientOptions) : @@ -35,8 +36,8 @@ class MessageServiceImpl internal constructor(private val clientOptions: ClientO private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -59,7 +60,13 @@ class MessageServiceImpl internal constructor(private val clientOptions: ClientO it.validate() } } - .let { MessageListPage.of(MessageServiceImpl(clientOptions), params, it) } + .let { + MessageListPage.builder() + .service(MessageServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } } } } diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/evals/RunServiceImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/evals/RunServiceImpl.kt index 04fbbf3e..aa985644 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/evals/RunServiceImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/evals/RunServiceImpl.kt @@ -22,6 +22,7 @@ import com.openai.models.evals.runs.RunCreateResponse import com.openai.models.evals.runs.RunDeleteParams import com.openai.models.evals.runs.RunDeleteResponse import com.openai.models.evals.runs.RunListPage +import com.openai.models.evals.runs.RunListPageResponse import com.openai.models.evals.runs.RunListParams import com.openai.models.evals.runs.RunRetrieveParams import com.openai.models.evals.runs.RunRetrieveResponse @@ -137,8 +138,8 @@ class RunServiceImpl internal constructor(private val clientOptions: ClientOptio } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -161,7 +162,13 @@ class RunServiceImpl internal constructor(private val clientOptions: ClientOptio it.validate() } } - .let { RunListPage.of(RunServiceImpl(clientOptions), params, it) } + .let { + RunListPage.builder() + .service(RunServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } } } diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/evals/runs/OutputItemServiceImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/evals/runs/OutputItemServiceImpl.kt index 7d3637fb..cce944dd 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/evals/runs/OutputItemServiceImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/evals/runs/OutputItemServiceImpl.kt @@ -15,6 +15,7 @@ import com.openai.core.http.parseable import com.openai.core.prepare import com.openai.models.ErrorObject import com.openai.models.evals.runs.outputitems.OutputItemListPage +import com.openai.models.evals.runs.outputitems.OutputItemListPageResponse import com.openai.models.evals.runs.outputitems.OutputItemListParams import com.openai.models.evals.runs.outputitems.OutputItemRetrieveParams import com.openai.models.evals.runs.outputitems.OutputItemRetrieveResponse @@ -81,8 +82,8 @@ class OutputItemServiceImpl internal constructor(private val clientOptions: Clie } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -111,7 +112,13 @@ class OutputItemServiceImpl internal constructor(private val clientOptions: Clie it.validate() } } - .let { OutputItemListPage.of(OutputItemServiceImpl(clientOptions), params, it) } + .let { + OutputItemListPage.builder() + .service(OutputItemServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } } } } diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/finetuning/JobServiceImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/finetuning/JobServiceImpl.kt index 7ceb8d91..64319c98 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/finetuning/JobServiceImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/finetuning/JobServiceImpl.kt @@ -19,8 +19,10 @@ import com.openai.models.finetuning.jobs.FineTuningJob import com.openai.models.finetuning.jobs.JobCancelParams import com.openai.models.finetuning.jobs.JobCreateParams import com.openai.models.finetuning.jobs.JobListEventsPage +import com.openai.models.finetuning.jobs.JobListEventsPageResponse import com.openai.models.finetuning.jobs.JobListEventsParams import com.openai.models.finetuning.jobs.JobListPage +import com.openai.models.finetuning.jobs.JobListPageResponse import com.openai.models.finetuning.jobs.JobListParams import com.openai.models.finetuning.jobs.JobRetrieveParams import com.openai.services.blocking.finetuning.jobs.CheckpointService @@ -128,8 +130,8 @@ class JobServiceImpl internal constructor(private val clientOptions: ClientOptio } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -152,7 +154,13 @@ class JobServiceImpl internal constructor(private val clientOptions: ClientOptio it.validate() } } - .let { JobListPage.of(JobServiceImpl(clientOptions), params, it) } + .let { + JobListPage.builder() + .service(JobServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } } } @@ -183,8 +191,8 @@ class JobServiceImpl internal constructor(private val clientOptions: ClientOptio } } - private val listEventsHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listEventsHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun listEvents( @@ -207,7 +215,13 @@ class JobServiceImpl internal constructor(private val clientOptions: ClientOptio it.validate() } } - .let { JobListEventsPage.of(JobServiceImpl(clientOptions), params, it) } + .let { + JobListEventsPage.builder() + .service(JobServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } } } } diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/finetuning/checkpoints/PermissionServiceImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/finetuning/checkpoints/PermissionServiceImpl.kt index a6cf93a3..71299b54 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/finetuning/checkpoints/PermissionServiceImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/finetuning/checkpoints/PermissionServiceImpl.kt @@ -16,6 +16,7 @@ import com.openai.core.http.parseable import com.openai.core.prepare import com.openai.models.ErrorObject import com.openai.models.finetuning.checkpoints.permissions.PermissionCreatePage +import com.openai.models.finetuning.checkpoints.permissions.PermissionCreatePageResponse import com.openai.models.finetuning.checkpoints.permissions.PermissionCreateParams import com.openai.models.finetuning.checkpoints.permissions.PermissionDeleteParams import com.openai.models.finetuning.checkpoints.permissions.PermissionDeleteResponse @@ -57,8 +58,8 @@ class PermissionServiceImpl internal constructor(private val clientOptions: Clie private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) - private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val createHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun create( @@ -88,7 +89,11 @@ class PermissionServiceImpl internal constructor(private val clientOptions: Clie } } .let { - PermissionCreatePage.of(PermissionServiceImpl(clientOptions), params, it) + PermissionCreatePage.builder() + .service(PermissionServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/finetuning/jobs/CheckpointServiceImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/finetuning/jobs/CheckpointServiceImpl.kt index 4eba5568..34d91dc8 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/finetuning/jobs/CheckpointServiceImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/finetuning/jobs/CheckpointServiceImpl.kt @@ -15,6 +15,7 @@ import com.openai.core.http.parseable import com.openai.core.prepare import com.openai.models.ErrorObject import com.openai.models.finetuning.jobs.checkpoints.CheckpointListPage +import com.openai.models.finetuning.jobs.checkpoints.CheckpointListPageResponse import com.openai.models.finetuning.jobs.checkpoints.CheckpointListParams class CheckpointServiceImpl internal constructor(private val clientOptions: ClientOptions) : @@ -38,8 +39,8 @@ class CheckpointServiceImpl internal constructor(private val clientOptions: Clie private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -62,7 +63,13 @@ class CheckpointServiceImpl internal constructor(private val clientOptions: Clie it.validate() } } - .let { CheckpointListPage.of(CheckpointServiceImpl(clientOptions), params, it) } + .let { + CheckpointListPage.builder() + .service(CheckpointServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } } } } diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/responses/InputItemServiceImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/responses/InputItemServiceImpl.kt index 99994de7..19e1a397 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/responses/InputItemServiceImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/responses/InputItemServiceImpl.kt @@ -16,6 +16,7 @@ import com.openai.core.prepare import com.openai.models.ErrorObject import com.openai.models.responses.inputitems.InputItemListPage import com.openai.models.responses.inputitems.InputItemListParams +import com.openai.models.responses.inputitems.ResponseItemList class InputItemServiceImpl internal constructor(private val clientOptions: ClientOptions) : InputItemService { @@ -38,9 +39,8 @@ class InputItemServiceImpl internal constructor(private val clientOptions: Clien private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) override fun list( params: InputItemListParams, @@ -62,7 +62,13 @@ class InputItemServiceImpl internal constructor(private val clientOptions: Clien it.validate() } } - .let { InputItemListPage.of(InputItemServiceImpl(clientOptions), params, it) } + .let { + InputItemListPage.builder() + .service(InputItemServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } } } } diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/vectorstores/FileBatchServiceImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/vectorstores/FileBatchServiceImpl.kt index 26446576..516848c4 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/vectorstores/FileBatchServiceImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/vectorstores/FileBatchServiceImpl.kt @@ -19,6 +19,7 @@ import com.openai.models.ErrorObject import com.openai.models.vectorstores.filebatches.FileBatchCancelParams import com.openai.models.vectorstores.filebatches.FileBatchCreateParams import com.openai.models.vectorstores.filebatches.FileBatchListFilesPage +import com.openai.models.vectorstores.filebatches.FileBatchListFilesPageResponse import com.openai.models.vectorstores.filebatches.FileBatchListFilesParams import com.openai.models.vectorstores.filebatches.FileBatchRetrieveParams import com.openai.models.vectorstores.filebatches.VectorStoreFileBatch @@ -167,8 +168,8 @@ class FileBatchServiceImpl internal constructor(private val clientOptions: Clien } } - private val listFilesHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listFilesHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun listFiles( @@ -199,7 +200,11 @@ class FileBatchServiceImpl internal constructor(private val clientOptions: Clien } } .let { - FileBatchListFilesPage.of(FileBatchServiceImpl(clientOptions), params, it) + FileBatchListFilesPage.builder() + .service(FileBatchServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() } } } diff --git a/openai-java-core/src/main/kotlin/com/openai/services/blocking/vectorstores/FileServiceImpl.kt b/openai-java-core/src/main/kotlin/com/openai/services/blocking/vectorstores/FileServiceImpl.kt index ca6c2bac..c3e9174a 100644 --- a/openai-java-core/src/main/kotlin/com/openai/services/blocking/vectorstores/FileServiceImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/services/blocking/vectorstores/FileServiceImpl.kt @@ -17,10 +17,12 @@ import com.openai.core.http.parseable import com.openai.core.prepare import com.openai.models.ErrorObject import com.openai.models.vectorstores.files.FileContentPage +import com.openai.models.vectorstores.files.FileContentPageResponse import com.openai.models.vectorstores.files.FileContentParams import com.openai.models.vectorstores.files.FileCreateParams import com.openai.models.vectorstores.files.FileDeleteParams import com.openai.models.vectorstores.files.FileListPage +import com.openai.models.vectorstores.files.FileListPageResponse import com.openai.models.vectorstores.files.FileListParams import com.openai.models.vectorstores.files.FileRetrieveParams import com.openai.models.vectorstores.files.FileUpdateParams @@ -171,8 +173,8 @@ class FileServiceImpl internal constructor(private val clientOptions: ClientOpti } } - private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun list( @@ -196,7 +198,13 @@ class FileServiceImpl internal constructor(private val clientOptions: ClientOpti it.validate() } } - .let { FileListPage.of(FileServiceImpl(clientOptions), params, it) } + .let { + FileListPage.builder() + .service(FileServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } } } @@ -234,8 +242,8 @@ class FileServiceImpl internal constructor(private val clientOptions: ClientOpti } } - private val contentHandler: Handler = - jsonHandler(clientOptions.jsonMapper) + private val contentHandler: Handler = + jsonHandler(clientOptions.jsonMapper) .withErrorHandler(errorHandler) override fun content( @@ -265,7 +273,13 @@ class FileServiceImpl internal constructor(private val clientOptions: ClientOpti it.validate() } } - .let { FileContentPage.of(FileServiceImpl(clientOptions), params, it) } + .let { + FileContentPage.builder() + .service(FileServiceImpl(clientOptions)) + .params(params) + .response(it) + .build() + } } } } diff --git a/openai-java-core/src/test/kotlin/com/openai/models/batches/BatchListPageResponseTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/batches/BatchListPageResponseTest.kt new file mode 100644 index 00000000..728f330a --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/batches/BatchListPageResponseTest.kt @@ -0,0 +1,169 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.batches + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.JsonValue +import com.openai.core.jsonMapper +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BatchListPageResponseTest { + + @Test + fun create() { + val batchListPageResponse = + BatchListPageResponse.builder() + .addData( + Batch.builder() + .id("id") + .completionWindow("completion_window") + .createdAt(0L) + .endpoint("endpoint") + .inputFileId("input_file_id") + .status(Batch.Status.VALIDATING) + .cancelledAt(0L) + .cancellingAt(0L) + .completedAt(0L) + .errorFileId("error_file_id") + .errors( + Batch.Errors.builder() + .addData( + BatchError.builder() + .code("code") + .line(0L) + .message("message") + .param("param") + .build() + ) + .object_("object") + .build() + ) + .expiredAt(0L) + .expiresAt(0L) + .failedAt(0L) + .finalizingAt(0L) + .inProgressAt(0L) + .metadata( + Batch.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .outputFileId("output_file_id") + .requestCounts( + BatchRequestCounts.builder().completed(0L).failed(0L).total(0L).build() + ) + .build() + ) + .hasMore(true) + .firstId("batch_abc123") + .lastId("batch_abc456") + .build() + + assertThat(batchListPageResponse.data()) + .containsExactly( + Batch.builder() + .id("id") + .completionWindow("completion_window") + .createdAt(0L) + .endpoint("endpoint") + .inputFileId("input_file_id") + .status(Batch.Status.VALIDATING) + .cancelledAt(0L) + .cancellingAt(0L) + .completedAt(0L) + .errorFileId("error_file_id") + .errors( + Batch.Errors.builder() + .addData( + BatchError.builder() + .code("code") + .line(0L) + .message("message") + .param("param") + .build() + ) + .object_("object") + .build() + ) + .expiredAt(0L) + .expiresAt(0L) + .failedAt(0L) + .finalizingAt(0L) + .inProgressAt(0L) + .metadata( + Batch.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .outputFileId("output_file_id") + .requestCounts( + BatchRequestCounts.builder().completed(0L).failed(0L).total(0L).build() + ) + .build() + ) + assertThat(batchListPageResponse.hasMore()).isEqualTo(true) + assertThat(batchListPageResponse.firstId()).contains("batch_abc123") + assertThat(batchListPageResponse.lastId()).contains("batch_abc456") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val batchListPageResponse = + BatchListPageResponse.builder() + .addData( + Batch.builder() + .id("id") + .completionWindow("completion_window") + .createdAt(0L) + .endpoint("endpoint") + .inputFileId("input_file_id") + .status(Batch.Status.VALIDATING) + .cancelledAt(0L) + .cancellingAt(0L) + .completedAt(0L) + .errorFileId("error_file_id") + .errors( + Batch.Errors.builder() + .addData( + BatchError.builder() + .code("code") + .line(0L) + .message("message") + .param("param") + .build() + ) + .object_("object") + .build() + ) + .expiredAt(0L) + .expiresAt(0L) + .failedAt(0L) + .finalizingAt(0L) + .inProgressAt(0L) + .metadata( + Batch.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .outputFileId("output_file_id") + .requestCounts( + BatchRequestCounts.builder().completed(0L).failed(0L).total(0L).build() + ) + .build() + ) + .hasMore(true) + .firstId("batch_abc123") + .lastId("batch_abc456") + .build() + + val roundtrippedBatchListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(batchListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBatchListPageResponse).isEqualTo(batchListPageResponse) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/beta/assistants/AssistantListPageResponseTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/beta/assistants/AssistantListPageResponseTest.kt new file mode 100644 index 00000000..cc0e1fc0 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/beta/assistants/AssistantListPageResponseTest.kt @@ -0,0 +1,148 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.beta.assistants + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.JsonValue +import com.openai.core.jsonMapper +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class AssistantListPageResponseTest { + + @Test + fun create() { + val assistantListPageResponse = + AssistantListPageResponse.builder() + .addData( + Assistant.builder() + .id("id") + .createdAt(0L) + .description("description") + .instructions("instructions") + .metadata( + Assistant.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .model("model") + .name("name") + .addTool(CodeInterpreterTool.builder().build()) + .responseFormatAuto() + .temperature(1.0) + .toolResources( + Assistant.ToolResources.builder() + .codeInterpreter( + Assistant.ToolResources.CodeInterpreter.builder() + .addFileId("string") + .build() + ) + .fileSearch( + Assistant.ToolResources.FileSearch.builder() + .addVectorStoreId("string") + .build() + ) + .build() + ) + .topP(1.0) + .build() + ) + .firstId("asst_abc123") + .hasMore(false) + .lastId("asst_abc456") + .object_("list") + .build() + + assertThat(assistantListPageResponse.data()) + .containsExactly( + Assistant.builder() + .id("id") + .createdAt(0L) + .description("description") + .instructions("instructions") + .metadata( + Assistant.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .model("model") + .name("name") + .addTool(CodeInterpreterTool.builder().build()) + .responseFormatAuto() + .temperature(1.0) + .toolResources( + Assistant.ToolResources.builder() + .codeInterpreter( + Assistant.ToolResources.CodeInterpreter.builder() + .addFileId("string") + .build() + ) + .fileSearch( + Assistant.ToolResources.FileSearch.builder() + .addVectorStoreId("string") + .build() + ) + .build() + ) + .topP(1.0) + .build() + ) + assertThat(assistantListPageResponse.firstId()).isEqualTo("asst_abc123") + assertThat(assistantListPageResponse.hasMore()).isEqualTo(false) + assertThat(assistantListPageResponse.lastId()).isEqualTo("asst_abc456") + assertThat(assistantListPageResponse.object_()).isEqualTo("list") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val assistantListPageResponse = + AssistantListPageResponse.builder() + .addData( + Assistant.builder() + .id("id") + .createdAt(0L) + .description("description") + .instructions("instructions") + .metadata( + Assistant.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .model("model") + .name("name") + .addTool(CodeInterpreterTool.builder().build()) + .responseFormatAuto() + .temperature(1.0) + .toolResources( + Assistant.ToolResources.builder() + .codeInterpreter( + Assistant.ToolResources.CodeInterpreter.builder() + .addFileId("string") + .build() + ) + .fileSearch( + Assistant.ToolResources.FileSearch.builder() + .addVectorStoreId("string") + .build() + ) + .build() + ) + .topP(1.0) + .build() + ) + .firstId("asst_abc123") + .hasMore(false) + .lastId("asst_abc456") + .object_("list") + .build() + + val roundtrippedAssistantListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(assistantListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedAssistantListPageResponse).isEqualTo(assistantListPageResponse) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/beta/threads/messages/MessageListPageResponseTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/beta/threads/messages/MessageListPageResponseTest.kt new file mode 100644 index 00000000..5efdc096 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/beta/threads/messages/MessageListPageResponseTest.kt @@ -0,0 +1,152 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.beta.threads.messages + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.JsonValue +import com.openai.core.jsonMapper +import com.openai.models.beta.assistants.CodeInterpreterTool +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class MessageListPageResponseTest { + + @Test + fun create() { + val messageListPageResponse = + MessageListPageResponse.builder() + .addData( + Message.builder() + .id("id") + .assistantId("assistant_id") + .addAttachment( + Message.Attachment.builder() + .fileId("file_id") + .addTool(CodeInterpreterTool.builder().build()) + .build() + ) + .completedAt(0L) + .addImageFileContent( + ImageFile.builder() + .fileId("file_id") + .detail(ImageFile.Detail.AUTO) + .build() + ) + .createdAt(0L) + .incompleteAt(0L) + .incompleteDetails( + Message.IncompleteDetails.builder() + .reason(Message.IncompleteDetails.Reason.CONTENT_FILTER) + .build() + ) + .metadata( + Message.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .role(Message.Role.USER) + .runId("run_id") + .status(Message.Status.IN_PROGRESS) + .threadId("thread_id") + .build() + ) + .firstId("msg_abc123") + .hasMore(false) + .lastId("msg_abc123") + .object_("list") + .build() + + assertThat(messageListPageResponse.data()) + .containsExactly( + Message.builder() + .id("id") + .assistantId("assistant_id") + .addAttachment( + Message.Attachment.builder() + .fileId("file_id") + .addTool(CodeInterpreterTool.builder().build()) + .build() + ) + .completedAt(0L) + .addImageFileContent( + ImageFile.builder().fileId("file_id").detail(ImageFile.Detail.AUTO).build() + ) + .createdAt(0L) + .incompleteAt(0L) + .incompleteDetails( + Message.IncompleteDetails.builder() + .reason(Message.IncompleteDetails.Reason.CONTENT_FILTER) + .build() + ) + .metadata( + Message.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .role(Message.Role.USER) + .runId("run_id") + .status(Message.Status.IN_PROGRESS) + .threadId("thread_id") + .build() + ) + assertThat(messageListPageResponse.firstId()).isEqualTo("msg_abc123") + assertThat(messageListPageResponse.hasMore()).isEqualTo(false) + assertThat(messageListPageResponse.lastId()).isEqualTo("msg_abc123") + assertThat(messageListPageResponse.object_()).isEqualTo("list") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val messageListPageResponse = + MessageListPageResponse.builder() + .addData( + Message.builder() + .id("id") + .assistantId("assistant_id") + .addAttachment( + Message.Attachment.builder() + .fileId("file_id") + .addTool(CodeInterpreterTool.builder().build()) + .build() + ) + .completedAt(0L) + .addImageFileContent( + ImageFile.builder() + .fileId("file_id") + .detail(ImageFile.Detail.AUTO) + .build() + ) + .createdAt(0L) + .incompleteAt(0L) + .incompleteDetails( + Message.IncompleteDetails.builder() + .reason(Message.IncompleteDetails.Reason.CONTENT_FILTER) + .build() + ) + .metadata( + Message.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .role(Message.Role.USER) + .runId("run_id") + .status(Message.Status.IN_PROGRESS) + .threadId("thread_id") + .build() + ) + .firstId("msg_abc123") + .hasMore(false) + .lastId("msg_abc123") + .object_("list") + .build() + + val roundtrippedMessageListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(messageListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedMessageListPageResponse).isEqualTo(messageListPageResponse) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/beta/threads/runs/RunListPageResponseTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/beta/threads/runs/RunListPageResponseTest.kt new file mode 100644 index 00000000..0b370711 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/beta/threads/runs/RunListPageResponseTest.kt @@ -0,0 +1,269 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.beta.threads.runs + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.JsonValue +import com.openai.core.jsonMapper +import com.openai.models.beta.assistants.CodeInterpreterTool +import com.openai.models.beta.threads.AssistantToolChoiceOption +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class RunListPageResponseTest { + + @Test + fun create() { + val runListPageResponse = + RunListPageResponse.builder() + .addData( + Run.builder() + .id("id") + .assistantId("assistant_id") + .cancelledAt(0L) + .completedAt(0L) + .createdAt(0L) + .expiresAt(0L) + .failedAt(0L) + .incompleteDetails( + Run.IncompleteDetails.builder() + .reason(Run.IncompleteDetails.Reason.MAX_COMPLETION_TOKENS) + .build() + ) + .instructions("instructions") + .lastError( + Run.LastError.builder() + .code(Run.LastError.Code.SERVER_ERROR) + .message("message") + .build() + ) + .maxCompletionTokens(256L) + .maxPromptTokens(256L) + .metadata( + Run.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .model("model") + .parallelToolCalls(true) + .requiredAction( + Run.RequiredAction.builder() + .submitToolOutputs( + Run.RequiredAction.SubmitToolOutputs.builder() + .addToolCall( + RequiredActionFunctionToolCall.builder() + .id("id") + .function( + RequiredActionFunctionToolCall.Function + .builder() + .arguments("arguments") + .name("name") + .build() + ) + .build() + ) + .build() + ) + .build() + ) + .responseFormatAuto() + .startedAt(0L) + .status(RunStatus.QUEUED) + .threadId("thread_id") + .toolChoice(AssistantToolChoiceOption.Auto.NONE) + .addTool(CodeInterpreterTool.builder().build()) + .truncationStrategy( + Run.TruncationStrategy.builder() + .type(Run.TruncationStrategy.Type.AUTO) + .lastMessages(1L) + .build() + ) + .usage( + Run.Usage.builder() + .completionTokens(0L) + .promptTokens(0L) + .totalTokens(0L) + .build() + ) + .temperature(0.0) + .topP(0.0) + .build() + ) + .firstId("run_abc123") + .hasMore(false) + .lastId("run_abc456") + .object_("list") + .build() + + assertThat(runListPageResponse.data()) + .containsExactly( + Run.builder() + .id("id") + .assistantId("assistant_id") + .cancelledAt(0L) + .completedAt(0L) + .createdAt(0L) + .expiresAt(0L) + .failedAt(0L) + .incompleteDetails( + Run.IncompleteDetails.builder() + .reason(Run.IncompleteDetails.Reason.MAX_COMPLETION_TOKENS) + .build() + ) + .instructions("instructions") + .lastError( + Run.LastError.builder() + .code(Run.LastError.Code.SERVER_ERROR) + .message("message") + .build() + ) + .maxCompletionTokens(256L) + .maxPromptTokens(256L) + .metadata( + Run.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .model("model") + .parallelToolCalls(true) + .requiredAction( + Run.RequiredAction.builder() + .submitToolOutputs( + Run.RequiredAction.SubmitToolOutputs.builder() + .addToolCall( + RequiredActionFunctionToolCall.builder() + .id("id") + .function( + RequiredActionFunctionToolCall.Function.builder() + .arguments("arguments") + .name("name") + .build() + ) + .build() + ) + .build() + ) + .build() + ) + .responseFormatAuto() + .startedAt(0L) + .status(RunStatus.QUEUED) + .threadId("thread_id") + .toolChoice(AssistantToolChoiceOption.Auto.NONE) + .addTool(CodeInterpreterTool.builder().build()) + .truncationStrategy( + Run.TruncationStrategy.builder() + .type(Run.TruncationStrategy.Type.AUTO) + .lastMessages(1L) + .build() + ) + .usage( + Run.Usage.builder() + .completionTokens(0L) + .promptTokens(0L) + .totalTokens(0L) + .build() + ) + .temperature(0.0) + .topP(0.0) + .build() + ) + assertThat(runListPageResponse.firstId()).isEqualTo("run_abc123") + assertThat(runListPageResponse.hasMore()).isEqualTo(false) + assertThat(runListPageResponse.lastId()).isEqualTo("run_abc456") + assertThat(runListPageResponse.object_()).isEqualTo("list") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val runListPageResponse = + RunListPageResponse.builder() + .addData( + Run.builder() + .id("id") + .assistantId("assistant_id") + .cancelledAt(0L) + .completedAt(0L) + .createdAt(0L) + .expiresAt(0L) + .failedAt(0L) + .incompleteDetails( + Run.IncompleteDetails.builder() + .reason(Run.IncompleteDetails.Reason.MAX_COMPLETION_TOKENS) + .build() + ) + .instructions("instructions") + .lastError( + Run.LastError.builder() + .code(Run.LastError.Code.SERVER_ERROR) + .message("message") + .build() + ) + .maxCompletionTokens(256L) + .maxPromptTokens(256L) + .metadata( + Run.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .model("model") + .parallelToolCalls(true) + .requiredAction( + Run.RequiredAction.builder() + .submitToolOutputs( + Run.RequiredAction.SubmitToolOutputs.builder() + .addToolCall( + RequiredActionFunctionToolCall.builder() + .id("id") + .function( + RequiredActionFunctionToolCall.Function + .builder() + .arguments("arguments") + .name("name") + .build() + ) + .build() + ) + .build() + ) + .build() + ) + .responseFormatAuto() + .startedAt(0L) + .status(RunStatus.QUEUED) + .threadId("thread_id") + .toolChoice(AssistantToolChoiceOption.Auto.NONE) + .addTool(CodeInterpreterTool.builder().build()) + .truncationStrategy( + Run.TruncationStrategy.builder() + .type(Run.TruncationStrategy.Type.AUTO) + .lastMessages(1L) + .build() + ) + .usage( + Run.Usage.builder() + .completionTokens(0L) + .promptTokens(0L) + .totalTokens(0L) + .build() + ) + .temperature(0.0) + .topP(0.0) + .build() + ) + .firstId("run_abc123") + .hasMore(false) + .lastId("run_abc456") + .object_("list") + .build() + + val roundtrippedRunListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(runListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedRunListPageResponse).isEqualTo(runListPageResponse) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/beta/threads/runs/steps/StepListPageResponseTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/beta/threads/runs/steps/StepListPageResponseTest.kt new file mode 100644 index 00000000..5e0a2ef8 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/beta/threads/runs/steps/StepListPageResponseTest.kt @@ -0,0 +1,163 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.beta.threads.runs.steps + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.JsonValue +import com.openai.core.jsonMapper +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class StepListPageResponseTest { + + @Test + fun create() { + val stepListPageResponse = + StepListPageResponse.builder() + .addData( + RunStep.builder() + .id("id") + .assistantId("assistant_id") + .cancelledAt(0L) + .completedAt(0L) + .createdAt(0L) + .expiredAt(0L) + .failedAt(0L) + .lastError( + RunStep.LastError.builder() + .code(RunStep.LastError.Code.SERVER_ERROR) + .message("message") + .build() + ) + .metadata( + RunStep.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .runId("run_id") + .status(RunStep.Status.IN_PROGRESS) + .messageCreationStepDetails( + MessageCreationStepDetails.MessageCreation.builder() + .messageId("message_id") + .build() + ) + .threadId("thread_id") + .type(RunStep.Type.MESSAGE_CREATION) + .usage( + RunStep.Usage.builder() + .completionTokens(0L) + .promptTokens(0L) + .totalTokens(0L) + .build() + ) + .build() + ) + .firstId("step_abc123") + .hasMore(false) + .lastId("step_abc456") + .object_("list") + .build() + + assertThat(stepListPageResponse.data()) + .containsExactly( + RunStep.builder() + .id("id") + .assistantId("assistant_id") + .cancelledAt(0L) + .completedAt(0L) + .createdAt(0L) + .expiredAt(0L) + .failedAt(0L) + .lastError( + RunStep.LastError.builder() + .code(RunStep.LastError.Code.SERVER_ERROR) + .message("message") + .build() + ) + .metadata( + RunStep.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .runId("run_id") + .status(RunStep.Status.IN_PROGRESS) + .messageCreationStepDetails( + MessageCreationStepDetails.MessageCreation.builder() + .messageId("message_id") + .build() + ) + .threadId("thread_id") + .type(RunStep.Type.MESSAGE_CREATION) + .usage( + RunStep.Usage.builder() + .completionTokens(0L) + .promptTokens(0L) + .totalTokens(0L) + .build() + ) + .build() + ) + assertThat(stepListPageResponse.firstId()).isEqualTo("step_abc123") + assertThat(stepListPageResponse.hasMore()).isEqualTo(false) + assertThat(stepListPageResponse.lastId()).isEqualTo("step_abc456") + assertThat(stepListPageResponse.object_()).isEqualTo("list") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val stepListPageResponse = + StepListPageResponse.builder() + .addData( + RunStep.builder() + .id("id") + .assistantId("assistant_id") + .cancelledAt(0L) + .completedAt(0L) + .createdAt(0L) + .expiredAt(0L) + .failedAt(0L) + .lastError( + RunStep.LastError.builder() + .code(RunStep.LastError.Code.SERVER_ERROR) + .message("message") + .build() + ) + .metadata( + RunStep.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .runId("run_id") + .status(RunStep.Status.IN_PROGRESS) + .messageCreationStepDetails( + MessageCreationStepDetails.MessageCreation.builder() + .messageId("message_id") + .build() + ) + .threadId("thread_id") + .type(RunStep.Type.MESSAGE_CREATION) + .usage( + RunStep.Usage.builder() + .completionTokens(0L) + .promptTokens(0L) + .totalTokens(0L) + .build() + ) + .build() + ) + .firstId("step_abc123") + .hasMore(false) + .lastId("step_abc456") + .object_("list") + .build() + + val roundtrippedStepListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(stepListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedStepListPageResponse).isEqualTo(stepListPageResponse) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/chat/completions/ChatCompletionListPageResponseTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/chat/completions/ChatCompletionListPageResponseTest.kt new file mode 100644 index 00000000..26cab2fc --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/chat/completions/ChatCompletionListPageResponseTest.kt @@ -0,0 +1,383 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.chat.completions + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.jsonMapper +import com.openai.models.completions.CompletionUsage +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ChatCompletionListPageResponseTest { + + @Test + fun create() { + val chatCompletionListPageResponse = + ChatCompletionListPageResponse.builder() + .addData( + ChatCompletion.builder() + .id("id") + .addChoice( + ChatCompletion.Choice.builder() + .finishReason(ChatCompletion.Choice.FinishReason.STOP) + .index(0L) + .logprobs( + ChatCompletion.Choice.Logprobs.builder() + .addContent( + ChatCompletionTokenLogprob.builder() + .token("token") + .addByte(0L) + .logprob(0.0) + .addTopLogprob( + ChatCompletionTokenLogprob.TopLogprob.builder() + .token("token") + .addByte(0L) + .logprob(0.0) + .build() + ) + .build() + ) + .addRefusal( + ChatCompletionTokenLogprob.builder() + .token("token") + .addByte(0L) + .logprob(0.0) + .addTopLogprob( + ChatCompletionTokenLogprob.TopLogprob.builder() + .token("token") + .addByte(0L) + .logprob(0.0) + .build() + ) + .build() + ) + .build() + ) + .message( + ChatCompletionMessage.builder() + .content("content") + .refusal("refusal") + .addAnnotation( + ChatCompletionMessage.Annotation.builder() + .urlCitation( + ChatCompletionMessage.Annotation.UrlCitation + .builder() + .endIndex(0L) + .startIndex(0L) + .title("title") + ./service/https://github.com/url("url") + .build() + ) + .build() + ) + .audio( + ChatCompletionAudio.builder() + .id("id") + .data("data") + .expiresAt(0L) + .transcript("transcript") + .build() + ) + .functionCall( + ChatCompletionMessage.FunctionCall.builder() + .arguments("arguments") + .name("name") + .build() + ) + .addToolCall( + ChatCompletionMessageToolCall.builder() + .id("id") + .function( + ChatCompletionMessageToolCall.Function.builder() + .arguments("arguments") + .name("name") + .build() + ) + .build() + ) + .build() + ) + .build() + ) + .created(0L) + .model("model") + .serviceTier(ChatCompletion.ServiceTier.SCALE) + .systemFingerprint("system_fingerprint") + .usage( + CompletionUsage.builder() + .completionTokens(0L) + .promptTokens(0L) + .totalTokens(0L) + .completionTokensDetails( + CompletionUsage.CompletionTokensDetails.builder() + .acceptedPredictionTokens(0L) + .audioTokens(0L) + .reasoningTokens(0L) + .rejectedPredictionTokens(0L) + .build() + ) + .promptTokensDetails( + CompletionUsage.PromptTokensDetails.builder() + .audioTokens(0L) + .cachedTokens(0L) + .build() + ) + .build() + ) + .build() + ) + .firstId("first_id") + .hasMore(true) + .lastId("last_id") + .build() + + assertThat(chatCompletionListPageResponse.data()) + .containsExactly( + ChatCompletion.builder() + .id("id") + .addChoice( + ChatCompletion.Choice.builder() + .finishReason(ChatCompletion.Choice.FinishReason.STOP) + .index(0L) + .logprobs( + ChatCompletion.Choice.Logprobs.builder() + .addContent( + ChatCompletionTokenLogprob.builder() + .token("token") + .addByte(0L) + .logprob(0.0) + .addTopLogprob( + ChatCompletionTokenLogprob.TopLogprob.builder() + .token("token") + .addByte(0L) + .logprob(0.0) + .build() + ) + .build() + ) + .addRefusal( + ChatCompletionTokenLogprob.builder() + .token("token") + .addByte(0L) + .logprob(0.0) + .addTopLogprob( + ChatCompletionTokenLogprob.TopLogprob.builder() + .token("token") + .addByte(0L) + .logprob(0.0) + .build() + ) + .build() + ) + .build() + ) + .message( + ChatCompletionMessage.builder() + .content("content") + .refusal("refusal") + .addAnnotation( + ChatCompletionMessage.Annotation.builder() + .urlCitation( + ChatCompletionMessage.Annotation.UrlCitation + .builder() + .endIndex(0L) + .startIndex(0L) + .title("title") + ./service/https://github.com/url("url") + .build() + ) + .build() + ) + .audio( + ChatCompletionAudio.builder() + .id("id") + .data("data") + .expiresAt(0L) + .transcript("transcript") + .build() + ) + .functionCall( + ChatCompletionMessage.FunctionCall.builder() + .arguments("arguments") + .name("name") + .build() + ) + .addToolCall( + ChatCompletionMessageToolCall.builder() + .id("id") + .function( + ChatCompletionMessageToolCall.Function.builder() + .arguments("arguments") + .name("name") + .build() + ) + .build() + ) + .build() + ) + .build() + ) + .created(0L) + .model("model") + .serviceTier(ChatCompletion.ServiceTier.SCALE) + .systemFingerprint("system_fingerprint") + .usage( + CompletionUsage.builder() + .completionTokens(0L) + .promptTokens(0L) + .totalTokens(0L) + .completionTokensDetails( + CompletionUsage.CompletionTokensDetails.builder() + .acceptedPredictionTokens(0L) + .audioTokens(0L) + .reasoningTokens(0L) + .rejectedPredictionTokens(0L) + .build() + ) + .promptTokensDetails( + CompletionUsage.PromptTokensDetails.builder() + .audioTokens(0L) + .cachedTokens(0L) + .build() + ) + .build() + ) + .build() + ) + assertThat(chatCompletionListPageResponse.firstId()).isEqualTo("first_id") + assertThat(chatCompletionListPageResponse.hasMore()).isEqualTo(true) + assertThat(chatCompletionListPageResponse.lastId()).isEqualTo("last_id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val chatCompletionListPageResponse = + ChatCompletionListPageResponse.builder() + .addData( + ChatCompletion.builder() + .id("id") + .addChoice( + ChatCompletion.Choice.builder() + .finishReason(ChatCompletion.Choice.FinishReason.STOP) + .index(0L) + .logprobs( + ChatCompletion.Choice.Logprobs.builder() + .addContent( + ChatCompletionTokenLogprob.builder() + .token("token") + .addByte(0L) + .logprob(0.0) + .addTopLogprob( + ChatCompletionTokenLogprob.TopLogprob.builder() + .token("token") + .addByte(0L) + .logprob(0.0) + .build() + ) + .build() + ) + .addRefusal( + ChatCompletionTokenLogprob.builder() + .token("token") + .addByte(0L) + .logprob(0.0) + .addTopLogprob( + ChatCompletionTokenLogprob.TopLogprob.builder() + .token("token") + .addByte(0L) + .logprob(0.0) + .build() + ) + .build() + ) + .build() + ) + .message( + ChatCompletionMessage.builder() + .content("content") + .refusal("refusal") + .addAnnotation( + ChatCompletionMessage.Annotation.builder() + .urlCitation( + ChatCompletionMessage.Annotation.UrlCitation + .builder() + .endIndex(0L) + .startIndex(0L) + .title("title") + ./service/https://github.com/url("url") + .build() + ) + .build() + ) + .audio( + ChatCompletionAudio.builder() + .id("id") + .data("data") + .expiresAt(0L) + .transcript("transcript") + .build() + ) + .functionCall( + ChatCompletionMessage.FunctionCall.builder() + .arguments("arguments") + .name("name") + .build() + ) + .addToolCall( + ChatCompletionMessageToolCall.builder() + .id("id") + .function( + ChatCompletionMessageToolCall.Function.builder() + .arguments("arguments") + .name("name") + .build() + ) + .build() + ) + .build() + ) + .build() + ) + .created(0L) + .model("model") + .serviceTier(ChatCompletion.ServiceTier.SCALE) + .systemFingerprint("system_fingerprint") + .usage( + CompletionUsage.builder() + .completionTokens(0L) + .promptTokens(0L) + .totalTokens(0L) + .completionTokensDetails( + CompletionUsage.CompletionTokensDetails.builder() + .acceptedPredictionTokens(0L) + .audioTokens(0L) + .reasoningTokens(0L) + .rejectedPredictionTokens(0L) + .build() + ) + .promptTokensDetails( + CompletionUsage.PromptTokensDetails.builder() + .audioTokens(0L) + .cachedTokens(0L) + .build() + ) + .build() + ) + .build() + ) + .firstId("first_id") + .hasMore(true) + .lastId("last_id") + .build() + + val roundtrippedChatCompletionListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(chatCompletionListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedChatCompletionListPageResponse) + .isEqualTo(chatCompletionListPageResponse) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/chat/completions/messages/MessageListPageResponseTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/chat/completions/messages/MessageListPageResponseTest.kt new file mode 100644 index 00000000..75db7ba3 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/chat/completions/messages/MessageListPageResponseTest.kt @@ -0,0 +1,181 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.chat.completions.messages + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.jsonMapper +import com.openai.models.chat.completions.ChatCompletionAudio +import com.openai.models.chat.completions.ChatCompletionMessage +import com.openai.models.chat.completions.ChatCompletionMessageToolCall +import com.openai.models.chat.completions.ChatCompletionStoreMessage +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class MessageListPageResponseTest { + + @Test + fun create() { + val messageListPageResponse = + MessageListPageResponse.builder() + .addData( + ChatCompletionStoreMessage.builder() + .content("content") + .refusal("refusal") + .addAnnotation( + ChatCompletionMessage.Annotation.builder() + .urlCitation( + ChatCompletionMessage.Annotation.UrlCitation.builder() + .endIndex(0L) + .startIndex(0L) + .title("title") + ./service/https://github.com/url("url") + .build() + ) + .build() + ) + .audio( + ChatCompletionAudio.builder() + .id("id") + .data("data") + .expiresAt(0L) + .transcript("transcript") + .build() + ) + .functionCall( + ChatCompletionMessage.FunctionCall.builder() + .arguments("arguments") + .name("name") + .build() + ) + .addToolCall( + ChatCompletionMessageToolCall.builder() + .id("id") + .function( + ChatCompletionMessageToolCall.Function.builder() + .arguments("arguments") + .name("name") + .build() + ) + .build() + ) + .id("id") + .build() + ) + .firstId("first_id") + .hasMore(true) + .lastId("last_id") + .build() + + assertThat(messageListPageResponse.data()) + .containsExactly( + ChatCompletionStoreMessage.builder() + .content("content") + .refusal("refusal") + .addAnnotation( + ChatCompletionMessage.Annotation.builder() + .urlCitation( + ChatCompletionMessage.Annotation.UrlCitation.builder() + .endIndex(0L) + .startIndex(0L) + .title("title") + ./service/https://github.com/url("url") + .build() + ) + .build() + ) + .audio( + ChatCompletionAudio.builder() + .id("id") + .data("data") + .expiresAt(0L) + .transcript("transcript") + .build() + ) + .functionCall( + ChatCompletionMessage.FunctionCall.builder() + .arguments("arguments") + .name("name") + .build() + ) + .addToolCall( + ChatCompletionMessageToolCall.builder() + .id("id") + .function( + ChatCompletionMessageToolCall.Function.builder() + .arguments("arguments") + .name("name") + .build() + ) + .build() + ) + .id("id") + .build() + ) + assertThat(messageListPageResponse.firstId()).isEqualTo("first_id") + assertThat(messageListPageResponse.hasMore()).isEqualTo(true) + assertThat(messageListPageResponse.lastId()).isEqualTo("last_id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val messageListPageResponse = + MessageListPageResponse.builder() + .addData( + ChatCompletionStoreMessage.builder() + .content("content") + .refusal("refusal") + .addAnnotation( + ChatCompletionMessage.Annotation.builder() + .urlCitation( + ChatCompletionMessage.Annotation.UrlCitation.builder() + .endIndex(0L) + .startIndex(0L) + .title("title") + ./service/https://github.com/url("url") + .build() + ) + .build() + ) + .audio( + ChatCompletionAudio.builder() + .id("id") + .data("data") + .expiresAt(0L) + .transcript("transcript") + .build() + ) + .functionCall( + ChatCompletionMessage.FunctionCall.builder() + .arguments("arguments") + .name("name") + .build() + ) + .addToolCall( + ChatCompletionMessageToolCall.builder() + .id("id") + .function( + ChatCompletionMessageToolCall.Function.builder() + .arguments("arguments") + .name("name") + .build() + ) + .build() + ) + .id("id") + .build() + ) + .firstId("first_id") + .hasMore(true) + .lastId("last_id") + .build() + + val roundtrippedMessageListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(messageListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedMessageListPageResponse).isEqualTo(messageListPageResponse) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/evals/EvalListPageResponseTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/evals/EvalListPageResponseTest.kt new file mode 100644 index 00000000..c7b27ebd --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/evals/EvalListPageResponseTest.kt @@ -0,0 +1,173 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.evals + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.JsonValue +import com.openai.core.jsonMapper +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class EvalListPageResponseTest { + + @Test + fun create() { + val evalListPageResponse = + EvalListPageResponse.builder() + .addData( + EvalListResponse.builder() + .id("id") + .createdAt(0L) + .customDataSourceConfig( + EvalCustomDataSourceConfig.Schema.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .metadata( + EvalListResponse.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .name("Chatbot effectiveness Evaluation") + .shareWithOpenAI(true) + .addTestingCriterion( + EvalLabelModelGrader.builder() + .addInput( + EvalLabelModelGrader.Input.InputMessage.builder() + .content( + EvalLabelModelGrader.Input.InputMessage.Content + .builder() + .text("text") + .type( + EvalLabelModelGrader.Input.InputMessage.Content + .Type + .INPUT_TEXT + ) + .build() + ) + .role(EvalLabelModelGrader.Input.InputMessage.Role.USER) + .type(EvalLabelModelGrader.Input.InputMessage.Type.MESSAGE) + .build() + ) + .addLabel("string") + .model("model") + .name("name") + .addPassingLabel("string") + .build() + ) + .build() + ) + .firstId("first_id") + .hasMore(true) + .lastId("last_id") + .build() + + assertThat(evalListPageResponse.data()) + .containsExactly( + EvalListResponse.builder() + .id("id") + .createdAt(0L) + .customDataSourceConfig( + EvalCustomDataSourceConfig.Schema.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .metadata( + EvalListResponse.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .name("Chatbot effectiveness Evaluation") + .shareWithOpenAI(true) + .addTestingCriterion( + EvalLabelModelGrader.builder() + .addInput( + EvalLabelModelGrader.Input.InputMessage.builder() + .content( + EvalLabelModelGrader.Input.InputMessage.Content.builder() + .text("text") + .type( + EvalLabelModelGrader.Input.InputMessage.Content.Type + .INPUT_TEXT + ) + .build() + ) + .role(EvalLabelModelGrader.Input.InputMessage.Role.USER) + .type(EvalLabelModelGrader.Input.InputMessage.Type.MESSAGE) + .build() + ) + .addLabel("string") + .model("model") + .name("name") + .addPassingLabel("string") + .build() + ) + .build() + ) + assertThat(evalListPageResponse.firstId()).isEqualTo("first_id") + assertThat(evalListPageResponse.hasMore()).isEqualTo(true) + assertThat(evalListPageResponse.lastId()).isEqualTo("last_id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val evalListPageResponse = + EvalListPageResponse.builder() + .addData( + EvalListResponse.builder() + .id("id") + .createdAt(0L) + .customDataSourceConfig( + EvalCustomDataSourceConfig.Schema.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .metadata( + EvalListResponse.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .name("Chatbot effectiveness Evaluation") + .shareWithOpenAI(true) + .addTestingCriterion( + EvalLabelModelGrader.builder() + .addInput( + EvalLabelModelGrader.Input.InputMessage.builder() + .content( + EvalLabelModelGrader.Input.InputMessage.Content + .builder() + .text("text") + .type( + EvalLabelModelGrader.Input.InputMessage.Content + .Type + .INPUT_TEXT + ) + .build() + ) + .role(EvalLabelModelGrader.Input.InputMessage.Role.USER) + .type(EvalLabelModelGrader.Input.InputMessage.Type.MESSAGE) + .build() + ) + .addLabel("string") + .model("model") + .name("name") + .addPassingLabel("string") + .build() + ) + .build() + ) + .firstId("first_id") + .hasMore(true) + .lastId("last_id") + .build() + + val roundtrippedEvalListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(evalListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedEvalListPageResponse).isEqualTo(evalListPageResponse) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/evals/runs/RunListPageResponseTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/evals/runs/RunListPageResponseTest.kt new file mode 100644 index 00000000..c51e01a8 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/evals/runs/RunListPageResponseTest.kt @@ -0,0 +1,228 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.evals.runs + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.JsonValue +import com.openai.core.jsonMapper +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class RunListPageResponseTest { + + @Test + fun create() { + val runListPageResponse = + RunListPageResponse.builder() + .addData( + RunListResponse.builder() + .id("id") + .createdAt(0L) + .fileContentJsonlDataSource( + listOf( + CreateEvalJsonlRunDataSource.Source.FileContent.Content.builder() + .item( + CreateEvalJsonlRunDataSource.Source.FileContent.Content.Item + .builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .sample( + CreateEvalJsonlRunDataSource.Source.FileContent.Content + .Sample + .builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .build() + ) + ) + .error(EvalApiError.builder().code("code").message("message").build()) + .evalId("eval_id") + .metadata( + RunListResponse.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .model("model") + .name("name") + .addPerModelUsage( + RunListResponse.PerModelUsage.builder() + .cachedTokens(0L) + .completionTokens(0L) + .invocationCount(0L) + .modelName("model_name") + .promptTokens(0L) + .totalTokens(0L) + .build() + ) + .addPerTestingCriteriaResult( + RunListResponse.PerTestingCriteriaResult.builder() + .failed(0L) + .passed(0L) + .testingCriteria("testing_criteria") + .build() + ) + .reportUrl("report_url") + .resultCounts( + RunListResponse.ResultCounts.builder() + .errored(0L) + .failed(0L) + .passed(0L) + .total(0L) + .build() + ) + .status("status") + .build() + ) + .firstId("first_id") + .hasMore(true) + .lastId("last_id") + .build() + + assertThat(runListPageResponse.data()) + .containsExactly( + RunListResponse.builder() + .id("id") + .createdAt(0L) + .fileContentJsonlDataSource( + listOf( + CreateEvalJsonlRunDataSource.Source.FileContent.Content.builder() + .item( + CreateEvalJsonlRunDataSource.Source.FileContent.Content.Item + .builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .sample( + CreateEvalJsonlRunDataSource.Source.FileContent.Content.Sample + .builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .build() + ) + ) + .error(EvalApiError.builder().code("code").message("message").build()) + .evalId("eval_id") + .metadata( + RunListResponse.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .model("model") + .name("name") + .addPerModelUsage( + RunListResponse.PerModelUsage.builder() + .cachedTokens(0L) + .completionTokens(0L) + .invocationCount(0L) + .modelName("model_name") + .promptTokens(0L) + .totalTokens(0L) + .build() + ) + .addPerTestingCriteriaResult( + RunListResponse.PerTestingCriteriaResult.builder() + .failed(0L) + .passed(0L) + .testingCriteria("testing_criteria") + .build() + ) + .reportUrl("report_url") + .resultCounts( + RunListResponse.ResultCounts.builder() + .errored(0L) + .failed(0L) + .passed(0L) + .total(0L) + .build() + ) + .status("status") + .build() + ) + assertThat(runListPageResponse.firstId()).isEqualTo("first_id") + assertThat(runListPageResponse.hasMore()).isEqualTo(true) + assertThat(runListPageResponse.lastId()).isEqualTo("last_id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val runListPageResponse = + RunListPageResponse.builder() + .addData( + RunListResponse.builder() + .id("id") + .createdAt(0L) + .fileContentJsonlDataSource( + listOf( + CreateEvalJsonlRunDataSource.Source.FileContent.Content.builder() + .item( + CreateEvalJsonlRunDataSource.Source.FileContent.Content.Item + .builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .sample( + CreateEvalJsonlRunDataSource.Source.FileContent.Content + .Sample + .builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .build() + ) + ) + .error(EvalApiError.builder().code("code").message("message").build()) + .evalId("eval_id") + .metadata( + RunListResponse.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .model("model") + .name("name") + .addPerModelUsage( + RunListResponse.PerModelUsage.builder() + .cachedTokens(0L) + .completionTokens(0L) + .invocationCount(0L) + .modelName("model_name") + .promptTokens(0L) + .totalTokens(0L) + .build() + ) + .addPerTestingCriteriaResult( + RunListResponse.PerTestingCriteriaResult.builder() + .failed(0L) + .passed(0L) + .testingCriteria("testing_criteria") + .build() + ) + .reportUrl("report_url") + .resultCounts( + RunListResponse.ResultCounts.builder() + .errored(0L) + .failed(0L) + .passed(0L) + .total(0L) + .build() + ) + .status("status") + .build() + ) + .firstId("first_id") + .hasMore(true) + .lastId("last_id") + .build() + + val roundtrippedRunListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(runListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedRunListPageResponse).isEqualTo(runListPageResponse) + } +} 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 new file mode 100644 index 00000000..291a9054 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/evals/runs/outputitems/OutputItemListPageResponseTest.kt @@ -0,0 +1,204 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.evals.runs.outputitems + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.JsonValue +import com.openai.core.jsonMapper +import com.openai.models.evals.runs.EvalApiError +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class OutputItemListPageResponseTest { + + @Test + fun create() { + val outputItemListPageResponse = + OutputItemListPageResponse.builder() + .addData( + OutputItemListResponse.builder() + .id("id") + .createdAt(0L) + .datasourceItem( + OutputItemListResponse.DatasourceItem.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .datasourceItemId(0L) + .evalId("eval_id") + .addResult( + OutputItemListResponse.Result.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .runId("run_id") + .sample( + OutputItemListResponse.Sample.builder() + .error( + EvalApiError.builder().code("code").message("message").build() + ) + .finishReason("finish_reason") + .addInput( + OutputItemListResponse.Sample.Input.builder() + .content("content") + .role("role") + .build() + ) + .maxCompletionTokens(0L) + .model("model") + .addOutput( + OutputItemListResponse.Sample.Output.builder() + .content("content") + .role("role") + .build() + ) + .seed(0L) + .temperature(0.0) + .topP(0.0) + .usage( + OutputItemListResponse.Sample.Usage.builder() + .cachedTokens(0L) + .completionTokens(0L) + .promptTokens(0L) + .totalTokens(0L) + .build() + ) + .build() + ) + .status("status") + .build() + ) + .firstId("first_id") + .hasMore(true) + .lastId("last_id") + .build() + + assertThat(outputItemListPageResponse.data()) + .containsExactly( + OutputItemListResponse.builder() + .id("id") + .createdAt(0L) + .datasourceItem( + OutputItemListResponse.DatasourceItem.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .datasourceItemId(0L) + .evalId("eval_id") + .addResult( + OutputItemListResponse.Result.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .runId("run_id") + .sample( + OutputItemListResponse.Sample.builder() + .error(EvalApiError.builder().code("code").message("message").build()) + .finishReason("finish_reason") + .addInput( + OutputItemListResponse.Sample.Input.builder() + .content("content") + .role("role") + .build() + ) + .maxCompletionTokens(0L) + .model("model") + .addOutput( + OutputItemListResponse.Sample.Output.builder() + .content("content") + .role("role") + .build() + ) + .seed(0L) + .temperature(0.0) + .topP(0.0) + .usage( + OutputItemListResponse.Sample.Usage.builder() + .cachedTokens(0L) + .completionTokens(0L) + .promptTokens(0L) + .totalTokens(0L) + .build() + ) + .build() + ) + .status("status") + .build() + ) + assertThat(outputItemListPageResponse.firstId()).isEqualTo("first_id") + assertThat(outputItemListPageResponse.hasMore()).isEqualTo(true) + assertThat(outputItemListPageResponse.lastId()).isEqualTo("last_id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val outputItemListPageResponse = + OutputItemListPageResponse.builder() + .addData( + OutputItemListResponse.builder() + .id("id") + .createdAt(0L) + .datasourceItem( + OutputItemListResponse.DatasourceItem.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .datasourceItemId(0L) + .evalId("eval_id") + .addResult( + OutputItemListResponse.Result.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .runId("run_id") + .sample( + OutputItemListResponse.Sample.builder() + .error( + EvalApiError.builder().code("code").message("message").build() + ) + .finishReason("finish_reason") + .addInput( + OutputItemListResponse.Sample.Input.builder() + .content("content") + .role("role") + .build() + ) + .maxCompletionTokens(0L) + .model("model") + .addOutput( + OutputItemListResponse.Sample.Output.builder() + .content("content") + .role("role") + .build() + ) + .seed(0L) + .temperature(0.0) + .topP(0.0) + .usage( + OutputItemListResponse.Sample.Usage.builder() + .cachedTokens(0L) + .completionTokens(0L) + .promptTokens(0L) + .totalTokens(0L) + .build() + ) + .build() + ) + .status("status") + .build() + ) + .firstId("first_id") + .hasMore(true) + .lastId("last_id") + .build() + + val roundtrippedOutputItemListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(outputItemListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedOutputItemListPageResponse).isEqualTo(outputItemListPageResponse) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/files/FileListPageResponseTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/files/FileListPageResponseTest.kt new file mode 100644 index 00000000..b5da4e92 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/files/FileListPageResponseTest.kt @@ -0,0 +1,84 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.files + +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 FileListPageResponseTest { + + @Test + fun create() { + val fileListPageResponse = + FileListPageResponse.builder() + .addData( + FileObject.builder() + .id("id") + .bytes(0L) + .createdAt(0L) + .filename("filename") + .purpose(FileObject.Purpose.ASSISTANTS) + .status(FileObject.Status.UPLOADED) + .expiresAt(0L) + .statusDetails("status_details") + .build() + ) + .firstId("file-abc123") + .hasMore(false) + .lastId("file-abc456") + .object_("list") + .build() + + assertThat(fileListPageResponse.data()) + .containsExactly( + FileObject.builder() + .id("id") + .bytes(0L) + .createdAt(0L) + .filename("filename") + .purpose(FileObject.Purpose.ASSISTANTS) + .status(FileObject.Status.UPLOADED) + .expiresAt(0L) + .statusDetails("status_details") + .build() + ) + assertThat(fileListPageResponse.firstId()).isEqualTo("file-abc123") + assertThat(fileListPageResponse.hasMore()).isEqualTo(false) + assertThat(fileListPageResponse.lastId()).isEqualTo("file-abc456") + assertThat(fileListPageResponse.object_()).isEqualTo("list") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val fileListPageResponse = + FileListPageResponse.builder() + .addData( + FileObject.builder() + .id("id") + .bytes(0L) + .createdAt(0L) + .filename("filename") + .purpose(FileObject.Purpose.ASSISTANTS) + .status(FileObject.Status.UPLOADED) + .expiresAt(0L) + .statusDetails("status_details") + .build() + ) + .firstId("file-abc123") + .hasMore(false) + .lastId("file-abc456") + .object_("list") + .build() + + val roundtrippedFileListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(fileListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedFileListPageResponse).isEqualTo(fileListPageResponse) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/finetuning/checkpoints/permissions/PermissionCreatePageResponseTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/finetuning/checkpoints/permissions/PermissionCreatePageResponseTest.kt new file mode 100644 index 00000000..65ca9e31 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/finetuning/checkpoints/permissions/PermissionCreatePageResponseTest.kt @@ -0,0 +1,66 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.finetuning.checkpoints.permissions + +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 PermissionCreatePageResponseTest { + + @Test + fun create() { + val permissionCreatePageResponse = + PermissionCreatePageResponse.builder() + .addData( + PermissionCreateResponse.builder() + .id("id") + .createdAt(0L) + .projectId("project_id") + .build() + ) + .hasMore(true) + .firstId("first_id") + .lastId("last_id") + .build() + + assertThat(permissionCreatePageResponse.data()) + .containsExactly( + PermissionCreateResponse.builder() + .id("id") + .createdAt(0L) + .projectId("project_id") + .build() + ) + assertThat(permissionCreatePageResponse.hasMore()).isEqualTo(true) + assertThat(permissionCreatePageResponse.firstId()).contains("first_id") + assertThat(permissionCreatePageResponse.lastId()).contains("last_id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val permissionCreatePageResponse = + PermissionCreatePageResponse.builder() + .addData( + PermissionCreateResponse.builder() + .id("id") + .createdAt(0L) + .projectId("project_id") + .build() + ) + .hasMore(true) + .firstId("first_id") + .lastId("last_id") + .build() + + val roundtrippedPermissionCreatePageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(permissionCreatePageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedPermissionCreatePageResponse).isEqualTo(permissionCreatePageResponse) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/finetuning/jobs/JobListEventsPageResponseTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/finetuning/jobs/JobListEventsPageResponseTest.kt new file mode 100644 index 00000000..b468b852 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/finetuning/jobs/JobListEventsPageResponseTest.kt @@ -0,0 +1,70 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.finetuning.jobs + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.JsonValue +import com.openai.core.jsonMapper +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class JobListEventsPageResponseTest { + + @Test + fun create() { + val jobListEventsPageResponse = + JobListEventsPageResponse.builder() + .addData( + FineTuningJobEvent.builder() + .id("id") + .createdAt(0L) + .level(FineTuningJobEvent.Level.INFO) + .message("message") + .data(JsonValue.from(mapOf())) + .type(FineTuningJobEvent.Type.MESSAGE) + .build() + ) + .hasMore(true) + .build() + + assertThat(jobListEventsPageResponse.data()) + .containsExactly( + FineTuningJobEvent.builder() + .id("id") + .createdAt(0L) + .level(FineTuningJobEvent.Level.INFO) + .message("message") + .data(JsonValue.from(mapOf())) + .type(FineTuningJobEvent.Type.MESSAGE) + .build() + ) + assertThat(jobListEventsPageResponse.hasMore()).isEqualTo(true) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val jobListEventsPageResponse = + JobListEventsPageResponse.builder() + .addData( + FineTuningJobEvent.builder() + .id("id") + .createdAt(0L) + .level(FineTuningJobEvent.Level.INFO) + .message("message") + .data(JsonValue.from(mapOf())) + .type(FineTuningJobEvent.Type.MESSAGE) + .build() + ) + .hasMore(true) + .build() + + val roundtrippedJobListEventsPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(jobListEventsPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedJobListEventsPageResponse).isEqualTo(jobListEventsPageResponse) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/finetuning/jobs/JobListPageResponseTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/finetuning/jobs/JobListPageResponseTest.kt new file mode 100644 index 00000000..833580a8 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/finetuning/jobs/JobListPageResponseTest.kt @@ -0,0 +1,270 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.finetuning.jobs + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.JsonValue +import com.openai.core.jsonMapper +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class JobListPageResponseTest { + + @Test + fun create() { + val jobListPageResponse = + JobListPageResponse.builder() + .addData( + FineTuningJob.builder() + .id("id") + .createdAt(0L) + .error( + FineTuningJob.Error.builder() + .code("code") + .message("message") + .param("param") + .build() + ) + .fineTunedModel("fine_tuned_model") + .finishedAt(0L) + .hyperparameters( + FineTuningJob.Hyperparameters.builder() + .batchSizeAuto() + .learningRateMultiplierAuto() + .nEpochsAuto() + .build() + ) + .model("model") + .organizationId("organization_id") + .addResultFile("file-abc123") + .seed(0L) + .status(FineTuningJob.Status.VALIDATING_FILES) + .trainedTokens(0L) + .trainingFile("training_file") + .validationFile("validation_file") + .estimatedFinish(0L) + .addIntegration( + FineTuningJobWandbIntegrationObject.builder() + .wandb( + FineTuningJobWandbIntegration.builder() + .project("my-wandb-project") + .entity("entity") + .name("name") + .addTag("custom-tag") + .build() + ) + .build() + ) + .metadata( + FineTuningJob.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .method( + FineTuningJob.Method.builder() + .dpo( + FineTuningJob.Method.Dpo.builder() + .hyperparameters( + FineTuningJob.Method.Dpo.Hyperparameters.builder() + .batchSizeAuto() + .betaAuto() + .learningRateMultiplierAuto() + .nEpochsAuto() + .build() + ) + .build() + ) + .supervised( + FineTuningJob.Method.Supervised.builder() + .hyperparameters( + FineTuningJob.Method.Supervised.Hyperparameters + .builder() + .batchSizeAuto() + .learningRateMultiplierAuto() + .nEpochsAuto() + .build() + ) + .build() + ) + .type(FineTuningJob.Method.Type.SUPERVISED) + .build() + ) + .build() + ) + .hasMore(true) + .build() + + assertThat(jobListPageResponse.data()) + .containsExactly( + FineTuningJob.builder() + .id("id") + .createdAt(0L) + .error( + FineTuningJob.Error.builder() + .code("code") + .message("message") + .param("param") + .build() + ) + .fineTunedModel("fine_tuned_model") + .finishedAt(0L) + .hyperparameters( + FineTuningJob.Hyperparameters.builder() + .batchSizeAuto() + .learningRateMultiplierAuto() + .nEpochsAuto() + .build() + ) + .model("model") + .organizationId("organization_id") + .addResultFile("file-abc123") + .seed(0L) + .status(FineTuningJob.Status.VALIDATING_FILES) + .trainedTokens(0L) + .trainingFile("training_file") + .validationFile("validation_file") + .estimatedFinish(0L) + .addIntegration( + FineTuningJobWandbIntegrationObject.builder() + .wandb( + FineTuningJobWandbIntegration.builder() + .project("my-wandb-project") + .entity("entity") + .name("name") + .addTag("custom-tag") + .build() + ) + .build() + ) + .metadata( + FineTuningJob.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .method( + FineTuningJob.Method.builder() + .dpo( + FineTuningJob.Method.Dpo.builder() + .hyperparameters( + FineTuningJob.Method.Dpo.Hyperparameters.builder() + .batchSizeAuto() + .betaAuto() + .learningRateMultiplierAuto() + .nEpochsAuto() + .build() + ) + .build() + ) + .supervised( + FineTuningJob.Method.Supervised.builder() + .hyperparameters( + FineTuningJob.Method.Supervised.Hyperparameters.builder() + .batchSizeAuto() + .learningRateMultiplierAuto() + .nEpochsAuto() + .build() + ) + .build() + ) + .type(FineTuningJob.Method.Type.SUPERVISED) + .build() + ) + .build() + ) + assertThat(jobListPageResponse.hasMore()).isEqualTo(true) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val jobListPageResponse = + JobListPageResponse.builder() + .addData( + FineTuningJob.builder() + .id("id") + .createdAt(0L) + .error( + FineTuningJob.Error.builder() + .code("code") + .message("message") + .param("param") + .build() + ) + .fineTunedModel("fine_tuned_model") + .finishedAt(0L) + .hyperparameters( + FineTuningJob.Hyperparameters.builder() + .batchSizeAuto() + .learningRateMultiplierAuto() + .nEpochsAuto() + .build() + ) + .model("model") + .organizationId("organization_id") + .addResultFile("file-abc123") + .seed(0L) + .status(FineTuningJob.Status.VALIDATING_FILES) + .trainedTokens(0L) + .trainingFile("training_file") + .validationFile("validation_file") + .estimatedFinish(0L) + .addIntegration( + FineTuningJobWandbIntegrationObject.builder() + .wandb( + FineTuningJobWandbIntegration.builder() + .project("my-wandb-project") + .entity("entity") + .name("name") + .addTag("custom-tag") + .build() + ) + .build() + ) + .metadata( + FineTuningJob.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .method( + FineTuningJob.Method.builder() + .dpo( + FineTuningJob.Method.Dpo.builder() + .hyperparameters( + FineTuningJob.Method.Dpo.Hyperparameters.builder() + .batchSizeAuto() + .betaAuto() + .learningRateMultiplierAuto() + .nEpochsAuto() + .build() + ) + .build() + ) + .supervised( + FineTuningJob.Method.Supervised.builder() + .hyperparameters( + FineTuningJob.Method.Supervised.Hyperparameters + .builder() + .batchSizeAuto() + .learningRateMultiplierAuto() + .nEpochsAuto() + .build() + ) + .build() + ) + .type(FineTuningJob.Method.Type.SUPERVISED) + .build() + ) + .build() + ) + .hasMore(true) + .build() + + val roundtrippedJobListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(jobListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedJobListPageResponse).isEqualTo(jobListPageResponse) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/finetuning/jobs/checkpoints/CheckpointListPageResponseTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/finetuning/jobs/checkpoints/CheckpointListPageResponseTest.kt new file mode 100644 index 00000000..4397f3e0 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/finetuning/jobs/checkpoints/CheckpointListPageResponseTest.kt @@ -0,0 +1,105 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.finetuning.jobs.checkpoints + +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 CheckpointListPageResponseTest { + + @Test + fun create() { + val checkpointListPageResponse = + CheckpointListPageResponse.builder() + .addData( + FineTuningJobCheckpoint.builder() + .id("id") + .createdAt(0L) + .fineTunedModelCheckpoint("fine_tuned_model_checkpoint") + .fineTuningJobId("fine_tuning_job_id") + .metrics( + FineTuningJobCheckpoint.Metrics.builder() + .fullValidLoss(0.0) + .fullValidMeanTokenAccuracy(0.0) + .step(0.0) + .trainLoss(0.0) + .trainMeanTokenAccuracy(0.0) + .validLoss(0.0) + .validMeanTokenAccuracy(0.0) + .build() + ) + .stepNumber(0L) + .build() + ) + .hasMore(true) + .firstId("first_id") + .lastId("last_id") + .build() + + assertThat(checkpointListPageResponse.data()) + .containsExactly( + FineTuningJobCheckpoint.builder() + .id("id") + .createdAt(0L) + .fineTunedModelCheckpoint("fine_tuned_model_checkpoint") + .fineTuningJobId("fine_tuning_job_id") + .metrics( + FineTuningJobCheckpoint.Metrics.builder() + .fullValidLoss(0.0) + .fullValidMeanTokenAccuracy(0.0) + .step(0.0) + .trainLoss(0.0) + .trainMeanTokenAccuracy(0.0) + .validLoss(0.0) + .validMeanTokenAccuracy(0.0) + .build() + ) + .stepNumber(0L) + .build() + ) + assertThat(checkpointListPageResponse.hasMore()).isEqualTo(true) + assertThat(checkpointListPageResponse.firstId()).contains("first_id") + assertThat(checkpointListPageResponse.lastId()).contains("last_id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val checkpointListPageResponse = + CheckpointListPageResponse.builder() + .addData( + FineTuningJobCheckpoint.builder() + .id("id") + .createdAt(0L) + .fineTunedModelCheckpoint("fine_tuned_model_checkpoint") + .fineTuningJobId("fine_tuning_job_id") + .metrics( + FineTuningJobCheckpoint.Metrics.builder() + .fullValidLoss(0.0) + .fullValidMeanTokenAccuracy(0.0) + .step(0.0) + .trainLoss(0.0) + .trainMeanTokenAccuracy(0.0) + .validLoss(0.0) + .validMeanTokenAccuracy(0.0) + .build() + ) + .stepNumber(0L) + .build() + ) + .hasMore(true) + .firstId("first_id") + .lastId("last_id") + .build() + + val roundtrippedCheckpointListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(checkpointListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedCheckpointListPageResponse).isEqualTo(checkpointListPageResponse) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/models/ModelListPageResponseTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/models/ModelListPageResponseTest.kt new file mode 100644 index 00000000..b66115be --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/models/ModelListPageResponseTest.kt @@ -0,0 +1,39 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.models + +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 ModelListPageResponseTest { + + @Test + fun create() { + val modelListPageResponse = + ModelListPageResponse.builder() + .addData(Model.builder().id("id").created(0L).ownedBy("owned_by").build()) + .build() + + assertThat(modelListPageResponse.data()) + .containsExactly(Model.builder().id("id").created(0L).ownedBy("owned_by").build()) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val modelListPageResponse = + ModelListPageResponse.builder() + .addData(Model.builder().id("id").created(0L).ownedBy("owned_by").build()) + .build() + + val roundtrippedModelListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(modelListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedModelListPageResponse).isEqualTo(modelListPageResponse) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/vectorstores/VectorStoreListPageResponseTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/vectorstores/VectorStoreListPageResponseTest.kt new file mode 100644 index 00000000..fce95de7 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/vectorstores/VectorStoreListPageResponseTest.kt @@ -0,0 +1,127 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.vectorstores + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.JsonValue +import com.openai.core.jsonMapper +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class VectorStoreListPageResponseTest { + + @Test + fun create() { + val vectorStoreListPageResponse = + VectorStoreListPageResponse.builder() + .addData( + VectorStore.builder() + .id("id") + .createdAt(0L) + .fileCounts( + VectorStore.FileCounts.builder() + .cancelled(0L) + .completed(0L) + .failed(0L) + .inProgress(0L) + .total(0L) + .build() + ) + .lastActiveAt(0L) + .metadata( + VectorStore.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .name("name") + .status(VectorStore.Status.EXPIRED) + .usageBytes(0L) + .expiresAfter(VectorStore.ExpiresAfter.builder().days(1L).build()) + .expiresAt(0L) + .build() + ) + .firstId("vs_abc123") + .hasMore(false) + .lastId("vs_abc456") + .object_("list") + .build() + + assertThat(vectorStoreListPageResponse.data()) + .containsExactly( + VectorStore.builder() + .id("id") + .createdAt(0L) + .fileCounts( + VectorStore.FileCounts.builder() + .cancelled(0L) + .completed(0L) + .failed(0L) + .inProgress(0L) + .total(0L) + .build() + ) + .lastActiveAt(0L) + .metadata( + VectorStore.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .name("name") + .status(VectorStore.Status.EXPIRED) + .usageBytes(0L) + .expiresAfter(VectorStore.ExpiresAfter.builder().days(1L).build()) + .expiresAt(0L) + .build() + ) + assertThat(vectorStoreListPageResponse.firstId()).isEqualTo("vs_abc123") + assertThat(vectorStoreListPageResponse.hasMore()).isEqualTo(false) + assertThat(vectorStoreListPageResponse.lastId()).isEqualTo("vs_abc456") + assertThat(vectorStoreListPageResponse.object_()).isEqualTo("list") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val vectorStoreListPageResponse = + VectorStoreListPageResponse.builder() + .addData( + VectorStore.builder() + .id("id") + .createdAt(0L) + .fileCounts( + VectorStore.FileCounts.builder() + .cancelled(0L) + .completed(0L) + .failed(0L) + .inProgress(0L) + .total(0L) + .build() + ) + .lastActiveAt(0L) + .metadata( + VectorStore.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .name("name") + .status(VectorStore.Status.EXPIRED) + .usageBytes(0L) + .expiresAfter(VectorStore.ExpiresAfter.builder().days(1L).build()) + .expiresAt(0L) + .build() + ) + .firstId("vs_abc123") + .hasMore(false) + .lastId("vs_abc456") + .object_("list") + .build() + + val roundtrippedVectorStoreListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(vectorStoreListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedVectorStoreListPageResponse).isEqualTo(vectorStoreListPageResponse) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/vectorstores/VectorStoreSearchPageResponseTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/vectorstores/VectorStoreSearchPageResponseTest.kt new file mode 100644 index 00000000..8093bf4b --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/vectorstores/VectorStoreSearchPageResponseTest.kt @@ -0,0 +1,101 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.vectorstores + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.JsonValue +import com.openai.core.jsonMapper +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class VectorStoreSearchPageResponseTest { + + @Test + fun create() { + val vectorStoreSearchPageResponse = + VectorStoreSearchPageResponse.builder() + .addData( + VectorStoreSearchResponse.builder() + .attributes( + VectorStoreSearchResponse.Attributes.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .addContent( + VectorStoreSearchResponse.Content.builder() + .text("text") + .type(VectorStoreSearchResponse.Content.Type.TEXT) + .build() + ) + .fileId("file_id") + .filename("filename") + .score(0.0) + .build() + ) + .hasMore(true) + .nextPage("next_page") + .addSearchQuery("string") + .build() + + assertThat(vectorStoreSearchPageResponse.data()) + .containsExactly( + VectorStoreSearchResponse.builder() + .attributes( + VectorStoreSearchResponse.Attributes.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .addContent( + VectorStoreSearchResponse.Content.builder() + .text("text") + .type(VectorStoreSearchResponse.Content.Type.TEXT) + .build() + ) + .fileId("file_id") + .filename("filename") + .score(0.0) + .build() + ) + assertThat(vectorStoreSearchPageResponse.hasMore()).isEqualTo(true) + assertThat(vectorStoreSearchPageResponse.nextPage()).contains("next_page") + assertThat(vectorStoreSearchPageResponse.searchQuery()).containsExactly("string") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val vectorStoreSearchPageResponse = + VectorStoreSearchPageResponse.builder() + .addData( + VectorStoreSearchResponse.builder() + .attributes( + VectorStoreSearchResponse.Attributes.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .addContent( + VectorStoreSearchResponse.Content.builder() + .text("text") + .type(VectorStoreSearchResponse.Content.Type.TEXT) + .build() + ) + .fileId("file_id") + .filename("filename") + .score(0.0) + .build() + ) + .hasMore(true) + .nextPage("next_page") + .addSearchQuery("string") + .build() + + val roundtrippedVectorStoreSearchPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(vectorStoreSearchPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedVectorStoreSearchPageResponse) + .isEqualTo(vectorStoreSearchPageResponse) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/vectorstores/filebatches/FileBatchListFilesPageResponseTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/vectorstores/filebatches/FileBatchListFilesPageResponseTest.kt new file mode 100644 index 00000000..13b9b20d --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/vectorstores/filebatches/FileBatchListFilesPageResponseTest.kt @@ -0,0 +1,130 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.vectorstores.filebatches + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.JsonValue +import com.openai.core.jsonMapper +import com.openai.models.vectorstores.StaticFileChunkingStrategy +import com.openai.models.vectorstores.files.VectorStoreFile +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class FileBatchListFilesPageResponseTest { + + @Test + fun create() { + val fileBatchListFilesPageResponse = + FileBatchListFilesPageResponse.builder() + .addData( + VectorStoreFile.builder() + .id("id") + .createdAt(0L) + .lastError( + VectorStoreFile.LastError.builder() + .code(VectorStoreFile.LastError.Code.SERVER_ERROR) + .message("message") + .build() + ) + .status(VectorStoreFile.Status.IN_PROGRESS) + .usageBytes(0L) + .vectorStoreId("vector_store_id") + .attributes( + VectorStoreFile.Attributes.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .staticChunkingStrategy( + StaticFileChunkingStrategy.builder() + .chunkOverlapTokens(0L) + .maxChunkSizeTokens(100L) + .build() + ) + .build() + ) + .firstId("file-abc123") + .hasMore(false) + .lastId("file-abc456") + .object_("list") + .build() + + assertThat(fileBatchListFilesPageResponse.data()) + .containsExactly( + VectorStoreFile.builder() + .id("id") + .createdAt(0L) + .lastError( + VectorStoreFile.LastError.builder() + .code(VectorStoreFile.LastError.Code.SERVER_ERROR) + .message("message") + .build() + ) + .status(VectorStoreFile.Status.IN_PROGRESS) + .usageBytes(0L) + .vectorStoreId("vector_store_id") + .attributes( + VectorStoreFile.Attributes.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .staticChunkingStrategy( + StaticFileChunkingStrategy.builder() + .chunkOverlapTokens(0L) + .maxChunkSizeTokens(100L) + .build() + ) + .build() + ) + assertThat(fileBatchListFilesPageResponse.firstId()).isEqualTo("file-abc123") + assertThat(fileBatchListFilesPageResponse.hasMore()).isEqualTo(false) + assertThat(fileBatchListFilesPageResponse.lastId()).isEqualTo("file-abc456") + assertThat(fileBatchListFilesPageResponse.object_()).isEqualTo("list") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val fileBatchListFilesPageResponse = + FileBatchListFilesPageResponse.builder() + .addData( + VectorStoreFile.builder() + .id("id") + .createdAt(0L) + .lastError( + VectorStoreFile.LastError.builder() + .code(VectorStoreFile.LastError.Code.SERVER_ERROR) + .message("message") + .build() + ) + .status(VectorStoreFile.Status.IN_PROGRESS) + .usageBytes(0L) + .vectorStoreId("vector_store_id") + .attributes( + VectorStoreFile.Attributes.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .staticChunkingStrategy( + StaticFileChunkingStrategy.builder() + .chunkOverlapTokens(0L) + .maxChunkSizeTokens(100L) + .build() + ) + .build() + ) + .firstId("file-abc123") + .hasMore(false) + .lastId("file-abc456") + .object_("list") + .build() + + val roundtrippedFileBatchListFilesPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(fileBatchListFilesPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedFileBatchListFilesPageResponse) + .isEqualTo(fileBatchListFilesPageResponse) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/vectorstores/files/FileContentPageResponseTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/vectorstores/files/FileContentPageResponseTest.kt new file mode 100644 index 00000000..a97d8252 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/vectorstores/files/FileContentPageResponseTest.kt @@ -0,0 +1,45 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.vectorstores.files + +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 FileContentPageResponseTest { + + @Test + fun create() { + val fileContentPageResponse = + FileContentPageResponse.builder() + .addData(FileContentResponse.builder().text("text").type("type").build()) + .hasMore(true) + .nextPage("next_page") + .build() + + assertThat(fileContentPageResponse.data()) + .containsExactly(FileContentResponse.builder().text("text").type("type").build()) + assertThat(fileContentPageResponse.hasMore()).isEqualTo(true) + assertThat(fileContentPageResponse.nextPage()).contains("next_page") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val fileContentPageResponse = + FileContentPageResponse.builder() + .addData(FileContentResponse.builder().text("text").type("type").build()) + .hasMore(true) + .nextPage("next_page") + .build() + + val roundtrippedFileContentPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(fileContentPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedFileContentPageResponse).isEqualTo(fileContentPageResponse) + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/vectorstores/files/FileListPageResponseTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/vectorstores/files/FileListPageResponseTest.kt new file mode 100644 index 00000000..971648d2 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/vectorstores/files/FileListPageResponseTest.kt @@ -0,0 +1,128 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.vectorstores.files + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.JsonValue +import com.openai.core.jsonMapper +import com.openai.models.vectorstores.StaticFileChunkingStrategy +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class FileListPageResponseTest { + + @Test + fun create() { + val fileListPageResponse = + FileListPageResponse.builder() + .addData( + VectorStoreFile.builder() + .id("id") + .createdAt(0L) + .lastError( + VectorStoreFile.LastError.builder() + .code(VectorStoreFile.LastError.Code.SERVER_ERROR) + .message("message") + .build() + ) + .status(VectorStoreFile.Status.IN_PROGRESS) + .usageBytes(0L) + .vectorStoreId("vector_store_id") + .attributes( + VectorStoreFile.Attributes.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .staticChunkingStrategy( + StaticFileChunkingStrategy.builder() + .chunkOverlapTokens(0L) + .maxChunkSizeTokens(100L) + .build() + ) + .build() + ) + .firstId("file-abc123") + .hasMore(false) + .lastId("file-abc456") + .object_("list") + .build() + + assertThat(fileListPageResponse.data()) + .containsExactly( + VectorStoreFile.builder() + .id("id") + .createdAt(0L) + .lastError( + VectorStoreFile.LastError.builder() + .code(VectorStoreFile.LastError.Code.SERVER_ERROR) + .message("message") + .build() + ) + .status(VectorStoreFile.Status.IN_PROGRESS) + .usageBytes(0L) + .vectorStoreId("vector_store_id") + .attributes( + VectorStoreFile.Attributes.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .staticChunkingStrategy( + StaticFileChunkingStrategy.builder() + .chunkOverlapTokens(0L) + .maxChunkSizeTokens(100L) + .build() + ) + .build() + ) + assertThat(fileListPageResponse.firstId()).isEqualTo("file-abc123") + assertThat(fileListPageResponse.hasMore()).isEqualTo(false) + assertThat(fileListPageResponse.lastId()).isEqualTo("file-abc456") + assertThat(fileListPageResponse.object_()).isEqualTo("list") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val fileListPageResponse = + FileListPageResponse.builder() + .addData( + VectorStoreFile.builder() + .id("id") + .createdAt(0L) + .lastError( + VectorStoreFile.LastError.builder() + .code(VectorStoreFile.LastError.Code.SERVER_ERROR) + .message("message") + .build() + ) + .status(VectorStoreFile.Status.IN_PROGRESS) + .usageBytes(0L) + .vectorStoreId("vector_store_id") + .attributes( + VectorStoreFile.Attributes.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .staticChunkingStrategy( + StaticFileChunkingStrategy.builder() + .chunkOverlapTokens(0L) + .maxChunkSizeTokens(100L) + .build() + ) + .build() + ) + .firstId("file-abc123") + .hasMore(false) + .lastId("file-abc456") + .object_("list") + .build() + + val roundtrippedFileListPageResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(fileListPageResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedFileListPageResponse).isEqualTo(fileListPageResponse) + } +}