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 @@
-[](https://central.sonatype.com/artifact/com.openai/openai-java/1.1.1)
-[](https://javadoc.io/doc/com.openai/openai-java/1.1.1)
+[](https://central.sonatype.com/artifact/com.openai/openai-java/1.2.0)
+[](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