diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 2b28d6ec..6d78745c 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.8.1" + ".": "0.9.0" } \ No newline at end of file diff --git a/.stats.yml b/.stats.yml index 18552296..86f76d76 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,2 +1,2 @@ -configured_endpoints: 24 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-a39aca84ed97ebafb707ebd5221e2787c5a42ff3d98f2ffaea8a0dcd84cbcbcb.yml +configured_endpoints: 60 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-02200a58ed631064b6419711da99fefd6e97bdbbeb577a80a1a6e0c8dbcb18f5.yml diff --git a/CHANGELOG.md b/CHANGELOG.md index 0fd17823..7df282aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,34 @@ # Changelog +## 0.9.0 (2025-01-03) + +Full Changelog: [v0.8.1...v0.9.0](https://github.com/openai/openai-java/compare/v0.8.1...v0.9.0) + +### ⚠ BREAKING CHANGES + +* **client:** switch query params objects to use `QueryParams` ([#64](https://github.com/openai/openai-java/issues/64)) + +### Features + +* **client:** add beta endpoints ([#79](https://github.com/openai/openai-java/issues/79)) ([8584a20](https://github.com/openai/openai-java/commit/8584a2029ec5402b205ce485e96702da0a692b76)) +* **client:** put body field in params, add more convenience methods, and add missing docs ([#77](https://github.com/openai/openai-java/issues/77)) ([0c74350](https://github.com/openai/openai-java/commit/0c74350f0e5d1f0a30ae9b27c50a306ca081b1a7)) + + +### Chores + +* bump license year ([#74](https://github.com/openai/openai-java/issues/74)) ([769175d](https://github.com/openai/openai-java/commit/769175d3c42b6679e8ea91847e1fba32ab76d9a6)) + + +### Documentation + +* add some missing javadocs ([#78](https://github.com/openai/openai-java/issues/78)) ([d153ef9](https://github.com/openai/openai-java/commit/d153ef99dff3a201bf5674ee4154f3a3d276f608)) + + +### Refactors + +* **client:** switch query params objects to use `QueryParams` ([#64](https://github.com/openai/openai-java/issues/64)) ([4e9c3eb](https://github.com/openai/openai-java/commit/4e9c3eb9351f308ed3d842bd4aa2d860c23d568e)) +* **internal:** use constructor to deserialize json ([#66](https://github.com/openai/openai-java/issues/66)) ([27389cd](https://github.com/openai/openai-java/commit/27389cd377ce9a109a4aa25f78f70c36ca62de14)) + ## 0.8.1 (2024-12-21) Full Changelog: [v0.8.0...v0.8.1](https://github.com/openai/openai-java/compare/v0.8.0...v0.8.1) diff --git a/LICENSE b/LICENSE index 621a6bec..f011417a 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2024 OpenAI + Copyright 2025 OpenAI Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/README.md b/README.md index d563e776..32d66e2e 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ -[![Maven Central](https://img.shields.io/maven-central/v/com.openai/openai-java)](https://central.sonatype.com/artifact/com.openai/openai-java/0.8.1) +[![Maven Central](https://img.shields.io/maven-central/v/com.openai/openai-java)](https://central.sonatype.com/artifact/com.openai/openai-java/0.9.0) @@ -32,7 +32,7 @@ The REST API documentation can be found on [platform.openai.com](https://platfo ```kotlin -implementation("com.openai:openai-java:0.8.1") +implementation("com.openai:openai-java:0.9.0") ``` #### Maven @@ -41,7 +41,7 @@ implementation("com.openai:openai-java:0.8.1") com.openai openai-java - 0.8.1 + 0.9.0 ``` diff --git a/build.gradle.kts b/build.gradle.kts index 54d9accf..4e56d011 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,7 +4,7 @@ plugins { allprojects { group = "com.openai" - version = "0.8.1" // x-release-please-version + version = "0.9.0" // x-release-please-version } diff --git a/openai-java-client-okhttp/src/main/kotlin/com/openai/client/okhttp/OpenAIOkHttpClient.kt b/openai-java-client-okhttp/src/main/kotlin/com/openai/client/okhttp/OpenAIOkHttpClient.kt index ecb4e82f..0a01dc68 100644 --- a/openai-java-client-okhttp/src/main/kotlin/com/openai/client/okhttp/OpenAIOkHttpClient.kt +++ b/openai-java-client-okhttp/src/main/kotlin/com/openai/client/okhttp/OpenAIOkHttpClient.kt @@ -138,9 +138,9 @@ class OpenAIOkHttpClient private constructor() { clientOptions.azureServiceVersion(azureServiceVersion) } - fun organization(organization: String?) = apply { clientOptions.organization(organization) } + fun organization(organization: String) = apply { clientOptions.organization(organization) } - fun project(project: String?) = apply { clientOptions.project(project) } + fun project(project: String) = apply { clientOptions.project(project) } fun fromEnv() = apply { clientOptions.fromEnv() } diff --git a/openai-java-client-okhttp/src/main/kotlin/com/openai/client/okhttp/OpenAIOkHttpClientAsync.kt b/openai-java-client-okhttp/src/main/kotlin/com/openai/client/okhttp/OpenAIOkHttpClientAsync.kt index cf4711aa..e88af696 100644 --- a/openai-java-client-okhttp/src/main/kotlin/com/openai/client/okhttp/OpenAIOkHttpClientAsync.kt +++ b/openai-java-client-okhttp/src/main/kotlin/com/openai/client/okhttp/OpenAIOkHttpClientAsync.kt @@ -138,9 +138,9 @@ class OpenAIOkHttpClientAsync private constructor() { clientOptions.azureServiceVersion(azureServiceVersion) } - fun organization(organization: String?) = apply { clientOptions.organization(organization) } + fun organization(organization: String) = apply { clientOptions.organization(organization) } - fun project(project: String?) = apply { clientOptions.project(project) } + fun project(project: String) = apply { clientOptions.project(project) } fun fromEnv() = apply { clientOptions.fromEnv() } diff --git a/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClient.kt b/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClient.kt index 1dce1fed..d3ca56e6 100644 --- a/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClient.kt +++ b/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClient.kt @@ -3,6 +3,7 @@ package com.openai.client import com.openai.services.blocking.BatchService +import com.openai.services.blocking.BetaService import com.openai.services.blocking.ChatService import com.openai.services.blocking.CompletionService import com.openai.services.blocking.EmbeddingService @@ -33,6 +34,8 @@ interface OpenAIClient { fun fineTuning(): FineTuningService + fun beta(): BetaService + fun batches(): BatchService fun uploads(): UploadService diff --git a/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsync.kt b/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsync.kt index 88af1944..4d02824b 100644 --- a/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsync.kt +++ b/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsync.kt @@ -3,6 +3,7 @@ package com.openai.client import com.openai.services.async.BatchServiceAsync +import com.openai.services.async.BetaServiceAsync import com.openai.services.async.ChatServiceAsync import com.openai.services.async.CompletionServiceAsync import com.openai.services.async.EmbeddingServiceAsync @@ -33,6 +34,8 @@ interface OpenAIClientAsync { fun fineTuning(): FineTuningServiceAsync + fun beta(): BetaServiceAsync + fun batches(): BatchServiceAsync fun uploads(): UploadServiceAsync diff --git a/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsyncImpl.kt b/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsyncImpl.kt index 9a14f773..9a8ecd11 100644 --- a/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsyncImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientAsyncImpl.kt @@ -6,6 +6,8 @@ import com.openai.core.ClientOptions import com.openai.core.getPackageVersion import com.openai.services.async.BatchServiceAsync import com.openai.services.async.BatchServiceAsyncImpl +import com.openai.services.async.BetaServiceAsync +import com.openai.services.async.BetaServiceAsyncImpl import com.openai.services.async.ChatServiceAsync import com.openai.services.async.ChatServiceAsyncImpl import com.openai.services.async.CompletionServiceAsync @@ -69,6 +71,8 @@ constructor( FineTuningServiceAsyncImpl(clientOptionsWithUserAgent) } + private val beta: BetaServiceAsync by lazy { BetaServiceAsyncImpl(clientOptionsWithUserAgent) } + private val batches: BatchServiceAsync by lazy { BatchServiceAsyncImpl(clientOptionsWithUserAgent) } @@ -95,6 +99,8 @@ constructor( override fun fineTuning(): FineTuningServiceAsync = fineTuning + override fun beta(): BetaServiceAsync = beta + override fun batches(): BatchServiceAsync = batches override fun uploads(): UploadServiceAsync = uploads diff --git a/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientImpl.kt b/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientImpl.kt index 8fd7ffe0..2870b2e0 100644 --- a/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientImpl.kt +++ b/openai-java-core/src/main/kotlin/com/openai/client/OpenAIClientImpl.kt @@ -6,6 +6,8 @@ import com.openai.core.ClientOptions import com.openai.core.getPackageVersion import com.openai.services.blocking.BatchService import com.openai.services.blocking.BatchServiceImpl +import com.openai.services.blocking.BetaService +import com.openai.services.blocking.BetaServiceImpl import com.openai.services.blocking.ChatService import com.openai.services.blocking.ChatServiceImpl import com.openai.services.blocking.CompletionService @@ -65,6 +67,8 @@ constructor( FineTuningServiceImpl(clientOptionsWithUserAgent) } + private val beta: BetaService by lazy { BetaServiceImpl(clientOptionsWithUserAgent) } + private val batches: BatchService by lazy { BatchServiceImpl(clientOptionsWithUserAgent) } private val uploads: UploadService by lazy { UploadServiceImpl(clientOptionsWithUserAgent) } @@ -87,6 +91,8 @@ constructor( override fun fineTuning(): FineTuningService = fineTuning + override fun beta(): BetaService = beta + override fun batches(): BatchService = batches override fun uploads(): UploadService = uploads diff --git a/openai-java-core/src/main/kotlin/com/openai/core/ClientOptions.kt b/openai-java-core/src/main/kotlin/com/openai/core/ClientOptions.kt index 6eee95f6..aa08c1c7 100644 --- a/openai-java-core/src/main/kotlin/com/openai/core/ClientOptions.kt +++ b/openai-java-core/src/main/kotlin/com/openai/core/ClientOptions.kt @@ -187,9 +187,9 @@ private constructor( this.azureServiceVersion = azureServiceVersion } - fun organization(organization: String?) = apply { this.organization = organization } + fun organization(organization: String) = apply { this.organization = organization } - fun project(project: String?) = apply { this.project = project } + fun project(project: String) = apply { this.project = project } fun fromEnv() = apply { val openAIKey = System.getenv("OPENAI_API_KEY") diff --git a/openai-java-core/src/main/kotlin/com/openai/core/Utils.kt b/openai-java-core/src/main/kotlin/com/openai/core/Utils.kt index 6601f8ef..e2cfee07 100644 --- a/openai-java-core/src/main/kotlin/com/openai/core/Utils.kt +++ b/openai-java-core/src/main/kotlin/com/openai/core/Utils.kt @@ -16,7 +16,9 @@ internal fun List.toImmutable(): List = @JvmSynthetic internal fun Map.toImmutable(): Map = - if (isEmpty()) Collections.emptyMap() else Collections.unmodifiableMap(toMap()) + if (isEmpty()) immutableEmptyMap() else Collections.unmodifiableMap(toMap()) + +@JvmSynthetic internal fun immutableEmptyMap(): Map = Collections.emptyMap() @JvmSynthetic internal fun , V> SortedMap.toImmutable(): SortedMap = diff --git a/openai-java-core/src/main/kotlin/com/openai/errors/OpenAIError.kt b/openai-java-core/src/main/kotlin/com/openai/errors/OpenAIError.kt index ca3ce740..e4cbac10 100644 --- a/openai-java-core/src/main/kotlin/com/openai/errors/OpenAIError.kt +++ b/openai-java-core/src/main/kotlin/com/openai/errors/OpenAIError.kt @@ -4,19 +4,23 @@ package com.openai.errors import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.databind.annotation.JsonDeserialize +import com.fasterxml.jackson.annotation.JsonCreator +import com.openai.core.ExcludeMissing import com.openai.core.JsonValue import com.openai.core.NoAutoDetect +import com.openai.core.immutableEmptyMap import com.openai.core.toImmutable import java.util.Objects -@JsonDeserialize(builder = OpenAIError.Builder::class) @NoAutoDetect class OpenAIError +@JsonCreator private constructor( @JsonAnyGetter + @ExcludeMissing + @JsonAnySetter @get:JvmName("additionalProperties") - val additionalProperties: Map, + val additionalProperties: Map = immutableEmptyMap(), ) { fun toBuilder() = Builder().from(this) @@ -40,7 +44,6 @@ private constructor( putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { additionalProperties.put(key, value) } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/Annotation.kt b/openai-java-core/src/main/kotlin/com/openai/models/Annotation.kt new file mode 100644 index 00000000..fba511f1 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/Annotation.kt @@ -0,0 +1,181 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models + +import com.fasterxml.jackson.core.JsonGenerator +import com.fasterxml.jackson.core.ObjectCodec +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.SerializerProvider +import com.fasterxml.jackson.databind.annotation.JsonDeserialize +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.BaseDeserializer +import com.openai.core.BaseSerializer +import com.openai.core.JsonValue +import com.openai.core.getOrThrow +import com.openai.errors.OpenAIInvalidDataException +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * A citation within the message that points to a specific quote from a specific File associated + * with the assistant or the message. Generated when the assistant uses the "file_search" tool to + * search files. + */ +@JsonDeserialize(using = Annotation.Deserializer::class) +@JsonSerialize(using = Annotation.Serializer::class) +class Annotation +private constructor( + private val fileCitationAnnotation: FileCitationAnnotation? = null, + private val filePathAnnotation: FilePathAnnotation? = null, + private val _json: JsonValue? = null, +) { + + private var validated: Boolean = false + + /** + * A citation within the message that points to a specific quote from a specific File associated + * with the assistant or the message. Generated when the assistant uses the "file_search" tool + * to search files. + */ + fun fileCitationAnnotation(): Optional = + Optional.ofNullable(fileCitationAnnotation) + /** + * A URL for the file that's generated when the assistant used the `code_interpreter` tool to + * generate a file. + */ + fun filePathAnnotation(): Optional = Optional.ofNullable(filePathAnnotation) + + fun isFileCitationAnnotation(): Boolean = fileCitationAnnotation != null + + fun isFilePathAnnotation(): Boolean = filePathAnnotation != null + + /** + * A citation within the message that points to a specific quote from a specific File associated + * with the assistant or the message. Generated when the assistant uses the "file_search" tool + * to search files. + */ + fun asFileCitationAnnotation(): FileCitationAnnotation = + fileCitationAnnotation.getOrThrow("fileCitationAnnotation") + /** + * A URL for the file that's generated when the assistant used the `code_interpreter` tool to + * generate a file. + */ + fun asFilePathAnnotation(): FilePathAnnotation = + filePathAnnotation.getOrThrow("filePathAnnotation") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + fileCitationAnnotation != null -> + visitor.visitFileCitationAnnotation(fileCitationAnnotation) + filePathAnnotation != null -> visitor.visitFilePathAnnotation(filePathAnnotation) + else -> visitor.unknown(_json) + } + } + + fun validate(): Annotation = apply { + if (!validated) { + if (fileCitationAnnotation == null && filePathAnnotation == null) { + throw OpenAIInvalidDataException("Unknown Annotation: $_json") + } + fileCitationAnnotation?.validate() + filePathAnnotation?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Annotation && fileCitationAnnotation == other.fileCitationAnnotation && filePathAnnotation == other.filePathAnnotation /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(fileCitationAnnotation, filePathAnnotation) /* spotless:on */ + + override fun toString(): String = + when { + fileCitationAnnotation != null -> + "Annotation{fileCitationAnnotation=$fileCitationAnnotation}" + filePathAnnotation != null -> "Annotation{filePathAnnotation=$filePathAnnotation}" + _json != null -> "Annotation{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Annotation") + } + + companion object { + + /** + * A citation within the message that points to a specific quote from a specific File + * associated with the assistant or the message. Generated when the assistant uses the + * "file_search" tool to search files. + */ + @JvmStatic + fun ofFileCitationAnnotation(fileCitationAnnotation: FileCitationAnnotation) = + Annotation(fileCitationAnnotation = fileCitationAnnotation) + + /** + * A URL for the file that's generated when the assistant used the `code_interpreter` tool + * to generate a file. + */ + @JvmStatic + fun ofFilePathAnnotation(filePathAnnotation: FilePathAnnotation) = + Annotation(filePathAnnotation = filePathAnnotation) + } + + interface Visitor { + + fun visitFileCitationAnnotation(fileCitationAnnotation: FileCitationAnnotation): T + + fun visitFilePathAnnotation(filePathAnnotation: FilePathAnnotation): T + + fun unknown(json: JsonValue?): T { + throw OpenAIInvalidDataException("Unknown Annotation: $json") + } + } + + class Deserializer : BaseDeserializer(Annotation::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Annotation { + val json = JsonValue.fromJsonNode(node) + val type = json.asObject().getOrNull()?.get("type")?.asString()?.getOrNull() + + when (type) { + "file_citation" -> { + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Annotation(fileCitationAnnotation = it, _json = json) + } + } + "file_path" -> { + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return Annotation(filePathAnnotation = it, _json = json) + } + } + } + + return Annotation(_json = json) + } + } + + class Serializer : BaseSerializer(Annotation::class) { + + override fun serialize( + value: Annotation, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.fileCitationAnnotation != null -> + generator.writeObject(value.fileCitationAnnotation) + value.filePathAnnotation != null -> generator.writeObject(value.filePathAnnotation) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Annotation") + } + } + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/AnnotationDelta.kt b/openai-java-core/src/main/kotlin/com/openai/models/AnnotationDelta.kt new file mode 100644 index 00000000..71c89ad4 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/AnnotationDelta.kt @@ -0,0 +1,192 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models + +import com.fasterxml.jackson.core.JsonGenerator +import com.fasterxml.jackson.core.ObjectCodec +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.SerializerProvider +import com.fasterxml.jackson.databind.annotation.JsonDeserialize +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.BaseDeserializer +import com.openai.core.BaseSerializer +import com.openai.core.JsonValue +import com.openai.core.getOrThrow +import com.openai.errors.OpenAIInvalidDataException +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * A citation within the message that points to a specific quote from a specific File associated + * with the assistant or the message. Generated when the assistant uses the "file_search" tool to + * search files. + */ +@JsonDeserialize(using = AnnotationDelta.Deserializer::class) +@JsonSerialize(using = AnnotationDelta.Serializer::class) +class AnnotationDelta +private constructor( + private val fileCitationDeltaAnnotation: FileCitationDeltaAnnotation? = null, + private val filePathDeltaAnnotation: FilePathDeltaAnnotation? = null, + private val _json: JsonValue? = null, +) { + + private var validated: Boolean = false + + /** + * A citation within the message that points to a specific quote from a specific File associated + * with the assistant or the message. Generated when the assistant uses the "file_search" tool + * to search files. + */ + fun fileCitationDeltaAnnotation(): Optional = + Optional.ofNullable(fileCitationDeltaAnnotation) + /** + * A URL for the file that's generated when the assistant used the `code_interpreter` tool to + * generate a file. + */ + fun filePathDeltaAnnotation(): Optional = + Optional.ofNullable(filePathDeltaAnnotation) + + fun isFileCitationDeltaAnnotation(): Boolean = fileCitationDeltaAnnotation != null + + fun isFilePathDeltaAnnotation(): Boolean = filePathDeltaAnnotation != null + + /** + * A citation within the message that points to a specific quote from a specific File associated + * with the assistant or the message. Generated when the assistant uses the "file_search" tool + * to search files. + */ + fun asFileCitationDeltaAnnotation(): FileCitationDeltaAnnotation = + fileCitationDeltaAnnotation.getOrThrow("fileCitationDeltaAnnotation") + /** + * A URL for the file that's generated when the assistant used the `code_interpreter` tool to + * generate a file. + */ + fun asFilePathDeltaAnnotation(): FilePathDeltaAnnotation = + filePathDeltaAnnotation.getOrThrow("filePathDeltaAnnotation") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + fileCitationDeltaAnnotation != null -> + visitor.visitFileCitationDeltaAnnotation(fileCitationDeltaAnnotation) + filePathDeltaAnnotation != null -> + visitor.visitFilePathDeltaAnnotation(filePathDeltaAnnotation) + else -> visitor.unknown(_json) + } + } + + fun validate(): AnnotationDelta = apply { + if (!validated) { + if (fileCitationDeltaAnnotation == null && filePathDeltaAnnotation == null) { + throw OpenAIInvalidDataException("Unknown AnnotationDelta: $_json") + } + fileCitationDeltaAnnotation?.validate() + filePathDeltaAnnotation?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is AnnotationDelta && fileCitationDeltaAnnotation == other.fileCitationDeltaAnnotation && filePathDeltaAnnotation == other.filePathDeltaAnnotation /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(fileCitationDeltaAnnotation, filePathDeltaAnnotation) /* spotless:on */ + + override fun toString(): String = + when { + fileCitationDeltaAnnotation != null -> + "AnnotationDelta{fileCitationDeltaAnnotation=$fileCitationDeltaAnnotation}" + filePathDeltaAnnotation != null -> + "AnnotationDelta{filePathDeltaAnnotation=$filePathDeltaAnnotation}" + _json != null -> "AnnotationDelta{_unknown=$_json}" + else -> throw IllegalStateException("Invalid AnnotationDelta") + } + + companion object { + + /** + * A citation within the message that points to a specific quote from a specific File + * associated with the assistant or the message. Generated when the assistant uses the + * "file_search" tool to search files. + */ + @JvmStatic + fun ofFileCitationDeltaAnnotation( + fileCitationDeltaAnnotation: FileCitationDeltaAnnotation + ) = AnnotationDelta(fileCitationDeltaAnnotation = fileCitationDeltaAnnotation) + + /** + * A URL for the file that's generated when the assistant used the `code_interpreter` tool + * to generate a file. + */ + @JvmStatic + fun ofFilePathDeltaAnnotation(filePathDeltaAnnotation: FilePathDeltaAnnotation) = + AnnotationDelta(filePathDeltaAnnotation = filePathDeltaAnnotation) + } + + interface Visitor { + + fun visitFileCitationDeltaAnnotation( + fileCitationDeltaAnnotation: FileCitationDeltaAnnotation + ): T + + fun visitFilePathDeltaAnnotation(filePathDeltaAnnotation: FilePathDeltaAnnotation): T + + fun unknown(json: JsonValue?): T { + throw OpenAIInvalidDataException("Unknown AnnotationDelta: $json") + } + } + + class Deserializer : BaseDeserializer(AnnotationDelta::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): AnnotationDelta { + val json = JsonValue.fromJsonNode(node) + val type = json.asObject().getOrNull()?.get("type")?.asString()?.getOrNull() + + when (type) { + "file_citation" -> { + tryDeserialize(node, jacksonTypeRef()) { + it.validate() + } + ?.let { + return AnnotationDelta(fileCitationDeltaAnnotation = it, _json = json) + } + } + "file_path" -> { + tryDeserialize(node, jacksonTypeRef()) { + it.validate() + } + ?.let { + return AnnotationDelta(filePathDeltaAnnotation = it, _json = json) + } + } + } + + return AnnotationDelta(_json = json) + } + } + + class Serializer : BaseSerializer(AnnotationDelta::class) { + + override fun serialize( + value: AnnotationDelta, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.fileCitationDeltaAnnotation != null -> + generator.writeObject(value.fileCitationDeltaAnnotation) + value.filePathDeltaAnnotation != null -> + generator.writeObject(value.filePathDeltaAnnotation) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid AnnotationDelta") + } + } + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/Assistant.kt b/openai-java-core/src/main/kotlin/com/openai/models/Assistant.kt new file mode 100644 index 00000000..061e331f --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/Assistant.kt @@ -0,0 +1,935 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.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.Enum +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.NoAutoDetect +import com.openai.core.immutableEmptyMap +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Objects +import java.util.Optional + +/** Represents an `assistant` that can call the model and use tools. */ +@NoAutoDetect +class Assistant +@JsonCreator +private constructor( + @JsonProperty("id") @ExcludeMissing private val id: JsonField = JsonMissing.of(), + @JsonProperty("object") + @ExcludeMissing + private val object_: JsonField = JsonMissing.of(), + @JsonProperty("created_at") + @ExcludeMissing + private val createdAt: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing private val name: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + private val description: JsonField = JsonMissing.of(), + @JsonProperty("model") @ExcludeMissing private val model: JsonField = JsonMissing.of(), + @JsonProperty("instructions") + @ExcludeMissing + private val instructions: JsonField = JsonMissing.of(), + @JsonProperty("tools") + @ExcludeMissing + private val tools: JsonField> = JsonMissing.of(), + @JsonProperty("tool_resources") + @ExcludeMissing + private val toolResources: JsonField = JsonMissing.of(), + @JsonProperty("metadata") @ExcludeMissing private val metadata: JsonValue = JsonMissing.of(), + @JsonProperty("temperature") + @ExcludeMissing + private val temperature: JsonField = JsonMissing.of(), + @JsonProperty("top_p") @ExcludeMissing private val topP: JsonField = JsonMissing.of(), + @JsonProperty("response_format") + @ExcludeMissing + private val responseFormat: JsonField = JsonMissing.of(), + @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), +) { + + /** The identifier, which can be referenced in API endpoints. */ + fun id(): String = id.getRequired("id") + + /** The object type, which is always `assistant`. */ + fun object_(): Object = object_.getRequired("object") + + /** The Unix timestamp (in seconds) for when the assistant was created. */ + fun createdAt(): Long = createdAt.getRequired("created_at") + + /** The name of the assistant. The maximum length is 256 characters. */ + fun name(): Optional = Optional.ofNullable(name.getNullable("name")) + + /** The description of the assistant. The maximum length is 512 characters. */ + fun description(): Optional = + Optional.ofNullable(description.getNullable("description")) + + /** + * ID of the model to use. You can use the + * [List models](https://platform.openai.com/docs/api-reference/models/list) API to see all of + * your available models, or see our [Model overview](https://platform.openai.com/docs/models) + * for descriptions of them. + */ + fun model(): String = model.getRequired("model") + + /** + * The system instructions that the assistant uses. The maximum length is 256,000 characters. + */ + fun instructions(): Optional = + Optional.ofNullable(instructions.getNullable("instructions")) + + /** + * A list of tool enabled on the assistant. There can be a maximum of 128 tools per assistant. + * Tools can be of types `code_interpreter`, `file_search`, or `function`. + */ + fun tools(): List = tools.getRequired("tools") + + /** + * A set of resources that are used by the assistant's tools. The resources are specific to the + * type of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the + * `file_search` tool requires a list of vector store IDs. + */ + fun toolResources(): Optional = + Optional.ofNullable(toolResources.getNullable("tool_resources")) + + /** + * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the + * output more random, while lower values like 0.2 will make it more focused and deterministic. + */ + fun temperature(): Optional = + Optional.ofNullable(temperature.getNullable("temperature")) + + /** + * An alternative to sampling with temperature, called nucleus sampling, where the model + * considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens + * comprising the top 10% probability mass are considered. + * + * We generally recommend altering this or temperature but not both. + */ + fun topP(): Optional = Optional.ofNullable(topP.getNullable("top_p")) + + /** + * Specifies the format that the model must output. Compatible with + * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o), [GPT-4 + * Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4), and all GPT-3.5 Turbo + * models since `gpt-3.5-turbo-1106`. + * + * Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured Outputs which + * ensures the model will match your supplied JSON schema. Learn more in the + * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs). + * + * Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the message the model + * generates is valid JSON. + * + * **Important:** when using JSON mode, you **must** also instruct the model to produce JSON + * yourself via a system or user message. Without this, the model may generate an unending + * stream of whitespace until the generation reaches the token limit, resulting in a + * long-running and seemingly "stuck" request. Also note that the message content may be + * partially cut off if `finish_reason="length"`, which indicates the generation exceeded + * `max_tokens` or the conversation exceeded the max context length. + */ + fun responseFormat(): Optional = + Optional.ofNullable(responseFormat.getNullable("response_format")) + + /** The identifier, which can be referenced in API endpoints. */ + @JsonProperty("id") @ExcludeMissing fun _id() = id + + /** The object type, which is always `assistant`. */ + @JsonProperty("object") @ExcludeMissing fun _object_() = object_ + + /** The Unix timestamp (in seconds) for when the assistant was created. */ + @JsonProperty("created_at") @ExcludeMissing fun _createdAt() = createdAt + + /** The name of the assistant. The maximum length is 256 characters. */ + @JsonProperty("name") @ExcludeMissing fun _name() = name + + /** The description of the assistant. The maximum length is 512 characters. */ + @JsonProperty("description") @ExcludeMissing fun _description() = description + + /** + * ID of the model to use. You can use the + * [List models](https://platform.openai.com/docs/api-reference/models/list) API to see all of + * your available models, or see our [Model overview](https://platform.openai.com/docs/models) + * for descriptions of them. + */ + @JsonProperty("model") @ExcludeMissing fun _model() = model + + /** + * The system instructions that the assistant uses. The maximum length is 256,000 characters. + */ + @JsonProperty("instructions") @ExcludeMissing fun _instructions() = instructions + + /** + * A list of tool enabled on the assistant. There can be a maximum of 128 tools per assistant. + * Tools can be of types `code_interpreter`, `file_search`, or `function`. + */ + @JsonProperty("tools") @ExcludeMissing fun _tools() = tools + + /** + * A set of resources that are used by the assistant's tools. The resources are specific to the + * type of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the + * `file_search` tool requires a list of vector store IDs. + */ + @JsonProperty("tool_resources") @ExcludeMissing fun _toolResources() = toolResources + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for storing + * additional information about the object in a structured format. Keys can be a maximum of 64 + * characters long and values can be a maximum of 512 characters long. + */ + @JsonProperty("metadata") @ExcludeMissing fun _metadata() = metadata + + /** + * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the + * output more random, while lower values like 0.2 will make it more focused and deterministic. + */ + @JsonProperty("temperature") @ExcludeMissing fun _temperature() = temperature + + /** + * An alternative to sampling with temperature, called nucleus sampling, where the model + * considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens + * comprising the top 10% probability mass are considered. + * + * We generally recommend altering this or temperature but not both. + */ + @JsonProperty("top_p") @ExcludeMissing fun _topP() = topP + + /** + * Specifies the format that the model must output. Compatible with + * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o), [GPT-4 + * Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4), and all GPT-3.5 Turbo + * models since `gpt-3.5-turbo-1106`. + * + * Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured Outputs which + * ensures the model will match your supplied JSON schema. Learn more in the + * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs). + * + * Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the message the model + * generates is valid JSON. + * + * **Important:** when using JSON mode, you **must** also instruct the model to produce JSON + * yourself via a system or user message. Without this, the model may generate an unending + * stream of whitespace until the generation reaches the token limit, resulting in a + * long-running and seemingly "stuck" request. Also note that the message content may be + * partially cut off if `finish_reason="length"`, which indicates the generation exceeded + * `max_tokens` or the conversation exceeded the max context length. + */ + @JsonProperty("response_format") @ExcludeMissing fun _responseFormat() = responseFormat + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + private var validated: Boolean = false + + fun validate(): Assistant = apply { + if (!validated) { + id() + object_() + createdAt() + name() + description() + model() + instructions() + tools() + toolResources().map { it.validate() } + temperature() + topP() + responseFormat() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var id: JsonField = JsonMissing.of() + private var object_: JsonField = JsonMissing.of() + private var createdAt: JsonField = JsonMissing.of() + private var name: JsonField = JsonMissing.of() + private var description: JsonField = JsonMissing.of() + private var model: JsonField = JsonMissing.of() + private var instructions: JsonField = JsonMissing.of() + private var tools: JsonField> = JsonMissing.of() + private var toolResources: JsonField = JsonMissing.of() + private var metadata: JsonValue = JsonMissing.of() + private var temperature: JsonField = JsonMissing.of() + private var topP: JsonField = JsonMissing.of() + private var responseFormat: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(assistant: Assistant) = apply { + id = assistant.id + object_ = assistant.object_ + createdAt = assistant.createdAt + name = assistant.name + description = assistant.description + model = assistant.model + instructions = assistant.instructions + tools = assistant.tools + toolResources = assistant.toolResources + metadata = assistant.metadata + temperature = assistant.temperature + topP = assistant.topP + responseFormat = assistant.responseFormat + additionalProperties = assistant.additionalProperties.toMutableMap() + } + + /** The identifier, which can be referenced in API endpoints. */ + fun id(id: String) = id(JsonField.of(id)) + + /** The identifier, which can be referenced in API endpoints. */ + fun id(id: JsonField) = apply { this.id = id } + + /** The object type, which is always `assistant`. */ + fun object_(object_: Object) = object_(JsonField.of(object_)) + + /** The object type, which is always `assistant`. */ + fun object_(object_: JsonField) = apply { this.object_ = object_ } + + /** The Unix timestamp (in seconds) for when the assistant was created. */ + fun createdAt(createdAt: Long) = createdAt(JsonField.of(createdAt)) + + /** The Unix timestamp (in seconds) for when the assistant was created. */ + fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } + + /** The name of the assistant. The maximum length is 256 characters. */ + fun name(name: String) = name(JsonField.of(name)) + + /** The name of the assistant. The maximum length is 256 characters. */ + fun name(name: JsonField) = apply { this.name = name } + + /** The description of the assistant. The maximum length is 512 characters. */ + fun description(description: String) = description(JsonField.of(description)) + + /** The description of the assistant. The maximum length is 512 characters. */ + fun description(description: JsonField) = apply { this.description = description } + + /** + * ID of the model to use. You can use the + * [List models](https://platform.openai.com/docs/api-reference/models/list) API to see all + * of your available models, or see our + * [Model overview](https://platform.openai.com/docs/models) for descriptions of them. + */ + fun model(model: String) = model(JsonField.of(model)) + + /** + * ID of the model to use. You can use the + * [List models](https://platform.openai.com/docs/api-reference/models/list) API to see all + * of your available models, or see our + * [Model overview](https://platform.openai.com/docs/models) for descriptions of them. + */ + fun model(model: JsonField) = apply { this.model = model } + + /** + * The system instructions that the assistant uses. The maximum length is 256,000 + * characters. + */ + fun instructions(instructions: String) = instructions(JsonField.of(instructions)) + + /** + * The system instructions that the assistant uses. The maximum length is 256,000 + * characters. + */ + fun instructions(instructions: JsonField) = apply { + this.instructions = instructions + } + + /** + * A list of tool enabled on the assistant. There can be a maximum of 128 tools per + * assistant. Tools can be of types `code_interpreter`, `file_search`, or `function`. + */ + fun tools(tools: List) = tools(JsonField.of(tools)) + + /** + * A list of tool enabled on the assistant. There can be a maximum of 128 tools per + * assistant. Tools can be of types `code_interpreter`, `file_search`, or `function`. + */ + fun tools(tools: JsonField>) = apply { this.tools = tools } + + /** + * A set of resources that are used by the assistant's tools. The resources are specific to + * the type of tool. For example, the `code_interpreter` tool requires a list of file IDs, + * while the `file_search` tool requires a list of vector store IDs. + */ + fun toolResources(toolResources: ToolResources) = toolResources(JsonField.of(toolResources)) + + /** + * A set of resources that are used by the assistant's tools. The resources are specific to + * the type of tool. For example, the `code_interpreter` tool requires a list of file IDs, + * while the `file_search` tool requires a list of vector store IDs. + */ + fun toolResources(toolResources: JsonField) = apply { + this.toolResources = toolResources + } + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format. Keys can be a + * maximum of 64 characters long and values can be a maximum of 512 characters long. + */ + fun metadata(metadata: JsonValue) = apply { this.metadata = metadata } + + /** + * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the + * output more random, while lower values like 0.2 will make it more focused and + * deterministic. + */ + fun temperature(temperature: Double) = temperature(JsonField.of(temperature)) + + /** + * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the + * output more random, while lower values like 0.2 will make it more focused and + * deterministic. + */ + fun temperature(temperature: JsonField) = apply { this.temperature = temperature } + + /** + * An alternative to sampling with temperature, called nucleus sampling, where the model + * considers the results of the tokens with top_p probability mass. So 0.1 means only the + * tokens comprising the top 10% probability mass are considered. + * + * We generally recommend altering this or temperature but not both. + */ + fun topP(topP: Double) = topP(JsonField.of(topP)) + + /** + * An alternative to sampling with temperature, called nucleus sampling, where the model + * considers the results of the tokens with top_p probability mass. So 0.1 means only the + * tokens comprising the top 10% probability mass are considered. + * + * We generally recommend altering this or temperature but not both. + */ + fun topP(topP: JsonField) = apply { this.topP = topP } + + /** + * Specifies the format that the model must output. Compatible with + * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o), [GPT-4 + * Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4), and all GPT-3.5 + * Turbo models since `gpt-3.5-turbo-1106`. + * + * Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured Outputs + * which ensures the model will match your supplied JSON schema. Learn more in the + * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs). + * + * Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the message the + * model generates is valid JSON. + * + * **Important:** when using JSON mode, you **must** also instruct the model to produce JSON + * yourself via a system or user message. Without this, the model may generate an unending + * stream of whitespace until the generation reaches the token limit, resulting in a + * long-running and seemingly "stuck" request. Also note that the message content may be + * partially cut off if `finish_reason="length"`, which indicates the generation exceeded + * `max_tokens` or the conversation exceeded the max context length. + */ + fun responseFormat(responseFormat: AssistantResponseFormatOption) = + responseFormat(JsonField.of(responseFormat)) + + /** + * Specifies the format that the model must output. Compatible with + * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o), [GPT-4 + * Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4), and all GPT-3.5 + * Turbo models since `gpt-3.5-turbo-1106`. + * + * Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured Outputs + * which ensures the model will match your supplied JSON schema. Learn more in the + * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs). + * + * Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the message the + * model generates is valid JSON. + * + * **Important:** when using JSON mode, you **must** also instruct the model to produce JSON + * yourself via a system or user message. Without this, the model may generate an unending + * stream of whitespace until the generation reaches the token limit, resulting in a + * long-running and seemingly "stuck" request. Also note that the message content may be + * partially cut off if `finish_reason="length"`, which indicates the generation exceeded + * `max_tokens` or the conversation exceeded the max context length. + */ + fun responseFormat(responseFormat: JsonField) = apply { + this.responseFormat = responseFormat + } + + 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) + } + + fun build(): Assistant = + Assistant( + id, + object_, + createdAt, + name, + description, + model, + instructions, + tools.map { it.toImmutable() }, + toolResources, + metadata, + temperature, + topP, + responseFormat, + additionalProperties.toImmutable(), + ) + } + + class Object + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val ASSISTANT = of("assistant") + + @JvmStatic fun of(value: String) = Object(JsonField.of(value)) + } + + enum class Known { + ASSISTANT, + } + + enum class Value { + ASSISTANT, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + ASSISTANT -> Value.ASSISTANT + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + ASSISTANT -> Known.ASSISTANT + else -> throw OpenAIInvalidDataException("Unknown Object: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Object && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** + * A set of resources that are used by the assistant's tools. The resources are specific to the + * type of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the + * `file_search` tool requires a list of vector store IDs. + */ + @NoAutoDetect + class ToolResources + @JsonCreator + private constructor( + @JsonProperty("code_interpreter") + @ExcludeMissing + private val codeInterpreter: JsonField = JsonMissing.of(), + @JsonProperty("file_search") + @ExcludeMissing + private val fileSearch: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + fun codeInterpreter(): Optional = + Optional.ofNullable(codeInterpreter.getNullable("code_interpreter")) + + fun fileSearch(): Optional = + Optional.ofNullable(fileSearch.getNullable("file_search")) + + @JsonProperty("code_interpreter") @ExcludeMissing fun _codeInterpreter() = codeInterpreter + + @JsonProperty("file_search") @ExcludeMissing fun _fileSearch() = fileSearch + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + private var validated: Boolean = false + + fun validate(): ToolResources = apply { + if (!validated) { + codeInterpreter().map { it.validate() } + fileSearch().map { it.validate() } + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var codeInterpreter: JsonField = JsonMissing.of() + private var fileSearch: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(toolResources: ToolResources) = apply { + codeInterpreter = toolResources.codeInterpreter + fileSearch = toolResources.fileSearch + additionalProperties = toolResources.additionalProperties.toMutableMap() + } + + fun codeInterpreter(codeInterpreter: CodeInterpreter) = + codeInterpreter(JsonField.of(codeInterpreter)) + + fun codeInterpreter(codeInterpreter: JsonField) = apply { + this.codeInterpreter = codeInterpreter + } + + fun fileSearch(fileSearch: FileSearch) = fileSearch(JsonField.of(fileSearch)) + + fun fileSearch(fileSearch: JsonField) = apply { + this.fileSearch = fileSearch + } + + 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) + } + + fun build(): ToolResources = + ToolResources( + codeInterpreter, + fileSearch, + additionalProperties.toImmutable(), + ) + } + + @NoAutoDetect + class CodeInterpreter + @JsonCreator + private constructor( + @JsonProperty("file_ids") + @ExcludeMissing + private val fileIds: JsonField> = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** + * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made + * available to the `code_interpreter`` tool. There can be a maximum of 20 files + * associated with the tool. + */ + fun fileIds(): Optional> = + Optional.ofNullable(fileIds.getNullable("file_ids")) + + /** + * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made + * available to the `code_interpreter`` tool. There can be a maximum of 20 files + * associated with the tool. + */ + @JsonProperty("file_ids") @ExcludeMissing fun _fileIds() = fileIds + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + private var validated: Boolean = false + + fun validate(): CodeInterpreter = apply { + if (!validated) { + fileIds() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var fileIds: JsonField> = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(codeInterpreter: CodeInterpreter) = apply { + fileIds = codeInterpreter.fileIds + additionalProperties = codeInterpreter.additionalProperties.toMutableMap() + } + + /** + * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made + * available to the `code_interpreter`` tool. There can be a maximum of 20 files + * associated with the tool. + */ + fun fileIds(fileIds: List) = fileIds(JsonField.of(fileIds)) + + /** + * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made + * available to the `code_interpreter`` tool. There can be a maximum of 20 files + * associated with the tool. + */ + fun fileIds(fileIds: JsonField>) = apply { this.fileIds = fileIds } + + 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) + } + + fun build(): CodeInterpreter = + CodeInterpreter( + fileIds.map { it.toImmutable() }, + additionalProperties.toImmutable() + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is CodeInterpreter && fileIds == other.fileIds && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(fileIds, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CodeInterpreter{fileIds=$fileIds, additionalProperties=$additionalProperties}" + } + + @NoAutoDetect + class FileSearch + @JsonCreator + private constructor( + @JsonProperty("vector_store_ids") + @ExcludeMissing + private val vectorStoreIds: JsonField> = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** + * The ID of the + * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object) + * attached to this assistant. There can be a maximum of 1 vector store attached to the + * assistant. + */ + fun vectorStoreIds(): Optional> = + Optional.ofNullable(vectorStoreIds.getNullable("vector_store_ids")) + + /** + * The ID of the + * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object) + * attached to this assistant. There can be a maximum of 1 vector store attached to the + * assistant. + */ + @JsonProperty("vector_store_ids") @ExcludeMissing fun _vectorStoreIds() = vectorStoreIds + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + private var validated: Boolean = false + + fun validate(): FileSearch = apply { + if (!validated) { + vectorStoreIds() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var vectorStoreIds: JsonField> = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(fileSearch: FileSearch) = apply { + vectorStoreIds = fileSearch.vectorStoreIds + additionalProperties = fileSearch.additionalProperties.toMutableMap() + } + + /** + * The ID of the + * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object) + * attached to this assistant. There can be a maximum of 1 vector store attached to + * the assistant. + */ + fun vectorStoreIds(vectorStoreIds: List) = + vectorStoreIds(JsonField.of(vectorStoreIds)) + + /** + * The ID of the + * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object) + * attached to this assistant. There can be a maximum of 1 vector store attached to + * the assistant. + */ + fun vectorStoreIds(vectorStoreIds: JsonField>) = apply { + this.vectorStoreIds = vectorStoreIds + } + + 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) + } + + fun build(): FileSearch = + FileSearch( + vectorStoreIds.map { it.toImmutable() }, + additionalProperties.toImmutable() + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is FileSearch && vectorStoreIds == other.vectorStoreIds && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(vectorStoreIds, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "FileSearch{vectorStoreIds=$vectorStoreIds, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ToolResources && codeInterpreter == other.codeInterpreter && fileSearch == other.fileSearch && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(codeInterpreter, fileSearch, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ToolResources{codeInterpreter=$codeInterpreter, fileSearch=$fileSearch, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Assistant && id == other.id && object_ == other.object_ && createdAt == other.createdAt && name == other.name && description == other.description && model == other.model && instructions == other.instructions && tools == other.tools && toolResources == other.toolResources && metadata == other.metadata && temperature == other.temperature && topP == other.topP && responseFormat == other.responseFormat && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(id, object_, createdAt, name, description, model, instructions, tools, toolResources, metadata, temperature, topP, responseFormat, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Assistant{id=$id, object_=$object_, createdAt=$createdAt, name=$name, description=$description, model=$model, instructions=$instructions, tools=$tools, toolResources=$toolResources, metadata=$metadata, temperature=$temperature, topP=$topP, responseFormat=$responseFormat, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/AssistantDeleted.kt b/openai-java-core/src/main/kotlin/com/openai/models/AssistantDeleted.kt new file mode 100644 index 00000000..072e3e55 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/AssistantDeleted.kt @@ -0,0 +1,190 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.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.Enum +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.NoAutoDetect +import com.openai.core.immutableEmptyMap +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Objects + +@NoAutoDetect +class AssistantDeleted +@JsonCreator +private constructor( + @JsonProperty("id") @ExcludeMissing private val id: JsonField = JsonMissing.of(), + @JsonProperty("deleted") + @ExcludeMissing + private val deleted: JsonField = JsonMissing.of(), + @JsonProperty("object") + @ExcludeMissing + private val object_: JsonField = JsonMissing.of(), + @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), +) { + + fun id(): String = id.getRequired("id") + + fun deleted(): Boolean = deleted.getRequired("deleted") + + fun object_(): Object = object_.getRequired("object") + + @JsonProperty("id") @ExcludeMissing fun _id() = id + + @JsonProperty("deleted") @ExcludeMissing fun _deleted() = deleted + + @JsonProperty("object") @ExcludeMissing fun _object_() = object_ + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + private var validated: Boolean = false + + fun validate(): AssistantDeleted = apply { + if (!validated) { + id() + deleted() + object_() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var id: JsonField = JsonMissing.of() + private var deleted: JsonField = JsonMissing.of() + private var object_: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(assistantDeleted: AssistantDeleted) = apply { + id = assistantDeleted.id + deleted = assistantDeleted.deleted + object_ = assistantDeleted.object_ + additionalProperties = assistantDeleted.additionalProperties.toMutableMap() + } + + fun id(id: String) = id(JsonField.of(id)) + + fun id(id: JsonField) = apply { this.id = id } + + fun deleted(deleted: Boolean) = deleted(JsonField.of(deleted)) + + fun deleted(deleted: JsonField) = apply { this.deleted = deleted } + + fun object_(object_: Object) = object_(JsonField.of(object_)) + + 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) + } + + fun build(): AssistantDeleted = + AssistantDeleted( + id, + deleted, + object_, + additionalProperties.toImmutable(), + ) + } + + class Object + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val ASSISTANT_DELETED = of("assistant.deleted") + + @JvmStatic fun of(value: String) = Object(JsonField.of(value)) + } + + enum class Known { + ASSISTANT_DELETED, + } + + enum class Value { + ASSISTANT_DELETED, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + ASSISTANT_DELETED -> Value.ASSISTANT_DELETED + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + ASSISTANT_DELETED -> Known.ASSISTANT_DELETED + else -> throw OpenAIInvalidDataException("Unknown Object: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Object && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is AssistantDeleted && id == other.id && deleted == other.deleted && object_ == other.object_ && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(id, deleted, object_, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AssistantDeleted{id=$id, deleted=$deleted, object_=$object_, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/AssistantResponseFormatOption.kt b/openai-java-core/src/main/kotlin/com/openai/models/AssistantResponseFormatOption.kt new file mode 100644 index 00000000..88b88260 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/AssistantResponseFormatOption.kt @@ -0,0 +1,278 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models + +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.core.JsonGenerator +import com.fasterxml.jackson.core.ObjectCodec +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.SerializerProvider +import com.fasterxml.jackson.databind.annotation.JsonDeserialize +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.BaseDeserializer +import com.openai.core.BaseSerializer +import com.openai.core.Enum +import com.openai.core.JsonField +import com.openai.core.JsonValue +import com.openai.core.getOrThrow +import com.openai.errors.OpenAIInvalidDataException +import java.util.Objects +import java.util.Optional + +/** + * Specifies the format that the model must output. Compatible with + * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o), [GPT-4 + * Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4), and all GPT-3.5 Turbo + * models since `gpt-3.5-turbo-1106`. + * + * Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured Outputs which + * ensures the model will match your supplied JSON schema. Learn more in the + * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs). + * + * Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the message the model + * generates is valid JSON. + * + * **Important:** when using JSON mode, you **must** also instruct the model to produce JSON + * yourself via a system or user message. Without this, the model may generate an unending stream of + * whitespace until the generation reaches the token limit, resulting in a long-running and + * seemingly "stuck" request. Also note that the message content may be partially cut off if + * `finish_reason="length"`, which indicates the generation exceeded `max_tokens` or the + * conversation exceeded the max context length. + */ +@JsonDeserialize(using = AssistantResponseFormatOption.Deserializer::class) +@JsonSerialize(using = AssistantResponseFormatOption.Serializer::class) +class AssistantResponseFormatOption +private constructor( + private val behavior: Behavior? = null, + private val responseFormatText: ResponseFormatText? = null, + private val responseFormatJsonObject: ResponseFormatJsonObject? = null, + private val responseFormatJsonSchema: ResponseFormatJsonSchema? = null, + private val _json: JsonValue? = null, +) { + + private var validated: Boolean = false + + /** `auto` is the default value */ + fun behavior(): Optional = Optional.ofNullable(behavior) + + fun responseFormatText(): Optional = Optional.ofNullable(responseFormatText) + + fun responseFormatJsonObject(): Optional = + Optional.ofNullable(responseFormatJsonObject) + + fun responseFormatJsonSchema(): Optional = + Optional.ofNullable(responseFormatJsonSchema) + + fun isBehavior(): Boolean = behavior != null + + fun isResponseFormatText(): Boolean = responseFormatText != null + + fun isResponseFormatJsonObject(): Boolean = responseFormatJsonObject != null + + fun isResponseFormatJsonSchema(): Boolean = responseFormatJsonSchema != null + + /** `auto` is the default value */ + fun asBehavior(): Behavior = behavior.getOrThrow("behavior") + + fun asResponseFormatText(): ResponseFormatText = + responseFormatText.getOrThrow("responseFormatText") + + fun asResponseFormatJsonObject(): ResponseFormatJsonObject = + responseFormatJsonObject.getOrThrow("responseFormatJsonObject") + + fun asResponseFormatJsonSchema(): ResponseFormatJsonSchema = + responseFormatJsonSchema.getOrThrow("responseFormatJsonSchema") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + behavior != null -> visitor.visitBehavior(behavior) + responseFormatText != null -> visitor.visitResponseFormatText(responseFormatText) + responseFormatJsonObject != null -> + visitor.visitResponseFormatJsonObject(responseFormatJsonObject) + responseFormatJsonSchema != null -> + visitor.visitResponseFormatJsonSchema(responseFormatJsonSchema) + else -> visitor.unknown(_json) + } + } + + fun validate(): AssistantResponseFormatOption = apply { + if (!validated) { + if ( + behavior == null && + responseFormatText == null && + responseFormatJsonObject == null && + responseFormatJsonSchema == null + ) { + throw OpenAIInvalidDataException("Unknown AssistantResponseFormatOption: $_json") + } + responseFormatText?.validate() + responseFormatJsonObject?.validate() + responseFormatJsonSchema?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is AssistantResponseFormatOption && behavior == other.behavior && responseFormatText == other.responseFormatText && responseFormatJsonObject == other.responseFormatJsonObject && responseFormatJsonSchema == other.responseFormatJsonSchema /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(behavior, responseFormatText, responseFormatJsonObject, responseFormatJsonSchema) /* spotless:on */ + + override fun toString(): String = + when { + behavior != null -> "AssistantResponseFormatOption{behavior=$behavior}" + responseFormatText != null -> + "AssistantResponseFormatOption{responseFormatText=$responseFormatText}" + responseFormatJsonObject != null -> + "AssistantResponseFormatOption{responseFormatJsonObject=$responseFormatJsonObject}" + responseFormatJsonSchema != null -> + "AssistantResponseFormatOption{responseFormatJsonSchema=$responseFormatJsonSchema}" + _json != null -> "AssistantResponseFormatOption{_unknown=$_json}" + else -> throw IllegalStateException("Invalid AssistantResponseFormatOption") + } + + companion object { + + /** `auto` is the default value */ + @JvmStatic + fun ofBehavior(behavior: Behavior) = AssistantResponseFormatOption(behavior = behavior) + + @JvmStatic + fun ofResponseFormatText(responseFormatText: ResponseFormatText) = + AssistantResponseFormatOption(responseFormatText = responseFormatText) + + @JvmStatic + fun ofResponseFormatJsonObject(responseFormatJsonObject: ResponseFormatJsonObject) = + AssistantResponseFormatOption(responseFormatJsonObject = responseFormatJsonObject) + + @JvmStatic + fun ofResponseFormatJsonSchema(responseFormatJsonSchema: ResponseFormatJsonSchema) = + AssistantResponseFormatOption(responseFormatJsonSchema = responseFormatJsonSchema) + } + + interface Visitor { + + fun visitBehavior(behavior: Behavior): T + + fun visitResponseFormatText(responseFormatText: ResponseFormatText): T + + fun visitResponseFormatJsonObject(responseFormatJsonObject: ResponseFormatJsonObject): T + + fun visitResponseFormatJsonSchema(responseFormatJsonSchema: ResponseFormatJsonSchema): T + + fun unknown(json: JsonValue?): T { + throw OpenAIInvalidDataException("Unknown AssistantResponseFormatOption: $json") + } + } + + class Deserializer : + BaseDeserializer(AssistantResponseFormatOption::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): AssistantResponseFormatOption { + val json = JsonValue.fromJsonNode(node) + + tryDeserialize(node, jacksonTypeRef())?.let { + return AssistantResponseFormatOption(behavior = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return AssistantResponseFormatOption(responseFormatText = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return AssistantResponseFormatOption( + responseFormatJsonObject = it, + _json = json + ) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return AssistantResponseFormatOption( + responseFormatJsonSchema = it, + _json = json + ) + } + + return AssistantResponseFormatOption(_json = json) + } + } + + class Serializer : + BaseSerializer(AssistantResponseFormatOption::class) { + + override fun serialize( + value: AssistantResponseFormatOption, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.behavior != null -> generator.writeObject(value.behavior) + value.responseFormatText != null -> generator.writeObject(value.responseFormatText) + value.responseFormatJsonObject != null -> + generator.writeObject(value.responseFormatJsonObject) + value.responseFormatJsonSchema != null -> + generator.writeObject(value.responseFormatJsonSchema) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid AssistantResponseFormatOption") + } + } + } + + class Behavior + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val AUTO = of("auto") + + @JvmStatic fun of(value: String) = Behavior(JsonField.of(value)) + } + + enum class Known { + AUTO, + } + + enum class Value { + AUTO, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + AUTO -> Value.AUTO + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + AUTO -> Known.AUTO + else -> throw OpenAIInvalidDataException("Unknown Behavior: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Behavior && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/AssistantStreamEvent.kt b/openai-java-core/src/main/kotlin/com/openai/models/AssistantStreamEvent.kt new file mode 100644 index 00000000..eb198c8b --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/AssistantStreamEvent.kt @@ -0,0 +1,5230 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.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.fasterxml.jackson.core.JsonGenerator +import com.fasterxml.jackson.core.ObjectCodec +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.SerializerProvider +import com.fasterxml.jackson.databind.annotation.JsonDeserialize +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.BaseDeserializer +import com.openai.core.BaseSerializer +import com.openai.core.Enum +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.NoAutoDetect +import com.openai.core.getOrThrow +import com.openai.core.immutableEmptyMap +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * Represents an event emitted when streaming a Run. + * + * Each event in a server-sent events stream has an `event` and `data` property: + * ``` + * event: thread.created + * data: {"id": "thread_123", "object": "thread", ...} + * ``` + * + * We emit events whenever a new object is created, transitions to a new state, or is being streamed + * in parts (deltas). For example, we emit `thread.run.created` when a new run is created, + * `thread.run.completed` when a run completes, and so on. When an Assistant chooses to create a + * message during a run, we emit a `thread.message.created event`, a `thread.message.in_progress` + * event, many `thread.message.delta` events, and finally a `thread.message.completed` event. + * + * We may add additional events over time, so we recommend handling unknown events gracefully in + * your code. See the + * [Assistants API quickstart](https://platform.openai.com/docs/assistants/overview) to learn how to + * integrate the Assistants API with streaming. + */ +@JsonDeserialize(using = AssistantStreamEvent.Deserializer::class) +@JsonSerialize(using = AssistantStreamEvent.Serializer::class) +class AssistantStreamEvent +private constructor( + private val threadCreated: ThreadCreated? = null, + private val threadRunCreated: ThreadRunCreated? = null, + private val threadRunQueued: ThreadRunQueued? = null, + private val threadRunInProgress: ThreadRunInProgress? = null, + private val threadRunRequiresAction: ThreadRunRequiresAction? = null, + private val threadRunCompleted: ThreadRunCompleted? = null, + private val threadRunIncomplete: ThreadRunIncomplete? = null, + private val threadRunFailed: ThreadRunFailed? = null, + private val threadRunCancelling: ThreadRunCancelling? = null, + private val threadRunCancelled: ThreadRunCancelled? = null, + private val threadRunExpired: ThreadRunExpired? = null, + private val threadRunStepCreated: ThreadRunStepCreated? = null, + private val threadRunStepInProgress: ThreadRunStepInProgress? = null, + private val threadRunStepDelta: ThreadRunStepDelta? = null, + private val threadRunStepCompleted: ThreadRunStepCompleted? = null, + private val threadRunStepFailed: ThreadRunStepFailed? = null, + private val threadRunStepCancelled: ThreadRunStepCancelled? = null, + private val threadRunStepExpired: ThreadRunStepExpired? = null, + private val threadMessageCreated: ThreadMessageCreated? = null, + private val threadMessageInProgress: ThreadMessageInProgress? = null, + private val threadMessageDelta: ThreadMessageDelta? = null, + private val threadMessageCompleted: ThreadMessageCompleted? = null, + private val threadMessageIncomplete: ThreadMessageIncomplete? = null, + private val errorEvent: ErrorEvent? = null, + private val _json: JsonValue? = null, +) { + + private var validated: Boolean = false + + /** + * Occurs when a new [thread](https://platform.openai.com/docs/api-reference/threads/object) is + * created. + */ + fun threadCreated(): Optional = Optional.ofNullable(threadCreated) + /** + * Occurs when a new [run](https://platform.openai.com/docs/api-reference/runs/object) is + * created. + */ + fun threadRunCreated(): Optional = Optional.ofNullable(threadRunCreated) + /** + * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object) moves to a + * `queued` status. + */ + fun threadRunQueued(): Optional = Optional.ofNullable(threadRunQueued) + /** + * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object) moves to an + * `in_progress` status. + */ + fun threadRunInProgress(): Optional = + Optional.ofNullable(threadRunInProgress) + /** + * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object) moves to a + * `requires_action` status. + */ + fun threadRunRequiresAction(): Optional = + Optional.ofNullable(threadRunRequiresAction) + /** + * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object) is completed. + */ + fun threadRunCompleted(): Optional = Optional.ofNullable(threadRunCompleted) + /** + * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object) ends with + * status `incomplete`. + */ + fun threadRunIncomplete(): Optional = + Optional.ofNullable(threadRunIncomplete) + /** Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object) fails. */ + fun threadRunFailed(): Optional = Optional.ofNullable(threadRunFailed) + /** + * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object) moves to a + * `cancelling` status. + */ + fun threadRunCancelling(): Optional = + Optional.ofNullable(threadRunCancelling) + /** + * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object) is cancelled. + */ + fun threadRunCancelled(): Optional = Optional.ofNullable(threadRunCancelled) + /** Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object) expires. */ + fun threadRunExpired(): Optional = Optional.ofNullable(threadRunExpired) + /** + * Occurs when a + * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object) is created. + */ + fun threadRunStepCreated(): Optional = + Optional.ofNullable(threadRunStepCreated) + /** + * Occurs when a + * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object) moves to an + * `in_progress` state. + */ + fun threadRunStepInProgress(): Optional = + Optional.ofNullable(threadRunStepInProgress) + /** + * Occurs when parts of a + * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object) are being + * streamed. + */ + fun threadRunStepDelta(): Optional = Optional.ofNullable(threadRunStepDelta) + /** + * Occurs when a + * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object) is + * completed. + */ + fun threadRunStepCompleted(): Optional = + Optional.ofNullable(threadRunStepCompleted) + /** + * Occurs when a + * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object) fails. + */ + fun threadRunStepFailed(): Optional = + Optional.ofNullable(threadRunStepFailed) + /** + * Occurs when a + * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object) is + * cancelled. + */ + fun threadRunStepCancelled(): Optional = + Optional.ofNullable(threadRunStepCancelled) + /** + * Occurs when a + * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object) expires. + */ + fun threadRunStepExpired(): Optional = + Optional.ofNullable(threadRunStepExpired) + /** + * Occurs when a [message](https://platform.openai.com/docs/api-reference/messages/object) is + * created. + */ + fun threadMessageCreated(): Optional = + Optional.ofNullable(threadMessageCreated) + /** + * Occurs when a [message](https://platform.openai.com/docs/api-reference/messages/object) moves + * to an `in_progress` state. + */ + fun threadMessageInProgress(): Optional = + Optional.ofNullable(threadMessageInProgress) + /** + * Occurs when parts of a + * [Message](https://platform.openai.com/docs/api-reference/messages/object) are being streamed. + */ + fun threadMessageDelta(): Optional = Optional.ofNullable(threadMessageDelta) + /** + * Occurs when a [message](https://platform.openai.com/docs/api-reference/messages/object) is + * completed. + */ + fun threadMessageCompleted(): Optional = + Optional.ofNullable(threadMessageCompleted) + /** + * Occurs when a [message](https://platform.openai.com/docs/api-reference/messages/object) ends + * before it is completed. + */ + fun threadMessageIncomplete(): Optional = + Optional.ofNullable(threadMessageIncomplete) + /** + * Occurs when an [error](https://platform.openai.com/docs/guides/error-codes#api-errors) + * occurs. This can happen due to an internal server error or a timeout. + */ + fun errorEvent(): Optional = Optional.ofNullable(errorEvent) + + fun isThreadCreated(): Boolean = threadCreated != null + + fun isThreadRunCreated(): Boolean = threadRunCreated != null + + fun isThreadRunQueued(): Boolean = threadRunQueued != null + + fun isThreadRunInProgress(): Boolean = threadRunInProgress != null + + fun isThreadRunRequiresAction(): Boolean = threadRunRequiresAction != null + + fun isThreadRunCompleted(): Boolean = threadRunCompleted != null + + fun isThreadRunIncomplete(): Boolean = threadRunIncomplete != null + + fun isThreadRunFailed(): Boolean = threadRunFailed != null + + fun isThreadRunCancelling(): Boolean = threadRunCancelling != null + + fun isThreadRunCancelled(): Boolean = threadRunCancelled != null + + fun isThreadRunExpired(): Boolean = threadRunExpired != null + + fun isThreadRunStepCreated(): Boolean = threadRunStepCreated != null + + fun isThreadRunStepInProgress(): Boolean = threadRunStepInProgress != null + + fun isThreadRunStepDelta(): Boolean = threadRunStepDelta != null + + fun isThreadRunStepCompleted(): Boolean = threadRunStepCompleted != null + + fun isThreadRunStepFailed(): Boolean = threadRunStepFailed != null + + fun isThreadRunStepCancelled(): Boolean = threadRunStepCancelled != null + + fun isThreadRunStepExpired(): Boolean = threadRunStepExpired != null + + fun isThreadMessageCreated(): Boolean = threadMessageCreated != null + + fun isThreadMessageInProgress(): Boolean = threadMessageInProgress != null + + fun isThreadMessageDelta(): Boolean = threadMessageDelta != null + + fun isThreadMessageCompleted(): Boolean = threadMessageCompleted != null + + fun isThreadMessageIncomplete(): Boolean = threadMessageIncomplete != null + + fun isErrorEvent(): Boolean = errorEvent != null + + /** + * Occurs when a new [thread](https://platform.openai.com/docs/api-reference/threads/object) is + * created. + */ + fun asThreadCreated(): ThreadCreated = threadCreated.getOrThrow("threadCreated") + /** + * Occurs when a new [run](https://platform.openai.com/docs/api-reference/runs/object) is + * created. + */ + fun asThreadRunCreated(): ThreadRunCreated = threadRunCreated.getOrThrow("threadRunCreated") + /** + * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object) moves to a + * `queued` status. + */ + fun asThreadRunQueued(): ThreadRunQueued = threadRunQueued.getOrThrow("threadRunQueued") + /** + * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object) moves to an + * `in_progress` status. + */ + fun asThreadRunInProgress(): ThreadRunInProgress = + threadRunInProgress.getOrThrow("threadRunInProgress") + /** + * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object) moves to a + * `requires_action` status. + */ + fun asThreadRunRequiresAction(): ThreadRunRequiresAction = + threadRunRequiresAction.getOrThrow("threadRunRequiresAction") + /** + * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object) is completed. + */ + fun asThreadRunCompleted(): ThreadRunCompleted = + threadRunCompleted.getOrThrow("threadRunCompleted") + /** + * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object) ends with + * status `incomplete`. + */ + fun asThreadRunIncomplete(): ThreadRunIncomplete = + threadRunIncomplete.getOrThrow("threadRunIncomplete") + /** Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object) fails. */ + fun asThreadRunFailed(): ThreadRunFailed = threadRunFailed.getOrThrow("threadRunFailed") + /** + * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object) moves to a + * `cancelling` status. + */ + fun asThreadRunCancelling(): ThreadRunCancelling = + threadRunCancelling.getOrThrow("threadRunCancelling") + /** + * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object) is cancelled. + */ + fun asThreadRunCancelled(): ThreadRunCancelled = + threadRunCancelled.getOrThrow("threadRunCancelled") + /** Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object) expires. */ + fun asThreadRunExpired(): ThreadRunExpired = threadRunExpired.getOrThrow("threadRunExpired") + /** + * Occurs when a + * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object) is created. + */ + fun asThreadRunStepCreated(): ThreadRunStepCreated = + threadRunStepCreated.getOrThrow("threadRunStepCreated") + /** + * Occurs when a + * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object) moves to an + * `in_progress` state. + */ + fun asThreadRunStepInProgress(): ThreadRunStepInProgress = + threadRunStepInProgress.getOrThrow("threadRunStepInProgress") + /** + * Occurs when parts of a + * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object) are being + * streamed. + */ + fun asThreadRunStepDelta(): ThreadRunStepDelta = + threadRunStepDelta.getOrThrow("threadRunStepDelta") + /** + * Occurs when a + * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object) is + * completed. + */ + fun asThreadRunStepCompleted(): ThreadRunStepCompleted = + threadRunStepCompleted.getOrThrow("threadRunStepCompleted") + /** + * Occurs when a + * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object) fails. + */ + fun asThreadRunStepFailed(): ThreadRunStepFailed = + threadRunStepFailed.getOrThrow("threadRunStepFailed") + /** + * Occurs when a + * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object) is + * cancelled. + */ + fun asThreadRunStepCancelled(): ThreadRunStepCancelled = + threadRunStepCancelled.getOrThrow("threadRunStepCancelled") + /** + * Occurs when a + * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object) expires. + */ + fun asThreadRunStepExpired(): ThreadRunStepExpired = + threadRunStepExpired.getOrThrow("threadRunStepExpired") + /** + * Occurs when a [message](https://platform.openai.com/docs/api-reference/messages/object) is + * created. + */ + fun asThreadMessageCreated(): ThreadMessageCreated = + threadMessageCreated.getOrThrow("threadMessageCreated") + /** + * Occurs when a [message](https://platform.openai.com/docs/api-reference/messages/object) moves + * to an `in_progress` state. + */ + fun asThreadMessageInProgress(): ThreadMessageInProgress = + threadMessageInProgress.getOrThrow("threadMessageInProgress") + /** + * Occurs when parts of a + * [Message](https://platform.openai.com/docs/api-reference/messages/object) are being streamed. + */ + fun asThreadMessageDelta(): ThreadMessageDelta = + threadMessageDelta.getOrThrow("threadMessageDelta") + /** + * Occurs when a [message](https://platform.openai.com/docs/api-reference/messages/object) is + * completed. + */ + fun asThreadMessageCompleted(): ThreadMessageCompleted = + threadMessageCompleted.getOrThrow("threadMessageCompleted") + /** + * Occurs when a [message](https://platform.openai.com/docs/api-reference/messages/object) ends + * before it is completed. + */ + fun asThreadMessageIncomplete(): ThreadMessageIncomplete = + threadMessageIncomplete.getOrThrow("threadMessageIncomplete") + /** + * Occurs when an [error](https://platform.openai.com/docs/guides/error-codes#api-errors) + * occurs. This can happen due to an internal server error or a timeout. + */ + fun asErrorEvent(): ErrorEvent = errorEvent.getOrThrow("errorEvent") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + threadCreated != null -> visitor.visitThreadCreated(threadCreated) + threadRunCreated != null -> visitor.visitThreadRunCreated(threadRunCreated) + threadRunQueued != null -> visitor.visitThreadRunQueued(threadRunQueued) + threadRunInProgress != null -> visitor.visitThreadRunInProgress(threadRunInProgress) + threadRunRequiresAction != null -> + visitor.visitThreadRunRequiresAction(threadRunRequiresAction) + threadRunCompleted != null -> visitor.visitThreadRunCompleted(threadRunCompleted) + threadRunIncomplete != null -> visitor.visitThreadRunIncomplete(threadRunIncomplete) + threadRunFailed != null -> visitor.visitThreadRunFailed(threadRunFailed) + threadRunCancelling != null -> visitor.visitThreadRunCancelling(threadRunCancelling) + threadRunCancelled != null -> visitor.visitThreadRunCancelled(threadRunCancelled) + threadRunExpired != null -> visitor.visitThreadRunExpired(threadRunExpired) + threadRunStepCreated != null -> visitor.visitThreadRunStepCreated(threadRunStepCreated) + threadRunStepInProgress != null -> + visitor.visitThreadRunStepInProgress(threadRunStepInProgress) + threadRunStepDelta != null -> visitor.visitThreadRunStepDelta(threadRunStepDelta) + threadRunStepCompleted != null -> + visitor.visitThreadRunStepCompleted(threadRunStepCompleted) + threadRunStepFailed != null -> visitor.visitThreadRunStepFailed(threadRunStepFailed) + threadRunStepCancelled != null -> + visitor.visitThreadRunStepCancelled(threadRunStepCancelled) + threadRunStepExpired != null -> visitor.visitThreadRunStepExpired(threadRunStepExpired) + threadMessageCreated != null -> visitor.visitThreadMessageCreated(threadMessageCreated) + threadMessageInProgress != null -> + visitor.visitThreadMessageInProgress(threadMessageInProgress) + threadMessageDelta != null -> visitor.visitThreadMessageDelta(threadMessageDelta) + threadMessageCompleted != null -> + visitor.visitThreadMessageCompleted(threadMessageCompleted) + threadMessageIncomplete != null -> + visitor.visitThreadMessageIncomplete(threadMessageIncomplete) + errorEvent != null -> visitor.visitErrorEvent(errorEvent) + else -> visitor.unknown(_json) + } + } + + fun validate(): AssistantStreamEvent = apply { + if (!validated) { + if ( + threadCreated == null && + threadRunCreated == null && + threadRunQueued == null && + threadRunInProgress == null && + threadRunRequiresAction == null && + threadRunCompleted == null && + threadRunIncomplete == null && + threadRunFailed == null && + threadRunCancelling == null && + threadRunCancelled == null && + threadRunExpired == null && + threadRunStepCreated == null && + threadRunStepInProgress == null && + threadRunStepDelta == null && + threadRunStepCompleted == null && + threadRunStepFailed == null && + threadRunStepCancelled == null && + threadRunStepExpired == null && + threadMessageCreated == null && + threadMessageInProgress == null && + threadMessageDelta == null && + threadMessageCompleted == null && + threadMessageIncomplete == null && + errorEvent == null + ) { + throw OpenAIInvalidDataException("Unknown AssistantStreamEvent: $_json") + } + threadCreated?.validate() + threadRunCreated?.validate() + threadRunQueued?.validate() + threadRunInProgress?.validate() + threadRunRequiresAction?.validate() + threadRunCompleted?.validate() + threadRunIncomplete?.validate() + threadRunFailed?.validate() + threadRunCancelling?.validate() + threadRunCancelled?.validate() + threadRunExpired?.validate() + threadRunStepCreated?.validate() + threadRunStepInProgress?.validate() + threadRunStepDelta?.validate() + threadRunStepCompleted?.validate() + threadRunStepFailed?.validate() + threadRunStepCancelled?.validate() + threadRunStepExpired?.validate() + threadMessageCreated?.validate() + threadMessageInProgress?.validate() + threadMessageDelta?.validate() + threadMessageCompleted?.validate() + threadMessageIncomplete?.validate() + errorEvent?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is AssistantStreamEvent && threadCreated == other.threadCreated && threadRunCreated == other.threadRunCreated && threadRunQueued == other.threadRunQueued && threadRunInProgress == other.threadRunInProgress && threadRunRequiresAction == other.threadRunRequiresAction && threadRunCompleted == other.threadRunCompleted && threadRunIncomplete == other.threadRunIncomplete && threadRunFailed == other.threadRunFailed && threadRunCancelling == other.threadRunCancelling && threadRunCancelled == other.threadRunCancelled && threadRunExpired == other.threadRunExpired && threadRunStepCreated == other.threadRunStepCreated && threadRunStepInProgress == other.threadRunStepInProgress && threadRunStepDelta == other.threadRunStepDelta && threadRunStepCompleted == other.threadRunStepCompleted && threadRunStepFailed == other.threadRunStepFailed && threadRunStepCancelled == other.threadRunStepCancelled && threadRunStepExpired == other.threadRunStepExpired && threadMessageCreated == other.threadMessageCreated && threadMessageInProgress == other.threadMessageInProgress && threadMessageDelta == other.threadMessageDelta && threadMessageCompleted == other.threadMessageCompleted && threadMessageIncomplete == other.threadMessageIncomplete && errorEvent == other.errorEvent /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(threadCreated, threadRunCreated, threadRunQueued, threadRunInProgress, threadRunRequiresAction, threadRunCompleted, threadRunIncomplete, threadRunFailed, threadRunCancelling, threadRunCancelled, threadRunExpired, threadRunStepCreated, threadRunStepInProgress, threadRunStepDelta, threadRunStepCompleted, threadRunStepFailed, threadRunStepCancelled, threadRunStepExpired, threadMessageCreated, threadMessageInProgress, threadMessageDelta, threadMessageCompleted, threadMessageIncomplete, errorEvent) /* spotless:on */ + + override fun toString(): String = + when { + threadCreated != null -> "AssistantStreamEvent{threadCreated=$threadCreated}" + threadRunCreated != null -> "AssistantStreamEvent{threadRunCreated=$threadRunCreated}" + threadRunQueued != null -> "AssistantStreamEvent{threadRunQueued=$threadRunQueued}" + threadRunInProgress != null -> + "AssistantStreamEvent{threadRunInProgress=$threadRunInProgress}" + threadRunRequiresAction != null -> + "AssistantStreamEvent{threadRunRequiresAction=$threadRunRequiresAction}" + threadRunCompleted != null -> + "AssistantStreamEvent{threadRunCompleted=$threadRunCompleted}" + threadRunIncomplete != null -> + "AssistantStreamEvent{threadRunIncomplete=$threadRunIncomplete}" + threadRunFailed != null -> "AssistantStreamEvent{threadRunFailed=$threadRunFailed}" + threadRunCancelling != null -> + "AssistantStreamEvent{threadRunCancelling=$threadRunCancelling}" + threadRunCancelled != null -> + "AssistantStreamEvent{threadRunCancelled=$threadRunCancelled}" + threadRunExpired != null -> "AssistantStreamEvent{threadRunExpired=$threadRunExpired}" + threadRunStepCreated != null -> + "AssistantStreamEvent{threadRunStepCreated=$threadRunStepCreated}" + threadRunStepInProgress != null -> + "AssistantStreamEvent{threadRunStepInProgress=$threadRunStepInProgress}" + threadRunStepDelta != null -> + "AssistantStreamEvent{threadRunStepDelta=$threadRunStepDelta}" + threadRunStepCompleted != null -> + "AssistantStreamEvent{threadRunStepCompleted=$threadRunStepCompleted}" + threadRunStepFailed != null -> + "AssistantStreamEvent{threadRunStepFailed=$threadRunStepFailed}" + threadRunStepCancelled != null -> + "AssistantStreamEvent{threadRunStepCancelled=$threadRunStepCancelled}" + threadRunStepExpired != null -> + "AssistantStreamEvent{threadRunStepExpired=$threadRunStepExpired}" + threadMessageCreated != null -> + "AssistantStreamEvent{threadMessageCreated=$threadMessageCreated}" + threadMessageInProgress != null -> + "AssistantStreamEvent{threadMessageInProgress=$threadMessageInProgress}" + threadMessageDelta != null -> + "AssistantStreamEvent{threadMessageDelta=$threadMessageDelta}" + threadMessageCompleted != null -> + "AssistantStreamEvent{threadMessageCompleted=$threadMessageCompleted}" + threadMessageIncomplete != null -> + "AssistantStreamEvent{threadMessageIncomplete=$threadMessageIncomplete}" + errorEvent != null -> "AssistantStreamEvent{errorEvent=$errorEvent}" + _json != null -> "AssistantStreamEvent{_unknown=$_json}" + else -> throw IllegalStateException("Invalid AssistantStreamEvent") + } + + companion object { + + /** + * Occurs when a new [thread](https://platform.openai.com/docs/api-reference/threads/object) + * is created. + */ + @JvmStatic + fun ofThreadCreated(threadCreated: ThreadCreated) = + AssistantStreamEvent(threadCreated = threadCreated) + + /** + * Occurs when a new [run](https://platform.openai.com/docs/api-reference/runs/object) is + * created. + */ + @JvmStatic + fun ofThreadRunCreated(threadRunCreated: ThreadRunCreated) = + AssistantStreamEvent(threadRunCreated = threadRunCreated) + + /** + * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object) moves to + * a `queued` status. + */ + @JvmStatic + fun ofThreadRunQueued(threadRunQueued: ThreadRunQueued) = + AssistantStreamEvent(threadRunQueued = threadRunQueued) + + /** + * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object) moves to + * an `in_progress` status. + */ + @JvmStatic + fun ofThreadRunInProgress(threadRunInProgress: ThreadRunInProgress) = + AssistantStreamEvent(threadRunInProgress = threadRunInProgress) + + /** + * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object) moves to + * a `requires_action` status. + */ + @JvmStatic + fun ofThreadRunRequiresAction(threadRunRequiresAction: ThreadRunRequiresAction) = + AssistantStreamEvent(threadRunRequiresAction = threadRunRequiresAction) + + /** + * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object) is + * completed. + */ + @JvmStatic + fun ofThreadRunCompleted(threadRunCompleted: ThreadRunCompleted) = + AssistantStreamEvent(threadRunCompleted = threadRunCompleted) + + /** + * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object) ends with + * status `incomplete`. + */ + @JvmStatic + fun ofThreadRunIncomplete(threadRunIncomplete: ThreadRunIncomplete) = + AssistantStreamEvent(threadRunIncomplete = threadRunIncomplete) + + /** + * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object) fails. + */ + @JvmStatic + fun ofThreadRunFailed(threadRunFailed: ThreadRunFailed) = + AssistantStreamEvent(threadRunFailed = threadRunFailed) + + /** + * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object) moves to + * a `cancelling` status. + */ + @JvmStatic + fun ofThreadRunCancelling(threadRunCancelling: ThreadRunCancelling) = + AssistantStreamEvent(threadRunCancelling = threadRunCancelling) + + /** + * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object) is + * cancelled. + */ + @JvmStatic + fun ofThreadRunCancelled(threadRunCancelled: ThreadRunCancelled) = + AssistantStreamEvent(threadRunCancelled = threadRunCancelled) + + /** + * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object) expires. + */ + @JvmStatic + fun ofThreadRunExpired(threadRunExpired: ThreadRunExpired) = + AssistantStreamEvent(threadRunExpired = threadRunExpired) + + /** + * Occurs when a + * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object) is + * created. + */ + @JvmStatic + fun ofThreadRunStepCreated(threadRunStepCreated: ThreadRunStepCreated) = + AssistantStreamEvent(threadRunStepCreated = threadRunStepCreated) + + /** + * Occurs when a + * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object) moves to + * an `in_progress` state. + */ + @JvmStatic + fun ofThreadRunStepInProgress(threadRunStepInProgress: ThreadRunStepInProgress) = + AssistantStreamEvent(threadRunStepInProgress = threadRunStepInProgress) + + /** + * Occurs when parts of a + * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object) are + * being streamed. + */ + @JvmStatic + fun ofThreadRunStepDelta(threadRunStepDelta: ThreadRunStepDelta) = + AssistantStreamEvent(threadRunStepDelta = threadRunStepDelta) + + /** + * Occurs when a + * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object) is + * completed. + */ + @JvmStatic + fun ofThreadRunStepCompleted(threadRunStepCompleted: ThreadRunStepCompleted) = + AssistantStreamEvent(threadRunStepCompleted = threadRunStepCompleted) + + /** + * Occurs when a + * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object) fails. + */ + @JvmStatic + fun ofThreadRunStepFailed(threadRunStepFailed: ThreadRunStepFailed) = + AssistantStreamEvent(threadRunStepFailed = threadRunStepFailed) + + /** + * Occurs when a + * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object) is + * cancelled. + */ + @JvmStatic + fun ofThreadRunStepCancelled(threadRunStepCancelled: ThreadRunStepCancelled) = + AssistantStreamEvent(threadRunStepCancelled = threadRunStepCancelled) + + /** + * Occurs when a + * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object) expires. + */ + @JvmStatic + fun ofThreadRunStepExpired(threadRunStepExpired: ThreadRunStepExpired) = + AssistantStreamEvent(threadRunStepExpired = threadRunStepExpired) + + /** + * Occurs when a [message](https://platform.openai.com/docs/api-reference/messages/object) + * is created. + */ + @JvmStatic + fun ofThreadMessageCreated(threadMessageCreated: ThreadMessageCreated) = + AssistantStreamEvent(threadMessageCreated = threadMessageCreated) + + /** + * Occurs when a [message](https://platform.openai.com/docs/api-reference/messages/object) + * moves to an `in_progress` state. + */ + @JvmStatic + fun ofThreadMessageInProgress(threadMessageInProgress: ThreadMessageInProgress) = + AssistantStreamEvent(threadMessageInProgress = threadMessageInProgress) + + /** + * Occurs when parts of a + * [Message](https://platform.openai.com/docs/api-reference/messages/object) are being + * streamed. + */ + @JvmStatic + fun ofThreadMessageDelta(threadMessageDelta: ThreadMessageDelta) = + AssistantStreamEvent(threadMessageDelta = threadMessageDelta) + + /** + * Occurs when a [message](https://platform.openai.com/docs/api-reference/messages/object) + * is completed. + */ + @JvmStatic + fun ofThreadMessageCompleted(threadMessageCompleted: ThreadMessageCompleted) = + AssistantStreamEvent(threadMessageCompleted = threadMessageCompleted) + + /** + * Occurs when a [message](https://platform.openai.com/docs/api-reference/messages/object) + * ends before it is completed. + */ + @JvmStatic + fun ofThreadMessageIncomplete(threadMessageIncomplete: ThreadMessageIncomplete) = + AssistantStreamEvent(threadMessageIncomplete = threadMessageIncomplete) + + /** + * Occurs when an [error](https://platform.openai.com/docs/guides/error-codes#api-errors) + * occurs. This can happen due to an internal server error or a timeout. + */ + @JvmStatic + fun ofErrorEvent(errorEvent: ErrorEvent) = AssistantStreamEvent(errorEvent = errorEvent) + } + + interface Visitor { + + fun visitThreadCreated(threadCreated: ThreadCreated): T + + fun visitThreadRunCreated(threadRunCreated: ThreadRunCreated): T + + fun visitThreadRunQueued(threadRunQueued: ThreadRunQueued): T + + fun visitThreadRunInProgress(threadRunInProgress: ThreadRunInProgress): T + + fun visitThreadRunRequiresAction(threadRunRequiresAction: ThreadRunRequiresAction): T + + fun visitThreadRunCompleted(threadRunCompleted: ThreadRunCompleted): T + + fun visitThreadRunIncomplete(threadRunIncomplete: ThreadRunIncomplete): T + + fun visitThreadRunFailed(threadRunFailed: ThreadRunFailed): T + + fun visitThreadRunCancelling(threadRunCancelling: ThreadRunCancelling): T + + fun visitThreadRunCancelled(threadRunCancelled: ThreadRunCancelled): T + + fun visitThreadRunExpired(threadRunExpired: ThreadRunExpired): T + + fun visitThreadRunStepCreated(threadRunStepCreated: ThreadRunStepCreated): T + + fun visitThreadRunStepInProgress(threadRunStepInProgress: ThreadRunStepInProgress): T + + fun visitThreadRunStepDelta(threadRunStepDelta: ThreadRunStepDelta): T + + fun visitThreadRunStepCompleted(threadRunStepCompleted: ThreadRunStepCompleted): T + + fun visitThreadRunStepFailed(threadRunStepFailed: ThreadRunStepFailed): T + + fun visitThreadRunStepCancelled(threadRunStepCancelled: ThreadRunStepCancelled): T + + fun visitThreadRunStepExpired(threadRunStepExpired: ThreadRunStepExpired): T + + fun visitThreadMessageCreated(threadMessageCreated: ThreadMessageCreated): T + + fun visitThreadMessageInProgress(threadMessageInProgress: ThreadMessageInProgress): T + + fun visitThreadMessageDelta(threadMessageDelta: ThreadMessageDelta): T + + fun visitThreadMessageCompleted(threadMessageCompleted: ThreadMessageCompleted): T + + fun visitThreadMessageIncomplete(threadMessageIncomplete: ThreadMessageIncomplete): T + + fun visitErrorEvent(errorEvent: ErrorEvent): T + + fun unknown(json: JsonValue?): T { + throw OpenAIInvalidDataException("Unknown AssistantStreamEvent: $json") + } + } + + class Deserializer : BaseDeserializer(AssistantStreamEvent::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): AssistantStreamEvent { + val json = JsonValue.fromJsonNode(node) + val event = json.asObject().getOrNull()?.get("event")?.asString()?.getOrNull() + + when (event) { + "thread.created" -> { + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return AssistantStreamEvent(threadCreated = it, _json = json) + } + } + "thread.run.created" -> { + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return AssistantStreamEvent(threadRunCreated = it, _json = json) + } + } + "thread.run.queued" -> { + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return AssistantStreamEvent(threadRunQueued = it, _json = json) + } + } + "thread.run.in_progress" -> { + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return AssistantStreamEvent(threadRunInProgress = it, _json = json) + } + } + "thread.run.requires_action" -> { + tryDeserialize(node, jacksonTypeRef()) { + it.validate() + } + ?.let { + return AssistantStreamEvent(threadRunRequiresAction = it, _json = json) + } + } + "thread.run.completed" -> { + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return AssistantStreamEvent(threadRunCompleted = it, _json = json) + } + } + "thread.run.incomplete" -> { + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return AssistantStreamEvent(threadRunIncomplete = it, _json = json) + } + } + "thread.run.failed" -> { + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return AssistantStreamEvent(threadRunFailed = it, _json = json) + } + } + "thread.run.cancelling" -> { + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return AssistantStreamEvent(threadRunCancelling = it, _json = json) + } + } + "thread.run.cancelled" -> { + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return AssistantStreamEvent(threadRunCancelled = it, _json = json) + } + } + "thread.run.expired" -> { + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return AssistantStreamEvent(threadRunExpired = it, _json = json) + } + } + "thread.run.step.created" -> { + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return AssistantStreamEvent(threadRunStepCreated = it, _json = json) + } + } + "thread.run.step.in_progress" -> { + tryDeserialize(node, jacksonTypeRef()) { + it.validate() + } + ?.let { + return AssistantStreamEvent(threadRunStepInProgress = it, _json = json) + } + } + "thread.run.step.delta" -> { + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return AssistantStreamEvent(threadRunStepDelta = it, _json = json) + } + } + "thread.run.step.completed" -> { + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return AssistantStreamEvent(threadRunStepCompleted = it, _json = json) + } + } + "thread.run.step.failed" -> { + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return AssistantStreamEvent(threadRunStepFailed = it, _json = json) + } + } + "thread.run.step.cancelled" -> { + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return AssistantStreamEvent(threadRunStepCancelled = it, _json = json) + } + } + "thread.run.step.expired" -> { + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return AssistantStreamEvent(threadRunStepExpired = it, _json = json) + } + } + "thread.message.created" -> { + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return AssistantStreamEvent(threadMessageCreated = it, _json = json) + } + } + "thread.message.in_progress" -> { + tryDeserialize(node, jacksonTypeRef()) { + it.validate() + } + ?.let { + return AssistantStreamEvent(threadMessageInProgress = it, _json = json) + } + } + "thread.message.delta" -> { + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return AssistantStreamEvent(threadMessageDelta = it, _json = json) + } + } + "thread.message.completed" -> { + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return AssistantStreamEvent(threadMessageCompleted = it, _json = json) + } + } + "thread.message.incomplete" -> { + tryDeserialize(node, jacksonTypeRef()) { + it.validate() + } + ?.let { + return AssistantStreamEvent(threadMessageIncomplete = it, _json = json) + } + } + "error" -> { + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return AssistantStreamEvent(errorEvent = it, _json = json) + } + } + } + + return AssistantStreamEvent(_json = json) + } + } + + class Serializer : BaseSerializer(AssistantStreamEvent::class) { + + override fun serialize( + value: AssistantStreamEvent, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.threadCreated != null -> generator.writeObject(value.threadCreated) + value.threadRunCreated != null -> generator.writeObject(value.threadRunCreated) + value.threadRunQueued != null -> generator.writeObject(value.threadRunQueued) + value.threadRunInProgress != null -> + generator.writeObject(value.threadRunInProgress) + value.threadRunRequiresAction != null -> + generator.writeObject(value.threadRunRequiresAction) + value.threadRunCompleted != null -> generator.writeObject(value.threadRunCompleted) + value.threadRunIncomplete != null -> + generator.writeObject(value.threadRunIncomplete) + value.threadRunFailed != null -> generator.writeObject(value.threadRunFailed) + value.threadRunCancelling != null -> + generator.writeObject(value.threadRunCancelling) + value.threadRunCancelled != null -> generator.writeObject(value.threadRunCancelled) + value.threadRunExpired != null -> generator.writeObject(value.threadRunExpired) + value.threadRunStepCreated != null -> + generator.writeObject(value.threadRunStepCreated) + value.threadRunStepInProgress != null -> + generator.writeObject(value.threadRunStepInProgress) + value.threadRunStepDelta != null -> generator.writeObject(value.threadRunStepDelta) + value.threadRunStepCompleted != null -> + generator.writeObject(value.threadRunStepCompleted) + value.threadRunStepFailed != null -> + generator.writeObject(value.threadRunStepFailed) + value.threadRunStepCancelled != null -> + generator.writeObject(value.threadRunStepCancelled) + value.threadRunStepExpired != null -> + generator.writeObject(value.threadRunStepExpired) + value.threadMessageCreated != null -> + generator.writeObject(value.threadMessageCreated) + value.threadMessageInProgress != null -> + generator.writeObject(value.threadMessageInProgress) + value.threadMessageDelta != null -> generator.writeObject(value.threadMessageDelta) + value.threadMessageCompleted != null -> + generator.writeObject(value.threadMessageCompleted) + value.threadMessageIncomplete != null -> + generator.writeObject(value.threadMessageIncomplete) + value.errorEvent != null -> generator.writeObject(value.errorEvent) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid AssistantStreamEvent") + } + } + } + + /** + * Occurs when a new [thread](https://platform.openai.com/docs/api-reference/threads/object) is + * created. + */ + @NoAutoDetect + class ThreadCreated + @JsonCreator + private constructor( + @JsonProperty("enabled") + @ExcludeMissing + private val enabled: JsonField = JsonMissing.of(), + @JsonProperty("event") + @ExcludeMissing + private val event: JsonField = JsonMissing.of(), + @JsonProperty("data") + @ExcludeMissing + private val data: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** Whether to enable input audio transcription. */ + fun enabled(): Optional = Optional.ofNullable(enabled.getNullable("enabled")) + + fun event(): Event = event.getRequired("event") + + /** + * Represents a thread that contains + * [messages](https://platform.openai.com/docs/api-reference/messages). + */ + fun data(): Thread = data.getRequired("data") + + /** Whether to enable input audio transcription. */ + @JsonProperty("enabled") @ExcludeMissing fun _enabled() = enabled + + @JsonProperty("event") @ExcludeMissing fun _event() = event + + /** + * Represents a thread that contains + * [messages](https://platform.openai.com/docs/api-reference/messages). + */ + @JsonProperty("data") @ExcludeMissing fun _data() = data + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + private var validated: Boolean = false + + fun validate(): ThreadCreated = apply { + if (!validated) { + enabled() + event() + data().validate() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var enabled: JsonField = JsonMissing.of() + private var event: JsonField = JsonMissing.of() + private var data: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(threadCreated: ThreadCreated) = apply { + enabled = threadCreated.enabled + event = threadCreated.event + data = threadCreated.data + additionalProperties = threadCreated.additionalProperties.toMutableMap() + } + + /** Whether to enable input audio transcription. */ + fun enabled(enabled: Boolean) = enabled(JsonField.of(enabled)) + + /** Whether to enable input audio transcription. */ + fun enabled(enabled: JsonField) = apply { this.enabled = enabled } + + fun event(event: Event) = event(JsonField.of(event)) + + fun event(event: JsonField) = apply { this.event = event } + + /** + * Represents a thread that contains + * [messages](https://platform.openai.com/docs/api-reference/messages). + */ + fun data(data: Thread) = data(JsonField.of(data)) + + /** + * Represents a thread that contains + * [messages](https://platform.openai.com/docs/api-reference/messages). + */ + fun data(data: JsonField) = apply { this.data = data } + + 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) + } + + fun build(): ThreadCreated = + ThreadCreated( + enabled, + event, + data, + additionalProperties.toImmutable(), + ) + } + + class Event + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val THREAD_CREATED = of("thread.created") + + @JvmStatic fun of(value: String) = Event(JsonField.of(value)) + } + + enum class Known { + THREAD_CREATED, + } + + enum class Value { + THREAD_CREATED, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + THREAD_CREATED -> Value.THREAD_CREATED + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + THREAD_CREATED -> Known.THREAD_CREATED + else -> throw OpenAIInvalidDataException("Unknown Event: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Event && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ThreadCreated && enabled == other.enabled && event == other.event && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(enabled, event, data, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ThreadCreated{enabled=$enabled, event=$event, data=$data, additionalProperties=$additionalProperties}" + } + + /** + * Occurs when a new [run](https://platform.openai.com/docs/api-reference/runs/object) is + * created. + */ + @NoAutoDetect + class ThreadRunCreated + @JsonCreator + private constructor( + @JsonProperty("event") + @ExcludeMissing + private val event: JsonField = JsonMissing.of(), + @JsonProperty("data") @ExcludeMissing private val data: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + fun event(): Event = event.getRequired("event") + + /** + * Represents an execution run on a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + fun data(): Run = data.getRequired("data") + + @JsonProperty("event") @ExcludeMissing fun _event() = event + + /** + * Represents an execution run on a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + @JsonProperty("data") @ExcludeMissing fun _data() = data + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + private var validated: Boolean = false + + fun validate(): ThreadRunCreated = apply { + if (!validated) { + event() + data().validate() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var event: JsonField = JsonMissing.of() + private var data: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(threadRunCreated: ThreadRunCreated) = apply { + event = threadRunCreated.event + data = threadRunCreated.data + additionalProperties = threadRunCreated.additionalProperties.toMutableMap() + } + + fun event(event: Event) = event(JsonField.of(event)) + + fun event(event: JsonField) = apply { this.event = event } + + /** + * Represents an execution run on a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + fun data(data: Run) = data(JsonField.of(data)) + + /** + * Represents an execution run on a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + fun data(data: JsonField) = apply { this.data = data } + + 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) + } + + fun build(): ThreadRunCreated = + ThreadRunCreated( + event, + data, + additionalProperties.toImmutable(), + ) + } + + class Event + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val THREAD_RUN_CREATED = of("thread.run.created") + + @JvmStatic fun of(value: String) = Event(JsonField.of(value)) + } + + enum class Known { + THREAD_RUN_CREATED, + } + + enum class Value { + THREAD_RUN_CREATED, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + THREAD_RUN_CREATED -> Value.THREAD_RUN_CREATED + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + THREAD_RUN_CREATED -> Known.THREAD_RUN_CREATED + else -> throw OpenAIInvalidDataException("Unknown Event: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Event && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ThreadRunCreated && event == other.event && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(event, data, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ThreadRunCreated{event=$event, data=$data, additionalProperties=$additionalProperties}" + } + + /** + * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object) moves to a + * `queued` status. + */ + @NoAutoDetect + class ThreadRunQueued + @JsonCreator + private constructor( + @JsonProperty("event") + @ExcludeMissing + private val event: JsonField = JsonMissing.of(), + @JsonProperty("data") @ExcludeMissing private val data: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + fun event(): Event = event.getRequired("event") + + /** + * Represents an execution run on a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + fun data(): Run = data.getRequired("data") + + @JsonProperty("event") @ExcludeMissing fun _event() = event + + /** + * Represents an execution run on a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + @JsonProperty("data") @ExcludeMissing fun _data() = data + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + private var validated: Boolean = false + + fun validate(): ThreadRunQueued = apply { + if (!validated) { + event() + data().validate() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var event: JsonField = JsonMissing.of() + private var data: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(threadRunQueued: ThreadRunQueued) = apply { + event = threadRunQueued.event + data = threadRunQueued.data + additionalProperties = threadRunQueued.additionalProperties.toMutableMap() + } + + fun event(event: Event) = event(JsonField.of(event)) + + fun event(event: JsonField) = apply { this.event = event } + + /** + * Represents an execution run on a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + fun data(data: Run) = data(JsonField.of(data)) + + /** + * Represents an execution run on a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + fun data(data: JsonField) = apply { this.data = data } + + 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) + } + + fun build(): ThreadRunQueued = + ThreadRunQueued( + event, + data, + additionalProperties.toImmutable(), + ) + } + + class Event + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val THREAD_RUN_QUEUED = of("thread.run.queued") + + @JvmStatic fun of(value: String) = Event(JsonField.of(value)) + } + + enum class Known { + THREAD_RUN_QUEUED, + } + + enum class Value { + THREAD_RUN_QUEUED, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + THREAD_RUN_QUEUED -> Value.THREAD_RUN_QUEUED + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + THREAD_RUN_QUEUED -> Known.THREAD_RUN_QUEUED + else -> throw OpenAIInvalidDataException("Unknown Event: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Event && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ThreadRunQueued && event == other.event && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(event, data, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ThreadRunQueued{event=$event, data=$data, additionalProperties=$additionalProperties}" + } + + /** + * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object) moves to an + * `in_progress` status. + */ + @NoAutoDetect + class ThreadRunInProgress + @JsonCreator + private constructor( + @JsonProperty("event") + @ExcludeMissing + private val event: JsonField = JsonMissing.of(), + @JsonProperty("data") @ExcludeMissing private val data: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + fun event(): Event = event.getRequired("event") + + /** + * Represents an execution run on a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + fun data(): Run = data.getRequired("data") + + @JsonProperty("event") @ExcludeMissing fun _event() = event + + /** + * Represents an execution run on a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + @JsonProperty("data") @ExcludeMissing fun _data() = data + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + private var validated: Boolean = false + + fun validate(): ThreadRunInProgress = apply { + if (!validated) { + event() + data().validate() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var event: JsonField = JsonMissing.of() + private var data: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(threadRunInProgress: ThreadRunInProgress) = apply { + event = threadRunInProgress.event + data = threadRunInProgress.data + additionalProperties = threadRunInProgress.additionalProperties.toMutableMap() + } + + fun event(event: Event) = event(JsonField.of(event)) + + fun event(event: JsonField) = apply { this.event = event } + + /** + * Represents an execution run on a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + fun data(data: Run) = data(JsonField.of(data)) + + /** + * Represents an execution run on a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + fun data(data: JsonField) = apply { this.data = data } + + 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) + } + + fun build(): ThreadRunInProgress = + ThreadRunInProgress( + event, + data, + additionalProperties.toImmutable(), + ) + } + + class Event + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val THREAD_RUN_IN_PROGRESS = of("thread.run.in_progress") + + @JvmStatic fun of(value: String) = Event(JsonField.of(value)) + } + + enum class Known { + THREAD_RUN_IN_PROGRESS, + } + + enum class Value { + THREAD_RUN_IN_PROGRESS, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + THREAD_RUN_IN_PROGRESS -> Value.THREAD_RUN_IN_PROGRESS + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + THREAD_RUN_IN_PROGRESS -> Known.THREAD_RUN_IN_PROGRESS + else -> throw OpenAIInvalidDataException("Unknown Event: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Event && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ThreadRunInProgress && event == other.event && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(event, data, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ThreadRunInProgress{event=$event, data=$data, additionalProperties=$additionalProperties}" + } + + /** + * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object) moves to a + * `requires_action` status. + */ + @NoAutoDetect + class ThreadRunRequiresAction + @JsonCreator + private constructor( + @JsonProperty("event") + @ExcludeMissing + private val event: JsonField = JsonMissing.of(), + @JsonProperty("data") @ExcludeMissing private val data: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + fun event(): Event = event.getRequired("event") + + /** + * Represents an execution run on a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + fun data(): Run = data.getRequired("data") + + @JsonProperty("event") @ExcludeMissing fun _event() = event + + /** + * Represents an execution run on a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + @JsonProperty("data") @ExcludeMissing fun _data() = data + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + private var validated: Boolean = false + + fun validate(): ThreadRunRequiresAction = apply { + if (!validated) { + event() + data().validate() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var event: JsonField = JsonMissing.of() + private var data: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(threadRunRequiresAction: ThreadRunRequiresAction) = apply { + event = threadRunRequiresAction.event + data = threadRunRequiresAction.data + additionalProperties = threadRunRequiresAction.additionalProperties.toMutableMap() + } + + fun event(event: Event) = event(JsonField.of(event)) + + fun event(event: JsonField) = apply { this.event = event } + + /** + * Represents an execution run on a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + fun data(data: Run) = data(JsonField.of(data)) + + /** + * Represents an execution run on a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + fun data(data: JsonField) = apply { this.data = data } + + 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) + } + + fun build(): ThreadRunRequiresAction = + ThreadRunRequiresAction( + event, + data, + additionalProperties.toImmutable(), + ) + } + + class Event + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val THREAD_RUN_REQUIRES_ACTION = of("thread.run.requires_action") + + @JvmStatic fun of(value: String) = Event(JsonField.of(value)) + } + + enum class Known { + THREAD_RUN_REQUIRES_ACTION, + } + + enum class Value { + THREAD_RUN_REQUIRES_ACTION, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + THREAD_RUN_REQUIRES_ACTION -> Value.THREAD_RUN_REQUIRES_ACTION + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + THREAD_RUN_REQUIRES_ACTION -> Known.THREAD_RUN_REQUIRES_ACTION + else -> throw OpenAIInvalidDataException("Unknown Event: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Event && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ThreadRunRequiresAction && event == other.event && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(event, data, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ThreadRunRequiresAction{event=$event, data=$data, additionalProperties=$additionalProperties}" + } + + /** + * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object) is completed. + */ + @NoAutoDetect + class ThreadRunCompleted + @JsonCreator + private constructor( + @JsonProperty("event") + @ExcludeMissing + private val event: JsonField = JsonMissing.of(), + @JsonProperty("data") @ExcludeMissing private val data: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + fun event(): Event = event.getRequired("event") + + /** + * Represents an execution run on a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + fun data(): Run = data.getRequired("data") + + @JsonProperty("event") @ExcludeMissing fun _event() = event + + /** + * Represents an execution run on a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + @JsonProperty("data") @ExcludeMissing fun _data() = data + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + private var validated: Boolean = false + + fun validate(): ThreadRunCompleted = apply { + if (!validated) { + event() + data().validate() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var event: JsonField = JsonMissing.of() + private var data: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(threadRunCompleted: ThreadRunCompleted) = apply { + event = threadRunCompleted.event + data = threadRunCompleted.data + additionalProperties = threadRunCompleted.additionalProperties.toMutableMap() + } + + fun event(event: Event) = event(JsonField.of(event)) + + fun event(event: JsonField) = apply { this.event = event } + + /** + * Represents an execution run on a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + fun data(data: Run) = data(JsonField.of(data)) + + /** + * Represents an execution run on a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + fun data(data: JsonField) = apply { this.data = data } + + 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) + } + + fun build(): ThreadRunCompleted = + ThreadRunCompleted( + event, + data, + additionalProperties.toImmutable(), + ) + } + + class Event + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val THREAD_RUN_COMPLETED = of("thread.run.completed") + + @JvmStatic fun of(value: String) = Event(JsonField.of(value)) + } + + enum class Known { + THREAD_RUN_COMPLETED, + } + + enum class Value { + THREAD_RUN_COMPLETED, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + THREAD_RUN_COMPLETED -> Value.THREAD_RUN_COMPLETED + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + THREAD_RUN_COMPLETED -> Known.THREAD_RUN_COMPLETED + else -> throw OpenAIInvalidDataException("Unknown Event: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Event && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ThreadRunCompleted && event == other.event && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(event, data, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ThreadRunCompleted{event=$event, data=$data, additionalProperties=$additionalProperties}" + } + + /** + * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object) ends with + * status `incomplete`. + */ + @NoAutoDetect + class ThreadRunIncomplete + @JsonCreator + private constructor( + @JsonProperty("event") + @ExcludeMissing + private val event: JsonField = JsonMissing.of(), + @JsonProperty("data") @ExcludeMissing private val data: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + fun event(): Event = event.getRequired("event") + + /** + * Represents an execution run on a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + fun data(): Run = data.getRequired("data") + + @JsonProperty("event") @ExcludeMissing fun _event() = event + + /** + * Represents an execution run on a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + @JsonProperty("data") @ExcludeMissing fun _data() = data + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + private var validated: Boolean = false + + fun validate(): ThreadRunIncomplete = apply { + if (!validated) { + event() + data().validate() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var event: JsonField = JsonMissing.of() + private var data: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(threadRunIncomplete: ThreadRunIncomplete) = apply { + event = threadRunIncomplete.event + data = threadRunIncomplete.data + additionalProperties = threadRunIncomplete.additionalProperties.toMutableMap() + } + + fun event(event: Event) = event(JsonField.of(event)) + + fun event(event: JsonField) = apply { this.event = event } + + /** + * Represents an execution run on a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + fun data(data: Run) = data(JsonField.of(data)) + + /** + * Represents an execution run on a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + fun data(data: JsonField) = apply { this.data = data } + + 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) + } + + fun build(): ThreadRunIncomplete = + ThreadRunIncomplete( + event, + data, + additionalProperties.toImmutable(), + ) + } + + class Event + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val THREAD_RUN_INCOMPLETE = of("thread.run.incomplete") + + @JvmStatic fun of(value: String) = Event(JsonField.of(value)) + } + + enum class Known { + THREAD_RUN_INCOMPLETE, + } + + enum class Value { + THREAD_RUN_INCOMPLETE, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + THREAD_RUN_INCOMPLETE -> Value.THREAD_RUN_INCOMPLETE + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + THREAD_RUN_INCOMPLETE -> Known.THREAD_RUN_INCOMPLETE + else -> throw OpenAIInvalidDataException("Unknown Event: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Event && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ThreadRunIncomplete && event == other.event && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(event, data, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ThreadRunIncomplete{event=$event, data=$data, additionalProperties=$additionalProperties}" + } + + /** Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object) fails. */ + @NoAutoDetect + class ThreadRunFailed + @JsonCreator + private constructor( + @JsonProperty("event") + @ExcludeMissing + private val event: JsonField = JsonMissing.of(), + @JsonProperty("data") @ExcludeMissing private val data: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + fun event(): Event = event.getRequired("event") + + /** + * Represents an execution run on a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + fun data(): Run = data.getRequired("data") + + @JsonProperty("event") @ExcludeMissing fun _event() = event + + /** + * Represents an execution run on a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + @JsonProperty("data") @ExcludeMissing fun _data() = data + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + private var validated: Boolean = false + + fun validate(): ThreadRunFailed = apply { + if (!validated) { + event() + data().validate() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var event: JsonField = JsonMissing.of() + private var data: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(threadRunFailed: ThreadRunFailed) = apply { + event = threadRunFailed.event + data = threadRunFailed.data + additionalProperties = threadRunFailed.additionalProperties.toMutableMap() + } + + fun event(event: Event) = event(JsonField.of(event)) + + fun event(event: JsonField) = apply { this.event = event } + + /** + * Represents an execution run on a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + fun data(data: Run) = data(JsonField.of(data)) + + /** + * Represents an execution run on a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + fun data(data: JsonField) = apply { this.data = data } + + 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) + } + + fun build(): ThreadRunFailed = + ThreadRunFailed( + event, + data, + additionalProperties.toImmutable(), + ) + } + + class Event + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val THREAD_RUN_FAILED = of("thread.run.failed") + + @JvmStatic fun of(value: String) = Event(JsonField.of(value)) + } + + enum class Known { + THREAD_RUN_FAILED, + } + + enum class Value { + THREAD_RUN_FAILED, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + THREAD_RUN_FAILED -> Value.THREAD_RUN_FAILED + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + THREAD_RUN_FAILED -> Known.THREAD_RUN_FAILED + else -> throw OpenAIInvalidDataException("Unknown Event: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Event && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ThreadRunFailed && event == other.event && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(event, data, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ThreadRunFailed{event=$event, data=$data, additionalProperties=$additionalProperties}" + } + + /** + * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object) moves to a + * `cancelling` status. + */ + @NoAutoDetect + class ThreadRunCancelling + @JsonCreator + private constructor( + @JsonProperty("event") + @ExcludeMissing + private val event: JsonField = JsonMissing.of(), + @JsonProperty("data") @ExcludeMissing private val data: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + fun event(): Event = event.getRequired("event") + + /** + * Represents an execution run on a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + fun data(): Run = data.getRequired("data") + + @JsonProperty("event") @ExcludeMissing fun _event() = event + + /** + * Represents an execution run on a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + @JsonProperty("data") @ExcludeMissing fun _data() = data + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + private var validated: Boolean = false + + fun validate(): ThreadRunCancelling = apply { + if (!validated) { + event() + data().validate() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var event: JsonField = JsonMissing.of() + private var data: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(threadRunCancelling: ThreadRunCancelling) = apply { + event = threadRunCancelling.event + data = threadRunCancelling.data + additionalProperties = threadRunCancelling.additionalProperties.toMutableMap() + } + + fun event(event: Event) = event(JsonField.of(event)) + + fun event(event: JsonField) = apply { this.event = event } + + /** + * Represents an execution run on a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + fun data(data: Run) = data(JsonField.of(data)) + + /** + * Represents an execution run on a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + fun data(data: JsonField) = apply { this.data = data } + + 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) + } + + fun build(): ThreadRunCancelling = + ThreadRunCancelling( + event, + data, + additionalProperties.toImmutable(), + ) + } + + class Event + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val THREAD_RUN_CANCELLING = of("thread.run.cancelling") + + @JvmStatic fun of(value: String) = Event(JsonField.of(value)) + } + + enum class Known { + THREAD_RUN_CANCELLING, + } + + enum class Value { + THREAD_RUN_CANCELLING, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + THREAD_RUN_CANCELLING -> Value.THREAD_RUN_CANCELLING + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + THREAD_RUN_CANCELLING -> Known.THREAD_RUN_CANCELLING + else -> throw OpenAIInvalidDataException("Unknown Event: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Event && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ThreadRunCancelling && event == other.event && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(event, data, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ThreadRunCancelling{event=$event, data=$data, additionalProperties=$additionalProperties}" + } + + /** + * Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object) is cancelled. + */ + @NoAutoDetect + class ThreadRunCancelled + @JsonCreator + private constructor( + @JsonProperty("event") + @ExcludeMissing + private val event: JsonField = JsonMissing.of(), + @JsonProperty("data") @ExcludeMissing private val data: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + fun event(): Event = event.getRequired("event") + + /** + * Represents an execution run on a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + fun data(): Run = data.getRequired("data") + + @JsonProperty("event") @ExcludeMissing fun _event() = event + + /** + * Represents an execution run on a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + @JsonProperty("data") @ExcludeMissing fun _data() = data + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + private var validated: Boolean = false + + fun validate(): ThreadRunCancelled = apply { + if (!validated) { + event() + data().validate() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var event: JsonField = JsonMissing.of() + private var data: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(threadRunCancelled: ThreadRunCancelled) = apply { + event = threadRunCancelled.event + data = threadRunCancelled.data + additionalProperties = threadRunCancelled.additionalProperties.toMutableMap() + } + + fun event(event: Event) = event(JsonField.of(event)) + + fun event(event: JsonField) = apply { this.event = event } + + /** + * Represents an execution run on a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + fun data(data: Run) = data(JsonField.of(data)) + + /** + * Represents an execution run on a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + fun data(data: JsonField) = apply { this.data = data } + + 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) + } + + fun build(): ThreadRunCancelled = + ThreadRunCancelled( + event, + data, + additionalProperties.toImmutable(), + ) + } + + class Event + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val THREAD_RUN_CANCELLED = of("thread.run.cancelled") + + @JvmStatic fun of(value: String) = Event(JsonField.of(value)) + } + + enum class Known { + THREAD_RUN_CANCELLED, + } + + enum class Value { + THREAD_RUN_CANCELLED, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + THREAD_RUN_CANCELLED -> Value.THREAD_RUN_CANCELLED + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + THREAD_RUN_CANCELLED -> Known.THREAD_RUN_CANCELLED + else -> throw OpenAIInvalidDataException("Unknown Event: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Event && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ThreadRunCancelled && event == other.event && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(event, data, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ThreadRunCancelled{event=$event, data=$data, additionalProperties=$additionalProperties}" + } + + /** Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object) expires. */ + @NoAutoDetect + class ThreadRunExpired + @JsonCreator + private constructor( + @JsonProperty("event") + @ExcludeMissing + private val event: JsonField = JsonMissing.of(), + @JsonProperty("data") @ExcludeMissing private val data: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + fun event(): Event = event.getRequired("event") + + /** + * Represents an execution run on a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + fun data(): Run = data.getRequired("data") + + @JsonProperty("event") @ExcludeMissing fun _event() = event + + /** + * Represents an execution run on a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + @JsonProperty("data") @ExcludeMissing fun _data() = data + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + private var validated: Boolean = false + + fun validate(): ThreadRunExpired = apply { + if (!validated) { + event() + data().validate() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var event: JsonField = JsonMissing.of() + private var data: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(threadRunExpired: ThreadRunExpired) = apply { + event = threadRunExpired.event + data = threadRunExpired.data + additionalProperties = threadRunExpired.additionalProperties.toMutableMap() + } + + fun event(event: Event) = event(JsonField.of(event)) + + fun event(event: JsonField) = apply { this.event = event } + + /** + * Represents an execution run on a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + fun data(data: Run) = data(JsonField.of(data)) + + /** + * Represents an execution run on a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + fun data(data: JsonField) = apply { this.data = data } + + 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) + } + + fun build(): ThreadRunExpired = + ThreadRunExpired( + event, + data, + additionalProperties.toImmutable(), + ) + } + + class Event + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val THREAD_RUN_EXPIRED = of("thread.run.expired") + + @JvmStatic fun of(value: String) = Event(JsonField.of(value)) + } + + enum class Known { + THREAD_RUN_EXPIRED, + } + + enum class Value { + THREAD_RUN_EXPIRED, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + THREAD_RUN_EXPIRED -> Value.THREAD_RUN_EXPIRED + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + THREAD_RUN_EXPIRED -> Known.THREAD_RUN_EXPIRED + else -> throw OpenAIInvalidDataException("Unknown Event: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Event && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ThreadRunExpired && event == other.event && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(event, data, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ThreadRunExpired{event=$event, data=$data, additionalProperties=$additionalProperties}" + } + + /** + * Occurs when a + * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object) is created. + */ + @NoAutoDetect + class ThreadRunStepCreated + @JsonCreator + private constructor( + @JsonProperty("event") + @ExcludeMissing + private val event: JsonField = JsonMissing.of(), + @JsonProperty("data") + @ExcludeMissing + private val data: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + fun event(): Event = event.getRequired("event") + + /** Represents a step in execution of a run. */ + fun data(): RunStep = data.getRequired("data") + + @JsonProperty("event") @ExcludeMissing fun _event() = event + + /** Represents a step in execution of a run. */ + @JsonProperty("data") @ExcludeMissing fun _data() = data + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + private var validated: Boolean = false + + fun validate(): ThreadRunStepCreated = apply { + if (!validated) { + event() + data().validate() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var event: JsonField = JsonMissing.of() + private var data: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(threadRunStepCreated: ThreadRunStepCreated) = apply { + event = threadRunStepCreated.event + data = threadRunStepCreated.data + additionalProperties = threadRunStepCreated.additionalProperties.toMutableMap() + } + + fun event(event: Event) = event(JsonField.of(event)) + + fun event(event: JsonField) = apply { this.event = event } + + /** Represents a step in execution of a run. */ + fun data(data: RunStep) = data(JsonField.of(data)) + + /** Represents a step in execution of a run. */ + fun data(data: JsonField) = apply { this.data = data } + + 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) + } + + fun build(): ThreadRunStepCreated = + ThreadRunStepCreated( + event, + data, + additionalProperties.toImmutable(), + ) + } + + class Event + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val THREAD_RUN_STEP_CREATED = of("thread.run.step.created") + + @JvmStatic fun of(value: String) = Event(JsonField.of(value)) + } + + enum class Known { + THREAD_RUN_STEP_CREATED, + } + + enum class Value { + THREAD_RUN_STEP_CREATED, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + THREAD_RUN_STEP_CREATED -> Value.THREAD_RUN_STEP_CREATED + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + THREAD_RUN_STEP_CREATED -> Known.THREAD_RUN_STEP_CREATED + else -> throw OpenAIInvalidDataException("Unknown Event: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Event && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ThreadRunStepCreated && event == other.event && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(event, data, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ThreadRunStepCreated{event=$event, data=$data, additionalProperties=$additionalProperties}" + } + + /** + * Occurs when a + * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object) moves to an + * `in_progress` state. + */ + @NoAutoDetect + class ThreadRunStepInProgress + @JsonCreator + private constructor( + @JsonProperty("event") + @ExcludeMissing + private val event: JsonField = JsonMissing.of(), + @JsonProperty("data") + @ExcludeMissing + private val data: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + fun event(): Event = event.getRequired("event") + + /** Represents a step in execution of a run. */ + fun data(): RunStep = data.getRequired("data") + + @JsonProperty("event") @ExcludeMissing fun _event() = event + + /** Represents a step in execution of a run. */ + @JsonProperty("data") @ExcludeMissing fun _data() = data + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + private var validated: Boolean = false + + fun validate(): ThreadRunStepInProgress = apply { + if (!validated) { + event() + data().validate() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var event: JsonField = JsonMissing.of() + private var data: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(threadRunStepInProgress: ThreadRunStepInProgress) = apply { + event = threadRunStepInProgress.event + data = threadRunStepInProgress.data + additionalProperties = threadRunStepInProgress.additionalProperties.toMutableMap() + } + + fun event(event: Event) = event(JsonField.of(event)) + + fun event(event: JsonField) = apply { this.event = event } + + /** Represents a step in execution of a run. */ + fun data(data: RunStep) = data(JsonField.of(data)) + + /** Represents a step in execution of a run. */ + fun data(data: JsonField) = apply { this.data = data } + + 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) + } + + fun build(): ThreadRunStepInProgress = + ThreadRunStepInProgress( + event, + data, + additionalProperties.toImmutable(), + ) + } + + class Event + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val THREAD_RUN_STEP_IN_PROGRESS = of("thread.run.step.in_progress") + + @JvmStatic fun of(value: String) = Event(JsonField.of(value)) + } + + enum class Known { + THREAD_RUN_STEP_IN_PROGRESS, + } + + enum class Value { + THREAD_RUN_STEP_IN_PROGRESS, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + THREAD_RUN_STEP_IN_PROGRESS -> Value.THREAD_RUN_STEP_IN_PROGRESS + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + THREAD_RUN_STEP_IN_PROGRESS -> Known.THREAD_RUN_STEP_IN_PROGRESS + else -> throw OpenAIInvalidDataException("Unknown Event: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Event && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ThreadRunStepInProgress && event == other.event && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(event, data, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ThreadRunStepInProgress{event=$event, data=$data, additionalProperties=$additionalProperties}" + } + + /** + * Occurs when parts of a + * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object) are being + * streamed. + */ + @NoAutoDetect + class ThreadRunStepDelta + @JsonCreator + private constructor( + @JsonProperty("event") + @ExcludeMissing + private val event: JsonField = JsonMissing.of(), + @JsonProperty("data") + @ExcludeMissing + private val data: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + fun event(): Event = event.getRequired("event") + + /** Represents a run step delta i.e. any changed fields on a run step during streaming. */ + fun data(): RunStepDeltaEvent = data.getRequired("data") + + @JsonProperty("event") @ExcludeMissing fun _event() = event + + /** Represents a run step delta i.e. any changed fields on a run step during streaming. */ + @JsonProperty("data") @ExcludeMissing fun _data() = data + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + private var validated: Boolean = false + + fun validate(): ThreadRunStepDelta = apply { + if (!validated) { + event() + data().validate() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var event: JsonField = JsonMissing.of() + private var data: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(threadRunStepDelta: ThreadRunStepDelta) = apply { + event = threadRunStepDelta.event + data = threadRunStepDelta.data + additionalProperties = threadRunStepDelta.additionalProperties.toMutableMap() + } + + fun event(event: Event) = event(JsonField.of(event)) + + fun event(event: JsonField) = apply { this.event = event } + + /** + * Represents a run step delta i.e. any changed fields on a run step during streaming. + */ + fun data(data: RunStepDeltaEvent) = data(JsonField.of(data)) + + /** + * Represents a run step delta i.e. any changed fields on a run step during streaming. + */ + fun data(data: JsonField) = apply { this.data = data } + + 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) + } + + fun build(): ThreadRunStepDelta = + ThreadRunStepDelta( + event, + data, + additionalProperties.toImmutable(), + ) + } + + class Event + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val THREAD_RUN_STEP_DELTA = of("thread.run.step.delta") + + @JvmStatic fun of(value: String) = Event(JsonField.of(value)) + } + + enum class Known { + THREAD_RUN_STEP_DELTA, + } + + enum class Value { + THREAD_RUN_STEP_DELTA, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + THREAD_RUN_STEP_DELTA -> Value.THREAD_RUN_STEP_DELTA + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + THREAD_RUN_STEP_DELTA -> Known.THREAD_RUN_STEP_DELTA + else -> throw OpenAIInvalidDataException("Unknown Event: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Event && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ThreadRunStepDelta && event == other.event && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(event, data, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ThreadRunStepDelta{event=$event, data=$data, additionalProperties=$additionalProperties}" + } + + /** + * Occurs when a + * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object) is + * completed. + */ + @NoAutoDetect + class ThreadRunStepCompleted + @JsonCreator + private constructor( + @JsonProperty("event") + @ExcludeMissing + private val event: JsonField = JsonMissing.of(), + @JsonProperty("data") + @ExcludeMissing + private val data: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + fun event(): Event = event.getRequired("event") + + /** Represents a step in execution of a run. */ + fun data(): RunStep = data.getRequired("data") + + @JsonProperty("event") @ExcludeMissing fun _event() = event + + /** Represents a step in execution of a run. */ + @JsonProperty("data") @ExcludeMissing fun _data() = data + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + private var validated: Boolean = false + + fun validate(): ThreadRunStepCompleted = apply { + if (!validated) { + event() + data().validate() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var event: JsonField = JsonMissing.of() + private var data: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(threadRunStepCompleted: ThreadRunStepCompleted) = apply { + event = threadRunStepCompleted.event + data = threadRunStepCompleted.data + additionalProperties = threadRunStepCompleted.additionalProperties.toMutableMap() + } + + fun event(event: Event) = event(JsonField.of(event)) + + fun event(event: JsonField) = apply { this.event = event } + + /** Represents a step in execution of a run. */ + fun data(data: RunStep) = data(JsonField.of(data)) + + /** Represents a step in execution of a run. */ + fun data(data: JsonField) = apply { this.data = data } + + 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) + } + + fun build(): ThreadRunStepCompleted = + ThreadRunStepCompleted( + event, + data, + additionalProperties.toImmutable(), + ) + } + + class Event + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val THREAD_RUN_STEP_COMPLETED = of("thread.run.step.completed") + + @JvmStatic fun of(value: String) = Event(JsonField.of(value)) + } + + enum class Known { + THREAD_RUN_STEP_COMPLETED, + } + + enum class Value { + THREAD_RUN_STEP_COMPLETED, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + THREAD_RUN_STEP_COMPLETED -> Value.THREAD_RUN_STEP_COMPLETED + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + THREAD_RUN_STEP_COMPLETED -> Known.THREAD_RUN_STEP_COMPLETED + else -> throw OpenAIInvalidDataException("Unknown Event: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Event && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ThreadRunStepCompleted && event == other.event && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(event, data, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ThreadRunStepCompleted{event=$event, data=$data, additionalProperties=$additionalProperties}" + } + + /** + * Occurs when a + * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object) fails. + */ + @NoAutoDetect + class ThreadRunStepFailed + @JsonCreator + private constructor( + @JsonProperty("event") + @ExcludeMissing + private val event: JsonField = JsonMissing.of(), + @JsonProperty("data") + @ExcludeMissing + private val data: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + fun event(): Event = event.getRequired("event") + + /** Represents a step in execution of a run. */ + fun data(): RunStep = data.getRequired("data") + + @JsonProperty("event") @ExcludeMissing fun _event() = event + + /** Represents a step in execution of a run. */ + @JsonProperty("data") @ExcludeMissing fun _data() = data + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + private var validated: Boolean = false + + fun validate(): ThreadRunStepFailed = apply { + if (!validated) { + event() + data().validate() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var event: JsonField = JsonMissing.of() + private var data: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(threadRunStepFailed: ThreadRunStepFailed) = apply { + event = threadRunStepFailed.event + data = threadRunStepFailed.data + additionalProperties = threadRunStepFailed.additionalProperties.toMutableMap() + } + + fun event(event: Event) = event(JsonField.of(event)) + + fun event(event: JsonField) = apply { this.event = event } + + /** Represents a step in execution of a run. */ + fun data(data: RunStep) = data(JsonField.of(data)) + + /** Represents a step in execution of a run. */ + fun data(data: JsonField) = apply { this.data = data } + + 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) + } + + fun build(): ThreadRunStepFailed = + ThreadRunStepFailed( + event, + data, + additionalProperties.toImmutable(), + ) + } + + class Event + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val THREAD_RUN_STEP_FAILED = of("thread.run.step.failed") + + @JvmStatic fun of(value: String) = Event(JsonField.of(value)) + } + + enum class Known { + THREAD_RUN_STEP_FAILED, + } + + enum class Value { + THREAD_RUN_STEP_FAILED, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + THREAD_RUN_STEP_FAILED -> Value.THREAD_RUN_STEP_FAILED + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + THREAD_RUN_STEP_FAILED -> Known.THREAD_RUN_STEP_FAILED + else -> throw OpenAIInvalidDataException("Unknown Event: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Event && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ThreadRunStepFailed && event == other.event && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(event, data, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ThreadRunStepFailed{event=$event, data=$data, additionalProperties=$additionalProperties}" + } + + /** + * Occurs when a + * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object) is + * cancelled. + */ + @NoAutoDetect + class ThreadRunStepCancelled + @JsonCreator + private constructor( + @JsonProperty("event") + @ExcludeMissing + private val event: JsonField = JsonMissing.of(), + @JsonProperty("data") + @ExcludeMissing + private val data: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + fun event(): Event = event.getRequired("event") + + /** Represents a step in execution of a run. */ + fun data(): RunStep = data.getRequired("data") + + @JsonProperty("event") @ExcludeMissing fun _event() = event + + /** Represents a step in execution of a run. */ + @JsonProperty("data") @ExcludeMissing fun _data() = data + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + private var validated: Boolean = false + + fun validate(): ThreadRunStepCancelled = apply { + if (!validated) { + event() + data().validate() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var event: JsonField = JsonMissing.of() + private var data: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(threadRunStepCancelled: ThreadRunStepCancelled) = apply { + event = threadRunStepCancelled.event + data = threadRunStepCancelled.data + additionalProperties = threadRunStepCancelled.additionalProperties.toMutableMap() + } + + fun event(event: Event) = event(JsonField.of(event)) + + fun event(event: JsonField) = apply { this.event = event } + + /** Represents a step in execution of a run. */ + fun data(data: RunStep) = data(JsonField.of(data)) + + /** Represents a step in execution of a run. */ + fun data(data: JsonField) = apply { this.data = data } + + 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) + } + + fun build(): ThreadRunStepCancelled = + ThreadRunStepCancelled( + event, + data, + additionalProperties.toImmutable(), + ) + } + + class Event + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val THREAD_RUN_STEP_CANCELLED = of("thread.run.step.cancelled") + + @JvmStatic fun of(value: String) = Event(JsonField.of(value)) + } + + enum class Known { + THREAD_RUN_STEP_CANCELLED, + } + + enum class Value { + THREAD_RUN_STEP_CANCELLED, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + THREAD_RUN_STEP_CANCELLED -> Value.THREAD_RUN_STEP_CANCELLED + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + THREAD_RUN_STEP_CANCELLED -> Known.THREAD_RUN_STEP_CANCELLED + else -> throw OpenAIInvalidDataException("Unknown Event: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Event && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ThreadRunStepCancelled && event == other.event && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(event, data, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ThreadRunStepCancelled{event=$event, data=$data, additionalProperties=$additionalProperties}" + } + + /** + * Occurs when a + * [run step](https://platform.openai.com/docs/api-reference/run-steps/step-object) expires. + */ + @NoAutoDetect + class ThreadRunStepExpired + @JsonCreator + private constructor( + @JsonProperty("event") + @ExcludeMissing + private val event: JsonField = JsonMissing.of(), + @JsonProperty("data") + @ExcludeMissing + private val data: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + fun event(): Event = event.getRequired("event") + + /** Represents a step in execution of a run. */ + fun data(): RunStep = data.getRequired("data") + + @JsonProperty("event") @ExcludeMissing fun _event() = event + + /** Represents a step in execution of a run. */ + @JsonProperty("data") @ExcludeMissing fun _data() = data + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + private var validated: Boolean = false + + fun validate(): ThreadRunStepExpired = apply { + if (!validated) { + event() + data().validate() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var event: JsonField = JsonMissing.of() + private var data: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(threadRunStepExpired: ThreadRunStepExpired) = apply { + event = threadRunStepExpired.event + data = threadRunStepExpired.data + additionalProperties = threadRunStepExpired.additionalProperties.toMutableMap() + } + + fun event(event: Event) = event(JsonField.of(event)) + + fun event(event: JsonField) = apply { this.event = event } + + /** Represents a step in execution of a run. */ + fun data(data: RunStep) = data(JsonField.of(data)) + + /** Represents a step in execution of a run. */ + fun data(data: JsonField) = apply { this.data = data } + + 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) + } + + fun build(): ThreadRunStepExpired = + ThreadRunStepExpired( + event, + data, + additionalProperties.toImmutable(), + ) + } + + class Event + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val THREAD_RUN_STEP_EXPIRED = of("thread.run.step.expired") + + @JvmStatic fun of(value: String) = Event(JsonField.of(value)) + } + + enum class Known { + THREAD_RUN_STEP_EXPIRED, + } + + enum class Value { + THREAD_RUN_STEP_EXPIRED, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + THREAD_RUN_STEP_EXPIRED -> Value.THREAD_RUN_STEP_EXPIRED + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + THREAD_RUN_STEP_EXPIRED -> Known.THREAD_RUN_STEP_EXPIRED + else -> throw OpenAIInvalidDataException("Unknown Event: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Event && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ThreadRunStepExpired && event == other.event && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(event, data, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ThreadRunStepExpired{event=$event, data=$data, additionalProperties=$additionalProperties}" + } + + /** + * Occurs when a [message](https://platform.openai.com/docs/api-reference/messages/object) is + * created. + */ + @NoAutoDetect + class ThreadMessageCreated + @JsonCreator + private constructor( + @JsonProperty("event") + @ExcludeMissing + private val event: JsonField = JsonMissing.of(), + @JsonProperty("data") + @ExcludeMissing + private val data: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + fun event(): Event = event.getRequired("event") + + /** + * Represents a message within a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + fun data(): Message = data.getRequired("data") + + @JsonProperty("event") @ExcludeMissing fun _event() = event + + /** + * Represents a message within a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + @JsonProperty("data") @ExcludeMissing fun _data() = data + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + private var validated: Boolean = false + + fun validate(): ThreadMessageCreated = apply { + if (!validated) { + event() + data().validate() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var event: JsonField = JsonMissing.of() + private var data: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(threadMessageCreated: ThreadMessageCreated) = apply { + event = threadMessageCreated.event + data = threadMessageCreated.data + additionalProperties = threadMessageCreated.additionalProperties.toMutableMap() + } + + fun event(event: Event) = event(JsonField.of(event)) + + fun event(event: JsonField) = apply { this.event = event } + + /** + * Represents a message within a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + fun data(data: Message) = data(JsonField.of(data)) + + /** + * Represents a message within a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + fun data(data: JsonField) = apply { this.data = data } + + 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) + } + + fun build(): ThreadMessageCreated = + ThreadMessageCreated( + event, + data, + additionalProperties.toImmutable(), + ) + } + + class Event + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val THREAD_MESSAGE_CREATED = of("thread.message.created") + + @JvmStatic fun of(value: String) = Event(JsonField.of(value)) + } + + enum class Known { + THREAD_MESSAGE_CREATED, + } + + enum class Value { + THREAD_MESSAGE_CREATED, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + THREAD_MESSAGE_CREATED -> Value.THREAD_MESSAGE_CREATED + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + THREAD_MESSAGE_CREATED -> Known.THREAD_MESSAGE_CREATED + else -> throw OpenAIInvalidDataException("Unknown Event: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Event && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ThreadMessageCreated && event == other.event && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(event, data, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ThreadMessageCreated{event=$event, data=$data, additionalProperties=$additionalProperties}" + } + + /** + * Occurs when a [message](https://platform.openai.com/docs/api-reference/messages/object) moves + * to an `in_progress` state. + */ + @NoAutoDetect + class ThreadMessageInProgress + @JsonCreator + private constructor( + @JsonProperty("event") + @ExcludeMissing + private val event: JsonField = JsonMissing.of(), + @JsonProperty("data") + @ExcludeMissing + private val data: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + fun event(): Event = event.getRequired("event") + + /** + * Represents a message within a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + fun data(): Message = data.getRequired("data") + + @JsonProperty("event") @ExcludeMissing fun _event() = event + + /** + * Represents a message within a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + @JsonProperty("data") @ExcludeMissing fun _data() = data + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + private var validated: Boolean = false + + fun validate(): ThreadMessageInProgress = apply { + if (!validated) { + event() + data().validate() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var event: JsonField = JsonMissing.of() + private var data: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(threadMessageInProgress: ThreadMessageInProgress) = apply { + event = threadMessageInProgress.event + data = threadMessageInProgress.data + additionalProperties = threadMessageInProgress.additionalProperties.toMutableMap() + } + + fun event(event: Event) = event(JsonField.of(event)) + + fun event(event: JsonField) = apply { this.event = event } + + /** + * Represents a message within a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + fun data(data: Message) = data(JsonField.of(data)) + + /** + * Represents a message within a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + fun data(data: JsonField) = apply { this.data = data } + + 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) + } + + fun build(): ThreadMessageInProgress = + ThreadMessageInProgress( + event, + data, + additionalProperties.toImmutable(), + ) + } + + class Event + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val THREAD_MESSAGE_IN_PROGRESS = of("thread.message.in_progress") + + @JvmStatic fun of(value: String) = Event(JsonField.of(value)) + } + + enum class Known { + THREAD_MESSAGE_IN_PROGRESS, + } + + enum class Value { + THREAD_MESSAGE_IN_PROGRESS, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + THREAD_MESSAGE_IN_PROGRESS -> Value.THREAD_MESSAGE_IN_PROGRESS + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + THREAD_MESSAGE_IN_PROGRESS -> Known.THREAD_MESSAGE_IN_PROGRESS + else -> throw OpenAIInvalidDataException("Unknown Event: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Event && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ThreadMessageInProgress && event == other.event && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(event, data, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ThreadMessageInProgress{event=$event, data=$data, additionalProperties=$additionalProperties}" + } + + /** + * Occurs when parts of a + * [Message](https://platform.openai.com/docs/api-reference/messages/object) are being streamed. + */ + @NoAutoDetect + class ThreadMessageDelta + @JsonCreator + private constructor( + @JsonProperty("event") + @ExcludeMissing + private val event: JsonField = JsonMissing.of(), + @JsonProperty("data") + @ExcludeMissing + private val data: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + fun event(): Event = event.getRequired("event") + + /** Represents a message delta i.e. any changed fields on a message during streaming. */ + fun data(): MessageDeltaEvent = data.getRequired("data") + + @JsonProperty("event") @ExcludeMissing fun _event() = event + + /** Represents a message delta i.e. any changed fields on a message during streaming. */ + @JsonProperty("data") @ExcludeMissing fun _data() = data + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + private var validated: Boolean = false + + fun validate(): ThreadMessageDelta = apply { + if (!validated) { + event() + data().validate() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var event: JsonField = JsonMissing.of() + private var data: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(threadMessageDelta: ThreadMessageDelta) = apply { + event = threadMessageDelta.event + data = threadMessageDelta.data + additionalProperties = threadMessageDelta.additionalProperties.toMutableMap() + } + + fun event(event: Event) = event(JsonField.of(event)) + + fun event(event: JsonField) = apply { this.event = event } + + /** Represents a message delta i.e. any changed fields on a message during streaming. */ + fun data(data: MessageDeltaEvent) = data(JsonField.of(data)) + + /** Represents a message delta i.e. any changed fields on a message during streaming. */ + fun data(data: JsonField) = apply { this.data = data } + + 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) + } + + fun build(): ThreadMessageDelta = + ThreadMessageDelta( + event, + data, + additionalProperties.toImmutable(), + ) + } + + class Event + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val THREAD_MESSAGE_DELTA = of("thread.message.delta") + + @JvmStatic fun of(value: String) = Event(JsonField.of(value)) + } + + enum class Known { + THREAD_MESSAGE_DELTA, + } + + enum class Value { + THREAD_MESSAGE_DELTA, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + THREAD_MESSAGE_DELTA -> Value.THREAD_MESSAGE_DELTA + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + THREAD_MESSAGE_DELTA -> Known.THREAD_MESSAGE_DELTA + else -> throw OpenAIInvalidDataException("Unknown Event: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Event && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ThreadMessageDelta && event == other.event && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(event, data, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ThreadMessageDelta{event=$event, data=$data, additionalProperties=$additionalProperties}" + } + + /** + * Occurs when a [message](https://platform.openai.com/docs/api-reference/messages/object) is + * completed. + */ + @NoAutoDetect + class ThreadMessageCompleted + @JsonCreator + private constructor( + @JsonProperty("event") + @ExcludeMissing + private val event: JsonField = JsonMissing.of(), + @JsonProperty("data") + @ExcludeMissing + private val data: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + fun event(): Event = event.getRequired("event") + + /** + * Represents a message within a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + fun data(): Message = data.getRequired("data") + + @JsonProperty("event") @ExcludeMissing fun _event() = event + + /** + * Represents a message within a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + @JsonProperty("data") @ExcludeMissing fun _data() = data + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + private var validated: Boolean = false + + fun validate(): ThreadMessageCompleted = apply { + if (!validated) { + event() + data().validate() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var event: JsonField = JsonMissing.of() + private var data: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(threadMessageCompleted: ThreadMessageCompleted) = apply { + event = threadMessageCompleted.event + data = threadMessageCompleted.data + additionalProperties = threadMessageCompleted.additionalProperties.toMutableMap() + } + + fun event(event: Event) = event(JsonField.of(event)) + + fun event(event: JsonField) = apply { this.event = event } + + /** + * Represents a message within a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + fun data(data: Message) = data(JsonField.of(data)) + + /** + * Represents a message within a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + fun data(data: JsonField) = apply { this.data = data } + + 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) + } + + fun build(): ThreadMessageCompleted = + ThreadMessageCompleted( + event, + data, + additionalProperties.toImmutable(), + ) + } + + class Event + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val THREAD_MESSAGE_COMPLETED = of("thread.message.completed") + + @JvmStatic fun of(value: String) = Event(JsonField.of(value)) + } + + enum class Known { + THREAD_MESSAGE_COMPLETED, + } + + enum class Value { + THREAD_MESSAGE_COMPLETED, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + THREAD_MESSAGE_COMPLETED -> Value.THREAD_MESSAGE_COMPLETED + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + THREAD_MESSAGE_COMPLETED -> Known.THREAD_MESSAGE_COMPLETED + else -> throw OpenAIInvalidDataException("Unknown Event: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Event && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ThreadMessageCompleted && event == other.event && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(event, data, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ThreadMessageCompleted{event=$event, data=$data, additionalProperties=$additionalProperties}" + } + + /** + * Occurs when a [message](https://platform.openai.com/docs/api-reference/messages/object) ends + * before it is completed. + */ + @NoAutoDetect + class ThreadMessageIncomplete + @JsonCreator + private constructor( + @JsonProperty("event") + @ExcludeMissing + private val event: JsonField = JsonMissing.of(), + @JsonProperty("data") + @ExcludeMissing + private val data: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + fun event(): Event = event.getRequired("event") + + /** + * Represents a message within a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + fun data(): Message = data.getRequired("data") + + @JsonProperty("event") @ExcludeMissing fun _event() = event + + /** + * Represents a message within a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + @JsonProperty("data") @ExcludeMissing fun _data() = data + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + private var validated: Boolean = false + + fun validate(): ThreadMessageIncomplete = apply { + if (!validated) { + event() + data().validate() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var event: JsonField = JsonMissing.of() + private var data: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(threadMessageIncomplete: ThreadMessageIncomplete) = apply { + event = threadMessageIncomplete.event + data = threadMessageIncomplete.data + additionalProperties = threadMessageIncomplete.additionalProperties.toMutableMap() + } + + fun event(event: Event) = event(JsonField.of(event)) + + fun event(event: JsonField) = apply { this.event = event } + + /** + * Represents a message within a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + fun data(data: Message) = data(JsonField.of(data)) + + /** + * Represents a message within a + * [thread](https://platform.openai.com/docs/api-reference/threads). + */ + fun data(data: JsonField) = apply { this.data = data } + + 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) + } + + fun build(): ThreadMessageIncomplete = + ThreadMessageIncomplete( + event, + data, + additionalProperties.toImmutable(), + ) + } + + class Event + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val THREAD_MESSAGE_INCOMPLETE = of("thread.message.incomplete") + + @JvmStatic fun of(value: String) = Event(JsonField.of(value)) + } + + enum class Known { + THREAD_MESSAGE_INCOMPLETE, + } + + enum class Value { + THREAD_MESSAGE_INCOMPLETE, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + THREAD_MESSAGE_INCOMPLETE -> Value.THREAD_MESSAGE_INCOMPLETE + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + THREAD_MESSAGE_INCOMPLETE -> Known.THREAD_MESSAGE_INCOMPLETE + else -> throw OpenAIInvalidDataException("Unknown Event: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Event && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ThreadMessageIncomplete && event == other.event && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(event, data, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ThreadMessageIncomplete{event=$event, data=$data, additionalProperties=$additionalProperties}" + } + + /** + * Occurs when an [error](https://platform.openai.com/docs/guides/error-codes#api-errors) + * occurs. This can happen due to an internal server error or a timeout. + */ + @NoAutoDetect + class ErrorEvent + @JsonCreator + private constructor( + @JsonProperty("event") + @ExcludeMissing + private val event: JsonField = JsonMissing.of(), + @JsonProperty("data") + @ExcludeMissing + private val data: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + fun event(): Event = event.getRequired("event") + + fun data(): ErrorObject = data.getRequired("data") + + @JsonProperty("event") @ExcludeMissing fun _event() = event + + @JsonProperty("data") @ExcludeMissing fun _data() = data + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + private var validated: Boolean = false + + fun validate(): ErrorEvent = apply { + if (!validated) { + event() + data().validate() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var event: JsonField = JsonMissing.of() + private var data: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(errorEvent: ErrorEvent) = apply { + event = errorEvent.event + data = errorEvent.data + additionalProperties = errorEvent.additionalProperties.toMutableMap() + } + + fun event(event: Event) = event(JsonField.of(event)) + + fun event(event: JsonField) = apply { this.event = event } + + fun data(data: ErrorObject) = data(JsonField.of(data)) + + fun data(data: JsonField) = apply { this.data = data } + + 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) + } + + fun build(): ErrorEvent = + ErrorEvent( + event, + data, + additionalProperties.toImmutable(), + ) + } + + class Event + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val ERROR = of("error") + + @JvmStatic fun of(value: String) = Event(JsonField.of(value)) + } + + enum class Known { + ERROR, + } + + enum class Value { + ERROR, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + ERROR -> Value.ERROR + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + ERROR -> Known.ERROR + else -> throw OpenAIInvalidDataException("Unknown Event: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Event && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ErrorEvent && event == other.event && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(event, data, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ErrorEvent{event=$event, data=$data, additionalProperties=$additionalProperties}" + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/AssistantTool.kt b/openai-java-core/src/main/kotlin/com/openai/models/AssistantTool.kt new file mode 100644 index 00000000..73fbbb0e --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/AssistantTool.kt @@ -0,0 +1,170 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models + +import com.fasterxml.jackson.core.JsonGenerator +import com.fasterxml.jackson.core.ObjectCodec +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.SerializerProvider +import com.fasterxml.jackson.databind.annotation.JsonDeserialize +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.BaseDeserializer +import com.openai.core.BaseSerializer +import com.openai.core.JsonValue +import com.openai.core.getOrThrow +import com.openai.errors.OpenAIInvalidDataException +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +@JsonDeserialize(using = AssistantTool.Deserializer::class) +@JsonSerialize(using = AssistantTool.Serializer::class) +class AssistantTool +private constructor( + private val codeInterpreterTool: CodeInterpreterTool? = null, + private val fileSearchTool: FileSearchTool? = null, + private val functionTool: FunctionTool? = null, + private val _json: JsonValue? = null, +) { + + private var validated: Boolean = false + + fun codeInterpreterTool(): Optional = + Optional.ofNullable(codeInterpreterTool) + + fun fileSearchTool(): Optional = Optional.ofNullable(fileSearchTool) + + fun functionTool(): Optional = Optional.ofNullable(functionTool) + + fun isCodeInterpreterTool(): Boolean = codeInterpreterTool != null + + fun isFileSearchTool(): Boolean = fileSearchTool != null + + fun isFunctionTool(): Boolean = functionTool != null + + fun asCodeInterpreterTool(): CodeInterpreterTool = + codeInterpreterTool.getOrThrow("codeInterpreterTool") + + fun asFileSearchTool(): FileSearchTool = fileSearchTool.getOrThrow("fileSearchTool") + + fun asFunctionTool(): FunctionTool = functionTool.getOrThrow("functionTool") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + codeInterpreterTool != null -> visitor.visitCodeInterpreterTool(codeInterpreterTool) + fileSearchTool != null -> visitor.visitFileSearchTool(fileSearchTool) + functionTool != null -> visitor.visitFunctionTool(functionTool) + else -> visitor.unknown(_json) + } + } + + fun validate(): AssistantTool = apply { + if (!validated) { + if (codeInterpreterTool == null && fileSearchTool == null && functionTool == null) { + throw OpenAIInvalidDataException("Unknown AssistantTool: $_json") + } + codeInterpreterTool?.validate() + fileSearchTool?.validate() + functionTool?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is AssistantTool && codeInterpreterTool == other.codeInterpreterTool && fileSearchTool == other.fileSearchTool && functionTool == other.functionTool /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(codeInterpreterTool, fileSearchTool, functionTool) /* spotless:on */ + + override fun toString(): String = + when { + codeInterpreterTool != null -> "AssistantTool{codeInterpreterTool=$codeInterpreterTool}" + fileSearchTool != null -> "AssistantTool{fileSearchTool=$fileSearchTool}" + functionTool != null -> "AssistantTool{functionTool=$functionTool}" + _json != null -> "AssistantTool{_unknown=$_json}" + else -> throw IllegalStateException("Invalid AssistantTool") + } + + companion object { + + @JvmStatic + fun ofCodeInterpreterTool(codeInterpreterTool: CodeInterpreterTool) = + AssistantTool(codeInterpreterTool = codeInterpreterTool) + + @JvmStatic + fun ofFileSearchTool(fileSearchTool: FileSearchTool) = + AssistantTool(fileSearchTool = fileSearchTool) + + @JvmStatic + fun ofFunctionTool(functionTool: FunctionTool) = AssistantTool(functionTool = functionTool) + } + + interface Visitor { + + fun visitCodeInterpreterTool(codeInterpreterTool: CodeInterpreterTool): T + + fun visitFileSearchTool(fileSearchTool: FileSearchTool): T + + fun visitFunctionTool(functionTool: FunctionTool): T + + fun unknown(json: JsonValue?): T { + throw OpenAIInvalidDataException("Unknown AssistantTool: $json") + } + } + + class Deserializer : BaseDeserializer(AssistantTool::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): AssistantTool { + val json = JsonValue.fromJsonNode(node) + val type = json.asObject().getOrNull()?.get("type")?.asString()?.getOrNull() + + when (type) { + "code_interpreter" -> { + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return AssistantTool(codeInterpreterTool = it, _json = json) + } + } + "file_search" -> { + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return AssistantTool(fileSearchTool = it, _json = json) + } + } + "function" -> { + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return AssistantTool(functionTool = it, _json = json) + } + } + } + + return AssistantTool(_json = json) + } + } + + class Serializer : BaseSerializer(AssistantTool::class) { + + override fun serialize( + value: AssistantTool, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.codeInterpreterTool != null -> + generator.writeObject(value.codeInterpreterTool) + value.fileSearchTool != null -> generator.writeObject(value.fileSearchTool) + value.functionTool != null -> generator.writeObject(value.functionTool) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid AssistantTool") + } + } + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/AssistantToolChoice.kt b/openai-java-core/src/main/kotlin/com/openai/models/AssistantToolChoice.kt new file mode 100644 index 00000000..0e4457fe --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/AssistantToolChoice.kt @@ -0,0 +1,196 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.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.Enum +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.NoAutoDetect +import com.openai.core.immutableEmptyMap +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Objects +import java.util.Optional + +/** Specifies a tool the model should use. Use to force the model to call a specific tool. */ +@NoAutoDetect +class AssistantToolChoice +@JsonCreator +private constructor( + @JsonProperty("type") @ExcludeMissing private val type: JsonField = JsonMissing.of(), + @JsonProperty("function") + @ExcludeMissing + private val function: JsonField = JsonMissing.of(), + @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), +) { + + /** The type of the tool. If type is `function`, the function name must be set */ + fun type(): Type = type.getRequired("type") + + fun function(): Optional = + Optional.ofNullable(function.getNullable("function")) + + /** The type of the tool. If type is `function`, the function name must be set */ + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonProperty("function") @ExcludeMissing fun _function() = function + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + private var validated: Boolean = false + + fun validate(): AssistantToolChoice = apply { + if (!validated) { + type() + function().map { it.validate() } + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var type: JsonField = JsonMissing.of() + private var function: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(assistantToolChoice: AssistantToolChoice) = apply { + type = assistantToolChoice.type + function = assistantToolChoice.function + additionalProperties = assistantToolChoice.additionalProperties.toMutableMap() + } + + /** The type of the tool. If type is `function`, the function name must be set */ + fun type(type: Type) = type(JsonField.of(type)) + + /** The type of the tool. If type is `function`, the function name must be set */ + fun type(type: JsonField) = apply { this.type = type } + + fun function(function: AssistantToolChoiceFunction) = function(JsonField.of(function)) + + fun function(function: JsonField) = apply { + this.function = function + } + + 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) + } + + fun build(): AssistantToolChoice = + AssistantToolChoice( + type, + function, + additionalProperties.toImmutable(), + ) + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val FUNCTION = of("function") + + @JvmField val CODE_INTERPRETER = of("code_interpreter") + + @JvmField val FILE_SEARCH = of("file_search") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + FUNCTION, + CODE_INTERPRETER, + FILE_SEARCH, + } + + enum class Value { + FUNCTION, + CODE_INTERPRETER, + FILE_SEARCH, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + FUNCTION -> Value.FUNCTION + CODE_INTERPRETER -> Value.CODE_INTERPRETER + FILE_SEARCH -> Value.FILE_SEARCH + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + FUNCTION -> Known.FUNCTION + CODE_INTERPRETER -> Known.CODE_INTERPRETER + FILE_SEARCH -> Known.FILE_SEARCH + else -> throw OpenAIInvalidDataException("Unknown Type: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is AssistantToolChoice && type == other.type && function == other.function && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(type, function, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AssistantToolChoice{type=$type, function=$function, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/AssistantToolChoiceFunction.kt b/openai-java-core/src/main/kotlin/com/openai/models/AssistantToolChoiceFunction.kt new file mode 100644 index 00000000..d756cd67 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/AssistantToolChoiceFunction.kt @@ -0,0 +1,108 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.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.NoAutoDetect +import com.openai.core.immutableEmptyMap +import com.openai.core.toImmutable +import java.util.Objects + +@NoAutoDetect +class AssistantToolChoiceFunction +@JsonCreator +private constructor( + @JsonProperty("name") @ExcludeMissing private val name: JsonField = JsonMissing.of(), + @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), +) { + + /** The name of the function to call. */ + fun name(): String = name.getRequired("name") + + /** The name of the function to call. */ + @JsonProperty("name") @ExcludeMissing fun _name() = name + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + private var validated: Boolean = false + + fun validate(): AssistantToolChoiceFunction = apply { + if (!validated) { + name() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var name: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(assistantToolChoiceFunction: AssistantToolChoiceFunction) = apply { + name = assistantToolChoiceFunction.name + additionalProperties = assistantToolChoiceFunction.additionalProperties.toMutableMap() + } + + /** The name of the function to call. */ + fun name(name: String) = name(JsonField.of(name)) + + /** The name of the function to call. */ + fun name(name: JsonField) = apply { this.name = name } + + 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) + } + + fun build(): AssistantToolChoiceFunction = + AssistantToolChoiceFunction(name, additionalProperties.toImmutable()) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is AssistantToolChoiceFunction && name == other.name && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(name, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AssistantToolChoiceFunction{name=$name, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/AssistantToolChoiceOption.kt b/openai-java-core/src/main/kotlin/com/openai/models/AssistantToolChoiceOption.kt new file mode 100644 index 00000000..a868b55a --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/AssistantToolChoiceOption.kt @@ -0,0 +1,231 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models + +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.core.JsonGenerator +import com.fasterxml.jackson.core.ObjectCodec +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.SerializerProvider +import com.fasterxml.jackson.databind.annotation.JsonDeserialize +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.BaseDeserializer +import com.openai.core.BaseSerializer +import com.openai.core.Enum +import com.openai.core.JsonField +import com.openai.core.JsonValue +import com.openai.core.getOrThrow +import com.openai.errors.OpenAIInvalidDataException +import java.util.Objects +import java.util.Optional + +/** + * Controls which (if any) tool is called by the model. `none` means the model will not call any + * tools and instead generates a message. `auto` is the default value and means the model can pick + * between generating a message or calling one or more tools. `required` means the model must call + * one or more tools before responding to the user. Specifying a particular tool like `{"type": + * "file_search"}` or `{"type": "function", "function": {"name": "my_function"}}` forces the model + * to call that tool. + */ +@JsonDeserialize(using = AssistantToolChoiceOption.Deserializer::class) +@JsonSerialize(using = AssistantToolChoiceOption.Serializer::class) +class AssistantToolChoiceOption +private constructor( + private val behavior: Behavior? = null, + private val assistantToolChoice: AssistantToolChoice? = null, + private val _json: JsonValue? = null, +) { + + private var validated: Boolean = false + + /** + * `none` means the model will not call any tools and instead generates a message. `auto` means + * the model can pick between generating a message or calling one or more tools. `required` + * means the model must call one or more tools before responding to the user. + */ + fun behavior(): Optional = Optional.ofNullable(behavior) + /** Specifies a tool the model should use. Use to force the model to call a specific tool. */ + fun assistantToolChoice(): Optional = + Optional.ofNullable(assistantToolChoice) + + fun isBehavior(): Boolean = behavior != null + + fun isAssistantToolChoice(): Boolean = assistantToolChoice != null + + /** + * `none` means the model will not call any tools and instead generates a message. `auto` means + * the model can pick between generating a message or calling one or more tools. `required` + * means the model must call one or more tools before responding to the user. + */ + fun asBehavior(): Behavior = behavior.getOrThrow("behavior") + /** Specifies a tool the model should use. Use to force the model to call a specific tool. */ + fun asAssistantToolChoice(): AssistantToolChoice = + assistantToolChoice.getOrThrow("assistantToolChoice") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + behavior != null -> visitor.visitBehavior(behavior) + assistantToolChoice != null -> visitor.visitAssistantToolChoice(assistantToolChoice) + else -> visitor.unknown(_json) + } + } + + fun validate(): AssistantToolChoiceOption = apply { + if (!validated) { + if (behavior == null && assistantToolChoice == null) { + throw OpenAIInvalidDataException("Unknown AssistantToolChoiceOption: $_json") + } + assistantToolChoice?.validate() + validated = true + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is AssistantToolChoiceOption && behavior == other.behavior && assistantToolChoice == other.assistantToolChoice /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(behavior, assistantToolChoice) /* spotless:on */ + + override fun toString(): String = + when { + behavior != null -> "AssistantToolChoiceOption{behavior=$behavior}" + assistantToolChoice != null -> + "AssistantToolChoiceOption{assistantToolChoice=$assistantToolChoice}" + _json != null -> "AssistantToolChoiceOption{_unknown=$_json}" + else -> throw IllegalStateException("Invalid AssistantToolChoiceOption") + } + + companion object { + + /** + * `none` means the model will not call any tools and instead generates a message. `auto` + * means the model can pick between generating a message or calling one or more tools. + * `required` means the model must call one or more tools before responding to the user. + */ + @JvmStatic + fun ofBehavior(behavior: Behavior) = AssistantToolChoiceOption(behavior = behavior) + + /** + * Specifies a tool the model should use. Use to force the model to call a specific tool. + */ + @JvmStatic + fun ofAssistantToolChoice(assistantToolChoice: AssistantToolChoice) = + AssistantToolChoiceOption(assistantToolChoice = assistantToolChoice) + } + + interface Visitor { + + fun visitBehavior(behavior: Behavior): T + + fun visitAssistantToolChoice(assistantToolChoice: AssistantToolChoice): T + + fun unknown(json: JsonValue?): T { + throw OpenAIInvalidDataException("Unknown AssistantToolChoiceOption: $json") + } + } + + class Deserializer : + BaseDeserializer(AssistantToolChoiceOption::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): AssistantToolChoiceOption { + val json = JsonValue.fromJsonNode(node) + + tryDeserialize(node, jacksonTypeRef())?.let { + return AssistantToolChoiceOption(behavior = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef()) { it.validate() } + ?.let { + return AssistantToolChoiceOption(assistantToolChoice = it, _json = json) + } + + return AssistantToolChoiceOption(_json = json) + } + } + + class Serializer : BaseSerializer(AssistantToolChoiceOption::class) { + + override fun serialize( + value: AssistantToolChoiceOption, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.behavior != null -> generator.writeObject(value.behavior) + value.assistantToolChoice != null -> + generator.writeObject(value.assistantToolChoice) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid AssistantToolChoiceOption") + } + } + } + + class Behavior + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val NONE = of("none") + + @JvmField val AUTO = of("auto") + + @JvmField val REQUIRED = of("required") + + @JvmStatic fun of(value: String) = Behavior(JsonField.of(value)) + } + + enum class Known { + NONE, + AUTO, + REQUIRED, + } + + enum class Value { + NONE, + AUTO, + REQUIRED, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + NONE -> Value.NONE + AUTO -> Value.AUTO + REQUIRED -> Value.REQUIRED + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + NONE -> Known.NONE + AUTO -> Known.AUTO + REQUIRED -> Known.REQUIRED + else -> throw OpenAIInvalidDataException("Unknown Behavior: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Behavior && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/AutoFileChunkingStrategyParam.kt b/openai-java-core/src/main/kotlin/com/openai/models/AutoFileChunkingStrategyParam.kt new file mode 100644 index 00000000..19138937 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/AutoFileChunkingStrategyParam.kt @@ -0,0 +1,165 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.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.Enum +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonMissing +import com.openai.core.JsonValue +import com.openai.core.NoAutoDetect +import com.openai.core.immutableEmptyMap +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Objects + +/** + * The default strategy. This strategy currently uses a `max_chunk_size_tokens` of `800` and + * `chunk_overlap_tokens` of `400`. + */ +@NoAutoDetect +class AutoFileChunkingStrategyParam +@JsonCreator +private constructor( + @JsonProperty("type") @ExcludeMissing private val type: JsonField = JsonMissing.of(), + @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), +) { + + /** Always `auto`. */ + fun type(): Type = type.getRequired("type") + + /** Always `auto`. */ + @JsonProperty("type") @ExcludeMissing fun _type() = type + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + private var validated: Boolean = false + + fun validate(): AutoFileChunkingStrategyParam = apply { + if (!validated) { + type() + validated = true + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var type: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(autoFileChunkingStrategyParam: AutoFileChunkingStrategyParam) = apply { + type = autoFileChunkingStrategyParam.type + additionalProperties = autoFileChunkingStrategyParam.additionalProperties.toMutableMap() + } + + /** Always `auto`. */ + fun type(type: Type) = type(JsonField.of(type)) + + /** Always `auto`. */ + fun type(type: JsonField) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + fun build(): AutoFileChunkingStrategyParam = + AutoFileChunkingStrategyParam(type, additionalProperties.toImmutable()) + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val AUTO = of("auto") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + AUTO, + } + + enum class Value { + AUTO, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + AUTO -> Value.AUTO + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + AUTO -> Known.AUTO + else -> throw OpenAIInvalidDataException("Unknown Type: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is AutoFileChunkingStrategyParam && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(type, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AutoFileChunkingStrategyParam{type=$type, additionalProperties=$additionalProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/Batch.kt b/openai-java-core/src/main/kotlin/com/openai/models/Batch.kt index c4d8a6d0..e9f188af 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/Batch.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/Batch.kt @@ -6,47 +6,81 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.databind.annotation.JsonDeserialize import com.openai.core.Enum import com.openai.core.ExcludeMissing import com.openai.core.JsonField import com.openai.core.JsonMissing import com.openai.core.JsonValue import com.openai.core.NoAutoDetect +import com.openai.core.immutableEmptyMap import com.openai.core.toImmutable import com.openai.errors.OpenAIInvalidDataException import java.util.Objects import java.util.Optional -@JsonDeserialize(builder = Batch.Builder::class) @NoAutoDetect class Batch +@JsonCreator private constructor( - private val id: JsonField, - private val object_: JsonField, - private val endpoint: JsonField, - private val errors: JsonField, - private val inputFileId: JsonField, - private val completionWindow: JsonField, - private val status: JsonField, - private val outputFileId: JsonField, - private val errorFileId: JsonField, - private val createdAt: JsonField, - private val inProgressAt: JsonField, - private val expiresAt: JsonField, - private val finalizingAt: JsonField, - private val completedAt: JsonField, - private val failedAt: JsonField, - private val expiredAt: JsonField, - private val cancellingAt: JsonField, - private val cancelledAt: JsonField, - private val requestCounts: JsonField, - private val metadata: JsonValue, - private val additionalProperties: Map, + @JsonProperty("id") @ExcludeMissing private val id: JsonField = JsonMissing.of(), + @JsonProperty("object") + @ExcludeMissing + private val object_: JsonField = JsonMissing.of(), + @JsonProperty("endpoint") + @ExcludeMissing + private val endpoint: JsonField = JsonMissing.of(), + @JsonProperty("errors") + @ExcludeMissing + private val errors: JsonField = JsonMissing.of(), + @JsonProperty("input_file_id") + @ExcludeMissing + private val inputFileId: JsonField = JsonMissing.of(), + @JsonProperty("completion_window") + @ExcludeMissing + private val completionWindow: JsonField = JsonMissing.of(), + @JsonProperty("status") + @ExcludeMissing + private val status: JsonField = JsonMissing.of(), + @JsonProperty("output_file_id") + @ExcludeMissing + private val outputFileId: JsonField = JsonMissing.of(), + @JsonProperty("error_file_id") + @ExcludeMissing + private val errorFileId: JsonField = JsonMissing.of(), + @JsonProperty("created_at") + @ExcludeMissing + private val createdAt: JsonField = JsonMissing.of(), + @JsonProperty("in_progress_at") + @ExcludeMissing + private val inProgressAt: JsonField = JsonMissing.of(), + @JsonProperty("expires_at") + @ExcludeMissing + private val expiresAt: JsonField = JsonMissing.of(), + @JsonProperty("finalizing_at") + @ExcludeMissing + private val finalizingAt: JsonField = JsonMissing.of(), + @JsonProperty("completed_at") + @ExcludeMissing + private val completedAt: JsonField = JsonMissing.of(), + @JsonProperty("failed_at") + @ExcludeMissing + private val failedAt: JsonField = JsonMissing.of(), + @JsonProperty("expired_at") + @ExcludeMissing + private val expiredAt: JsonField = JsonMissing.of(), + @JsonProperty("cancelling_at") + @ExcludeMissing + private val cancellingAt: JsonField = JsonMissing.of(), + @JsonProperty("cancelled_at") + @ExcludeMissing + private val cancelledAt: JsonField = JsonMissing.of(), + @JsonProperty("request_counts") + @ExcludeMissing + private val requestCounts: JsonField = JsonMissing.of(), + @JsonProperty("metadata") @ExcludeMissing private val metadata: JsonValue = JsonMissing.of(), + @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun id(): String = id.getRequired("id") /** The object type, which is always `batch`. */ @@ -174,6 +208,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Batch = apply { if (!validated) { id() @@ -232,61 +268,53 @@ private constructor( @JvmSynthetic internal fun from(batch: Batch) = apply { - this.id = batch.id - this.object_ = batch.object_ - this.endpoint = batch.endpoint - this.errors = batch.errors - this.inputFileId = batch.inputFileId - this.completionWindow = batch.completionWindow - this.status = batch.status - this.outputFileId = batch.outputFileId - this.errorFileId = batch.errorFileId - this.createdAt = batch.createdAt - this.inProgressAt = batch.inProgressAt - this.expiresAt = batch.expiresAt - this.finalizingAt = batch.finalizingAt - this.completedAt = batch.completedAt - this.failedAt = batch.failedAt - this.expiredAt = batch.expiredAt - this.cancellingAt = batch.cancellingAt - this.cancelledAt = batch.cancelledAt - this.requestCounts = batch.requestCounts - this.metadata = batch.metadata - additionalProperties(batch.additionalProperties) + id = batch.id + object_ = batch.object_ + endpoint = batch.endpoint + errors = batch.errors + inputFileId = batch.inputFileId + completionWindow = batch.completionWindow + status = batch.status + outputFileId = batch.outputFileId + errorFileId = batch.errorFileId + createdAt = batch.createdAt + inProgressAt = batch.inProgressAt + expiresAt = batch.expiresAt + finalizingAt = batch.finalizingAt + completedAt = batch.completedAt + failedAt = batch.failedAt + expiredAt = batch.expiredAt + cancellingAt = batch.cancellingAt + cancelledAt = batch.cancelledAt + requestCounts = batch.requestCounts + metadata = batch.metadata + additionalProperties = batch.additionalProperties.toMutableMap() } fun id(id: String) = id(JsonField.of(id)) - @JsonProperty("id") @ExcludeMissing fun id(id: JsonField) = apply { this.id = id } + fun id(id: JsonField) = apply { this.id = id } /** The object type, which is always `batch`. */ fun object_(object_: Object) = object_(JsonField.of(object_)) /** The object type, which is always `batch`. */ - @JsonProperty("object") - @ExcludeMissing fun object_(object_: JsonField) = apply { this.object_ = object_ } /** The OpenAI API endpoint used by the batch. */ fun endpoint(endpoint: String) = endpoint(JsonField.of(endpoint)) /** The OpenAI API endpoint used by the batch. */ - @JsonProperty("endpoint") - @ExcludeMissing fun endpoint(endpoint: JsonField) = apply { this.endpoint = endpoint } fun errors(errors: Errors) = errors(JsonField.of(errors)) - @JsonProperty("errors") - @ExcludeMissing fun errors(errors: JsonField) = apply { this.errors = errors } /** The ID of the input file for the batch. */ fun inputFileId(inputFileId: String) = inputFileId(JsonField.of(inputFileId)) /** The ID of the input file for the batch. */ - @JsonProperty("input_file_id") - @ExcludeMissing fun inputFileId(inputFileId: JsonField) = apply { this.inputFileId = inputFileId } /** The time frame within which the batch should be processed. */ @@ -294,8 +322,6 @@ private constructor( completionWindow(JsonField.of(completionWindow)) /** The time frame within which the batch should be processed. */ - @JsonProperty("completion_window") - @ExcludeMissing fun completionWindow(completionWindow: JsonField) = apply { this.completionWindow = completionWindow } @@ -304,16 +330,12 @@ private constructor( fun status(status: Status) = status(JsonField.of(status)) /** The current status of the batch. */ - @JsonProperty("status") - @ExcludeMissing fun status(status: JsonField) = apply { this.status = status } /** The ID of the file containing the outputs of successfully executed requests. */ fun outputFileId(outputFileId: String) = outputFileId(JsonField.of(outputFileId)) /** The ID of the file containing the outputs of successfully executed requests. */ - @JsonProperty("output_file_id") - @ExcludeMissing fun outputFileId(outputFileId: JsonField) = apply { this.outputFileId = outputFileId } @@ -322,80 +344,60 @@ private constructor( fun errorFileId(errorFileId: String) = errorFileId(JsonField.of(errorFileId)) /** The ID of the file containing the outputs of requests with errors. */ - @JsonProperty("error_file_id") - @ExcludeMissing fun errorFileId(errorFileId: JsonField) = apply { this.errorFileId = errorFileId } /** The Unix timestamp (in seconds) for when the batch was created. */ fun createdAt(createdAt: Long) = createdAt(JsonField.of(createdAt)) /** The Unix timestamp (in seconds) for when the batch was created. */ - @JsonProperty("created_at") - @ExcludeMissing fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } /** The Unix timestamp (in seconds) for when the batch started processing. */ fun inProgressAt(inProgressAt: Long) = inProgressAt(JsonField.of(inProgressAt)) /** The Unix timestamp (in seconds) for when the batch started processing. */ - @JsonProperty("in_progress_at") - @ExcludeMissing fun inProgressAt(inProgressAt: JsonField) = apply { this.inProgressAt = inProgressAt } /** The Unix timestamp (in seconds) for when the batch will expire. */ fun expiresAt(expiresAt: Long) = expiresAt(JsonField.of(expiresAt)) /** The Unix timestamp (in seconds) for when the batch will expire. */ - @JsonProperty("expires_at") - @ExcludeMissing fun expiresAt(expiresAt: JsonField) = apply { this.expiresAt = expiresAt } /** The Unix timestamp (in seconds) for when the batch started finalizing. */ fun finalizingAt(finalizingAt: Long) = finalizingAt(JsonField.of(finalizingAt)) /** The Unix timestamp (in seconds) for when the batch started finalizing. */ - @JsonProperty("finalizing_at") - @ExcludeMissing fun finalizingAt(finalizingAt: JsonField) = apply { this.finalizingAt = finalizingAt } /** The Unix timestamp (in seconds) for when the batch was completed. */ fun completedAt(completedAt: Long) = completedAt(JsonField.of(completedAt)) /** The Unix timestamp (in seconds) for when the batch was completed. */ - @JsonProperty("completed_at") - @ExcludeMissing fun completedAt(completedAt: JsonField) = apply { this.completedAt = completedAt } /** The Unix timestamp (in seconds) for when the batch failed. */ fun failedAt(failedAt: Long) = failedAt(JsonField.of(failedAt)) /** The Unix timestamp (in seconds) for when the batch failed. */ - @JsonProperty("failed_at") - @ExcludeMissing fun failedAt(failedAt: JsonField) = apply { this.failedAt = failedAt } /** The Unix timestamp (in seconds) for when the batch expired. */ fun expiredAt(expiredAt: Long) = expiredAt(JsonField.of(expiredAt)) /** The Unix timestamp (in seconds) for when the batch expired. */ - @JsonProperty("expired_at") - @ExcludeMissing fun expiredAt(expiredAt: JsonField) = apply { this.expiredAt = expiredAt } /** The Unix timestamp (in seconds) for when the batch started cancelling. */ fun cancellingAt(cancellingAt: Long) = cancellingAt(JsonField.of(cancellingAt)) /** The Unix timestamp (in seconds) for when the batch started cancelling. */ - @JsonProperty("cancelling_at") - @ExcludeMissing fun cancellingAt(cancellingAt: JsonField) = apply { this.cancellingAt = cancellingAt } /** The Unix timestamp (in seconds) for when the batch was cancelled. */ fun cancelledAt(cancelledAt: Long) = cancelledAt(JsonField.of(cancelledAt)) /** The Unix timestamp (in seconds) for when the batch was cancelled. */ - @JsonProperty("cancelled_at") - @ExcludeMissing fun cancelledAt(cancelledAt: JsonField) = apply { this.cancelledAt = cancelledAt } /** The request counts for different statuses within the batch. */ @@ -403,8 +405,6 @@ private constructor( requestCounts(JsonField.of(requestCounts)) /** The request counts for different statuses within the batch. */ - @JsonProperty("request_counts") - @ExcludeMissing fun requestCounts(requestCounts: JsonField) = apply { this.requestCounts = requestCounts } @@ -414,24 +414,27 @@ private constructor( * storing additional information about the object in a structured format. Keys can be a * maximum of 64 characters long and values can be a maximum of 512 characters long. */ - @JsonProperty("metadata") - @ExcludeMissing fun metadata(metadata: JsonValue) = apply { this.metadata = metadata } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + 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) + } + fun build(): Batch = Batch( id, @@ -602,17 +605,20 @@ private constructor( override fun toString() = value.toString() } - @JsonDeserialize(builder = Errors.Builder::class) @NoAutoDetect class Errors + @JsonCreator private constructor( - private val object_: JsonField, - private val data: JsonField>, - private val additionalProperties: Map, + @JsonProperty("object") + @ExcludeMissing + private val object_: JsonField = JsonMissing.of(), + @JsonProperty("data") + @ExcludeMissing + private val data: JsonField> = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - /** The object type, which is always `list`. */ fun object_(): Optional = Optional.ofNullable(object_.getNullable("object")) @@ -627,6 +633,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Errors = apply { if (!validated) { object_() @@ -650,39 +658,40 @@ private constructor( @JvmSynthetic internal fun from(errors: Errors) = apply { - this.object_ = errors.object_ - this.data = errors.data - additionalProperties(errors.additionalProperties) + object_ = errors.object_ + data = errors.data + additionalProperties = errors.additionalProperties.toMutableMap() } /** The object type, which is always `list`. */ fun object_(object_: String) = object_(JsonField.of(object_)) /** The object type, which is always `list`. */ - @JsonProperty("object") - @ExcludeMissing fun object_(object_: JsonField) = apply { this.object_ = object_ } fun data(data: List) = data(JsonField.of(data)) - @JsonProperty("data") - @ExcludeMissing fun data(data: JsonField>) = apply { this.data = data } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + 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) + } + fun build(): Errors = Errors( object_, diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BatchCancelParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BatchCancelParams.kt index 5492f57b..7b50d4dc 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/BatchCancelParams.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/BatchCancelParams.kt @@ -27,9 +27,8 @@ constructor( fun _additionalBodyProperties(): Map = additionalBodyProperties @JvmSynthetic - internal fun getBody(): Optional> { - return Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) - } + internal fun getBody(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BatchCreateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BatchCreateParams.kt index a2ba22b5..8c62580c 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/BatchCreateParams.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/BatchCreateParams.kt @@ -6,7 +6,6 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.databind.annotation.JsonDeserialize import com.openai.core.Enum import com.openai.core.ExcludeMissing import com.openai.core.JsonField @@ -14,6 +13,7 @@ import com.openai.core.JsonValue import com.openai.core.NoAutoDetect import com.openai.core.http.Headers import com.openai.core.http.QueryParams +import com.openai.core.immutableEmptyMap import com.openai.core.toImmutable import com.openai.errors.OpenAIInvalidDataException import java.util.Objects @@ -21,53 +21,61 @@ import java.util.Optional class BatchCreateParams constructor( - private val completionWindow: CompletionWindow, - private val endpoint: Endpoint, - private val inputFileId: String, - private val metadata: Metadata?, + private val body: BatchCreateBody, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, - private val additionalBodyProperties: Map, ) { - fun completionWindow(): CompletionWindow = completionWindow + /** + * The time frame within which the batch should be processed. Currently only `24h` is supported. + */ + fun completionWindow(): CompletionWindow = body.completionWindow() + + /** + * The endpoint to be used for all requests in the batch. Currently `/v1/chat/completions`, + * `/v1/embeddings`, and `/v1/completions` are supported. Note that `/v1/embeddings` batches are + * also restricted to a maximum of 50,000 embedding inputs across all requests in the batch. + */ + fun endpoint(): Endpoint = body.endpoint() + + /** + * The ID of an uploaded file that contains requests for the new batch. + * + * See [upload file](https://platform.openai.com/docs/api-reference/files/create) for how to + * upload a file. + * + * Your input file must be formatted as a + * [JSONL file](https://platform.openai.com/docs/api-reference/batch/request-input), and must be + * uploaded with the purpose `batch`. The file can contain up to 50,000 requests, and can be up + * to 200 MB in size. + */ + fun inputFileId(): String = body.inputFileId() - fun endpoint(): Endpoint = endpoint - - fun inputFileId(): String = inputFileId - - fun metadata(): Optional = Optional.ofNullable(metadata) + /** Optional custom metadata for the batch. */ + fun metadata(): Optional = body.metadata() fun _additionalHeaders(): Headers = additionalHeaders fun _additionalQueryParams(): QueryParams = additionalQueryParams - fun _additionalBodyProperties(): Map = additionalBodyProperties - - @JvmSynthetic - internal fun getBody(): BatchCreateBody { - return BatchCreateBody( - completionWindow, - endpoint, - inputFileId, - metadata, - additionalBodyProperties, - ) - } + fun _additionalBodyProperties(): Map = body._additionalProperties() + + @JvmSynthetic internal fun getBody(): BatchCreateBody = body @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams - @JsonDeserialize(builder = BatchCreateBody.Builder::class) @NoAutoDetect class BatchCreateBody + @JsonCreator internal constructor( - private val completionWindow: CompletionWindow?, - private val endpoint: Endpoint?, - private val inputFileId: String?, - private val metadata: Metadata?, - private val additionalProperties: Map, + @JsonProperty("completion_window") private val completionWindow: CompletionWindow, + @JsonProperty("endpoint") private val endpoint: Endpoint, + @JsonProperty("input_file_id") private val inputFileId: String, + @JsonProperty("metadata") private val metadata: Metadata?, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { /** @@ -75,7 +83,7 @@ constructor( * supported. */ @JsonProperty("completion_window") - fun completionWindow(): CompletionWindow? = completionWindow + fun completionWindow(): CompletionWindow = completionWindow /** * The endpoint to be used for all requests in the batch. Currently `/v1/chat/completions`, @@ -83,7 +91,7 @@ constructor( * are also restricted to a maximum of 50,000 embedding inputs across all requests in the * batch. */ - @JsonProperty("endpoint") fun endpoint(): Endpoint? = endpoint + @JsonProperty("endpoint") fun endpoint(): Endpoint = endpoint /** * The ID of an uploaded file that contains requests for the new batch. @@ -96,10 +104,10 @@ constructor( * must be uploaded with the purpose `batch`. The file can contain up to 50,000 requests, * and can be up to 200 MB in size. */ - @JsonProperty("input_file_id") fun inputFileId(): String? = inputFileId + @JsonProperty("input_file_id") fun inputFileId(): String = inputFileId /** Optional custom metadata for the batch. */ - @JsonProperty("metadata") fun metadata(): Metadata? = metadata + @JsonProperty("metadata") fun metadata(): Optional = Optional.ofNullable(metadata) @JsonAnyGetter @ExcludeMissing @@ -122,18 +130,17 @@ constructor( @JvmSynthetic internal fun from(batchCreateBody: BatchCreateBody) = apply { - this.completionWindow = batchCreateBody.completionWindow - this.endpoint = batchCreateBody.endpoint - this.inputFileId = batchCreateBody.inputFileId - this.metadata = batchCreateBody.metadata - additionalProperties(batchCreateBody.additionalProperties) + completionWindow = batchCreateBody.completionWindow + endpoint = batchCreateBody.endpoint + inputFileId = batchCreateBody.inputFileId + metadata = batchCreateBody.metadata + additionalProperties = batchCreateBody.additionalProperties.toMutableMap() } /** * The time frame within which the batch should be processed. Currently only `24h` is * supported. */ - @JsonProperty("completion_window") fun completionWindow(completionWindow: CompletionWindow) = apply { this.completionWindow = completionWindow } @@ -144,7 +151,6 @@ constructor( * that `/v1/embeddings` batches are also restricted to a maximum of 50,000 embedding * inputs across all requests in the batch. */ - @JsonProperty("endpoint") fun endpoint(endpoint: Endpoint) = apply { this.endpoint = endpoint } /** @@ -158,27 +164,30 @@ constructor( * must be uploaded with the purpose `batch`. The file can contain up to 50,000 * requests, and can be up to 200 MB in size. */ - @JsonProperty("input_file_id") fun inputFileId(inputFileId: String) = apply { this.inputFileId = inputFileId } /** Optional custom metadata for the batch. */ - @JsonProperty("metadata") fun metadata(metadata: Metadata) = apply { this.metadata = metadata } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + 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) + } + fun build(): BatchCreateBody = BatchCreateBody( checkNotNull(completionWindow) { @@ -219,23 +228,15 @@ constructor( @NoAutoDetect class Builder { - private var completionWindow: CompletionWindow? = null - private var endpoint: Endpoint? = null - private var inputFileId: String? = null - private var metadata: Metadata? = null + private var body: BatchCreateBody.Builder = BatchCreateBody.builder() private var additionalHeaders: Headers.Builder = Headers.builder() private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() - private var additionalBodyProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(batchCreateParams: BatchCreateParams) = apply { - completionWindow = batchCreateParams.completionWindow - endpoint = batchCreateParams.endpoint - inputFileId = batchCreateParams.inputFileId - metadata = batchCreateParams.metadata + body = batchCreateParams.body.toBuilder() additionalHeaders = batchCreateParams.additionalHeaders.toBuilder() additionalQueryParams = batchCreateParams.additionalQueryParams.toBuilder() - additionalBodyProperties = batchCreateParams.additionalBodyProperties.toMutableMap() } /** @@ -243,7 +244,7 @@ constructor( * supported. */ fun completionWindow(completionWindow: CompletionWindow) = apply { - this.completionWindow = completionWindow + body.completionWindow(completionWindow) } /** @@ -252,7 +253,7 @@ constructor( * are also restricted to a maximum of 50,000 embedding inputs across all requests in the * batch. */ - fun endpoint(endpoint: Endpoint) = apply { this.endpoint = endpoint } + fun endpoint(endpoint: Endpoint) = apply { body.endpoint(endpoint) } /** * The ID of an uploaded file that contains requests for the new batch. @@ -265,10 +266,10 @@ constructor( * must be uploaded with the purpose `batch`. The file can contain up to 50,000 requests, * and can be up to 200 MB in size. */ - fun inputFileId(inputFileId: String) = apply { this.inputFileId = inputFileId } + fun inputFileId(inputFileId: String) = apply { body.inputFileId(inputFileId) } /** Optional custom metadata for the batch. */ - fun metadata(metadata: Metadata) = apply { this.metadata = metadata } + fun metadata(metadata: Metadata) = apply { body.metadata(metadata) } fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -369,36 +370,29 @@ constructor( } fun additionalBodyProperties(additionalBodyProperties: Map) = apply { - this.additionalBodyProperties.clear() - putAllAdditionalBodyProperties(additionalBodyProperties) + body.additionalProperties(additionalBodyProperties) } fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - additionalBodyProperties.put(key, value) + body.putAdditionalProperty(key, value) } fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = apply { - this.additionalBodyProperties.putAll(additionalBodyProperties) + body.putAllAdditionalProperties(additionalBodyProperties) } - fun removeAdditionalBodyProperty(key: String) = apply { - additionalBodyProperties.remove(key) - } + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } fun removeAllAdditionalBodyProperties(keys: Set) = apply { - keys.forEach(::removeAdditionalBodyProperty) + body.removeAllAdditionalProperties(keys) } fun build(): BatchCreateParams = BatchCreateParams( - checkNotNull(completionWindow) { "`completionWindow` is required but was not set" }, - checkNotNull(endpoint) { "`endpoint` is required but was not set" }, - checkNotNull(inputFileId) { "`inputFileId` is required but was not set" }, - metadata, + body.build(), additionalHeaders.build(), additionalQueryParams.build(), - additionalBodyProperties.toImmutable(), ) } @@ -517,11 +511,12 @@ constructor( } /** Optional custom metadata for the batch. */ - @JsonDeserialize(builder = Metadata.Builder::class) @NoAutoDetect class Metadata + @JsonCreator private constructor( - private val additionalProperties: Map, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { @JsonAnyGetter @@ -541,23 +536,28 @@ constructor( @JvmSynthetic internal fun from(metadata: Metadata) = apply { - additionalProperties(metadata.additionalProperties) + additionalProperties = metadata.additionalProperties.toMutableMap() } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + 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) + } + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) } @@ -583,11 +583,11 @@ constructor( return true } - return /* spotless:off */ other is BatchCreateParams && completionWindow == other.completionWindow && endpoint == other.endpoint && inputFileId == other.inputFileId && metadata == other.metadata && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + return /* spotless:off */ other is BatchCreateParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(completionWindow, endpoint, inputFileId, metadata, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ + override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ override fun toString() = - "BatchCreateParams{completionWindow=$completionWindow, endpoint=$endpoint, inputFileId=$inputFileId, metadata=$metadata, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" + "BatchCreateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BatchError.kt b/openai-java-core/src/main/kotlin/com/openai/models/BatchError.kt index 5dc77def..9695ca15 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/BatchError.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/BatchError.kt @@ -4,30 +4,31 @@ package com.openai.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.fasterxml.jackson.databind.annotation.JsonDeserialize import com.openai.core.ExcludeMissing import com.openai.core.JsonField import com.openai.core.JsonMissing import com.openai.core.JsonValue import com.openai.core.NoAutoDetect +import com.openai.core.immutableEmptyMap import com.openai.core.toImmutable import java.util.Objects import java.util.Optional -@JsonDeserialize(builder = BatchError.Builder::class) @NoAutoDetect class BatchError +@JsonCreator private constructor( - private val code: JsonField, - private val message: JsonField, - private val param: JsonField, - private val line: JsonField, - private val additionalProperties: Map, + @JsonProperty("code") @ExcludeMissing private val code: JsonField = JsonMissing.of(), + @JsonProperty("message") + @ExcludeMissing + private val message: JsonField = JsonMissing.of(), + @JsonProperty("param") @ExcludeMissing private val param: JsonField = JsonMissing.of(), + @JsonProperty("line") @ExcludeMissing private val line: JsonField = JsonMissing.of(), + @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - /** An error code identifying the error type. */ fun code(): Optional = Optional.ofNullable(code.getNullable("code")) @@ -56,6 +57,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): BatchError = apply { if (!validated) { code() @@ -83,59 +86,56 @@ private constructor( @JvmSynthetic internal fun from(batchError: BatchError) = apply { - this.code = batchError.code - this.message = batchError.message - this.param = batchError.param - this.line = batchError.line - additionalProperties(batchError.additionalProperties) + code = batchError.code + message = batchError.message + param = batchError.param + line = batchError.line + additionalProperties = batchError.additionalProperties.toMutableMap() } /** An error code identifying the error type. */ fun code(code: String) = code(JsonField.of(code)) /** An error code identifying the error type. */ - @JsonProperty("code") - @ExcludeMissing fun code(code: JsonField) = apply { this.code = code } /** A human-readable message providing more details about the error. */ fun message(message: String) = message(JsonField.of(message)) /** A human-readable message providing more details about the error. */ - @JsonProperty("message") - @ExcludeMissing fun message(message: JsonField) = apply { this.message = message } /** The name of the parameter that caused the error, if applicable. */ fun param(param: String) = param(JsonField.of(param)) /** The name of the parameter that caused the error, if applicable. */ - @JsonProperty("param") - @ExcludeMissing fun param(param: JsonField) = apply { this.param = param } /** The line number of the input file where the error occurred, if applicable. */ fun line(line: Long) = line(JsonField.of(line)) /** The line number of the input file where the error occurred, if applicable. */ - @JsonProperty("line") - @ExcludeMissing fun line(line: JsonField) = apply { this.line = line } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + 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) + } + fun build(): BatchError = BatchError( code, diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BatchListPage.kt b/openai-java-core/src/main/kotlin/com/openai/models/BatchListPage.kt index 4e914630..6e01dd49 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/BatchListPage.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/BatchListPage.kt @@ -4,13 +4,14 @@ package com.openai.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.fasterxml.jackson.databind.annotation.JsonDeserialize import com.openai.core.ExcludeMissing import com.openai.core.JsonField import com.openai.core.JsonMissing import com.openai.core.JsonValue import com.openai.core.NoAutoDetect +import com.openai.core.immutableEmptyMap import com.openai.core.toImmutable import com.openai.services.blocking.BatchService import java.util.Objects @@ -71,12 +72,13 @@ private constructor( ) } - @JsonDeserialize(builder = Response.Builder::class) @NoAutoDetect class Response + @JsonCreator constructor( - private val data: JsonField>, - private val additionalProperties: Map, + @JsonProperty("data") private val data: JsonField> = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { private var validated: Boolean = false @@ -129,10 +131,8 @@ private constructor( fun data(data: List) = data(JsonField.of(data)) - @JsonProperty("data") fun data(data: JsonField>) = apply { this.data = data } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { this.additionalProperties.put(key, value) } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BatchListPageAsync.kt b/openai-java-core/src/main/kotlin/com/openai/models/BatchListPageAsync.kt index 5e4b7b4c..70a27dd9 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/BatchListPageAsync.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/BatchListPageAsync.kt @@ -4,13 +4,14 @@ package com.openai.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.fasterxml.jackson.databind.annotation.JsonDeserialize import com.openai.core.ExcludeMissing import com.openai.core.JsonField import com.openai.core.JsonMissing import com.openai.core.JsonValue import com.openai.core.NoAutoDetect +import com.openai.core.immutableEmptyMap import com.openai.core.toImmutable import com.openai.services.async.BatchServiceAsync import java.util.Objects @@ -74,12 +75,13 @@ private constructor( ) } - @JsonDeserialize(builder = Response.Builder::class) @NoAutoDetect class Response + @JsonCreator constructor( - private val data: JsonField>, - private val additionalProperties: Map, + @JsonProperty("data") private val data: JsonField> = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { private var validated: Boolean = false @@ -132,10 +134,8 @@ private constructor( fun data(data: List) = data(JsonField.of(data)) - @JsonProperty("data") fun data(data: JsonField>) = apply { this.data = data } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { this.additionalProperties.put(key, value) } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BatchListParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BatchListParams.kt index 648c0c97..8e9d7d33 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/BatchListParams.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/BatchListParams.kt @@ -16,8 +16,17 @@ constructor( private val additionalQueryParams: QueryParams, ) { + /** + * A cursor for use in pagination. `after` is an object ID that defines your place in the list. + * For instance, if you make a list request and receive 100 objects, ending with obj_foo, your + * subsequent call can include after=obj_foo in order to fetch the next page of the list. + */ fun after(): Optional = Optional.ofNullable(after) + /** + * A limit on the number of objects to be returned. Limit can range between 1 and 100, and the + * default is 20. + */ fun limit(): Optional = Optional.ofNullable(limit) fun _additionalHeaders(): Headers = additionalHeaders diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BatchRequestCounts.kt b/openai-java-core/src/main/kotlin/com/openai/models/BatchRequestCounts.kt index 9b5d4b69..e3a553d0 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/BatchRequestCounts.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/BatchRequestCounts.kt @@ -4,29 +4,30 @@ package com.openai.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.fasterxml.jackson.databind.annotation.JsonDeserialize import com.openai.core.ExcludeMissing import com.openai.core.JsonField import com.openai.core.JsonMissing import com.openai.core.JsonValue import com.openai.core.NoAutoDetect +import com.openai.core.immutableEmptyMap import com.openai.core.toImmutable import java.util.Objects /** The request counts for different statuses within the batch. */ -@JsonDeserialize(builder = BatchRequestCounts.Builder::class) @NoAutoDetect class BatchRequestCounts +@JsonCreator private constructor( - private val total: JsonField, - private val completed: JsonField, - private val failed: JsonField, - private val additionalProperties: Map, + @JsonProperty("total") @ExcludeMissing private val total: JsonField = JsonMissing.of(), + @JsonProperty("completed") + @ExcludeMissing + private val completed: JsonField = JsonMissing.of(), + @JsonProperty("failed") @ExcludeMissing private val failed: JsonField = JsonMissing.of(), + @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - /** Total number of requests in the batch. */ fun total(): Long = total.getRequired("total") @@ -49,6 +50,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): BatchRequestCounts = apply { if (!validated) { total() @@ -74,50 +77,49 @@ private constructor( @JvmSynthetic internal fun from(batchRequestCounts: BatchRequestCounts) = apply { - this.total = batchRequestCounts.total - this.completed = batchRequestCounts.completed - this.failed = batchRequestCounts.failed - additionalProperties(batchRequestCounts.additionalProperties) + total = batchRequestCounts.total + completed = batchRequestCounts.completed + failed = batchRequestCounts.failed + additionalProperties = batchRequestCounts.additionalProperties.toMutableMap() } /** Total number of requests in the batch. */ fun total(total: Long) = total(JsonField.of(total)) /** Total number of requests in the batch. */ - @JsonProperty("total") - @ExcludeMissing fun total(total: JsonField) = apply { this.total = total } /** Number of requests that have been completed successfully. */ fun completed(completed: Long) = completed(JsonField.of(completed)) /** Number of requests that have been completed successfully. */ - @JsonProperty("completed") - @ExcludeMissing fun completed(completed: JsonField) = apply { this.completed = completed } /** Number of requests that have failed. */ fun failed(failed: Long) = failed(JsonField.of(failed)) /** Number of requests that have failed. */ - @JsonProperty("failed") - @ExcludeMissing fun failed(failed: JsonField) = apply { this.failed = failed } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + 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) + } + fun build(): BatchRequestCounts = BatchRequestCounts( total, diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaAssistantCreateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaAssistantCreateParams.kt new file mode 100644 index 00000000..e209b814 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaAssistantCreateParams.kt @@ -0,0 +1,1210 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.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.JsonValue +import com.openai.core.NoAutoDetect +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.core.immutableEmptyMap +import com.openai.core.toImmutable +import java.util.Objects +import java.util.Optional + +class BetaAssistantCreateParams +constructor( + private val body: BetaAssistantCreateBody, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) { + + /** + * ID of the model to use. You can use the + * [List models](https://platform.openai.com/docs/api-reference/models/list) API to see all of + * your available models, or see our [Model overview](https://platform.openai.com/docs/models) + * for descriptions of them. + */ + fun model(): ChatModel = body.model() + + /** The description of the assistant. The maximum length is 512 characters. */ + fun description(): Optional = body.description() + + /** + * The system instructions that the assistant uses. The maximum length is 256,000 characters. + */ + fun instructions(): Optional = body.instructions() + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for storing + * additional information about the object in a structured format. Keys can be a maximum of 64 + * characters long and values can be a maximum of 512 characters long. + */ + fun metadata(): Optional = body.metadata() + + /** The name of the assistant. The maximum length is 256 characters. */ + fun name(): Optional = body.name() + + /** + * Specifies the format that the model must output. Compatible with + * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o), [GPT-4 + * Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4), and all GPT-3.5 Turbo + * models since `gpt-3.5-turbo-1106`. + * + * Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured Outputs which + * ensures the model will match your supplied JSON schema. Learn more in the + * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs). + * + * Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the message the model + * generates is valid JSON. + * + * **Important:** when using JSON mode, you **must** also instruct the model to produce JSON + * yourself via a system or user message. Without this, the model may generate an unending + * stream of whitespace until the generation reaches the token limit, resulting in a + * long-running and seemingly "stuck" request. Also note that the message content may be + * partially cut off if `finish_reason="length"`, which indicates the generation exceeded + * `max_tokens` or the conversation exceeded the max context length. + */ + fun responseFormat(): Optional = body.responseFormat() + + /** + * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the + * output more random, while lower values like 0.2 will make it more focused and deterministic. + */ + fun temperature(): Optional = body.temperature() + + /** + * A set of resources that are used by the assistant's tools. The resources are specific to the + * type of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the + * `file_search` tool requires a list of vector store IDs. + */ + fun toolResources(): Optional = body.toolResources() + + /** + * A list of tool enabled on the assistant. There can be a maximum of 128 tools per assistant. + * Tools can be of types `code_interpreter`, `file_search`, or `function`. + */ + fun tools(): Optional> = body.tools() + + /** + * An alternative to sampling with temperature, called nucleus sampling, where the model + * considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens + * comprising the top 10% probability mass are considered. + * + * We generally recommend altering this or temperature but not both. + */ + fun topP(): Optional = body.topP() + + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun _additionalBodyProperties(): Map = body._additionalProperties() + + @JvmSynthetic internal fun getBody(): BetaAssistantCreateBody = body + + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + + @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams + + @NoAutoDetect + class BetaAssistantCreateBody + @JsonCreator + internal constructor( + @JsonProperty("model") private val model: ChatModel, + @JsonProperty("description") private val description: String?, + @JsonProperty("instructions") private val instructions: String?, + @JsonProperty("metadata") private val metadata: JsonValue?, + @JsonProperty("name") private val name: String?, + @JsonProperty("response_format") private val responseFormat: AssistantResponseFormatOption?, + @JsonProperty("temperature") private val temperature: Double?, + @JsonProperty("tool_resources") private val toolResources: ToolResources?, + @JsonProperty("tools") private val tools: List?, + @JsonProperty("top_p") private val topP: Double?, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** + * ID of the model to use. You can use the + * [List models](https://platform.openai.com/docs/api-reference/models/list) API to see all + * of your available models, or see our + * [Model overview](https://platform.openai.com/docs/models) for descriptions of them. + */ + @JsonProperty("model") fun model(): ChatModel = model + + /** The description of the assistant. The maximum length is 512 characters. */ + @JsonProperty("description") + fun description(): Optional = Optional.ofNullable(description) + + /** + * The system instructions that the assistant uses. The maximum length is 256,000 + * characters. + */ + @JsonProperty("instructions") + fun instructions(): Optional = Optional.ofNullable(instructions) + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format. Keys can be a + * maximum of 64 characters long and values can be a maximum of 512 characters long. + */ + @JsonProperty("metadata") + fun metadata(): Optional = Optional.ofNullable(metadata) + + /** The name of the assistant. The maximum length is 256 characters. */ + @JsonProperty("name") fun name(): Optional = Optional.ofNullable(name) + + /** + * Specifies the format that the model must output. Compatible with + * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o), [GPT-4 + * Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4), and all GPT-3.5 + * Turbo models since `gpt-3.5-turbo-1106`. + * + * Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured Outputs + * which ensures the model will match your supplied JSON schema. Learn more in the + * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs). + * + * Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the message the + * model generates is valid JSON. + * + * **Important:** when using JSON mode, you **must** also instruct the model to produce JSON + * yourself via a system or user message. Without this, the model may generate an unending + * stream of whitespace until the generation reaches the token limit, resulting in a + * long-running and seemingly "stuck" request. Also note that the message content may be + * partially cut off if `finish_reason="length"`, which indicates the generation exceeded + * `max_tokens` or the conversation exceeded the max context length. + */ + @JsonProperty("response_format") + fun responseFormat(): Optional = + Optional.ofNullable(responseFormat) + + /** + * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the + * output more random, while lower values like 0.2 will make it more focused and + * deterministic. + */ + @JsonProperty("temperature") + fun temperature(): Optional = Optional.ofNullable(temperature) + + /** + * A set of resources that are used by the assistant's tools. The resources are specific to + * the type of tool. For example, the `code_interpreter` tool requires a list of file IDs, + * while the `file_search` tool requires a list of vector store IDs. + */ + @JsonProperty("tool_resources") + fun toolResources(): Optional = Optional.ofNullable(toolResources) + + /** + * A list of tool enabled on the assistant. There can be a maximum of 128 tools per + * assistant. Tools can be of types `code_interpreter`, `file_search`, or `function`. + */ + @JsonProperty("tools") + fun tools(): Optional> = Optional.ofNullable(tools) + + /** + * An alternative to sampling with temperature, called nucleus sampling, where the model + * considers the results of the tokens with top_p probability mass. So 0.1 means only the + * tokens comprising the top 10% probability mass are considered. + * + * We generally recommend altering this or temperature but not both. + */ + @JsonProperty("top_p") fun topP(): Optional = Optional.ofNullable(topP) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var model: ChatModel? = null + private var description: String? = null + private var instructions: String? = null + private var metadata: JsonValue? = null + private var name: String? = null + private var responseFormat: AssistantResponseFormatOption? = null + private var temperature: Double? = null + private var toolResources: ToolResources? = null + private var tools: MutableList? = null + private var topP: Double? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaAssistantCreateBody: BetaAssistantCreateBody) = apply { + model = betaAssistantCreateBody.model + description = betaAssistantCreateBody.description + instructions = betaAssistantCreateBody.instructions + metadata = betaAssistantCreateBody.metadata + name = betaAssistantCreateBody.name + responseFormat = betaAssistantCreateBody.responseFormat + temperature = betaAssistantCreateBody.temperature + toolResources = betaAssistantCreateBody.toolResources + tools = betaAssistantCreateBody.tools?.toMutableList() + topP = betaAssistantCreateBody.topP + additionalProperties = betaAssistantCreateBody.additionalProperties.toMutableMap() + } + + /** + * ID of the model to use. You can use the + * [List models](https://platform.openai.com/docs/api-reference/models/list) API to see + * all of your available models, or see our + * [Model overview](https://platform.openai.com/docs/models) for descriptions of them. + */ + fun model(model: ChatModel) = apply { this.model = model } + + /** + * ID of the model to use. You can use the + * [List models](https://platform.openai.com/docs/api-reference/models/list) API to see + * all of your available models, or see our + * [Model overview](https://platform.openai.com/docs/models) for descriptions of them. + */ + fun model(value: String) = apply { model = ChatModel.of(value) } + + /** The description of the assistant. The maximum length is 512 characters. */ + fun description(description: String) = apply { this.description = description } + + /** + * The system instructions that the assistant uses. The maximum length is 256,000 + * characters. + */ + fun instructions(instructions: String) = apply { this.instructions = instructions } + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format. Keys can be a + * maximum of 64 characters long and values can be a maximum of 512 characters long. + */ + fun metadata(metadata: JsonValue) = apply { this.metadata = metadata } + + /** The name of the assistant. The maximum length is 256 characters. */ + fun name(name: String) = apply { this.name = name } + + /** + * Specifies the format that the model must output. Compatible with + * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o), [GPT-4 + * Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4), and all + * GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`. + * + * Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured + * Outputs which ensures the model will match your supplied JSON schema. Learn more in + * the + * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs). + * + * Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the message + * the model generates is valid JSON. + * + * **Important:** when using JSON mode, you **must** also instruct the model to produce + * JSON yourself via a system or user message. Without this, the model may generate an + * unending stream of whitespace until the generation reaches the token limit, resulting + * in a long-running and seemingly "stuck" request. Also note that the message content + * may be partially cut off if `finish_reason="length"`, which indicates the generation + * exceeded `max_tokens` or the conversation exceeded the max context length. + */ + fun responseFormat(responseFormat: AssistantResponseFormatOption) = apply { + this.responseFormat = responseFormat + } + + /** `auto` is the default value */ + fun responseFormat(behavior: AssistantResponseFormatOption.Behavior) = apply { + this.responseFormat = AssistantResponseFormatOption.ofBehavior(behavior) + } + + fun responseFormat(responseFormatText: ResponseFormatText) = apply { + this.responseFormat = + AssistantResponseFormatOption.ofResponseFormatText(responseFormatText) + } + + fun responseFormat(responseFormatJsonObject: ResponseFormatJsonObject) = apply { + this.responseFormat = + AssistantResponseFormatOption.ofResponseFormatJsonObject( + responseFormatJsonObject + ) + } + + fun responseFormat(responseFormatJsonSchema: ResponseFormatJsonSchema) = apply { + this.responseFormat = + AssistantResponseFormatOption.ofResponseFormatJsonSchema( + responseFormatJsonSchema + ) + } + + /** + * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make + * the output more random, while lower values like 0.2 will make it more focused and + * deterministic. + */ + fun temperature(temperature: Double) = apply { this.temperature = temperature } + + /** + * A set of resources that are used by the assistant's tools. The resources are specific + * to the type of tool. For example, the `code_interpreter` tool requires a list of file + * IDs, while the `file_search` tool requires a list of vector store IDs. + */ + fun toolResources(toolResources: ToolResources) = apply { + this.toolResources = toolResources + } + + /** + * A list of tool enabled on the assistant. There can be a maximum of 128 tools per + * assistant. Tools can be of types `code_interpreter`, `file_search`, or `function`. + */ + fun tools(tools: List) = apply { this.tools = tools.toMutableList() } + + /** + * A list of tool enabled on the assistant. There can be a maximum of 128 tools per + * assistant. Tools can be of types `code_interpreter`, `file_search`, or `function`. + */ + fun addTool(tool: AssistantTool) = apply { + tools = (tools ?: mutableListOf()).apply { add(tool) } + } + + /** + * An alternative to sampling with temperature, called nucleus sampling, where the model + * considers the results of the tokens with top_p probability mass. So 0.1 means only + * the tokens comprising the top 10% probability mass are considered. + * + * We generally recommend altering this or temperature but not both. + */ + fun topP(topP: Double) = apply { this.topP = topP } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + fun build(): BetaAssistantCreateBody = + BetaAssistantCreateBody( + checkNotNull(model) { "`model` is required but was not set" }, + description, + instructions, + metadata, + name, + responseFormat, + temperature, + toolResources, + tools?.toImmutable(), + topP, + additionalProperties.toImmutable(), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaAssistantCreateBody && model == other.model && description == other.description && instructions == other.instructions && metadata == other.metadata && name == other.name && responseFormat == other.responseFormat && temperature == other.temperature && toolResources == other.toolResources && tools == other.tools && topP == other.topP && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(model, description, instructions, metadata, name, responseFormat, temperature, toolResources, tools, topP, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaAssistantCreateBody{model=$model, description=$description, instructions=$instructions, metadata=$metadata, name=$name, responseFormat=$responseFormat, temperature=$temperature, toolResources=$toolResources, tools=$tools, topP=$topP, additionalProperties=$additionalProperties}" + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + @NoAutoDetect + class Builder { + + private var body: BetaAssistantCreateBody.Builder = BetaAssistantCreateBody.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(betaAssistantCreateParams: BetaAssistantCreateParams) = apply { + body = betaAssistantCreateParams.body.toBuilder() + additionalHeaders = betaAssistantCreateParams.additionalHeaders.toBuilder() + additionalQueryParams = betaAssistantCreateParams.additionalQueryParams.toBuilder() + } + + /** + * ID of the model to use. You can use the + * [List models](https://platform.openai.com/docs/api-reference/models/list) API to see all + * of your available models, or see our + * [Model overview](https://platform.openai.com/docs/models) for descriptions of them. + */ + fun model(model: ChatModel) = apply { body.model(model) } + + /** + * ID of the model to use. You can use the + * [List models](https://platform.openai.com/docs/api-reference/models/list) API to see all + * of your available models, or see our + * [Model overview](https://platform.openai.com/docs/models) for descriptions of them. + */ + fun model(value: String) = apply { body.model(value) } + + /** The description of the assistant. The maximum length is 512 characters. */ + fun description(description: String) = apply { body.description(description) } + + /** + * The system instructions that the assistant uses. The maximum length is 256,000 + * characters. + */ + fun instructions(instructions: String) = apply { body.instructions(instructions) } + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format. Keys can be a + * maximum of 64 characters long and values can be a maximum of 512 characters long. + */ + fun metadata(metadata: JsonValue) = apply { body.metadata(metadata) } + + /** The name of the assistant. The maximum length is 256 characters. */ + fun name(name: String) = apply { body.name(name) } + + /** + * Specifies the format that the model must output. Compatible with + * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o), [GPT-4 + * Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4), and all GPT-3.5 + * Turbo models since `gpt-3.5-turbo-1106`. + * + * Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured Outputs + * which ensures the model will match your supplied JSON schema. Learn more in the + * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs). + * + * Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the message the + * model generates is valid JSON. + * + * **Important:** when using JSON mode, you **must** also instruct the model to produce JSON + * yourself via a system or user message. Without this, the model may generate an unending + * stream of whitespace until the generation reaches the token limit, resulting in a + * long-running and seemingly "stuck" request. Also note that the message content may be + * partially cut off if `finish_reason="length"`, which indicates the generation exceeded + * `max_tokens` or the conversation exceeded the max context length. + */ + fun responseFormat(responseFormat: AssistantResponseFormatOption) = apply { + body.responseFormat(responseFormat) + } + + /** `auto` is the default value */ + fun responseFormat(behavior: AssistantResponseFormatOption.Behavior) = apply { + body.responseFormat(behavior) + } + + fun responseFormat(responseFormatText: ResponseFormatText) = apply { + body.responseFormat(responseFormatText) + } + + fun responseFormat(responseFormatJsonObject: ResponseFormatJsonObject) = apply { + body.responseFormat(responseFormatJsonObject) + } + + fun responseFormat(responseFormatJsonSchema: ResponseFormatJsonSchema) = apply { + body.responseFormat(responseFormatJsonSchema) + } + + /** + * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the + * output more random, while lower values like 0.2 will make it more focused and + * deterministic. + */ + fun temperature(temperature: Double) = apply { body.temperature(temperature) } + + /** + * A set of resources that are used by the assistant's tools. The resources are specific to + * the type of tool. For example, the `code_interpreter` tool requires a list of file IDs, + * while the `file_search` tool requires a list of vector store IDs. + */ + fun toolResources(toolResources: ToolResources) = apply { + body.toolResources(toolResources) + } + + /** + * A list of tool enabled on the assistant. There can be a maximum of 128 tools per + * assistant. Tools can be of types `code_interpreter`, `file_search`, or `function`. + */ + fun tools(tools: List) = apply { body.tools(tools) } + + /** + * A list of tool enabled on the assistant. There can be a maximum of 128 tools per + * assistant. Tools can be of types `code_interpreter`, `file_search`, or `function`. + */ + fun addTool(tool: AssistantTool) = apply { body.addTool(tool) } + + /** + * An alternative to sampling with temperature, called nucleus sampling, where the model + * considers the results of the tokens with top_p probability mass. So 0.1 means only the + * tokens comprising the top 10% probability mass are considered. + * + * We generally recommend altering this or temperature but not both. + */ + fun topP(topP: Double) = apply { body.topP(topP) } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } + + fun build(): BetaAssistantCreateParams = + BetaAssistantCreateParams( + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + /** + * A set of resources that are used by the assistant's tools. The resources are specific to the + * type of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the + * `file_search` tool requires a list of vector store IDs. + */ + @NoAutoDetect + class ToolResources + @JsonCreator + private constructor( + @JsonProperty("code_interpreter") private val codeInterpreter: CodeInterpreter?, + @JsonProperty("file_search") private val fileSearch: FileSearch?, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + @JsonProperty("code_interpreter") + fun codeInterpreter(): Optional = Optional.ofNullable(codeInterpreter) + + @JsonProperty("file_search") + fun fileSearch(): Optional = Optional.ofNullable(fileSearch) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var codeInterpreter: CodeInterpreter? = null + private var fileSearch: FileSearch? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(toolResources: ToolResources) = apply { + codeInterpreter = toolResources.codeInterpreter + fileSearch = toolResources.fileSearch + additionalProperties = toolResources.additionalProperties.toMutableMap() + } + + fun codeInterpreter(codeInterpreter: CodeInterpreter) = apply { + this.codeInterpreter = codeInterpreter + } + + fun fileSearch(fileSearch: FileSearch) = apply { this.fileSearch = fileSearch } + + 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) + } + + fun build(): ToolResources = + ToolResources( + codeInterpreter, + fileSearch, + additionalProperties.toImmutable(), + ) + } + + @NoAutoDetect + class CodeInterpreter + @JsonCreator + private constructor( + @JsonProperty("file_ids") private val fileIds: List?, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** + * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made + * available to the `code_interpreter` tool. There can be a maximum of 20 files + * associated with the tool. + */ + @JsonProperty("file_ids") + fun fileIds(): Optional> = Optional.ofNullable(fileIds) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var fileIds: MutableList? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(codeInterpreter: CodeInterpreter) = apply { + fileIds = codeInterpreter.fileIds?.toMutableList() + additionalProperties = codeInterpreter.additionalProperties.toMutableMap() + } + + /** + * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made + * available to the `code_interpreter` tool. There can be a maximum of 20 files + * associated with the tool. + */ + fun fileIds(fileIds: List) = apply { + this.fileIds = fileIds.toMutableList() + } + + /** + * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made + * available to the `code_interpreter` tool. There can be a maximum of 20 files + * associated with the tool. + */ + fun addFileId(fileId: String) = apply { + fileIds = (fileIds ?: mutableListOf()).apply { add(fileId) } + } + + 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) + } + + fun build(): CodeInterpreter = + CodeInterpreter(fileIds?.toImmutable(), additionalProperties.toImmutable()) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is CodeInterpreter && fileIds == other.fileIds && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(fileIds, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CodeInterpreter{fileIds=$fileIds, additionalProperties=$additionalProperties}" + } + + @NoAutoDetect + class FileSearch + @JsonCreator + private constructor( + @JsonProperty("vector_store_ids") private val vectorStoreIds: List?, + @JsonProperty("vector_stores") private val vectorStores: List?, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** + * The + * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object) + * attached to this assistant. There can be a maximum of 1 vector store attached to the + * assistant. + */ + @JsonProperty("vector_store_ids") + fun vectorStoreIds(): Optional> = Optional.ofNullable(vectorStoreIds) + + /** + * A helper to create a + * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object) + * with file_ids and attach it to this assistant. There can be a maximum of 1 vector + * store attached to the assistant. + */ + @JsonProperty("vector_stores") + fun vectorStores(): Optional> = Optional.ofNullable(vectorStores) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var vectorStoreIds: MutableList? = null + private var vectorStores: MutableList? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(fileSearch: FileSearch) = apply { + vectorStoreIds = fileSearch.vectorStoreIds?.toMutableList() + vectorStores = fileSearch.vectorStores?.toMutableList() + additionalProperties = fileSearch.additionalProperties.toMutableMap() + } + + /** + * The + * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object) + * attached to this assistant. There can be a maximum of 1 vector store attached to + * the assistant. + */ + fun vectorStoreIds(vectorStoreIds: List) = apply { + this.vectorStoreIds = vectorStoreIds.toMutableList() + } + + /** + * The + * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object) + * attached to this assistant. There can be a maximum of 1 vector store attached to + * the assistant. + */ + fun addVectorStoreId(vectorStoreId: String) = apply { + vectorStoreIds = + (vectorStoreIds ?: mutableListOf()).apply { add(vectorStoreId) } + } + + /** + * A helper to create a + * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object) + * with file_ids and attach it to this assistant. There can be a maximum of 1 vector + * store attached to the assistant. + */ + fun vectorStores(vectorStores: List) = apply { + this.vectorStores = vectorStores.toMutableList() + } + + /** + * A helper to create a + * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object) + * with file_ids and attach it to this assistant. There can be a maximum of 1 vector + * store attached to the assistant. + */ + fun addVectorStore(vectorStore: VectorStore) = apply { + vectorStores = (vectorStores ?: mutableListOf()).apply { add(vectorStore) } + } + + 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) + } + + fun build(): FileSearch = + FileSearch( + vectorStoreIds?.toImmutable(), + vectorStores?.toImmutable(), + additionalProperties.toImmutable(), + ) + } + + @NoAutoDetect + class VectorStore + @JsonCreator + private constructor( + @JsonProperty("file_ids") private val fileIds: List?, + @JsonProperty("chunking_strategy") + private val chunkingStrategy: FileChunkingStrategyParam?, + @JsonProperty("metadata") private val metadata: JsonValue?, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** + * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs to add + * to the vector store. There can be a maximum of 10000 files in a vector store. + */ + @JsonProperty("file_ids") + fun fileIds(): Optional> = Optional.ofNullable(fileIds) + + /** + * The chunking strategy used to chunk the file(s). If not set, will use the `auto` + * strategy. Only applicable if `file_ids` is non-empty. + */ + @JsonProperty("chunking_strategy") + fun chunkingStrategy(): Optional = + Optional.ofNullable(chunkingStrategy) + + /** + * Set of 16 key-value pairs that can be attached to a vector store. This can be + * useful for storing additional information about the vector store in a structured + * format. Keys can be a maximum of 64 characters long and values can be a maximum + * of 512 characters long. + */ + @JsonProperty("metadata") + fun metadata(): Optional = Optional.ofNullable(metadata) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var fileIds: MutableList? = null + private var chunkingStrategy: FileChunkingStrategyParam? = null + private var metadata: JsonValue? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(vectorStore: VectorStore) = apply { + fileIds = vectorStore.fileIds?.toMutableList() + chunkingStrategy = vectorStore.chunkingStrategy + metadata = vectorStore.metadata + additionalProperties = vectorStore.additionalProperties.toMutableMap() + } + + /** + * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs to + * add to the vector store. There can be a maximum of 10000 files in a vector + * store. + */ + fun fileIds(fileIds: List) = apply { + this.fileIds = fileIds.toMutableList() + } + + /** + * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs to + * add to the vector store. There can be a maximum of 10000 files in a vector + * store. + */ + fun addFileId(fileId: String) = apply { + fileIds = (fileIds ?: mutableListOf()).apply { add(fileId) } + } + + /** + * The chunking strategy used to chunk the file(s). If not set, will use the + * `auto` strategy. Only applicable if `file_ids` is non-empty. + */ + fun chunkingStrategy(chunkingStrategy: FileChunkingStrategyParam) = apply { + this.chunkingStrategy = chunkingStrategy + } + + /** + * The default strategy. This strategy currently uses a `max_chunk_size_tokens` + * of `800` and `chunk_overlap_tokens` of `400`. + */ + fun chunkingStrategy( + autoFileChunkingStrategyParam: AutoFileChunkingStrategyParam + ) = apply { + this.chunkingStrategy = + FileChunkingStrategyParam.ofAutoFileChunkingStrategyParam( + autoFileChunkingStrategyParam + ) + } + + fun chunkingStrategy( + staticFileChunkingStrategyParam: StaticFileChunkingStrategyParam + ) = apply { + this.chunkingStrategy = + FileChunkingStrategyParam.ofStaticFileChunkingStrategyParam( + staticFileChunkingStrategyParam + ) + } + + /** + * Set of 16 key-value pairs that can be attached to a vector store. This can be + * useful for storing additional information about the vector store in a + * structured format. Keys can be a maximum of 64 characters long and values can + * be a maximum of 512 characters long. + */ + fun metadata(metadata: JsonValue) = apply { this.metadata = metadata } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + fun build(): VectorStore = + VectorStore( + fileIds?.toImmutable(), + chunkingStrategy, + metadata, + additionalProperties.toImmutable(), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is VectorStore && fileIds == other.fileIds && chunkingStrategy == other.chunkingStrategy && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(fileIds, chunkingStrategy, metadata, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "VectorStore{fileIds=$fileIds, chunkingStrategy=$chunkingStrategy, metadata=$metadata, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is FileSearch && vectorStoreIds == other.vectorStoreIds && vectorStores == other.vectorStores && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(vectorStoreIds, vectorStores, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "FileSearch{vectorStoreIds=$vectorStoreIds, vectorStores=$vectorStores, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ToolResources && codeInterpreter == other.codeInterpreter && fileSearch == other.fileSearch && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(codeInterpreter, fileSearch, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ToolResources{codeInterpreter=$codeInterpreter, fileSearch=$fileSearch, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaAssistantCreateParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "BetaAssistantCreateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaAssistantDeleteParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaAssistantDeleteParams.kt new file mode 100644 index 00000000..76e0c8e9 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaAssistantDeleteParams.kt @@ -0,0 +1,211 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models + +import com.openai.core.JsonValue +import com.openai.core.NoAutoDetect +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.core.toImmutable +import java.util.Objects +import java.util.Optional + +class BetaAssistantDeleteParams +constructor( + private val assistantId: String, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, + private val additionalBodyProperties: Map, +) { + + fun assistantId(): String = assistantId + + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun _additionalBodyProperties(): Map = additionalBodyProperties + + @JvmSynthetic + internal fun getBody(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + + @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams + + fun getPathParam(index: Int): String { + return when (index) { + 0 -> assistantId + else -> "" + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + @NoAutoDetect + class Builder { + + private var assistantId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + private var additionalBodyProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaAssistantDeleteParams: BetaAssistantDeleteParams) = apply { + assistantId = betaAssistantDeleteParams.assistantId + additionalHeaders = betaAssistantDeleteParams.additionalHeaders.toBuilder() + additionalQueryParams = betaAssistantDeleteParams.additionalQueryParams.toBuilder() + additionalBodyProperties = + betaAssistantDeleteParams.additionalBodyProperties.toMutableMap() + } + + fun assistantId(assistantId: String) = apply { this.assistantId = assistantId } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + this.additionalBodyProperties.clear() + putAllAdditionalBodyProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + additionalBodyProperties.put(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + this.additionalBodyProperties.putAll(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { + additionalBodyProperties.remove(key) + } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalBodyProperty) + } + + fun build(): BetaAssistantDeleteParams = + BetaAssistantDeleteParams( + checkNotNull(assistantId) { "`assistantId` is required but was not set" }, + additionalHeaders.build(), + additionalQueryParams.build(), + additionalBodyProperties.toImmutable(), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaAssistantDeleteParams && assistantId == other.assistantId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(assistantId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ + + override fun toString() = + "BetaAssistantDeleteParams{assistantId=$assistantId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaAssistantListPage.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaAssistantListPage.kt new file mode 100644 index 00000000..89fa3370 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaAssistantListPage.kt @@ -0,0 +1,171 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.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.NoAutoDetect +import com.openai.core.immutableEmptyMap +import com.openai.core.toImmutable +import com.openai.services.blocking.beta.AssistantService +import java.util.Objects +import java.util.Optional +import java.util.stream.Stream +import java.util.stream.StreamSupport + +class BetaAssistantListPage +private constructor( + private val assistantsService: AssistantService, + private val params: BetaAssistantListParams, + private val response: Response, +) { + + fun response(): Response = response + + fun data(): List = response().data() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaAssistantListPage && 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() = + "BetaAssistantListPage{assistantsService=$assistantsService, params=$params, response=$response}" + + fun hasNextPage(): Boolean { + return !data().isEmpty() + } + + fun getNextPageParams(): Optional { + if (!hasNextPage()) { + return Optional.empty() + } + + return Optional.of( + BetaAssistantListParams.builder().from(params).after(data().last().id()).build() + ) + } + + fun getNextPage(): Optional { + return getNextPageParams().map { assistantsService.list(it) } + } + + fun autoPager(): AutoPager = AutoPager(this) + + companion object { + + @JvmStatic + fun of( + assistantsService: AssistantService, + params: BetaAssistantListParams, + response: Response + ) = + BetaAssistantListPage( + assistantsService, + params, + response, + ) + } + + @NoAutoDetect + class Response + @JsonCreator + constructor( + @JsonProperty("data") private val data: JsonField> = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + private var validated: Boolean = false + + fun data(): List = data.getNullable("data") ?: listOf() + + @JsonProperty("data") + fun _data(): Optional>> = Optional.ofNullable(data) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Response = apply { + if (!validated) { + data().map { it.validate() } + validated = true + } + } + + 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 && additionalProperties == other.additionalProperties /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, additionalProperties) /* spotless:on */ + + override fun toString() = "Response{data=$data, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var data: JsonField> = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(page: Response) = apply { + this.data = page.data + this.additionalProperties.putAll(page.additionalProperties) + } + + fun data(data: List) = data(JsonField.of(data)) + + fun data(data: JsonField>) = apply { this.data = data } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun build() = Response(data, additionalProperties.toImmutable()) + } + } + + class AutoPager + constructor( + private val firstPage: BetaAssistantListPage, + ) : Iterable { + + override fun iterator(): Iterator = iterator { + var page = firstPage + var index = 0 + while (true) { + while (index < page.data().size) { + yield(page.data()[index++]) + } + page = page.getNextPage().orElse(null) ?: break + index = 0 + } + } + + fun stream(): Stream { + return StreamSupport.stream(spliterator(), false) + } + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaAssistantListPageAsync.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaAssistantListPageAsync.kt new file mode 100644 index 00000000..b2f2899a --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaAssistantListPageAsync.kt @@ -0,0 +1,181 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.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.NoAutoDetect +import com.openai.core.immutableEmptyMap +import com.openai.core.toImmutable +import com.openai.services.async.beta.AssistantServiceAsync +import java.util.Objects +import java.util.Optional +import java.util.concurrent.CompletableFuture +import java.util.concurrent.Executor +import java.util.function.Predicate + +class BetaAssistantListPageAsync +private constructor( + private val assistantsService: AssistantServiceAsync, + private val params: BetaAssistantListParams, + private val response: Response, +) { + + fun response(): Response = response + + fun data(): List = response().data() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaAssistantListPageAsync && 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() = + "BetaAssistantListPageAsync{assistantsService=$assistantsService, params=$params, response=$response}" + + fun hasNextPage(): Boolean { + return !data().isEmpty() + } + + fun getNextPageParams(): Optional { + if (!hasNextPage()) { + return Optional.empty() + } + + return Optional.of( + BetaAssistantListParams.builder().from(params).after(data().last().id()).build() + ) + } + + fun getNextPage(): CompletableFuture> { + return getNextPageParams() + .map { assistantsService.list(it).thenApply { Optional.of(it) } } + .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + } + + fun autoPager(): AutoPager = AutoPager(this) + + companion object { + + @JvmStatic + fun of( + assistantsService: AssistantServiceAsync, + params: BetaAssistantListParams, + response: Response + ) = + BetaAssistantListPageAsync( + assistantsService, + params, + response, + ) + } + + @NoAutoDetect + class Response + @JsonCreator + constructor( + @JsonProperty("data") private val data: JsonField> = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + private var validated: Boolean = false + + fun data(): List = data.getNullable("data") ?: listOf() + + @JsonProperty("data") + fun _data(): Optional>> = Optional.ofNullable(data) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Response = apply { + if (!validated) { + data().map { it.validate() } + validated = true + } + } + + 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 && additionalProperties == other.additionalProperties /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, additionalProperties) /* spotless:on */ + + override fun toString() = "Response{data=$data, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var data: JsonField> = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(page: Response) = apply { + this.data = page.data + this.additionalProperties.putAll(page.additionalProperties) + } + + fun data(data: List) = data(JsonField.of(data)) + + fun data(data: JsonField>) = apply { this.data = data } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun build() = Response(data, additionalProperties.toImmutable()) + } + } + + class AutoPager + constructor( + private val firstPage: BetaAssistantListPageAsync, + ) { + + fun forEach(action: Predicate, executor: Executor): CompletableFuture { + fun CompletableFuture>.forEach( + action: (Assistant) -> Boolean, + executor: Executor + ): CompletableFuture = + thenComposeAsync( + { page -> + page + .filter { it.data().all(action) } + .map { it.getNextPage().forEach(action, executor) } + .orElseGet { CompletableFuture.completedFuture(null) } + }, + executor + ) + return CompletableFuture.completedFuture(Optional.of(firstPage)) + .forEach(action::test, executor) + } + + fun toList(executor: Executor): CompletableFuture> { + val values = mutableListOf() + return forEach(values::add, executor).thenApply { values } + } + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaAssistantListParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaAssistantListParams.kt new file mode 100644 index 00000000..21912e34 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaAssistantListParams.kt @@ -0,0 +1,301 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models + +import com.fasterxml.jackson.annotation.JsonCreator +import com.openai.core.Enum +import com.openai.core.JsonField +import com.openai.core.NoAutoDetect +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.errors.OpenAIInvalidDataException +import java.util.Objects +import java.util.Optional + +class BetaAssistantListParams +constructor( + private val after: String?, + private val before: String?, + private val limit: Long?, + private val order: Order?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) { + + /** + * A cursor for use in pagination. `after` is an object ID that defines your place in the list. + * For instance, if you make a list request and receive 100 objects, ending with obj_foo, your + * subsequent call can include after=obj_foo in order to fetch the next page of the list. + */ + fun after(): Optional = Optional.ofNullable(after) + + /** + * A cursor for use in pagination. `before` is an object ID that defines your place in the list. + * For instance, if you make a list request and receive 100 objects, starting with obj_foo, your + * subsequent call can include before=obj_foo in order to fetch the previous page of the list. + */ + fun before(): Optional = Optional.ofNullable(before) + + /** + * A limit on the number of objects to be returned. Limit can range between 1 and 100, and the + * default is 20. + */ + fun limit(): Optional = Optional.ofNullable(limit) + + /** + * Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and `desc` + * for descending order. + */ + fun order(): Optional = Optional.ofNullable(order) + + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + + @JvmSynthetic + internal fun getQueryParams(): QueryParams { + val queryParams = QueryParams.builder() + this.after?.let { queryParams.put("after", listOf(it.toString())) } + this.before?.let { queryParams.put("before", listOf(it.toString())) } + this.limit?.let { queryParams.put("limit", listOf(it.toString())) } + this.order?.let { queryParams.put("order", listOf(it.toString())) } + queryParams.putAll(additionalQueryParams) + return queryParams.build() + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + @NoAutoDetect + class Builder { + + private var after: String? = null + private var before: String? = null + private var limit: Long? = null + private var order: Order? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(betaAssistantListParams: BetaAssistantListParams) = apply { + after = betaAssistantListParams.after + before = betaAssistantListParams.before + limit = betaAssistantListParams.limit + order = betaAssistantListParams.order + additionalHeaders = betaAssistantListParams.additionalHeaders.toBuilder() + additionalQueryParams = betaAssistantListParams.additionalQueryParams.toBuilder() + } + + /** + * A cursor for use in pagination. `after` is an object ID that defines your place in the + * list. For instance, if you make a list request and receive 100 objects, ending with + * obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page + * of the list. + */ + fun after(after: String) = apply { this.after = after } + + /** + * A cursor for use in pagination. `before` is an object ID that defines your place in the + * list. For instance, if you make a list request and receive 100 objects, starting with + * obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous + * page of the list. + */ + fun before(before: String) = apply { this.before = before } + + /** + * A limit on the number of objects to be returned. Limit can range between 1 and 100, and + * the default is 20. + */ + fun limit(limit: Long) = apply { this.limit = limit } + + /** + * Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and + * `desc` for descending order. + */ + fun order(order: Order) = apply { this.order = order } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun build(): BetaAssistantListParams = + BetaAssistantListParams( + after, + before, + limit, + order, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + class Order + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val ASC = of("asc") + + @JvmField val DESC = of("desc") + + @JvmStatic fun of(value: String) = Order(JsonField.of(value)) + } + + enum class Known { + ASC, + DESC, + } + + enum class Value { + ASC, + DESC, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + ASC -> Value.ASC + DESC -> Value.DESC + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + ASC -> Known.ASC + DESC -> Known.DESC + else -> throw OpenAIInvalidDataException("Unknown Order: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Order && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaAssistantListParams && after == other.after && before == other.before && limit == other.limit && order == other.order && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(after, before, limit, order, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "BetaAssistantListParams{after=$after, before=$before, limit=$limit, order=$order, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaAssistantRetrieveParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaAssistantRetrieveParams.kt new file mode 100644 index 00000000..3607834e --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaAssistantRetrieveParams.kt @@ -0,0 +1,175 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models + +import com.openai.core.NoAutoDetect +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import java.util.Objects + +class BetaAssistantRetrieveParams +constructor( + private val assistantId: String, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) { + + fun assistantId(): String = assistantId + + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + + @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams + + fun getPathParam(index: Int): String { + return when (index) { + 0 -> assistantId + else -> "" + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + @NoAutoDetect + class Builder { + + private var assistantId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(betaAssistantRetrieveParams: BetaAssistantRetrieveParams) = apply { + assistantId = betaAssistantRetrieveParams.assistantId + additionalHeaders = betaAssistantRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = betaAssistantRetrieveParams.additionalQueryParams.toBuilder() + } + + fun assistantId(assistantId: String) = apply { this.assistantId = assistantId } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun build(): BetaAssistantRetrieveParams = + BetaAssistantRetrieveParams( + checkNotNull(assistantId) { "`assistantId` is required but was not set" }, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaAssistantRetrieveParams && assistantId == other.assistantId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(assistantId, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "BetaAssistantRetrieveParams{assistantId=$assistantId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaAssistantUpdateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaAssistantUpdateParams.kt new file mode 100644 index 00000000..9c782ac9 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaAssistantUpdateParams.kt @@ -0,0 +1,1008 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.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.JsonValue +import com.openai.core.NoAutoDetect +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.core.immutableEmptyMap +import com.openai.core.toImmutable +import java.util.Objects +import java.util.Optional + +class BetaAssistantUpdateParams +constructor( + private val assistantId: String, + private val body: BetaAssistantUpdateBody, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) { + + fun assistantId(): String = assistantId + + /** The description of the assistant. The maximum length is 512 characters. */ + fun description(): Optional = body.description() + + /** + * The system instructions that the assistant uses. The maximum length is 256,000 characters. + */ + fun instructions(): Optional = body.instructions() + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for storing + * additional information about the object in a structured format. Keys can be a maximum of 64 + * characters long and values can be a maximum of 512 characters long. + */ + fun metadata(): Optional = body.metadata() + + /** + * ID of the model to use. You can use the + * [List models](https://platform.openai.com/docs/api-reference/models/list) API to see all of + * your available models, or see our [Model overview](https://platform.openai.com/docs/models) + * for descriptions of them. + */ + fun model(): Optional = body.model() + + /** The name of the assistant. The maximum length is 256 characters. */ + fun name(): Optional = body.name() + + /** + * Specifies the format that the model must output. Compatible with + * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o), [GPT-4 + * Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4), and all GPT-3.5 Turbo + * models since `gpt-3.5-turbo-1106`. + * + * Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured Outputs which + * ensures the model will match your supplied JSON schema. Learn more in the + * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs). + * + * Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the message the model + * generates is valid JSON. + * + * **Important:** when using JSON mode, you **must** also instruct the model to produce JSON + * yourself via a system or user message. Without this, the model may generate an unending + * stream of whitespace until the generation reaches the token limit, resulting in a + * long-running and seemingly "stuck" request. Also note that the message content may be + * partially cut off if `finish_reason="length"`, which indicates the generation exceeded + * `max_tokens` or the conversation exceeded the max context length. + */ + fun responseFormat(): Optional = body.responseFormat() + + /** + * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the + * output more random, while lower values like 0.2 will make it more focused and deterministic. + */ + fun temperature(): Optional = body.temperature() + + /** + * A set of resources that are used by the assistant's tools. The resources are specific to the + * type of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the + * `file_search` tool requires a list of vector store IDs. + */ + fun toolResources(): Optional = body.toolResources() + + /** + * A list of tool enabled on the assistant. There can be a maximum of 128 tools per assistant. + * Tools can be of types `code_interpreter`, `file_search`, or `function`. + */ + fun tools(): Optional> = body.tools() + + /** + * An alternative to sampling with temperature, called nucleus sampling, where the model + * considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens + * comprising the top 10% probability mass are considered. + * + * We generally recommend altering this or temperature but not both. + */ + fun topP(): Optional = body.topP() + + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun _additionalBodyProperties(): Map = body._additionalProperties() + + @JvmSynthetic internal fun getBody(): BetaAssistantUpdateBody = body + + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + + @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams + + fun getPathParam(index: Int): String { + return when (index) { + 0 -> assistantId + else -> "" + } + } + + @NoAutoDetect + class BetaAssistantUpdateBody + @JsonCreator + internal constructor( + @JsonProperty("description") private val description: String?, + @JsonProperty("instructions") private val instructions: String?, + @JsonProperty("metadata") private val metadata: JsonValue?, + @JsonProperty("model") private val model: String?, + @JsonProperty("name") private val name: String?, + @JsonProperty("response_format") private val responseFormat: AssistantResponseFormatOption?, + @JsonProperty("temperature") private val temperature: Double?, + @JsonProperty("tool_resources") private val toolResources: ToolResources?, + @JsonProperty("tools") private val tools: List?, + @JsonProperty("top_p") private val topP: Double?, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** The description of the assistant. The maximum length is 512 characters. */ + @JsonProperty("description") + fun description(): Optional = Optional.ofNullable(description) + + /** + * The system instructions that the assistant uses. The maximum length is 256,000 + * characters. + */ + @JsonProperty("instructions") + fun instructions(): Optional = Optional.ofNullable(instructions) + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format. Keys can be a + * maximum of 64 characters long and values can be a maximum of 512 characters long. + */ + @JsonProperty("metadata") + fun metadata(): Optional = Optional.ofNullable(metadata) + + /** + * ID of the model to use. You can use the + * [List models](https://platform.openai.com/docs/api-reference/models/list) API to see all + * of your available models, or see our + * [Model overview](https://platform.openai.com/docs/models) for descriptions of them. + */ + @JsonProperty("model") fun model(): Optional = Optional.ofNullable(model) + + /** The name of the assistant. The maximum length is 256 characters. */ + @JsonProperty("name") fun name(): Optional = Optional.ofNullable(name) + + /** + * Specifies the format that the model must output. Compatible with + * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o), [GPT-4 + * Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4), and all GPT-3.5 + * Turbo models since `gpt-3.5-turbo-1106`. + * + * Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured Outputs + * which ensures the model will match your supplied JSON schema. Learn more in the + * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs). + * + * Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the message the + * model generates is valid JSON. + * + * **Important:** when using JSON mode, you **must** also instruct the model to produce JSON + * yourself via a system or user message. Without this, the model may generate an unending + * stream of whitespace until the generation reaches the token limit, resulting in a + * long-running and seemingly "stuck" request. Also note that the message content may be + * partially cut off if `finish_reason="length"`, which indicates the generation exceeded + * `max_tokens` or the conversation exceeded the max context length. + */ + @JsonProperty("response_format") + fun responseFormat(): Optional = + Optional.ofNullable(responseFormat) + + /** + * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the + * output more random, while lower values like 0.2 will make it more focused and + * deterministic. + */ + @JsonProperty("temperature") + fun temperature(): Optional = Optional.ofNullable(temperature) + + /** + * A set of resources that are used by the assistant's tools. The resources are specific to + * the type of tool. For example, the `code_interpreter` tool requires a list of file IDs, + * while the `file_search` tool requires a list of vector store IDs. + */ + @JsonProperty("tool_resources") + fun toolResources(): Optional = Optional.ofNullable(toolResources) + + /** + * A list of tool enabled on the assistant. There can be a maximum of 128 tools per + * assistant. Tools can be of types `code_interpreter`, `file_search`, or `function`. + */ + @JsonProperty("tools") + fun tools(): Optional> = Optional.ofNullable(tools) + + /** + * An alternative to sampling with temperature, called nucleus sampling, where the model + * considers the results of the tokens with top_p probability mass. So 0.1 means only the + * tokens comprising the top 10% probability mass are considered. + * + * We generally recommend altering this or temperature but not both. + */ + @JsonProperty("top_p") fun topP(): Optional = Optional.ofNullable(topP) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var description: String? = null + private var instructions: String? = null + private var metadata: JsonValue? = null + private var model: String? = null + private var name: String? = null + private var responseFormat: AssistantResponseFormatOption? = null + private var temperature: Double? = null + private var toolResources: ToolResources? = null + private var tools: MutableList? = null + private var topP: Double? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaAssistantUpdateBody: BetaAssistantUpdateBody) = apply { + description = betaAssistantUpdateBody.description + instructions = betaAssistantUpdateBody.instructions + metadata = betaAssistantUpdateBody.metadata + model = betaAssistantUpdateBody.model + name = betaAssistantUpdateBody.name + responseFormat = betaAssistantUpdateBody.responseFormat + temperature = betaAssistantUpdateBody.temperature + toolResources = betaAssistantUpdateBody.toolResources + tools = betaAssistantUpdateBody.tools?.toMutableList() + topP = betaAssistantUpdateBody.topP + additionalProperties = betaAssistantUpdateBody.additionalProperties.toMutableMap() + } + + /** The description of the assistant. The maximum length is 512 characters. */ + fun description(description: String) = apply { this.description = description } + + /** + * The system instructions that the assistant uses. The maximum length is 256,000 + * characters. + */ + fun instructions(instructions: String) = apply { this.instructions = instructions } + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format. Keys can be a + * maximum of 64 characters long and values can be a maximum of 512 characters long. + */ + fun metadata(metadata: JsonValue) = apply { this.metadata = metadata } + + /** + * ID of the model to use. You can use the + * [List models](https://platform.openai.com/docs/api-reference/models/list) API to see + * all of your available models, or see our + * [Model overview](https://platform.openai.com/docs/models) for descriptions of them. + */ + fun model(model: String) = apply { this.model = model } + + /** The name of the assistant. The maximum length is 256 characters. */ + fun name(name: String) = apply { this.name = name } + + /** + * Specifies the format that the model must output. Compatible with + * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o), [GPT-4 + * Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4), and all + * GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`. + * + * Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured + * Outputs which ensures the model will match your supplied JSON schema. Learn more in + * the + * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs). + * + * Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the message + * the model generates is valid JSON. + * + * **Important:** when using JSON mode, you **must** also instruct the model to produce + * JSON yourself via a system or user message. Without this, the model may generate an + * unending stream of whitespace until the generation reaches the token limit, resulting + * in a long-running and seemingly "stuck" request. Also note that the message content + * may be partially cut off if `finish_reason="length"`, which indicates the generation + * exceeded `max_tokens` or the conversation exceeded the max context length. + */ + fun responseFormat(responseFormat: AssistantResponseFormatOption) = apply { + this.responseFormat = responseFormat + } + + /** `auto` is the default value */ + fun responseFormat(behavior: AssistantResponseFormatOption.Behavior) = apply { + this.responseFormat = AssistantResponseFormatOption.ofBehavior(behavior) + } + + fun responseFormat(responseFormatText: ResponseFormatText) = apply { + this.responseFormat = + AssistantResponseFormatOption.ofResponseFormatText(responseFormatText) + } + + fun responseFormat(responseFormatJsonObject: ResponseFormatJsonObject) = apply { + this.responseFormat = + AssistantResponseFormatOption.ofResponseFormatJsonObject( + responseFormatJsonObject + ) + } + + fun responseFormat(responseFormatJsonSchema: ResponseFormatJsonSchema) = apply { + this.responseFormat = + AssistantResponseFormatOption.ofResponseFormatJsonSchema( + responseFormatJsonSchema + ) + } + + /** + * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make + * the output more random, while lower values like 0.2 will make it more focused and + * deterministic. + */ + fun temperature(temperature: Double) = apply { this.temperature = temperature } + + /** + * A set of resources that are used by the assistant's tools. The resources are specific + * to the type of tool. For example, the `code_interpreter` tool requires a list of file + * IDs, while the `file_search` tool requires a list of vector store IDs. + */ + fun toolResources(toolResources: ToolResources) = apply { + this.toolResources = toolResources + } + + /** + * A list of tool enabled on the assistant. There can be a maximum of 128 tools per + * assistant. Tools can be of types `code_interpreter`, `file_search`, or `function`. + */ + fun tools(tools: List) = apply { this.tools = tools.toMutableList() } + + /** + * A list of tool enabled on the assistant. There can be a maximum of 128 tools per + * assistant. Tools can be of types `code_interpreter`, `file_search`, or `function`. + */ + fun addTool(tool: AssistantTool) = apply { + tools = (tools ?: mutableListOf()).apply { add(tool) } + } + + /** + * An alternative to sampling with temperature, called nucleus sampling, where the model + * considers the results of the tokens with top_p probability mass. So 0.1 means only + * the tokens comprising the top 10% probability mass are considered. + * + * We generally recommend altering this or temperature but not both. + */ + fun topP(topP: Double) = apply { this.topP = topP } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + fun build(): BetaAssistantUpdateBody = + BetaAssistantUpdateBody( + description, + instructions, + metadata, + model, + name, + responseFormat, + temperature, + toolResources, + tools?.toImmutable(), + topP, + additionalProperties.toImmutable(), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaAssistantUpdateBody && description == other.description && instructions == other.instructions && metadata == other.metadata && model == other.model && name == other.name && responseFormat == other.responseFormat && temperature == other.temperature && toolResources == other.toolResources && tools == other.tools && topP == other.topP && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(description, instructions, metadata, model, name, responseFormat, temperature, toolResources, tools, topP, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaAssistantUpdateBody{description=$description, instructions=$instructions, metadata=$metadata, model=$model, name=$name, responseFormat=$responseFormat, temperature=$temperature, toolResources=$toolResources, tools=$tools, topP=$topP, additionalProperties=$additionalProperties}" + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + @NoAutoDetect + class Builder { + + private var assistantId: String? = null + private var body: BetaAssistantUpdateBody.Builder = BetaAssistantUpdateBody.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(betaAssistantUpdateParams: BetaAssistantUpdateParams) = apply { + assistantId = betaAssistantUpdateParams.assistantId + body = betaAssistantUpdateParams.body.toBuilder() + additionalHeaders = betaAssistantUpdateParams.additionalHeaders.toBuilder() + additionalQueryParams = betaAssistantUpdateParams.additionalQueryParams.toBuilder() + } + + fun assistantId(assistantId: String) = apply { this.assistantId = assistantId } + + /** The description of the assistant. The maximum length is 512 characters. */ + fun description(description: String) = apply { body.description(description) } + + /** + * The system instructions that the assistant uses. The maximum length is 256,000 + * characters. + */ + fun instructions(instructions: String) = apply { body.instructions(instructions) } + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format. Keys can be a + * maximum of 64 characters long and values can be a maximum of 512 characters long. + */ + fun metadata(metadata: JsonValue) = apply { body.metadata(metadata) } + + /** + * ID of the model to use. You can use the + * [List models](https://platform.openai.com/docs/api-reference/models/list) API to see all + * of your available models, or see our + * [Model overview](https://platform.openai.com/docs/models) for descriptions of them. + */ + fun model(model: String) = apply { body.model(model) } + + /** The name of the assistant. The maximum length is 256 characters. */ + fun name(name: String) = apply { body.name(name) } + + /** + * Specifies the format that the model must output. Compatible with + * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o), [GPT-4 + * Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4), and all GPT-3.5 + * Turbo models since `gpt-3.5-turbo-1106`. + * + * Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured Outputs + * which ensures the model will match your supplied JSON schema. Learn more in the + * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs). + * + * Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the message the + * model generates is valid JSON. + * + * **Important:** when using JSON mode, you **must** also instruct the model to produce JSON + * yourself via a system or user message. Without this, the model may generate an unending + * stream of whitespace until the generation reaches the token limit, resulting in a + * long-running and seemingly "stuck" request. Also note that the message content may be + * partially cut off if `finish_reason="length"`, which indicates the generation exceeded + * `max_tokens` or the conversation exceeded the max context length. + */ + fun responseFormat(responseFormat: AssistantResponseFormatOption) = apply { + body.responseFormat(responseFormat) + } + + /** `auto` is the default value */ + fun responseFormat(behavior: AssistantResponseFormatOption.Behavior) = apply { + body.responseFormat(behavior) + } + + fun responseFormat(responseFormatText: ResponseFormatText) = apply { + body.responseFormat(responseFormatText) + } + + fun responseFormat(responseFormatJsonObject: ResponseFormatJsonObject) = apply { + body.responseFormat(responseFormatJsonObject) + } + + fun responseFormat(responseFormatJsonSchema: ResponseFormatJsonSchema) = apply { + body.responseFormat(responseFormatJsonSchema) + } + + /** + * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the + * output more random, while lower values like 0.2 will make it more focused and + * deterministic. + */ + fun temperature(temperature: Double) = apply { body.temperature(temperature) } + + /** + * A set of resources that are used by the assistant's tools. The resources are specific to + * the type of tool. For example, the `code_interpreter` tool requires a list of file IDs, + * while the `file_search` tool requires a list of vector store IDs. + */ + fun toolResources(toolResources: ToolResources) = apply { + body.toolResources(toolResources) + } + + /** + * A list of tool enabled on the assistant. There can be a maximum of 128 tools per + * assistant. Tools can be of types `code_interpreter`, `file_search`, or `function`. + */ + fun tools(tools: List) = apply { body.tools(tools) } + + /** + * A list of tool enabled on the assistant. There can be a maximum of 128 tools per + * assistant. Tools can be of types `code_interpreter`, `file_search`, or `function`. + */ + fun addTool(tool: AssistantTool) = apply { body.addTool(tool) } + + /** + * An alternative to sampling with temperature, called nucleus sampling, where the model + * considers the results of the tokens with top_p probability mass. So 0.1 means only the + * tokens comprising the top 10% probability mass are considered. + * + * We generally recommend altering this or temperature but not both. + */ + fun topP(topP: Double) = apply { body.topP(topP) } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } + + fun build(): BetaAssistantUpdateParams = + BetaAssistantUpdateParams( + checkNotNull(assistantId) { "`assistantId` is required but was not set" }, + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + /** + * A set of resources that are used by the assistant's tools. The resources are specific to the + * type of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the + * `file_search` tool requires a list of vector store IDs. + */ + @NoAutoDetect + class ToolResources + @JsonCreator + private constructor( + @JsonProperty("code_interpreter") private val codeInterpreter: CodeInterpreter?, + @JsonProperty("file_search") private val fileSearch: FileSearch?, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + @JsonProperty("code_interpreter") + fun codeInterpreter(): Optional = Optional.ofNullable(codeInterpreter) + + @JsonProperty("file_search") + fun fileSearch(): Optional = Optional.ofNullable(fileSearch) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var codeInterpreter: CodeInterpreter? = null + private var fileSearch: FileSearch? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(toolResources: ToolResources) = apply { + codeInterpreter = toolResources.codeInterpreter + fileSearch = toolResources.fileSearch + additionalProperties = toolResources.additionalProperties.toMutableMap() + } + + fun codeInterpreter(codeInterpreter: CodeInterpreter) = apply { + this.codeInterpreter = codeInterpreter + } + + fun fileSearch(fileSearch: FileSearch) = apply { this.fileSearch = fileSearch } + + 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) + } + + fun build(): ToolResources = + ToolResources( + codeInterpreter, + fileSearch, + additionalProperties.toImmutable(), + ) + } + + @NoAutoDetect + class CodeInterpreter + @JsonCreator + private constructor( + @JsonProperty("file_ids") private val fileIds: List?, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** + * Overrides the list of [file](https://platform.openai.com/docs/api-reference/files) + * IDs made available to the `code_interpreter` tool. There can be a maximum of 20 files + * associated with the tool. + */ + @JsonProperty("file_ids") + fun fileIds(): Optional> = Optional.ofNullable(fileIds) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var fileIds: MutableList? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(codeInterpreter: CodeInterpreter) = apply { + fileIds = codeInterpreter.fileIds?.toMutableList() + additionalProperties = codeInterpreter.additionalProperties.toMutableMap() + } + + /** + * Overrides the list of + * [file](https://platform.openai.com/docs/api-reference/files) IDs made available + * to the `code_interpreter` tool. There can be a maximum of 20 files associated + * with the tool. + */ + fun fileIds(fileIds: List) = apply { + this.fileIds = fileIds.toMutableList() + } + + /** + * Overrides the list of + * [file](https://platform.openai.com/docs/api-reference/files) IDs made available + * to the `code_interpreter` tool. There can be a maximum of 20 files associated + * with the tool. + */ + fun addFileId(fileId: String) = apply { + fileIds = (fileIds ?: mutableListOf()).apply { add(fileId) } + } + + 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) + } + + fun build(): CodeInterpreter = + CodeInterpreter(fileIds?.toImmutable(), additionalProperties.toImmutable()) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is CodeInterpreter && fileIds == other.fileIds && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(fileIds, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CodeInterpreter{fileIds=$fileIds, additionalProperties=$additionalProperties}" + } + + @NoAutoDetect + class FileSearch + @JsonCreator + private constructor( + @JsonProperty("vector_store_ids") private val vectorStoreIds: List?, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** + * Overrides the + * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object) + * attached to this assistant. There can be a maximum of 1 vector store attached to the + * assistant. + */ + @JsonProperty("vector_store_ids") + fun vectorStoreIds(): Optional> = Optional.ofNullable(vectorStoreIds) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var vectorStoreIds: MutableList? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(fileSearch: FileSearch) = apply { + vectorStoreIds = fileSearch.vectorStoreIds?.toMutableList() + additionalProperties = fileSearch.additionalProperties.toMutableMap() + } + + /** + * Overrides the + * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object) + * attached to this assistant. There can be a maximum of 1 vector store attached to + * the assistant. + */ + fun vectorStoreIds(vectorStoreIds: List) = apply { + this.vectorStoreIds = vectorStoreIds.toMutableList() + } + + /** + * Overrides the + * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object) + * attached to this assistant. There can be a maximum of 1 vector store attached to + * the assistant. + */ + fun addVectorStoreId(vectorStoreId: String) = apply { + vectorStoreIds = + (vectorStoreIds ?: mutableListOf()).apply { add(vectorStoreId) } + } + + 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) + } + + fun build(): FileSearch = + FileSearch(vectorStoreIds?.toImmutable(), additionalProperties.toImmutable()) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is FileSearch && vectorStoreIds == other.vectorStoreIds && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(vectorStoreIds, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "FileSearch{vectorStoreIds=$vectorStoreIds, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ToolResources && codeInterpreter == other.codeInterpreter && fileSearch == other.fileSearch && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(codeInterpreter, fileSearch, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ToolResources{codeInterpreter=$codeInterpreter, fileSearch=$fileSearch, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaAssistantUpdateParams && assistantId == other.assistantId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(assistantId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "BetaAssistantUpdateParams{assistantId=$assistantId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadCreateAndRunParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadCreateAndRunParams.kt new file mode 100644 index 00000000..8b722f3e --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadCreateAndRunParams.kt @@ -0,0 +1,2915 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.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.fasterxml.jackson.core.JsonGenerator +import com.fasterxml.jackson.core.ObjectCodec +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.SerializerProvider +import com.fasterxml.jackson.databind.annotation.JsonDeserialize +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.BaseDeserializer +import com.openai.core.BaseSerializer +import com.openai.core.Enum +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonValue +import com.openai.core.NoAutoDetect +import com.openai.core.getOrThrow +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.core.immutableEmptyMap +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +class BetaThreadCreateAndRunParams +constructor( + private val body: BetaThreadCreateAndRunBody, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) { + + /** + * The ID of the [assistant](https://platform.openai.com/docs/api-reference/assistants) to use + * to execute this run. + */ + fun assistantId(): String = body.assistantId() + + /** + * Override the default system message of the assistant. This is useful for modifying the + * behavior on a per-run basis. + */ + fun instructions(): Optional = body.instructions() + + /** + * The maximum number of completion tokens that may be used over the course of the run. The run + * will make a best effort to use only the number of completion tokens specified, across + * multiple turns of the run. If the run exceeds the number of completion tokens specified, the + * run will end with status `incomplete`. See `incomplete_details` for more info. + */ + fun maxCompletionTokens(): Optional = body.maxCompletionTokens() + + /** + * The maximum number of prompt tokens that may be used over the course of the run. The run will + * make a best effort to use only the number of prompt tokens specified, across multiple turns + * of the run. If the run exceeds the number of prompt tokens specified, the run will end with + * status `incomplete`. See `incomplete_details` for more info. + */ + fun maxPromptTokens(): Optional = body.maxPromptTokens() + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for storing + * additional information about the object in a structured format. Keys can be a maximum of 64 + * characters long and values can be a maximum of 512 characters long. + */ + fun metadata(): Optional = body.metadata() + + /** + * The ID of the [Model](https://platform.openai.com/docs/api-reference/models) to be used to + * execute this run. If a value is provided here, it will override the model associated with the + * assistant. If not, the model associated with the assistant will be used. + */ + fun model(): Optional = body.model() + + /** + * Whether to enable + * [parallel function calling](https://platform.openai.com/docs/guides/function-calling#configuring-parallel-function-calling) + * during tool use. + */ + fun parallelToolCalls(): Optional = body.parallelToolCalls() + + /** + * Specifies the format that the model must output. Compatible with + * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o), [GPT-4 + * Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4), and all GPT-3.5 Turbo + * models since `gpt-3.5-turbo-1106`. + * + * Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured Outputs which + * ensures the model will match your supplied JSON schema. Learn more in the + * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs). + * + * Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the message the model + * generates is valid JSON. + * + * **Important:** when using JSON mode, you **must** also instruct the model to produce JSON + * yourself via a system or user message. Without this, the model may generate an unending + * stream of whitespace until the generation reaches the token limit, resulting in a + * long-running and seemingly "stuck" request. Also note that the message content may be + * partially cut off if `finish_reason="length"`, which indicates the generation exceeded + * `max_tokens` or the conversation exceeded the max context length. + */ + fun responseFormat(): Optional = body.responseFormat() + + /** + * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the + * output more random, while lower values like 0.2 will make it more focused and deterministic. + */ + fun temperature(): Optional = body.temperature() + + /** If no thread is provided, an empty thread will be created. */ + fun thread(): Optional = body.thread() + + /** + * Controls which (if any) tool is called by the model. `none` means the model will not call any + * tools and instead generates a message. `auto` is the default value and means the model can + * pick between generating a message or calling one or more tools. `required` means the model + * must call one or more tools before responding to the user. Specifying a particular tool like + * `{"type": "file_search"}` or `{"type": "function", "function": {"name": "my_function"}}` + * forces the model to call that tool. + */ + fun toolChoice(): Optional = body.toolChoice() + + /** + * A set of resources that are used by the assistant's tools. The resources are specific to the + * type of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the + * `file_search` tool requires a list of vector store IDs. + */ + fun toolResources(): Optional = body.toolResources() + + /** + * Override the tools the assistant can use for this run. This is useful for modifying the + * behavior on a per-run basis. + */ + fun tools(): Optional> = body.tools() + + /** + * An alternative to sampling with temperature, called nucleus sampling, where the model + * considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens + * comprising the top 10% probability mass are considered. + * + * We generally recommend altering this or temperature but not both. + */ + fun topP(): Optional = body.topP() + + /** + * Controls for how a thread will be truncated prior to the run. Use this to control the intial + * context window of the run. + */ + fun truncationStrategy(): Optional = body.truncationStrategy() + + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun _additionalBodyProperties(): Map = body._additionalProperties() + + @JvmSynthetic internal fun getBody(): BetaThreadCreateAndRunBody = body + + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + + @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams + + @NoAutoDetect + class BetaThreadCreateAndRunBody + @JsonCreator + internal constructor( + @JsonProperty("assistant_id") private val assistantId: String, + @JsonProperty("instructions") private val instructions: String?, + @JsonProperty("max_completion_tokens") private val maxCompletionTokens: Long?, + @JsonProperty("max_prompt_tokens") private val maxPromptTokens: Long?, + @JsonProperty("metadata") private val metadata: JsonValue?, + @JsonProperty("model") private val model: ChatModel?, + @JsonProperty("parallel_tool_calls") private val parallelToolCalls: Boolean?, + @JsonProperty("response_format") private val responseFormat: AssistantResponseFormatOption?, + @JsonProperty("temperature") private val temperature: Double?, + @JsonProperty("thread") private val thread: Thread?, + @JsonProperty("tool_choice") private val toolChoice: AssistantToolChoiceOption?, + @JsonProperty("tool_resources") private val toolResources: ToolResources?, + @JsonProperty("tools") private val tools: List?, + @JsonProperty("top_p") private val topP: Double?, + @JsonProperty("truncation_strategy") private val truncationStrategy: TruncationStrategy?, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** + * The ID of the [assistant](https://platform.openai.com/docs/api-reference/assistants) to + * use to execute this run. + */ + @JsonProperty("assistant_id") fun assistantId(): String = assistantId + + /** + * Override the default system message of the assistant. This is useful for modifying the + * behavior on a per-run basis. + */ + @JsonProperty("instructions") + fun instructions(): Optional = Optional.ofNullable(instructions) + + /** + * The maximum number of completion tokens that may be used over the course of the run. The + * run will make a best effort to use only the number of completion tokens specified, across + * multiple turns of the run. If the run exceeds the number of completion tokens specified, + * the run will end with status `incomplete`. See `incomplete_details` for more info. + */ + @JsonProperty("max_completion_tokens") + fun maxCompletionTokens(): Optional = Optional.ofNullable(maxCompletionTokens) + + /** + * The maximum number of prompt tokens that may be used over the course of the run. The run + * will make a best effort to use only the number of prompt tokens specified, across + * multiple turns of the run. If the run exceeds the number of prompt tokens specified, the + * run will end with status `incomplete`. See `incomplete_details` for more info. + */ + @JsonProperty("max_prompt_tokens") + fun maxPromptTokens(): Optional = Optional.ofNullable(maxPromptTokens) + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format. Keys can be a + * maximum of 64 characters long and values can be a maximum of 512 characters long. + */ + @JsonProperty("metadata") + fun metadata(): Optional = Optional.ofNullable(metadata) + + /** + * The ID of the [Model](https://platform.openai.com/docs/api-reference/models) to be used + * to execute this run. If a value is provided here, it will override the model associated + * with the assistant. If not, the model associated with the assistant will be used. + */ + @JsonProperty("model") fun model(): Optional = Optional.ofNullable(model) + + /** + * Whether to enable + * [parallel function calling](https://platform.openai.com/docs/guides/function-calling#configuring-parallel-function-calling) + * during tool use. + */ + @JsonProperty("parallel_tool_calls") + fun parallelToolCalls(): Optional = Optional.ofNullable(parallelToolCalls) + + /** + * Specifies the format that the model must output. Compatible with + * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o), [GPT-4 + * Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4), and all GPT-3.5 + * Turbo models since `gpt-3.5-turbo-1106`. + * + * Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured Outputs + * which ensures the model will match your supplied JSON schema. Learn more in the + * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs). + * + * Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the message the + * model generates is valid JSON. + * + * **Important:** when using JSON mode, you **must** also instruct the model to produce JSON + * yourself via a system or user message. Without this, the model may generate an unending + * stream of whitespace until the generation reaches the token limit, resulting in a + * long-running and seemingly "stuck" request. Also note that the message content may be + * partially cut off if `finish_reason="length"`, which indicates the generation exceeded + * `max_tokens` or the conversation exceeded the max context length. + */ + @JsonProperty("response_format") + fun responseFormat(): Optional = + Optional.ofNullable(responseFormat) + + /** + * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the + * output more random, while lower values like 0.2 will make it more focused and + * deterministic. + */ + @JsonProperty("temperature") + fun temperature(): Optional = Optional.ofNullable(temperature) + + /** If no thread is provided, an empty thread will be created. */ + @JsonProperty("thread") fun thread(): Optional = Optional.ofNullable(thread) + + /** + * Controls which (if any) tool is called by the model. `none` means the model will not call + * any tools and instead generates a message. `auto` is the default value and means the + * model can pick between generating a message or calling one or more tools. `required` + * means the model must call one or more tools before responding to the user. Specifying a + * particular tool like `{"type": "file_search"}` or `{"type": "function", "function": + * {"name": "my_function"}}` forces the model to call that tool. + */ + @JsonProperty("tool_choice") + fun toolChoice(): Optional = Optional.ofNullable(toolChoice) + + /** + * A set of resources that are used by the assistant's tools. The resources are specific to + * the type of tool. For example, the `code_interpreter` tool requires a list of file IDs, + * while the `file_search` tool requires a list of vector store IDs. + */ + @JsonProperty("tool_resources") + fun toolResources(): Optional = Optional.ofNullable(toolResources) + + /** + * Override the tools the assistant can use for this run. This is useful for modifying the + * behavior on a per-run basis. + */ + @JsonProperty("tools") fun tools(): Optional> = Optional.ofNullable(tools) + + /** + * An alternative to sampling with temperature, called nucleus sampling, where the model + * considers the results of the tokens with top_p probability mass. So 0.1 means only the + * tokens comprising the top 10% probability mass are considered. + * + * We generally recommend altering this or temperature but not both. + */ + @JsonProperty("top_p") fun topP(): Optional = Optional.ofNullable(topP) + + /** + * Controls for how a thread will be truncated prior to the run. Use this to control the + * intial context window of the run. + */ + @JsonProperty("truncation_strategy") + fun truncationStrategy(): Optional = + Optional.ofNullable(truncationStrategy) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var assistantId: String? = null + private var instructions: String? = null + private var maxCompletionTokens: Long? = null + private var maxPromptTokens: Long? = null + private var metadata: JsonValue? = null + private var model: ChatModel? = null + private var parallelToolCalls: Boolean? = null + private var responseFormat: AssistantResponseFormatOption? = null + private var temperature: Double? = null + private var thread: Thread? = null + private var toolChoice: AssistantToolChoiceOption? = null + private var toolResources: ToolResources? = null + private var tools: MutableList? = null + private var topP: Double? = null + private var truncationStrategy: TruncationStrategy? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaThreadCreateAndRunBody: BetaThreadCreateAndRunBody) = apply { + assistantId = betaThreadCreateAndRunBody.assistantId + instructions = betaThreadCreateAndRunBody.instructions + maxCompletionTokens = betaThreadCreateAndRunBody.maxCompletionTokens + maxPromptTokens = betaThreadCreateAndRunBody.maxPromptTokens + metadata = betaThreadCreateAndRunBody.metadata + model = betaThreadCreateAndRunBody.model + parallelToolCalls = betaThreadCreateAndRunBody.parallelToolCalls + responseFormat = betaThreadCreateAndRunBody.responseFormat + temperature = betaThreadCreateAndRunBody.temperature + thread = betaThreadCreateAndRunBody.thread + toolChoice = betaThreadCreateAndRunBody.toolChoice + toolResources = betaThreadCreateAndRunBody.toolResources + tools = betaThreadCreateAndRunBody.tools?.toMutableList() + topP = betaThreadCreateAndRunBody.topP + truncationStrategy = betaThreadCreateAndRunBody.truncationStrategy + additionalProperties = + betaThreadCreateAndRunBody.additionalProperties.toMutableMap() + } + + /** + * The ID of the [assistant](https://platform.openai.com/docs/api-reference/assistants) + * to use to execute this run. + */ + fun assistantId(assistantId: String) = apply { this.assistantId = assistantId } + + /** + * Override the default system message of the assistant. This is useful for modifying + * the behavior on a per-run basis. + */ + fun instructions(instructions: String) = apply { this.instructions = instructions } + + /** + * The maximum number of completion tokens that may be used over the course of the run. + * The run will make a best effort to use only the number of completion tokens + * specified, across multiple turns of the run. If the run exceeds the number of + * completion tokens specified, the run will end with status `incomplete`. See + * `incomplete_details` for more info. + */ + fun maxCompletionTokens(maxCompletionTokens: Long) = apply { + this.maxCompletionTokens = maxCompletionTokens + } + + /** + * The maximum number of prompt tokens that may be used over the course of the run. The + * run will make a best effort to use only the number of prompt tokens specified, across + * multiple turns of the run. If the run exceeds the number of prompt tokens specified, + * the run will end with status `incomplete`. See `incomplete_details` for more info. + */ + fun maxPromptTokens(maxPromptTokens: Long) = apply { + this.maxPromptTokens = maxPromptTokens + } + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format. Keys can be a + * maximum of 64 characters long and values can be a maximum of 512 characters long. + */ + fun metadata(metadata: JsonValue) = apply { this.metadata = metadata } + + /** + * The ID of the [Model](https://platform.openai.com/docs/api-reference/models) to be + * used to execute this run. If a value is provided here, it will override the model + * associated with the assistant. If not, the model associated with the assistant will + * be used. + */ + fun model(model: ChatModel) = apply { this.model = model } + + /** + * The ID of the [Model](https://platform.openai.com/docs/api-reference/models) to be + * used to execute this run. If a value is provided here, it will override the model + * associated with the assistant. If not, the model associated with the assistant will + * be used. + */ + fun model(value: String) = apply { model = ChatModel.of(value) } + + /** + * Whether to enable + * [parallel function calling](https://platform.openai.com/docs/guides/function-calling#configuring-parallel-function-calling) + * during tool use. + */ + fun parallelToolCalls(parallelToolCalls: Boolean) = apply { + this.parallelToolCalls = parallelToolCalls + } + + /** + * Specifies the format that the model must output. Compatible with + * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o), [GPT-4 + * Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4), and all + * GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`. + * + * Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured + * Outputs which ensures the model will match your supplied JSON schema. Learn more in + * the + * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs). + * + * Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the message + * the model generates is valid JSON. + * + * **Important:** when using JSON mode, you **must** also instruct the model to produce + * JSON yourself via a system or user message. Without this, the model may generate an + * unending stream of whitespace until the generation reaches the token limit, resulting + * in a long-running and seemingly "stuck" request. Also note that the message content + * may be partially cut off if `finish_reason="length"`, which indicates the generation + * exceeded `max_tokens` or the conversation exceeded the max context length. + */ + fun responseFormat(responseFormat: AssistantResponseFormatOption) = apply { + this.responseFormat = responseFormat + } + + /** `auto` is the default value */ + fun responseFormat(behavior: AssistantResponseFormatOption.Behavior) = apply { + this.responseFormat = AssistantResponseFormatOption.ofBehavior(behavior) + } + + fun responseFormat(responseFormatText: ResponseFormatText) = apply { + this.responseFormat = + AssistantResponseFormatOption.ofResponseFormatText(responseFormatText) + } + + fun responseFormat(responseFormatJsonObject: ResponseFormatJsonObject) = apply { + this.responseFormat = + AssistantResponseFormatOption.ofResponseFormatJsonObject( + responseFormatJsonObject + ) + } + + fun responseFormat(responseFormatJsonSchema: ResponseFormatJsonSchema) = apply { + this.responseFormat = + AssistantResponseFormatOption.ofResponseFormatJsonSchema( + responseFormatJsonSchema + ) + } + + /** + * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make + * the output more random, while lower values like 0.2 will make it more focused and + * deterministic. + */ + fun temperature(temperature: Double) = apply { this.temperature = temperature } + + /** If no thread is provided, an empty thread will be created. */ + fun thread(thread: Thread) = apply { this.thread = thread } + + /** + * Controls which (if any) tool is called by the model. `none` means the model will not + * call any tools and instead generates a message. `auto` is the default value and means + * the model can pick between generating a message or calling one or more tools. + * `required` means the model must call one or more tools before responding to the user. + * Specifying a particular tool like `{"type": "file_search"}` or `{"type": "function", + * "function": {"name": "my_function"}}` forces the model to call that tool. + */ + fun toolChoice(toolChoice: AssistantToolChoiceOption) = apply { + this.toolChoice = toolChoice + } + + /** + * `none` means the model will not call any tools and instead generates a message. + * `auto` means the model can pick between generating a message or calling one or more + * tools. `required` means the model must call one or more tools before responding to + * the user. + */ + fun toolChoice(behavior: AssistantToolChoiceOption.Behavior) = apply { + this.toolChoice = AssistantToolChoiceOption.ofBehavior(behavior) + } + + /** + * Specifies a tool the model should use. Use to force the model to call a specific + * tool. + */ + fun toolChoice(assistantToolChoice: AssistantToolChoice) = apply { + this.toolChoice = + AssistantToolChoiceOption.ofAssistantToolChoice(assistantToolChoice) + } + + /** + * A set of resources that are used by the assistant's tools. The resources are specific + * to the type of tool. For example, the `code_interpreter` tool requires a list of file + * IDs, while the `file_search` tool requires a list of vector store IDs. + */ + fun toolResources(toolResources: ToolResources) = apply { + this.toolResources = toolResources + } + + /** + * Override the tools the assistant can use for this run. This is useful for modifying + * the behavior on a per-run basis. + */ + fun tools(tools: List) = apply { this.tools = tools.toMutableList() } + + /** + * Override the tools the assistant can use for this run. This is useful for modifying + * the behavior on a per-run basis. + */ + fun addTool(tool: Tool) = apply { + tools = (tools ?: mutableListOf()).apply { add(tool) } + } + + /** + * An alternative to sampling with temperature, called nucleus sampling, where the model + * considers the results of the tokens with top_p probability mass. So 0.1 means only + * the tokens comprising the top 10% probability mass are considered. + * + * We generally recommend altering this or temperature but not both. + */ + fun topP(topP: Double) = apply { this.topP = topP } + + /** + * Controls for how a thread will be truncated prior to the run. Use this to control the + * intial context window of the run. + */ + fun truncationStrategy(truncationStrategy: TruncationStrategy) = apply { + this.truncationStrategy = truncationStrategy + } + + 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) + } + + fun build(): BetaThreadCreateAndRunBody = + BetaThreadCreateAndRunBody( + checkNotNull(assistantId) { "`assistantId` is required but was not set" }, + instructions, + maxCompletionTokens, + maxPromptTokens, + metadata, + model, + parallelToolCalls, + responseFormat, + temperature, + thread, + toolChoice, + toolResources, + tools?.toImmutable(), + topP, + truncationStrategy, + additionalProperties.toImmutable(), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaThreadCreateAndRunBody && assistantId == other.assistantId && instructions == other.instructions && maxCompletionTokens == other.maxCompletionTokens && maxPromptTokens == other.maxPromptTokens && metadata == other.metadata && model == other.model && parallelToolCalls == other.parallelToolCalls && responseFormat == other.responseFormat && temperature == other.temperature && thread == other.thread && toolChoice == other.toolChoice && toolResources == other.toolResources && tools == other.tools && topP == other.topP && truncationStrategy == other.truncationStrategy && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(assistantId, instructions, maxCompletionTokens, maxPromptTokens, metadata, model, parallelToolCalls, responseFormat, temperature, thread, toolChoice, toolResources, tools, topP, truncationStrategy, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaThreadCreateAndRunBody{assistantId=$assistantId, instructions=$instructions, maxCompletionTokens=$maxCompletionTokens, maxPromptTokens=$maxPromptTokens, metadata=$metadata, model=$model, parallelToolCalls=$parallelToolCalls, responseFormat=$responseFormat, temperature=$temperature, thread=$thread, toolChoice=$toolChoice, toolResources=$toolResources, tools=$tools, topP=$topP, truncationStrategy=$truncationStrategy, additionalProperties=$additionalProperties}" + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + @NoAutoDetect + class Builder { + + private var body: BetaThreadCreateAndRunBody.Builder = BetaThreadCreateAndRunBody.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(betaThreadCreateAndRunParams: BetaThreadCreateAndRunParams) = apply { + body = betaThreadCreateAndRunParams.body.toBuilder() + additionalHeaders = betaThreadCreateAndRunParams.additionalHeaders.toBuilder() + additionalQueryParams = betaThreadCreateAndRunParams.additionalQueryParams.toBuilder() + } + + /** + * The ID of the [assistant](https://platform.openai.com/docs/api-reference/assistants) to + * use to execute this run. + */ + fun assistantId(assistantId: String) = apply { body.assistantId(assistantId) } + + /** + * Override the default system message of the assistant. This is useful for modifying the + * behavior on a per-run basis. + */ + fun instructions(instructions: String) = apply { body.instructions(instructions) } + + /** + * The maximum number of completion tokens that may be used over the course of the run. The + * run will make a best effort to use only the number of completion tokens specified, across + * multiple turns of the run. If the run exceeds the number of completion tokens specified, + * the run will end with status `incomplete`. See `incomplete_details` for more info. + */ + fun maxCompletionTokens(maxCompletionTokens: Long) = apply { + body.maxCompletionTokens(maxCompletionTokens) + } + + /** + * The maximum number of prompt tokens that may be used over the course of the run. The run + * will make a best effort to use only the number of prompt tokens specified, across + * multiple turns of the run. If the run exceeds the number of prompt tokens specified, the + * run will end with status `incomplete`. See `incomplete_details` for more info. + */ + fun maxPromptTokens(maxPromptTokens: Long) = apply { body.maxPromptTokens(maxPromptTokens) } + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format. Keys can be a + * maximum of 64 characters long and values can be a maximum of 512 characters long. + */ + fun metadata(metadata: JsonValue) = apply { body.metadata(metadata) } + + /** + * The ID of the [Model](https://platform.openai.com/docs/api-reference/models) to be used + * to execute this run. If a value is provided here, it will override the model associated + * with the assistant. If not, the model associated with the assistant will be used. + */ + fun model(model: ChatModel) = apply { body.model(model) } + + /** + * The ID of the [Model](https://platform.openai.com/docs/api-reference/models) to be used + * to execute this run. If a value is provided here, it will override the model associated + * with the assistant. If not, the model associated with the assistant will be used. + */ + fun model(value: String) = apply { body.model(value) } + + /** + * Whether to enable + * [parallel function calling](https://platform.openai.com/docs/guides/function-calling#configuring-parallel-function-calling) + * during tool use. + */ + fun parallelToolCalls(parallelToolCalls: Boolean) = apply { + body.parallelToolCalls(parallelToolCalls) + } + + /** + * Specifies the format that the model must output. Compatible with + * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o), [GPT-4 + * Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4), and all GPT-3.5 + * Turbo models since `gpt-3.5-turbo-1106`. + * + * Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured Outputs + * which ensures the model will match your supplied JSON schema. Learn more in the + * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs). + * + * Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the message the + * model generates is valid JSON. + * + * **Important:** when using JSON mode, you **must** also instruct the model to produce JSON + * yourself via a system or user message. Without this, the model may generate an unending + * stream of whitespace until the generation reaches the token limit, resulting in a + * long-running and seemingly "stuck" request. Also note that the message content may be + * partially cut off if `finish_reason="length"`, which indicates the generation exceeded + * `max_tokens` or the conversation exceeded the max context length. + */ + fun responseFormat(responseFormat: AssistantResponseFormatOption) = apply { + body.responseFormat(responseFormat) + } + + /** `auto` is the default value */ + fun responseFormat(behavior: AssistantResponseFormatOption.Behavior) = apply { + body.responseFormat(behavior) + } + + fun responseFormat(responseFormatText: ResponseFormatText) = apply { + body.responseFormat(responseFormatText) + } + + fun responseFormat(responseFormatJsonObject: ResponseFormatJsonObject) = apply { + body.responseFormat(responseFormatJsonObject) + } + + fun responseFormat(responseFormatJsonSchema: ResponseFormatJsonSchema) = apply { + body.responseFormat(responseFormatJsonSchema) + } + + /** + * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the + * output more random, while lower values like 0.2 will make it more focused and + * deterministic. + */ + fun temperature(temperature: Double) = apply { body.temperature(temperature) } + + /** If no thread is provided, an empty thread will be created. */ + fun thread(thread: Thread) = apply { body.thread(thread) } + + /** + * Controls which (if any) tool is called by the model. `none` means the model will not call + * any tools and instead generates a message. `auto` is the default value and means the + * model can pick between generating a message or calling one or more tools. `required` + * means the model must call one or more tools before responding to the user. Specifying a + * particular tool like `{"type": "file_search"}` or `{"type": "function", "function": + * {"name": "my_function"}}` forces the model to call that tool. + */ + fun toolChoice(toolChoice: AssistantToolChoiceOption) = apply { + body.toolChoice(toolChoice) + } + + /** + * `none` means the model will not call any tools and instead generates a message. `auto` + * means the model can pick between generating a message or calling one or more tools. + * `required` means the model must call one or more tools before responding to the user. + */ + fun toolChoice(behavior: AssistantToolChoiceOption.Behavior) = apply { + body.toolChoice(behavior) + } + + /** + * Specifies a tool the model should use. Use to force the model to call a specific tool. + */ + fun toolChoice(assistantToolChoice: AssistantToolChoice) = apply { + body.toolChoice(assistantToolChoice) + } + + /** + * A set of resources that are used by the assistant's tools. The resources are specific to + * the type of tool. For example, the `code_interpreter` tool requires a list of file IDs, + * while the `file_search` tool requires a list of vector store IDs. + */ + fun toolResources(toolResources: ToolResources) = apply { + body.toolResources(toolResources) + } + + /** + * Override the tools the assistant can use for this run. This is useful for modifying the + * behavior on a per-run basis. + */ + fun tools(tools: List) = apply { body.tools(tools) } + + /** + * Override the tools the assistant can use for this run. This is useful for modifying the + * behavior on a per-run basis. + */ + fun addTool(tool: Tool) = apply { body.addTool(tool) } + + /** + * An alternative to sampling with temperature, called nucleus sampling, where the model + * considers the results of the tokens with top_p probability mass. So 0.1 means only the + * tokens comprising the top 10% probability mass are considered. + * + * We generally recommend altering this or temperature but not both. + */ + fun topP(topP: Double) = apply { body.topP(topP) } + + /** + * Controls for how a thread will be truncated prior to the run. Use this to control the + * intial context window of the run. + */ + fun truncationStrategy(truncationStrategy: TruncationStrategy) = apply { + body.truncationStrategy(truncationStrategy) + } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } + + fun build(): BetaThreadCreateAndRunParams = + BetaThreadCreateAndRunParams( + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + /** If no thread is provided, an empty thread will be created. */ + @NoAutoDetect + class Thread + @JsonCreator + private constructor( + @JsonProperty("messages") private val messages: List?, + @JsonProperty("tool_resources") private val toolResources: ToolResources?, + @JsonProperty("metadata") private val metadata: JsonValue?, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** + * A list of [messages](https://platform.openai.com/docs/api-reference/messages) to start + * the thread with. + */ + @JsonProperty("messages") + fun messages(): Optional> = Optional.ofNullable(messages) + + /** + * A set of resources that are made available to the assistant's tools in this thread. The + * resources are specific to the type of tool. For example, the `code_interpreter` tool + * requires a list of file IDs, while the `file_search` tool requires a list of vector store + * IDs. + */ + @JsonProperty("tool_resources") + fun toolResources(): Optional = Optional.ofNullable(toolResources) + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format. Keys can be a + * maximum of 64 characters long and values can be a maximum of 512 characters long. + */ + @JsonProperty("metadata") + fun metadata(): Optional = Optional.ofNullable(metadata) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var messages: MutableList? = null + private var toolResources: ToolResources? = null + private var metadata: JsonValue? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(thread: Thread) = apply { + messages = thread.messages?.toMutableList() + toolResources = thread.toolResources + metadata = thread.metadata + additionalProperties = thread.additionalProperties.toMutableMap() + } + + /** + * A list of [messages](https://platform.openai.com/docs/api-reference/messages) to + * start the thread with. + */ + fun messages(messages: List) = apply { + this.messages = messages.toMutableList() + } + + /** + * A list of [messages](https://platform.openai.com/docs/api-reference/messages) to + * start the thread with. + */ + fun addMessage(message: Message) = apply { + messages = (messages ?: mutableListOf()).apply { add(message) } + } + + /** + * A set of resources that are made available to the assistant's tools in this thread. + * The resources are specific to the type of tool. For example, the `code_interpreter` + * tool requires a list of file IDs, while the `file_search` tool requires a list of + * vector store IDs. + */ + fun toolResources(toolResources: ToolResources) = apply { + this.toolResources = toolResources + } + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format. Keys can be a + * maximum of 64 characters long and values can be a maximum of 512 characters long. + */ + fun metadata(metadata: JsonValue) = apply { this.metadata = metadata } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + fun build(): Thread = + Thread( + messages?.toImmutable(), + toolResources, + metadata, + additionalProperties.toImmutable(), + ) + } + + @NoAutoDetect + class Message + @JsonCreator + private constructor( + @JsonProperty("role") private val role: Role, + @JsonProperty("content") private val content: Content, + @JsonProperty("attachments") private val attachments: List?, + @JsonProperty("metadata") private val metadata: JsonValue?, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** + * The role of the entity that is creating the message. Allowed values include: + * - `user`: Indicates the message is sent by an actual user and should be used in most + * cases to represent user-generated messages. + * - `assistant`: Indicates the message is generated by the assistant. Use this value to + * insert messages from the assistant into the conversation. + */ + @JsonProperty("role") fun role(): Role = role + + /** The text contents of the message. */ + @JsonProperty("content") fun content(): Content = content + + /** A list of files attached to the message, and the tools they should be added to. */ + @JsonProperty("attachments") + fun attachments(): Optional> = Optional.ofNullable(attachments) + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format. Keys can be a + * maximum of 64 characters long and values can be a maximum of 512 characters long. + */ + @JsonProperty("metadata") + fun metadata(): Optional = Optional.ofNullable(metadata) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var role: Role? = null + private var content: Content? = null + private var attachments: MutableList? = null + private var metadata: JsonValue? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(message: Message) = apply { + role = message.role + content = message.content + attachments = message.attachments?.toMutableList() + metadata = message.metadata + additionalProperties = message.additionalProperties.toMutableMap() + } + + /** + * The role of the entity that is creating the message. Allowed values include: + * - `user`: Indicates the message is sent by an actual user and should be used in + * most cases to represent user-generated messages. + * - `assistant`: Indicates the message is generated by the assistant. Use this + * value to insert messages from the assistant into the conversation. + */ + fun role(role: Role) = apply { this.role = role } + + /** The text contents of the message. */ + fun content(content: Content) = apply { this.content = content } + + /** The text contents of the message. */ + fun content(textContent: String) = apply { + this.content = Content.ofTextContent(textContent) + } + + /** + * An array of content parts with a defined type, each can be of type `text` or + * images can be passed with `image_url` or `image_file`. Image types are only + * supported on [Vision-compatible models](https://platform.openai.com/docs/models). + */ + fun contentOfArrayOfContentParts( + arrayOfContentParts: List + ) = apply { this.content = Content.ofArrayOfContentParts(arrayOfContentParts) } + + /** + * A list of files attached to the message, and the tools they should be added to. + */ + fun attachments(attachments: List) = apply { + this.attachments = attachments.toMutableList() + } + + /** + * A list of files attached to the message, and the tools they should be added to. + */ + fun addAttachment(attachment: Attachment) = apply { + attachments = (attachments ?: mutableListOf()).apply { add(attachment) } + } + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful + * for storing additional information about the object in a structured format. Keys + * can be a maximum of 64 characters long and values can be a maximum of 512 + * characters long. + */ + fun metadata(metadata: JsonValue) = apply { this.metadata = metadata } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + fun build(): Message = + Message( + checkNotNull(role) { "`role` is required but was not set" }, + checkNotNull(content) { "`content` is required but was not set" }, + attachments?.toImmutable(), + metadata, + additionalProperties.toImmutable(), + ) + } + + /** The text contents of the message. */ + @JsonDeserialize(using = Content.Deserializer::class) + @JsonSerialize(using = Content.Serializer::class) + class Content + private constructor( + private val textContent: String? = null, + private val arrayOfContentParts: List? = null, + private val _json: JsonValue? = null, + ) { + + /** The text contents of the message. */ + fun textContent(): Optional = Optional.ofNullable(textContent) + /** + * An array of content parts with a defined type, each can be of type `text` or + * images can be passed with `image_url` or `image_file`. Image types are only + * supported on [Vision-compatible models](https://platform.openai.com/docs/models). + */ + fun arrayOfContentParts(): Optional> = + Optional.ofNullable(arrayOfContentParts) + + fun isTextContent(): Boolean = textContent != null + + fun isArrayOfContentParts(): Boolean = arrayOfContentParts != null + + /** The text contents of the message. */ + fun asTextContent(): String = textContent.getOrThrow("textContent") + /** + * An array of content parts with a defined type, each can be of type `text` or + * images can be passed with `image_url` or `image_file`. Image types are only + * supported on [Vision-compatible models](https://platform.openai.com/docs/models). + */ + fun asArrayOfContentParts(): List = + arrayOfContentParts.getOrThrow("arrayOfContentParts") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + textContent != null -> visitor.visitTextContent(textContent) + arrayOfContentParts != null -> + visitor.visitArrayOfContentParts(arrayOfContentParts) + else -> visitor.unknown(_json) + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Content && textContent == other.textContent && arrayOfContentParts == other.arrayOfContentParts /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(textContent, arrayOfContentParts) /* spotless:on */ + + override fun toString(): String = + when { + textContent != null -> "Content{textContent=$textContent}" + arrayOfContentParts != null -> + "Content{arrayOfContentParts=$arrayOfContentParts}" + _json != null -> "Content{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Content") + } + + companion object { + + /** The text contents of the message. */ + @JvmStatic + fun ofTextContent(textContent: String) = Content(textContent = textContent) + + /** + * An array of content parts with a defined type, each can be of type `text` or + * images can be passed with `image_url` or `image_file`. Image types are only + * supported on + * [Vision-compatible models](https://platform.openai.com/docs/models). + */ + @JvmStatic + fun ofArrayOfContentParts(arrayOfContentParts: List) = + Content(arrayOfContentParts = arrayOfContentParts) + } + + interface Visitor { + + fun visitTextContent(textContent: String): T + + fun visitArrayOfContentParts( + arrayOfContentParts: List + ): T + + fun unknown(json: JsonValue?): T { + throw OpenAIInvalidDataException("Unknown Content: $json") + } + } + + class Deserializer : BaseDeserializer(Content::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Content { + val json = JsonValue.fromJsonNode(node) + + tryDeserialize(node, jacksonTypeRef())?.let { + return Content(textContent = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef>())?.let { + return Content(arrayOfContentParts = it, _json = json) + } + + return Content(_json = json) + } + } + + class Serializer : BaseSerializer(Content::class) { + + override fun serialize( + value: Content, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.textContent != null -> generator.writeObject(value.textContent) + value.arrayOfContentParts != null -> + generator.writeObject(value.arrayOfContentParts) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Content") + } + } + } + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val USER = of("user") + + @JvmField val ASSISTANT = of("assistant") + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + USER, + ASSISTANT, + } + + enum class Value { + USER, + ASSISTANT, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + USER -> Value.USER + ASSISTANT -> Value.ASSISTANT + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + USER -> Known.USER + ASSISTANT -> Known.ASSISTANT + else -> throw OpenAIInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Role && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + @NoAutoDetect + class Attachment + @JsonCreator + private constructor( + @JsonProperty("file_id") private val fileId: String?, + @JsonProperty("tools") private val tools: List?, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** The ID of the file to attach to the message. */ + @JsonProperty("file_id") + fun fileId(): Optional = Optional.ofNullable(fileId) + + /** The tools to add this file to. */ + @JsonProperty("tools") + fun tools(): Optional> = Optional.ofNullable(tools) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var fileId: String? = null + private var tools: MutableList? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(attachment: Attachment) = apply { + fileId = attachment.fileId + tools = attachment.tools?.toMutableList() + additionalProperties = attachment.additionalProperties.toMutableMap() + } + + /** The ID of the file to attach to the message. */ + fun fileId(fileId: String) = apply { this.fileId = fileId } + + /** The tools to add this file to. */ + fun tools(tools: List) = apply { this.tools = tools.toMutableList() } + + /** The tools to add this file to. */ + fun addTool(tool: Tool) = apply { + tools = (tools ?: mutableListOf()).apply { add(tool) } + } + + 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) + } + + fun build(): Attachment = + Attachment( + fileId, + tools?.toImmutable(), + additionalProperties.toImmutable(), + ) + } + + @JsonDeserialize(using = Tool.Deserializer::class) + @JsonSerialize(using = Tool.Serializer::class) + class Tool + private constructor( + private val codeInterpreterTool: CodeInterpreterTool? = null, + private val fileSearch: FileSearch? = null, + private val _json: JsonValue? = null, + ) { + + fun codeInterpreterTool(): Optional = + Optional.ofNullable(codeInterpreterTool) + + fun fileSearch(): Optional = Optional.ofNullable(fileSearch) + + fun isCodeInterpreterTool(): Boolean = codeInterpreterTool != null + + fun isFileSearch(): Boolean = fileSearch != null + + fun asCodeInterpreterTool(): CodeInterpreterTool = + codeInterpreterTool.getOrThrow("codeInterpreterTool") + + fun asFileSearch(): FileSearch = fileSearch.getOrThrow("fileSearch") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + codeInterpreterTool != null -> + visitor.visitCodeInterpreterTool(codeInterpreterTool) + fileSearch != null -> visitor.visitFileSearch(fileSearch) + else -> visitor.unknown(_json) + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Tool && codeInterpreterTool == other.codeInterpreterTool && fileSearch == other.fileSearch /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(codeInterpreterTool, fileSearch) /* spotless:on */ + + override fun toString(): String = + when { + codeInterpreterTool != null -> + "Tool{codeInterpreterTool=$codeInterpreterTool}" + fileSearch != null -> "Tool{fileSearch=$fileSearch}" + _json != null -> "Tool{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Tool") + } + + companion object { + + @JvmStatic + fun ofCodeInterpreterTool(codeInterpreterTool: CodeInterpreterTool) = + Tool(codeInterpreterTool = codeInterpreterTool) + + @JvmStatic + fun ofFileSearch(fileSearch: FileSearch) = Tool(fileSearch = fileSearch) + } + + interface Visitor { + + fun visitCodeInterpreterTool(codeInterpreterTool: CodeInterpreterTool): T + + fun visitFileSearch(fileSearch: FileSearch): T + + fun unknown(json: JsonValue?): T { + throw OpenAIInvalidDataException("Unknown Tool: $json") + } + } + + class Deserializer : BaseDeserializer(Tool::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Tool { + val json = JsonValue.fromJsonNode(node) + val type = + json.asObject().getOrNull()?.get("type")?.asString()?.getOrNull() + + when (type) { + "code_interpreter" -> { + tryDeserialize(node, jacksonTypeRef()) + ?.let { + return Tool(codeInterpreterTool = it, _json = json) + } + } + "file_search" -> { + tryDeserialize(node, jacksonTypeRef())?.let { + return Tool(fileSearch = it, _json = json) + } + } + } + + return Tool(_json = json) + } + } + + class Serializer : BaseSerializer(Tool::class) { + + override fun serialize( + value: Tool, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.codeInterpreterTool != null -> + generator.writeObject(value.codeInterpreterTool) + value.fileSearch != null -> generator.writeObject(value.fileSearch) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Tool") + } + } + } + + @NoAutoDetect + class FileSearch + @JsonCreator + private constructor( + @JsonProperty("type") private val type: Type, + @JsonAnySetter + private val additionalProperties: Map = + immutableEmptyMap(), + ) { + + /** The type of tool being defined: `file_search` */ + @JsonProperty("type") fun type(): Type = type + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var type: Type? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(fileSearch: FileSearch) = apply { + type = fileSearch.type + additionalProperties = + fileSearch.additionalProperties.toMutableMap() + } + + /** The type of tool being defined: `file_search` */ + fun type(type: Type) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + fun build(): FileSearch = + FileSearch( + checkNotNull(type) { "`type` is required but was not set" }, + additionalProperties.toImmutable() + ) + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + companion object { + + @JvmField val FILE_SEARCH = of("file_search") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + FILE_SEARCH, + } + + enum class Value { + FILE_SEARCH, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + FILE_SEARCH -> Value.FILE_SEARCH + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + FILE_SEARCH -> Known.FILE_SEARCH + else -> throw OpenAIInvalidDataException("Unknown Type: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is FileSearch && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(type, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "FileSearch{type=$type, additionalProperties=$additionalProperties}" + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Attachment && fileId == other.fileId && tools == other.tools && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(fileId, tools, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Attachment{fileId=$fileId, tools=$tools, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Message && role == other.role && content == other.content && attachments == other.attachments && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(role, content, attachments, metadata, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Message{role=$role, content=$content, attachments=$attachments, metadata=$metadata, additionalProperties=$additionalProperties}" + } + + /** + * A set of resources that are made available to the assistant's tools in this thread. The + * resources are specific to the type of tool. For example, the `code_interpreter` tool + * requires a list of file IDs, while the `file_search` tool requires a list of vector store + * IDs. + */ + @NoAutoDetect + class ToolResources + @JsonCreator + private constructor( + @JsonProperty("code_interpreter") private val codeInterpreter: CodeInterpreter?, + @JsonProperty("file_search") private val fileSearch: FileSearch?, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + @JsonProperty("code_interpreter") + fun codeInterpreter(): Optional = Optional.ofNullable(codeInterpreter) + + @JsonProperty("file_search") + fun fileSearch(): Optional = Optional.ofNullable(fileSearch) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var codeInterpreter: CodeInterpreter? = null + private var fileSearch: FileSearch? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(toolResources: ToolResources) = apply { + codeInterpreter = toolResources.codeInterpreter + fileSearch = toolResources.fileSearch + additionalProperties = toolResources.additionalProperties.toMutableMap() + } + + fun codeInterpreter(codeInterpreter: CodeInterpreter) = apply { + this.codeInterpreter = codeInterpreter + } + + fun fileSearch(fileSearch: FileSearch) = apply { this.fileSearch = fileSearch } + + 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) + } + + fun build(): ToolResources = + ToolResources( + codeInterpreter, + fileSearch, + additionalProperties.toImmutable(), + ) + } + + @NoAutoDetect + class CodeInterpreter + @JsonCreator + private constructor( + @JsonProperty("file_ids") private val fileIds: List?, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** + * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made + * available to the `code_interpreter` tool. There can be a maximum of 20 files + * associated with the tool. + */ + @JsonProperty("file_ids") + fun fileIds(): Optional> = Optional.ofNullable(fileIds) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var fileIds: MutableList? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(codeInterpreter: CodeInterpreter) = apply { + fileIds = codeInterpreter.fileIds?.toMutableList() + additionalProperties = codeInterpreter.additionalProperties.toMutableMap() + } + + /** + * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs + * made available to the `code_interpreter` tool. There can be a maximum of 20 + * files associated with the tool. + */ + fun fileIds(fileIds: List) = apply { + this.fileIds = fileIds.toMutableList() + } + + /** + * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs + * made available to the `code_interpreter` tool. There can be a maximum of 20 + * files associated with the tool. + */ + fun addFileId(fileId: String) = apply { + fileIds = (fileIds ?: mutableListOf()).apply { add(fileId) } + } + + 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) + } + + fun build(): CodeInterpreter = + CodeInterpreter(fileIds?.toImmutable(), additionalProperties.toImmutable()) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is CodeInterpreter && fileIds == other.fileIds && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(fileIds, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CodeInterpreter{fileIds=$fileIds, additionalProperties=$additionalProperties}" + } + + @NoAutoDetect + class FileSearch + @JsonCreator + private constructor( + @JsonProperty("vector_store_ids") private val vectorStoreIds: List?, + @JsonProperty("vector_stores") private val vectorStores: List?, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** + * The + * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object) + * attached to this thread. There can be a maximum of 1 vector store attached to the + * thread. + */ + @JsonProperty("vector_store_ids") + fun vectorStoreIds(): Optional> = Optional.ofNullable(vectorStoreIds) + + /** + * A helper to create a + * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object) + * with file_ids and attach it to this thread. There can be a maximum of 1 vector + * store attached to the thread. + */ + @JsonProperty("vector_stores") + fun vectorStores(): Optional> = Optional.ofNullable(vectorStores) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var vectorStoreIds: MutableList? = null + private var vectorStores: MutableList? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(fileSearch: FileSearch) = apply { + vectorStoreIds = fileSearch.vectorStoreIds?.toMutableList() + vectorStores = fileSearch.vectorStores?.toMutableList() + additionalProperties = fileSearch.additionalProperties.toMutableMap() + } + + /** + * The + * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object) + * attached to this thread. There can be a maximum of 1 vector store attached to + * the thread. + */ + fun vectorStoreIds(vectorStoreIds: List) = apply { + this.vectorStoreIds = vectorStoreIds.toMutableList() + } + + /** + * The + * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object) + * attached to this thread. There can be a maximum of 1 vector store attached to + * the thread. + */ + fun addVectorStoreId(vectorStoreId: String) = apply { + vectorStoreIds = + (vectorStoreIds ?: mutableListOf()).apply { add(vectorStoreId) } + } + + /** + * A helper to create a + * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object) + * with file_ids and attach it to this thread. There can be a maximum of 1 + * vector store attached to the thread. + */ + fun vectorStores(vectorStores: List) = apply { + this.vectorStores = vectorStores.toMutableList() + } + + /** + * A helper to create a + * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object) + * with file_ids and attach it to this thread. There can be a maximum of 1 + * vector store attached to the thread. + */ + fun addVectorStore(vectorStore: VectorStore) = apply { + vectorStores = (vectorStores ?: mutableListOf()).apply { add(vectorStore) } + } + + 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) + } + + fun build(): FileSearch = + FileSearch( + vectorStoreIds?.toImmutable(), + vectorStores?.toImmutable(), + additionalProperties.toImmutable(), + ) + } + + @NoAutoDetect + class VectorStore + @JsonCreator + private constructor( + @JsonProperty("file_ids") private val fileIds: List?, + @JsonProperty("chunking_strategy") + private val chunkingStrategy: FileChunkingStrategyParam?, + @JsonProperty("metadata") private val metadata: JsonValue?, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** + * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs to + * add to the vector store. There can be a maximum of 10000 files in a vector + * store. + */ + @JsonProperty("file_ids") + fun fileIds(): Optional> = Optional.ofNullable(fileIds) + + /** + * The chunking strategy used to chunk the file(s). If not set, will use the + * `auto` strategy. Only applicable if `file_ids` is non-empty. + */ + @JsonProperty("chunking_strategy") + fun chunkingStrategy(): Optional = + Optional.ofNullable(chunkingStrategy) + + /** + * Set of 16 key-value pairs that can be attached to a vector store. This can be + * useful for storing additional information about the vector store in a + * structured format. Keys can be a maximum of 64 characters long and values can + * be a maximum of 512 characters long. + */ + @JsonProperty("metadata") + fun metadata(): Optional = Optional.ofNullable(metadata) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var fileIds: MutableList? = null + private var chunkingStrategy: FileChunkingStrategyParam? = null + private var metadata: JsonValue? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(vectorStore: VectorStore) = apply { + fileIds = vectorStore.fileIds?.toMutableList() + chunkingStrategy = vectorStore.chunkingStrategy + metadata = vectorStore.metadata + additionalProperties = vectorStore.additionalProperties.toMutableMap() + } + + /** + * A list of [file](https://platform.openai.com/docs/api-reference/files) + * IDs to add to the vector store. There can be a maximum of 10000 files in + * a vector store. + */ + fun fileIds(fileIds: List) = apply { + this.fileIds = fileIds.toMutableList() + } + + /** + * A list of [file](https://platform.openai.com/docs/api-reference/files) + * IDs to add to the vector store. There can be a maximum of 10000 files in + * a vector store. + */ + fun addFileId(fileId: String) = apply { + fileIds = (fileIds ?: mutableListOf()).apply { add(fileId) } + } + + /** + * The chunking strategy used to chunk the file(s). If not set, will use the + * `auto` strategy. Only applicable if `file_ids` is non-empty. + */ + fun chunkingStrategy(chunkingStrategy: FileChunkingStrategyParam) = apply { + this.chunkingStrategy = chunkingStrategy + } + + /** + * The default strategy. This strategy currently uses a + * `max_chunk_size_tokens` of `800` and `chunk_overlap_tokens` of `400`. + */ + fun chunkingStrategy( + autoFileChunkingStrategyParam: AutoFileChunkingStrategyParam + ) = apply { + this.chunkingStrategy = + FileChunkingStrategyParam.ofAutoFileChunkingStrategyParam( + autoFileChunkingStrategyParam + ) + } + + fun chunkingStrategy( + staticFileChunkingStrategyParam: StaticFileChunkingStrategyParam + ) = apply { + this.chunkingStrategy = + FileChunkingStrategyParam.ofStaticFileChunkingStrategyParam( + staticFileChunkingStrategyParam + ) + } + + /** + * Set of 16 key-value pairs that can be attached to a vector store. This + * can be useful for storing additional information about the vector store + * in a structured format. Keys can be a maximum of 64 characters long and + * values can be a maximum of 512 characters long. + */ + fun metadata(metadata: JsonValue) = apply { this.metadata = metadata } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + fun build(): VectorStore = + VectorStore( + fileIds?.toImmutable(), + chunkingStrategy, + metadata, + additionalProperties.toImmutable(), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is VectorStore && fileIds == other.fileIds && chunkingStrategy == other.chunkingStrategy && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(fileIds, chunkingStrategy, metadata, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "VectorStore{fileIds=$fileIds, chunkingStrategy=$chunkingStrategy, metadata=$metadata, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is FileSearch && vectorStoreIds == other.vectorStoreIds && vectorStores == other.vectorStores && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(vectorStoreIds, vectorStores, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "FileSearch{vectorStoreIds=$vectorStoreIds, vectorStores=$vectorStores, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ToolResources && codeInterpreter == other.codeInterpreter && fileSearch == other.fileSearch && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(codeInterpreter, fileSearch, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ToolResources{codeInterpreter=$codeInterpreter, fileSearch=$fileSearch, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Thread && messages == other.messages && toolResources == other.toolResources && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(messages, toolResources, metadata, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Thread{messages=$messages, toolResources=$toolResources, metadata=$metadata, additionalProperties=$additionalProperties}" + } + + /** + * A set of resources that are used by the assistant's tools. The resources are specific to the + * type of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the + * `file_search` tool requires a list of vector store IDs. + */ + @NoAutoDetect + class ToolResources + @JsonCreator + private constructor( + @JsonProperty("code_interpreter") private val codeInterpreter: CodeInterpreter?, + @JsonProperty("file_search") private val fileSearch: FileSearch?, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + @JsonProperty("code_interpreter") + fun codeInterpreter(): Optional = Optional.ofNullable(codeInterpreter) + + @JsonProperty("file_search") + fun fileSearch(): Optional = Optional.ofNullable(fileSearch) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var codeInterpreter: CodeInterpreter? = null + private var fileSearch: FileSearch? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(toolResources: ToolResources) = apply { + codeInterpreter = toolResources.codeInterpreter + fileSearch = toolResources.fileSearch + additionalProperties = toolResources.additionalProperties.toMutableMap() + } + + fun codeInterpreter(codeInterpreter: CodeInterpreter) = apply { + this.codeInterpreter = codeInterpreter + } + + fun fileSearch(fileSearch: FileSearch) = apply { this.fileSearch = fileSearch } + + 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) + } + + fun build(): ToolResources = + ToolResources( + codeInterpreter, + fileSearch, + additionalProperties.toImmutable(), + ) + } + + @NoAutoDetect + class CodeInterpreter + @JsonCreator + private constructor( + @JsonProperty("file_ids") private val fileIds: List?, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** + * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made + * available to the `code_interpreter` tool. There can be a maximum of 20 files + * associated with the tool. + */ + @JsonProperty("file_ids") + fun fileIds(): Optional> = Optional.ofNullable(fileIds) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var fileIds: MutableList? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(codeInterpreter: CodeInterpreter) = apply { + fileIds = codeInterpreter.fileIds?.toMutableList() + additionalProperties = codeInterpreter.additionalProperties.toMutableMap() + } + + /** + * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made + * available to the `code_interpreter` tool. There can be a maximum of 20 files + * associated with the tool. + */ + fun fileIds(fileIds: List) = apply { + this.fileIds = fileIds.toMutableList() + } + + /** + * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made + * available to the `code_interpreter` tool. There can be a maximum of 20 files + * associated with the tool. + */ + fun addFileId(fileId: String) = apply { + fileIds = (fileIds ?: mutableListOf()).apply { add(fileId) } + } + + 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) + } + + fun build(): CodeInterpreter = + CodeInterpreter(fileIds?.toImmutable(), additionalProperties.toImmutable()) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is CodeInterpreter && fileIds == other.fileIds && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(fileIds, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CodeInterpreter{fileIds=$fileIds, additionalProperties=$additionalProperties}" + } + + @NoAutoDetect + class FileSearch + @JsonCreator + private constructor( + @JsonProperty("vector_store_ids") private val vectorStoreIds: List?, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** + * The ID of the + * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object) + * attached to this assistant. There can be a maximum of 1 vector store attached to the + * assistant. + */ + @JsonProperty("vector_store_ids") + fun vectorStoreIds(): Optional> = Optional.ofNullable(vectorStoreIds) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var vectorStoreIds: MutableList? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(fileSearch: FileSearch) = apply { + vectorStoreIds = fileSearch.vectorStoreIds?.toMutableList() + additionalProperties = fileSearch.additionalProperties.toMutableMap() + } + + /** + * The ID of the + * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object) + * attached to this assistant. There can be a maximum of 1 vector store attached to + * the assistant. + */ + fun vectorStoreIds(vectorStoreIds: List) = apply { + this.vectorStoreIds = vectorStoreIds.toMutableList() + } + + /** + * The ID of the + * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object) + * attached to this assistant. There can be a maximum of 1 vector store attached to + * the assistant. + */ + fun addVectorStoreId(vectorStoreId: String) = apply { + vectorStoreIds = + (vectorStoreIds ?: mutableListOf()).apply { add(vectorStoreId) } + } + + 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) + } + + fun build(): FileSearch = + FileSearch(vectorStoreIds?.toImmutable(), additionalProperties.toImmutable()) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is FileSearch && vectorStoreIds == other.vectorStoreIds && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(vectorStoreIds, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "FileSearch{vectorStoreIds=$vectorStoreIds, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ToolResources && codeInterpreter == other.codeInterpreter && fileSearch == other.fileSearch && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(codeInterpreter, fileSearch, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ToolResources{codeInterpreter=$codeInterpreter, fileSearch=$fileSearch, additionalProperties=$additionalProperties}" + } + + @JsonDeserialize(using = Tool.Deserializer::class) + @JsonSerialize(using = Tool.Serializer::class) + class Tool + private constructor( + private val codeInterpreterTool: CodeInterpreterTool? = null, + private val fileSearchTool: FileSearchTool? = null, + private val functionTool: FunctionTool? = null, + private val _json: JsonValue? = null, + ) { + + fun codeInterpreterTool(): Optional = + Optional.ofNullable(codeInterpreterTool) + + fun fileSearchTool(): Optional = Optional.ofNullable(fileSearchTool) + + fun functionTool(): Optional = Optional.ofNullable(functionTool) + + fun isCodeInterpreterTool(): Boolean = codeInterpreterTool != null + + fun isFileSearchTool(): Boolean = fileSearchTool != null + + fun isFunctionTool(): Boolean = functionTool != null + + fun asCodeInterpreterTool(): CodeInterpreterTool = + codeInterpreterTool.getOrThrow("codeInterpreterTool") + + fun asFileSearchTool(): FileSearchTool = fileSearchTool.getOrThrow("fileSearchTool") + + fun asFunctionTool(): FunctionTool = functionTool.getOrThrow("functionTool") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + codeInterpreterTool != null -> visitor.visitCodeInterpreterTool(codeInterpreterTool) + fileSearchTool != null -> visitor.visitFileSearchTool(fileSearchTool) + functionTool != null -> visitor.visitFunctionTool(functionTool) + else -> visitor.unknown(_json) + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Tool && codeInterpreterTool == other.codeInterpreterTool && fileSearchTool == other.fileSearchTool && functionTool == other.functionTool /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(codeInterpreterTool, fileSearchTool, functionTool) /* spotless:on */ + + override fun toString(): String = + when { + codeInterpreterTool != null -> "Tool{codeInterpreterTool=$codeInterpreterTool}" + fileSearchTool != null -> "Tool{fileSearchTool=$fileSearchTool}" + functionTool != null -> "Tool{functionTool=$functionTool}" + _json != null -> "Tool{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Tool") + } + + companion object { + + @JvmStatic + fun ofCodeInterpreterTool(codeInterpreterTool: CodeInterpreterTool) = + Tool(codeInterpreterTool = codeInterpreterTool) + + @JvmStatic + fun ofFileSearchTool(fileSearchTool: FileSearchTool) = + Tool(fileSearchTool = fileSearchTool) + + @JvmStatic + fun ofFunctionTool(functionTool: FunctionTool) = Tool(functionTool = functionTool) + } + + interface Visitor { + + fun visitCodeInterpreterTool(codeInterpreterTool: CodeInterpreterTool): T + + fun visitFileSearchTool(fileSearchTool: FileSearchTool): T + + fun visitFunctionTool(functionTool: FunctionTool): T + + fun unknown(json: JsonValue?): T { + throw OpenAIInvalidDataException("Unknown Tool: $json") + } + } + + class Deserializer : BaseDeserializer(Tool::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Tool { + val json = JsonValue.fromJsonNode(node) + + tryDeserialize(node, jacksonTypeRef())?.let { + return Tool(codeInterpreterTool = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef())?.let { + return Tool(fileSearchTool = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef())?.let { + return Tool(functionTool = it, _json = json) + } + + return Tool(_json = json) + } + } + + class Serializer : BaseSerializer(Tool::class) { + + override fun serialize( + value: Tool, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.codeInterpreterTool != null -> + generator.writeObject(value.codeInterpreterTool) + value.fileSearchTool != null -> generator.writeObject(value.fileSearchTool) + value.functionTool != null -> generator.writeObject(value.functionTool) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Tool") + } + } + } + } + + /** + * Controls for how a thread will be truncated prior to the run. Use this to control the intial + * context window of the run. + */ + @NoAutoDetect + class TruncationStrategy + @JsonCreator + private constructor( + @JsonProperty("type") private val type: Type, + @JsonProperty("last_messages") private val lastMessages: Long?, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** + * The truncation strategy to use for the thread. The default is `auto`. If set to + * `last_messages`, the thread will be truncated to the n most recent messages in the + * thread. When set to `auto`, messages in the middle of the thread will be dropped to fit + * the context length of the model, `max_prompt_tokens`. + */ + @JsonProperty("type") fun type(): Type = type + + /** + * The number of most recent messages from the thread when constructing the context for the + * run. + */ + @JsonProperty("last_messages") + fun lastMessages(): Optional = Optional.ofNullable(lastMessages) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var type: Type? = null + private var lastMessages: Long? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(truncationStrategy: TruncationStrategy) = apply { + type = truncationStrategy.type + lastMessages = truncationStrategy.lastMessages + additionalProperties = truncationStrategy.additionalProperties.toMutableMap() + } + + /** + * The truncation strategy to use for the thread. The default is `auto`. If set to + * `last_messages`, the thread will be truncated to the n most recent messages in the + * thread. When set to `auto`, messages in the middle of the thread will be dropped to + * fit the context length of the model, `max_prompt_tokens`. + */ + fun type(type: Type) = apply { this.type = type } + + /** + * The number of most recent messages from the thread when constructing the context for + * the run. + */ + fun lastMessages(lastMessages: Long) = apply { this.lastMessages = lastMessages } + + 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) + } + + fun build(): TruncationStrategy = + TruncationStrategy( + checkNotNull(type) { "`type` is required but was not set" }, + lastMessages, + additionalProperties.toImmutable(), + ) + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val AUTO = of("auto") + + @JvmField val LAST_MESSAGES = of("last_messages") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + AUTO, + LAST_MESSAGES, + } + + enum class Value { + AUTO, + LAST_MESSAGES, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + AUTO -> Value.AUTO + LAST_MESSAGES -> Value.LAST_MESSAGES + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + AUTO -> Known.AUTO + LAST_MESSAGES -> Known.LAST_MESSAGES + else -> throw OpenAIInvalidDataException("Unknown Type: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is TruncationStrategy && type == other.type && lastMessages == other.lastMessages && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(type, lastMessages, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "TruncationStrategy{type=$type, lastMessages=$lastMessages, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaThreadCreateAndRunParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "BetaThreadCreateAndRunParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadCreateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadCreateParams.kt new file mode 100644 index 00000000..6f2a9b9f --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadCreateParams.kt @@ -0,0 +1,1592 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.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.fasterxml.jackson.core.JsonGenerator +import com.fasterxml.jackson.core.ObjectCodec +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.SerializerProvider +import com.fasterxml.jackson.databind.annotation.JsonDeserialize +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.BaseDeserializer +import com.openai.core.BaseSerializer +import com.openai.core.Enum +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonValue +import com.openai.core.NoAutoDetect +import com.openai.core.getOrThrow +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.core.immutableEmptyMap +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +class BetaThreadCreateParams +constructor( + private val body: BetaThreadCreateBody, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) { + + /** + * A list of [messages](https://platform.openai.com/docs/api-reference/messages) to start the + * thread with. + */ + fun messages(): Optional> = body.messages() + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for storing + * additional information about the object in a structured format. Keys can be a maximum of 64 + * characters long and values can be a maximum of 512 characters long. + */ + fun metadata(): Optional = body.metadata() + + /** + * A set of resources that are made available to the assistant's tools in this thread. The + * resources are specific to the type of tool. For example, the `code_interpreter` tool requires + * a list of file IDs, while the `file_search` tool requires a list of vector store IDs. + */ + fun toolResources(): Optional = body.toolResources() + + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun _additionalBodyProperties(): Map = body._additionalProperties() + + @JvmSynthetic internal fun getBody(): BetaThreadCreateBody = body + + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + + @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams + + @NoAutoDetect + class BetaThreadCreateBody + @JsonCreator + internal constructor( + @JsonProperty("messages") private val messages: List?, + @JsonProperty("metadata") private val metadata: JsonValue?, + @JsonProperty("tool_resources") private val toolResources: ToolResources?, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** + * A list of [messages](https://platform.openai.com/docs/api-reference/messages) to start + * the thread with. + */ + @JsonProperty("messages") + fun messages(): Optional> = Optional.ofNullable(messages) + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format. Keys can be a + * maximum of 64 characters long and values can be a maximum of 512 characters long. + */ + @JsonProperty("metadata") + fun metadata(): Optional = Optional.ofNullable(metadata) + + /** + * A set of resources that are made available to the assistant's tools in this thread. The + * resources are specific to the type of tool. For example, the `code_interpreter` tool + * requires a list of file IDs, while the `file_search` tool requires a list of vector store + * IDs. + */ + @JsonProperty("tool_resources") + fun toolResources(): Optional = Optional.ofNullable(toolResources) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var messages: MutableList? = null + private var metadata: JsonValue? = null + private var toolResources: ToolResources? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaThreadCreateBody: BetaThreadCreateBody) = apply { + messages = betaThreadCreateBody.messages?.toMutableList() + metadata = betaThreadCreateBody.metadata + toolResources = betaThreadCreateBody.toolResources + additionalProperties = betaThreadCreateBody.additionalProperties.toMutableMap() + } + + /** + * A list of [messages](https://platform.openai.com/docs/api-reference/messages) to + * start the thread with. + */ + fun messages(messages: List) = apply { + this.messages = messages.toMutableList() + } + + /** + * A list of [messages](https://platform.openai.com/docs/api-reference/messages) to + * start the thread with. + */ + fun addMessage(message: Message) = apply { + messages = (messages ?: mutableListOf()).apply { add(message) } + } + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format. Keys can be a + * maximum of 64 characters long and values can be a maximum of 512 characters long. + */ + fun metadata(metadata: JsonValue) = apply { this.metadata = metadata } + + /** + * A set of resources that are made available to the assistant's tools in this thread. + * The resources are specific to the type of tool. For example, the `code_interpreter` + * tool requires a list of file IDs, while the `file_search` tool requires a list of + * vector store IDs. + */ + fun toolResources(toolResources: ToolResources) = apply { + this.toolResources = toolResources + } + + 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) + } + + fun build(): BetaThreadCreateBody = + BetaThreadCreateBody( + messages?.toImmutable(), + metadata, + toolResources, + additionalProperties.toImmutable(), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaThreadCreateBody && messages == other.messages && metadata == other.metadata && toolResources == other.toolResources && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(messages, metadata, toolResources, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaThreadCreateBody{messages=$messages, metadata=$metadata, toolResources=$toolResources, additionalProperties=$additionalProperties}" + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + @NoAutoDetect + class Builder { + + private var body: BetaThreadCreateBody.Builder = BetaThreadCreateBody.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(betaThreadCreateParams: BetaThreadCreateParams) = apply { + body = betaThreadCreateParams.body.toBuilder() + additionalHeaders = betaThreadCreateParams.additionalHeaders.toBuilder() + additionalQueryParams = betaThreadCreateParams.additionalQueryParams.toBuilder() + } + + /** + * A list of [messages](https://platform.openai.com/docs/api-reference/messages) to start + * the thread with. + */ + fun messages(messages: List) = apply { body.messages(messages) } + + /** + * A list of [messages](https://platform.openai.com/docs/api-reference/messages) to start + * the thread with. + */ + fun addMessage(message: Message) = apply { body.addMessage(message) } + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format. Keys can be a + * maximum of 64 characters long and values can be a maximum of 512 characters long. + */ + fun metadata(metadata: JsonValue) = apply { body.metadata(metadata) } + + /** + * A set of resources that are made available to the assistant's tools in this thread. The + * resources are specific to the type of tool. For example, the `code_interpreter` tool + * requires a list of file IDs, while the `file_search` tool requires a list of vector store + * IDs. + */ + fun toolResources(toolResources: ToolResources) = apply { + body.toolResources(toolResources) + } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } + + fun build(): BetaThreadCreateParams = + BetaThreadCreateParams( + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + @NoAutoDetect + class Message + @JsonCreator + private constructor( + @JsonProperty("role") private val role: Role, + @JsonProperty("content") private val content: Content, + @JsonProperty("attachments") private val attachments: List?, + @JsonProperty("metadata") private val metadata: JsonValue?, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** + * The role of the entity that is creating the message. Allowed values include: + * - `user`: Indicates the message is sent by an actual user and should be used in most + * cases to represent user-generated messages. + * - `assistant`: Indicates the message is generated by the assistant. Use this value to + * insert messages from the assistant into the conversation. + */ + @JsonProperty("role") fun role(): Role = role + + /** The text contents of the message. */ + @JsonProperty("content") fun content(): Content = content + + /** A list of files attached to the message, and the tools they should be added to. */ + @JsonProperty("attachments") + fun attachments(): Optional> = Optional.ofNullable(attachments) + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format. Keys can be a + * maximum of 64 characters long and values can be a maximum of 512 characters long. + */ + @JsonProperty("metadata") + fun metadata(): Optional = Optional.ofNullable(metadata) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var role: Role? = null + private var content: Content? = null + private var attachments: MutableList? = null + private var metadata: JsonValue? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(message: Message) = apply { + role = message.role + content = message.content + attachments = message.attachments?.toMutableList() + metadata = message.metadata + additionalProperties = message.additionalProperties.toMutableMap() + } + + /** + * The role of the entity that is creating the message. Allowed values include: + * - `user`: Indicates the message is sent by an actual user and should be used in most + * cases to represent user-generated messages. + * - `assistant`: Indicates the message is generated by the assistant. Use this value to + * insert messages from the assistant into the conversation. + */ + fun role(role: Role) = apply { this.role = role } + + /** The text contents of the message. */ + fun content(content: Content) = apply { this.content = content } + + /** The text contents of the message. */ + fun content(textContent: String) = apply { + this.content = Content.ofTextContent(textContent) + } + + /** + * An array of content parts with a defined type, each can be of type `text` or images + * can be passed with `image_url` or `image_file`. Image types are only supported on + * [Vision-compatible models](https://platform.openai.com/docs/models). + */ + fun contentOfArrayOfContentParts(arrayOfContentParts: List) = + apply { + this.content = Content.ofArrayOfContentParts(arrayOfContentParts) + } + + /** A list of files attached to the message, and the tools they should be added to. */ + fun attachments(attachments: List) = apply { + this.attachments = attachments.toMutableList() + } + + /** A list of files attached to the message, and the tools they should be added to. */ + fun addAttachment(attachment: Attachment) = apply { + attachments = (attachments ?: mutableListOf()).apply { add(attachment) } + } + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format. Keys can be a + * maximum of 64 characters long and values can be a maximum of 512 characters long. + */ + fun metadata(metadata: JsonValue) = apply { this.metadata = metadata } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + fun build(): Message = + Message( + checkNotNull(role) { "`role` is required but was not set" }, + checkNotNull(content) { "`content` is required but was not set" }, + attachments?.toImmutable(), + metadata, + additionalProperties.toImmutable(), + ) + } + + /** The text contents of the message. */ + @JsonDeserialize(using = Content.Deserializer::class) + @JsonSerialize(using = Content.Serializer::class) + class Content + private constructor( + private val textContent: String? = null, + private val arrayOfContentParts: List? = null, + private val _json: JsonValue? = null, + ) { + + /** The text contents of the message. */ + fun textContent(): Optional = Optional.ofNullable(textContent) + /** + * An array of content parts with a defined type, each can be of type `text` or images + * can be passed with `image_url` or `image_file`. Image types are only supported on + * [Vision-compatible models](https://platform.openai.com/docs/models). + */ + fun arrayOfContentParts(): Optional> = + Optional.ofNullable(arrayOfContentParts) + + fun isTextContent(): Boolean = textContent != null + + fun isArrayOfContentParts(): Boolean = arrayOfContentParts != null + + /** The text contents of the message. */ + fun asTextContent(): String = textContent.getOrThrow("textContent") + /** + * An array of content parts with a defined type, each can be of type `text` or images + * can be passed with `image_url` or `image_file`. Image types are only supported on + * [Vision-compatible models](https://platform.openai.com/docs/models). + */ + fun asArrayOfContentParts(): List = + arrayOfContentParts.getOrThrow("arrayOfContentParts") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + textContent != null -> visitor.visitTextContent(textContent) + arrayOfContentParts != null -> + visitor.visitArrayOfContentParts(arrayOfContentParts) + else -> visitor.unknown(_json) + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Content && textContent == other.textContent && arrayOfContentParts == other.arrayOfContentParts /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(textContent, arrayOfContentParts) /* spotless:on */ + + override fun toString(): String = + when { + textContent != null -> "Content{textContent=$textContent}" + arrayOfContentParts != null -> + "Content{arrayOfContentParts=$arrayOfContentParts}" + _json != null -> "Content{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Content") + } + + companion object { + + /** The text contents of the message. */ + @JvmStatic + fun ofTextContent(textContent: String) = Content(textContent = textContent) + + /** + * An array of content parts with a defined type, each can be of type `text` or + * images can be passed with `image_url` or `image_file`. Image types are only + * supported on [Vision-compatible models](https://platform.openai.com/docs/models). + */ + @JvmStatic + fun ofArrayOfContentParts(arrayOfContentParts: List) = + Content(arrayOfContentParts = arrayOfContentParts) + } + + interface Visitor { + + fun visitTextContent(textContent: String): T + + fun visitArrayOfContentParts(arrayOfContentParts: List): T + + fun unknown(json: JsonValue?): T { + throw OpenAIInvalidDataException("Unknown Content: $json") + } + } + + class Deserializer : BaseDeserializer(Content::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Content { + val json = JsonValue.fromJsonNode(node) + + tryDeserialize(node, jacksonTypeRef())?.let { + return Content(textContent = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef>())?.let { + return Content(arrayOfContentParts = it, _json = json) + } + + return Content(_json = json) + } + } + + class Serializer : BaseSerializer(Content::class) { + + override fun serialize( + value: Content, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.textContent != null -> generator.writeObject(value.textContent) + value.arrayOfContentParts != null -> + generator.writeObject(value.arrayOfContentParts) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Content") + } + } + } + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val USER = of("user") + + @JvmField val ASSISTANT = of("assistant") + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + USER, + ASSISTANT, + } + + enum class Value { + USER, + ASSISTANT, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + USER -> Value.USER + ASSISTANT -> Value.ASSISTANT + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + USER -> Known.USER + ASSISTANT -> Known.ASSISTANT + else -> throw OpenAIInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Role && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + @NoAutoDetect + class Attachment + @JsonCreator + private constructor( + @JsonProperty("file_id") private val fileId: String?, + @JsonProperty("tools") private val tools: List?, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** The ID of the file to attach to the message. */ + @JsonProperty("file_id") fun fileId(): Optional = Optional.ofNullable(fileId) + + /** The tools to add this file to. */ + @JsonProperty("tools") fun tools(): Optional> = Optional.ofNullable(tools) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var fileId: String? = null + private var tools: MutableList? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(attachment: Attachment) = apply { + fileId = attachment.fileId + tools = attachment.tools?.toMutableList() + additionalProperties = attachment.additionalProperties.toMutableMap() + } + + /** The ID of the file to attach to the message. */ + fun fileId(fileId: String) = apply { this.fileId = fileId } + + /** The tools to add this file to. */ + fun tools(tools: List) = apply { this.tools = tools.toMutableList() } + + /** The tools to add this file to. */ + fun addTool(tool: Tool) = apply { + tools = (tools ?: mutableListOf()).apply { add(tool) } + } + + 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) + } + + fun build(): Attachment = + Attachment( + fileId, + tools?.toImmutable(), + additionalProperties.toImmutable(), + ) + } + + @JsonDeserialize(using = Tool.Deserializer::class) + @JsonSerialize(using = Tool.Serializer::class) + class Tool + private constructor( + private val codeInterpreterTool: CodeInterpreterTool? = null, + private val fileSearch: FileSearch? = null, + private val _json: JsonValue? = null, + ) { + + fun codeInterpreterTool(): Optional = + Optional.ofNullable(codeInterpreterTool) + + fun fileSearch(): Optional = Optional.ofNullable(fileSearch) + + fun isCodeInterpreterTool(): Boolean = codeInterpreterTool != null + + fun isFileSearch(): Boolean = fileSearch != null + + fun asCodeInterpreterTool(): CodeInterpreterTool = + codeInterpreterTool.getOrThrow("codeInterpreterTool") + + fun asFileSearch(): FileSearch = fileSearch.getOrThrow("fileSearch") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + codeInterpreterTool != null -> + visitor.visitCodeInterpreterTool(codeInterpreterTool) + fileSearch != null -> visitor.visitFileSearch(fileSearch) + else -> visitor.unknown(_json) + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Tool && codeInterpreterTool == other.codeInterpreterTool && fileSearch == other.fileSearch /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(codeInterpreterTool, fileSearch) /* spotless:on */ + + override fun toString(): String = + when { + codeInterpreterTool != null -> + "Tool{codeInterpreterTool=$codeInterpreterTool}" + fileSearch != null -> "Tool{fileSearch=$fileSearch}" + _json != null -> "Tool{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Tool") + } + + companion object { + + @JvmStatic + fun ofCodeInterpreterTool(codeInterpreterTool: CodeInterpreterTool) = + Tool(codeInterpreterTool = codeInterpreterTool) + + @JvmStatic + fun ofFileSearch(fileSearch: FileSearch) = Tool(fileSearch = fileSearch) + } + + interface Visitor { + + fun visitCodeInterpreterTool(codeInterpreterTool: CodeInterpreterTool): T + + fun visitFileSearch(fileSearch: FileSearch): T + + fun unknown(json: JsonValue?): T { + throw OpenAIInvalidDataException("Unknown Tool: $json") + } + } + + class Deserializer : BaseDeserializer(Tool::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Tool { + val json = JsonValue.fromJsonNode(node) + val type = json.asObject().getOrNull()?.get("type")?.asString()?.getOrNull() + + when (type) { + "code_interpreter" -> { + tryDeserialize(node, jacksonTypeRef())?.let { + return Tool(codeInterpreterTool = it, _json = json) + } + } + "file_search" -> { + tryDeserialize(node, jacksonTypeRef())?.let { + return Tool(fileSearch = it, _json = json) + } + } + } + + return Tool(_json = json) + } + } + + class Serializer : BaseSerializer(Tool::class) { + + override fun serialize( + value: Tool, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.codeInterpreterTool != null -> + generator.writeObject(value.codeInterpreterTool) + value.fileSearch != null -> generator.writeObject(value.fileSearch) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Tool") + } + } + } + + @NoAutoDetect + class FileSearch + @JsonCreator + private constructor( + @JsonProperty("type") private val type: Type, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** The type of tool being defined: `file_search` */ + @JsonProperty("type") fun type(): Type = type + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var type: Type? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(fileSearch: FileSearch) = apply { + type = fileSearch.type + additionalProperties = fileSearch.additionalProperties.toMutableMap() + } + + /** The type of tool being defined: `file_search` */ + fun type(type: Type) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + fun build(): FileSearch = + FileSearch( + checkNotNull(type) { "`type` is required but was not set" }, + additionalProperties.toImmutable() + ) + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + companion object { + + @JvmField val FILE_SEARCH = of("file_search") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + FILE_SEARCH, + } + + enum class Value { + FILE_SEARCH, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + FILE_SEARCH -> Value.FILE_SEARCH + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + FILE_SEARCH -> Known.FILE_SEARCH + else -> throw OpenAIInvalidDataException("Unknown Type: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is FileSearch && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(type, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "FileSearch{type=$type, additionalProperties=$additionalProperties}" + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Attachment && fileId == other.fileId && tools == other.tools && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(fileId, tools, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Attachment{fileId=$fileId, tools=$tools, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Message && role == other.role && content == other.content && attachments == other.attachments && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(role, content, attachments, metadata, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Message{role=$role, content=$content, attachments=$attachments, metadata=$metadata, additionalProperties=$additionalProperties}" + } + + /** + * A set of resources that are made available to the assistant's tools in this thread. The + * resources are specific to the type of tool. For example, the `code_interpreter` tool requires + * a list of file IDs, while the `file_search` tool requires a list of vector store IDs. + */ + @NoAutoDetect + class ToolResources + @JsonCreator + private constructor( + @JsonProperty("code_interpreter") private val codeInterpreter: CodeInterpreter?, + @JsonProperty("file_search") private val fileSearch: FileSearch?, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + @JsonProperty("code_interpreter") + fun codeInterpreter(): Optional = Optional.ofNullable(codeInterpreter) + + @JsonProperty("file_search") + fun fileSearch(): Optional = Optional.ofNullable(fileSearch) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var codeInterpreter: CodeInterpreter? = null + private var fileSearch: FileSearch? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(toolResources: ToolResources) = apply { + codeInterpreter = toolResources.codeInterpreter + fileSearch = toolResources.fileSearch + additionalProperties = toolResources.additionalProperties.toMutableMap() + } + + fun codeInterpreter(codeInterpreter: CodeInterpreter) = apply { + this.codeInterpreter = codeInterpreter + } + + fun fileSearch(fileSearch: FileSearch) = apply { this.fileSearch = fileSearch } + + 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) + } + + fun build(): ToolResources = + ToolResources( + codeInterpreter, + fileSearch, + additionalProperties.toImmutable(), + ) + } + + @NoAutoDetect + class CodeInterpreter + @JsonCreator + private constructor( + @JsonProperty("file_ids") private val fileIds: List?, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** + * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made + * available to the `code_interpreter` tool. There can be a maximum of 20 files + * associated with the tool. + */ + @JsonProperty("file_ids") + fun fileIds(): Optional> = Optional.ofNullable(fileIds) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var fileIds: MutableList? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(codeInterpreter: CodeInterpreter) = apply { + fileIds = codeInterpreter.fileIds?.toMutableList() + additionalProperties = codeInterpreter.additionalProperties.toMutableMap() + } + + /** + * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made + * available to the `code_interpreter` tool. There can be a maximum of 20 files + * associated with the tool. + */ + fun fileIds(fileIds: List) = apply { + this.fileIds = fileIds.toMutableList() + } + + /** + * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made + * available to the `code_interpreter` tool. There can be a maximum of 20 files + * associated with the tool. + */ + fun addFileId(fileId: String) = apply { + fileIds = (fileIds ?: mutableListOf()).apply { add(fileId) } + } + + 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) + } + + fun build(): CodeInterpreter = + CodeInterpreter(fileIds?.toImmutable(), additionalProperties.toImmutable()) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is CodeInterpreter && fileIds == other.fileIds && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(fileIds, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CodeInterpreter{fileIds=$fileIds, additionalProperties=$additionalProperties}" + } + + @NoAutoDetect + class FileSearch + @JsonCreator + private constructor( + @JsonProperty("vector_store_ids") private val vectorStoreIds: List?, + @JsonProperty("vector_stores") private val vectorStores: List?, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** + * The + * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object) + * attached to this thread. There can be a maximum of 1 vector store attached to the + * thread. + */ + @JsonProperty("vector_store_ids") + fun vectorStoreIds(): Optional> = Optional.ofNullable(vectorStoreIds) + + /** + * A helper to create a + * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object) + * with file_ids and attach it to this thread. There can be a maximum of 1 vector store + * attached to the thread. + */ + @JsonProperty("vector_stores") + fun vectorStores(): Optional> = Optional.ofNullable(vectorStores) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var vectorStoreIds: MutableList? = null + private var vectorStores: MutableList? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(fileSearch: FileSearch) = apply { + vectorStoreIds = fileSearch.vectorStoreIds?.toMutableList() + vectorStores = fileSearch.vectorStores?.toMutableList() + additionalProperties = fileSearch.additionalProperties.toMutableMap() + } + + /** + * The + * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object) + * attached to this thread. There can be a maximum of 1 vector store attached to the + * thread. + */ + fun vectorStoreIds(vectorStoreIds: List) = apply { + this.vectorStoreIds = vectorStoreIds.toMutableList() + } + + /** + * The + * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object) + * attached to this thread. There can be a maximum of 1 vector store attached to the + * thread. + */ + fun addVectorStoreId(vectorStoreId: String) = apply { + vectorStoreIds = + (vectorStoreIds ?: mutableListOf()).apply { add(vectorStoreId) } + } + + /** + * A helper to create a + * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object) + * with file_ids and attach it to this thread. There can be a maximum of 1 vector + * store attached to the thread. + */ + fun vectorStores(vectorStores: List) = apply { + this.vectorStores = vectorStores.toMutableList() + } + + /** + * A helper to create a + * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object) + * with file_ids and attach it to this thread. There can be a maximum of 1 vector + * store attached to the thread. + */ + fun addVectorStore(vectorStore: VectorStore) = apply { + vectorStores = (vectorStores ?: mutableListOf()).apply { add(vectorStore) } + } + + 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) + } + + fun build(): FileSearch = + FileSearch( + vectorStoreIds?.toImmutable(), + vectorStores?.toImmutable(), + additionalProperties.toImmutable(), + ) + } + + @NoAutoDetect + class VectorStore + @JsonCreator + private constructor( + @JsonProperty("file_ids") private val fileIds: List?, + @JsonProperty("chunking_strategy") + private val chunkingStrategy: FileChunkingStrategyParam?, + @JsonProperty("metadata") private val metadata: JsonValue?, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** + * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs to add + * to the vector store. There can be a maximum of 10000 files in a vector store. + */ + @JsonProperty("file_ids") + fun fileIds(): Optional> = Optional.ofNullable(fileIds) + + /** + * The chunking strategy used to chunk the file(s). If not set, will use the `auto` + * strategy. Only applicable if `file_ids` is non-empty. + */ + @JsonProperty("chunking_strategy") + fun chunkingStrategy(): Optional = + Optional.ofNullable(chunkingStrategy) + + /** + * Set of 16 key-value pairs that can be attached to a vector store. This can be + * useful for storing additional information about the vector store in a structured + * format. Keys can be a maximum of 64 characters long and values can be a maximum + * of 512 characters long. + */ + @JsonProperty("metadata") + fun metadata(): Optional = Optional.ofNullable(metadata) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var fileIds: MutableList? = null + private var chunkingStrategy: FileChunkingStrategyParam? = null + private var metadata: JsonValue? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(vectorStore: VectorStore) = apply { + fileIds = vectorStore.fileIds?.toMutableList() + chunkingStrategy = vectorStore.chunkingStrategy + metadata = vectorStore.metadata + additionalProperties = vectorStore.additionalProperties.toMutableMap() + } + + /** + * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs to + * add to the vector store. There can be a maximum of 10000 files in a vector + * store. + */ + fun fileIds(fileIds: List) = apply { + this.fileIds = fileIds.toMutableList() + } + + /** + * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs to + * add to the vector store. There can be a maximum of 10000 files in a vector + * store. + */ + fun addFileId(fileId: String) = apply { + fileIds = (fileIds ?: mutableListOf()).apply { add(fileId) } + } + + /** + * The chunking strategy used to chunk the file(s). If not set, will use the + * `auto` strategy. Only applicable if `file_ids` is non-empty. + */ + fun chunkingStrategy(chunkingStrategy: FileChunkingStrategyParam) = apply { + this.chunkingStrategy = chunkingStrategy + } + + /** + * The default strategy. This strategy currently uses a `max_chunk_size_tokens` + * of `800` and `chunk_overlap_tokens` of `400`. + */ + fun chunkingStrategy( + autoFileChunkingStrategyParam: AutoFileChunkingStrategyParam + ) = apply { + this.chunkingStrategy = + FileChunkingStrategyParam.ofAutoFileChunkingStrategyParam( + autoFileChunkingStrategyParam + ) + } + + fun chunkingStrategy( + staticFileChunkingStrategyParam: StaticFileChunkingStrategyParam + ) = apply { + this.chunkingStrategy = + FileChunkingStrategyParam.ofStaticFileChunkingStrategyParam( + staticFileChunkingStrategyParam + ) + } + + /** + * Set of 16 key-value pairs that can be attached to a vector store. This can be + * useful for storing additional information about the vector store in a + * structured format. Keys can be a maximum of 64 characters long and values can + * be a maximum of 512 characters long. + */ + fun metadata(metadata: JsonValue) = apply { this.metadata = metadata } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + fun build(): VectorStore = + VectorStore( + fileIds?.toImmutable(), + chunkingStrategy, + metadata, + additionalProperties.toImmutable(), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is VectorStore && fileIds == other.fileIds && chunkingStrategy == other.chunkingStrategy && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(fileIds, chunkingStrategy, metadata, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "VectorStore{fileIds=$fileIds, chunkingStrategy=$chunkingStrategy, metadata=$metadata, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is FileSearch && vectorStoreIds == other.vectorStoreIds && vectorStores == other.vectorStores && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(vectorStoreIds, vectorStores, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "FileSearch{vectorStoreIds=$vectorStoreIds, vectorStores=$vectorStores, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ToolResources && codeInterpreter == other.codeInterpreter && fileSearch == other.fileSearch && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(codeInterpreter, fileSearch, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ToolResources{codeInterpreter=$codeInterpreter, fileSearch=$fileSearch, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaThreadCreateParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "BetaThreadCreateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadDeleteParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadDeleteParams.kt new file mode 100644 index 00000000..fc34f6f5 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadDeleteParams.kt @@ -0,0 +1,211 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models + +import com.openai.core.JsonValue +import com.openai.core.NoAutoDetect +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.core.toImmutable +import java.util.Objects +import java.util.Optional + +class BetaThreadDeleteParams +constructor( + private val threadId: String, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, + private val additionalBodyProperties: Map, +) { + + fun threadId(): String = threadId + + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun _additionalBodyProperties(): Map = additionalBodyProperties + + @JvmSynthetic + internal fun getBody(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + + @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams + + fun getPathParam(index: Int): String { + return when (index) { + 0 -> threadId + else -> "" + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + @NoAutoDetect + class Builder { + + private var threadId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + private var additionalBodyProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaThreadDeleteParams: BetaThreadDeleteParams) = apply { + threadId = betaThreadDeleteParams.threadId + additionalHeaders = betaThreadDeleteParams.additionalHeaders.toBuilder() + additionalQueryParams = betaThreadDeleteParams.additionalQueryParams.toBuilder() + additionalBodyProperties = + betaThreadDeleteParams.additionalBodyProperties.toMutableMap() + } + + fun threadId(threadId: String) = apply { this.threadId = threadId } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + this.additionalBodyProperties.clear() + putAllAdditionalBodyProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + additionalBodyProperties.put(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + this.additionalBodyProperties.putAll(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { + additionalBodyProperties.remove(key) + } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalBodyProperty) + } + + fun build(): BetaThreadDeleteParams = + BetaThreadDeleteParams( + checkNotNull(threadId) { "`threadId` is required but was not set" }, + additionalHeaders.build(), + additionalQueryParams.build(), + additionalBodyProperties.toImmutable(), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaThreadDeleteParams && threadId == other.threadId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(threadId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ + + override fun toString() = + "BetaThreadDeleteParams{threadId=$threadId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadMessageCreateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadMessageCreateParams.kt new file mode 100644 index 00000000..358eeb2a --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadMessageCreateParams.kt @@ -0,0 +1,966 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.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.fasterxml.jackson.core.JsonGenerator +import com.fasterxml.jackson.core.ObjectCodec +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.SerializerProvider +import com.fasterxml.jackson.databind.annotation.JsonDeserialize +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.BaseDeserializer +import com.openai.core.BaseSerializer +import com.openai.core.Enum +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonValue +import com.openai.core.NoAutoDetect +import com.openai.core.getOrThrow +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.core.immutableEmptyMap +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +class BetaThreadMessageCreateParams +constructor( + private val threadId: String, + private val body: BetaThreadMessageCreateBody, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) { + + fun threadId(): String = threadId + + /** The text contents of the message. */ + fun content(): Content = body.content() + + /** + * The role of the entity that is creating the message. Allowed values include: + * - `user`: Indicates the message is sent by an actual user and should be used in most cases to + * represent user-generated messages. + * - `assistant`: Indicates the message is generated by the assistant. Use this value to insert + * messages from the assistant into the conversation. + */ + fun role(): Role = body.role() + + /** A list of files attached to the message, and the tools they should be added to. */ + fun attachments(): Optional> = body.attachments() + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for storing + * additional information about the object in a structured format. Keys can be a maximum of 64 + * characters long and values can be a maximum of 512 characters long. + */ + fun metadata(): Optional = body.metadata() + + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun _additionalBodyProperties(): Map = body._additionalProperties() + + @JvmSynthetic internal fun getBody(): BetaThreadMessageCreateBody = body + + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + + @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams + + fun getPathParam(index: Int): String { + return when (index) { + 0 -> threadId + else -> "" + } + } + + @NoAutoDetect + class BetaThreadMessageCreateBody + @JsonCreator + internal constructor( + @JsonProperty("content") private val content: Content, + @JsonProperty("role") private val role: Role, + @JsonProperty("attachments") private val attachments: List?, + @JsonProperty("metadata") private val metadata: JsonValue?, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** The text contents of the message. */ + @JsonProperty("content") fun content(): Content = content + + /** + * The role of the entity that is creating the message. Allowed values include: + * - `user`: Indicates the message is sent by an actual user and should be used in most + * cases to represent user-generated messages. + * - `assistant`: Indicates the message is generated by the assistant. Use this value to + * insert messages from the assistant into the conversation. + */ + @JsonProperty("role") fun role(): Role = role + + /** A list of files attached to the message, and the tools they should be added to. */ + @JsonProperty("attachments") + fun attachments(): Optional> = Optional.ofNullable(attachments) + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format. Keys can be a + * maximum of 64 characters long and values can be a maximum of 512 characters long. + */ + @JsonProperty("metadata") + fun metadata(): Optional = Optional.ofNullable(metadata) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var content: Content? = null + private var role: Role? = null + private var attachments: MutableList? = null + private var metadata: JsonValue? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaThreadMessageCreateBody: BetaThreadMessageCreateBody) = apply { + content = betaThreadMessageCreateBody.content + role = betaThreadMessageCreateBody.role + attachments = betaThreadMessageCreateBody.attachments?.toMutableList() + metadata = betaThreadMessageCreateBody.metadata + additionalProperties = + betaThreadMessageCreateBody.additionalProperties.toMutableMap() + } + + /** The text contents of the message. */ + fun content(content: Content) = apply { this.content = content } + + /** The text contents of the message. */ + fun content(textContent: String) = apply { + this.content = Content.ofTextContent(textContent) + } + + /** + * An array of content parts with a defined type, each can be of type `text` or images + * can be passed with `image_url` or `image_file`. Image types are only supported on + * [Vision-compatible models](https://platform.openai.com/docs/models). + */ + fun contentOfArrayOfContentParts(arrayOfContentParts: List) = + apply { + this.content = Content.ofArrayOfContentParts(arrayOfContentParts) + } + + /** + * The role of the entity that is creating the message. Allowed values include: + * - `user`: Indicates the message is sent by an actual user and should be used in most + * cases to represent user-generated messages. + * - `assistant`: Indicates the message is generated by the assistant. Use this value to + * insert messages from the assistant into the conversation. + */ + fun role(role: Role) = apply { this.role = role } + + /** A list of files attached to the message, and the tools they should be added to. */ + fun attachments(attachments: List) = apply { + this.attachments = attachments.toMutableList() + } + + /** A list of files attached to the message, and the tools they should be added to. */ + fun addAttachment(attachment: Attachment) = apply { + attachments = (attachments ?: mutableListOf()).apply { add(attachment) } + } + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format. Keys can be a + * maximum of 64 characters long and values can be a maximum of 512 characters long. + */ + fun metadata(metadata: JsonValue) = apply { this.metadata = metadata } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + fun build(): BetaThreadMessageCreateBody = + BetaThreadMessageCreateBody( + checkNotNull(content) { "`content` is required but was not set" }, + checkNotNull(role) { "`role` is required but was not set" }, + attachments?.toImmutable(), + metadata, + additionalProperties.toImmutable(), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaThreadMessageCreateBody && content == other.content && role == other.role && attachments == other.attachments && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(content, role, attachments, metadata, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaThreadMessageCreateBody{content=$content, role=$role, attachments=$attachments, metadata=$metadata, additionalProperties=$additionalProperties}" + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + @NoAutoDetect + class Builder { + + private var threadId: String? = null + private var body: BetaThreadMessageCreateBody.Builder = + BetaThreadMessageCreateBody.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(betaThreadMessageCreateParams: BetaThreadMessageCreateParams) = apply { + threadId = betaThreadMessageCreateParams.threadId + body = betaThreadMessageCreateParams.body.toBuilder() + additionalHeaders = betaThreadMessageCreateParams.additionalHeaders.toBuilder() + additionalQueryParams = betaThreadMessageCreateParams.additionalQueryParams.toBuilder() + } + + fun threadId(threadId: String) = apply { this.threadId = threadId } + + /** The text contents of the message. */ + fun content(content: Content) = apply { body.content(content) } + + /** The text contents of the message. */ + fun content(textContent: String) = apply { body.content(textContent) } + + /** + * An array of content parts with a defined type, each can be of type `text` or images can + * be passed with `image_url` or `image_file`. Image types are only supported on + * [Vision-compatible models](https://platform.openai.com/docs/models). + */ + fun contentOfArrayOfContentParts(arrayOfContentParts: List) = + apply { + body.contentOfArrayOfContentParts(arrayOfContentParts) + } + + /** + * The role of the entity that is creating the message. Allowed values include: + * - `user`: Indicates the message is sent by an actual user and should be used in most + * cases to represent user-generated messages. + * - `assistant`: Indicates the message is generated by the assistant. Use this value to + * insert messages from the assistant into the conversation. + */ + fun role(role: Role) = apply { body.role(role) } + + /** A list of files attached to the message, and the tools they should be added to. */ + fun attachments(attachments: List) = apply { body.attachments(attachments) } + + /** A list of files attached to the message, and the tools they should be added to. */ + fun addAttachment(attachment: Attachment) = apply { body.addAttachment(attachment) } + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format. Keys can be a + * maximum of 64 characters long and values can be a maximum of 512 characters long. + */ + fun metadata(metadata: JsonValue) = apply { body.metadata(metadata) } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } + + fun build(): BetaThreadMessageCreateParams = + BetaThreadMessageCreateParams( + checkNotNull(threadId) { "`threadId` is required but was not set" }, + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + /** The text contents of the message. */ + @JsonDeserialize(using = Content.Deserializer::class) + @JsonSerialize(using = Content.Serializer::class) + class Content + private constructor( + private val textContent: String? = null, + private val arrayOfContentParts: List? = null, + private val _json: JsonValue? = null, + ) { + + /** The text contents of the message. */ + fun textContent(): Optional = Optional.ofNullable(textContent) + /** + * An array of content parts with a defined type, each can be of type `text` or images can + * be passed with `image_url` or `image_file`. Image types are only supported on + * [Vision-compatible models](https://platform.openai.com/docs/models). + */ + fun arrayOfContentParts(): Optional> = + Optional.ofNullable(arrayOfContentParts) + + fun isTextContent(): Boolean = textContent != null + + fun isArrayOfContentParts(): Boolean = arrayOfContentParts != null + + /** The text contents of the message. */ + fun asTextContent(): String = textContent.getOrThrow("textContent") + /** + * An array of content parts with a defined type, each can be of type `text` or images can + * be passed with `image_url` or `image_file`. Image types are only supported on + * [Vision-compatible models](https://platform.openai.com/docs/models). + */ + fun asArrayOfContentParts(): List = + arrayOfContentParts.getOrThrow("arrayOfContentParts") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + textContent != null -> visitor.visitTextContent(textContent) + arrayOfContentParts != null -> visitor.visitArrayOfContentParts(arrayOfContentParts) + else -> visitor.unknown(_json) + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Content && textContent == other.textContent && arrayOfContentParts == other.arrayOfContentParts /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(textContent, arrayOfContentParts) /* spotless:on */ + + override fun toString(): String = + when { + textContent != null -> "Content{textContent=$textContent}" + arrayOfContentParts != null -> "Content{arrayOfContentParts=$arrayOfContentParts}" + _json != null -> "Content{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Content") + } + + companion object { + + /** The text contents of the message. */ + @JvmStatic fun ofTextContent(textContent: String) = Content(textContent = textContent) + + /** + * An array of content parts with a defined type, each can be of type `text` or images + * can be passed with `image_url` or `image_file`. Image types are only supported on + * [Vision-compatible models](https://platform.openai.com/docs/models). + */ + @JvmStatic + fun ofArrayOfContentParts(arrayOfContentParts: List) = + Content(arrayOfContentParts = arrayOfContentParts) + } + + interface Visitor { + + fun visitTextContent(textContent: String): T + + fun visitArrayOfContentParts(arrayOfContentParts: List): T + + fun unknown(json: JsonValue?): T { + throw OpenAIInvalidDataException("Unknown Content: $json") + } + } + + class Deserializer : BaseDeserializer(Content::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Content { + val json = JsonValue.fromJsonNode(node) + + tryDeserialize(node, jacksonTypeRef())?.let { + return Content(textContent = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef>())?.let { + return Content(arrayOfContentParts = it, _json = json) + } + + return Content(_json = json) + } + } + + class Serializer : BaseSerializer(Content::class) { + + override fun serialize( + value: Content, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.textContent != null -> generator.writeObject(value.textContent) + value.arrayOfContentParts != null -> + generator.writeObject(value.arrayOfContentParts) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Content") + } + } + } + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val USER = of("user") + + @JvmField val ASSISTANT = of("assistant") + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + USER, + ASSISTANT, + } + + enum class Value { + USER, + ASSISTANT, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + USER -> Value.USER + ASSISTANT -> Value.ASSISTANT + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + USER -> Known.USER + ASSISTANT -> Known.ASSISTANT + else -> throw OpenAIInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Role && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + @NoAutoDetect + class Attachment + @JsonCreator + private constructor( + @JsonProperty("file_id") private val fileId: String?, + @JsonProperty("tools") private val tools: List?, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** The ID of the file to attach to the message. */ + @JsonProperty("file_id") fun fileId(): Optional = Optional.ofNullable(fileId) + + /** The tools to add this file to. */ + @JsonProperty("tools") fun tools(): Optional> = Optional.ofNullable(tools) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var fileId: String? = null + private var tools: MutableList? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(attachment: Attachment) = apply { + fileId = attachment.fileId + tools = attachment.tools?.toMutableList() + additionalProperties = attachment.additionalProperties.toMutableMap() + } + + /** The ID of the file to attach to the message. */ + fun fileId(fileId: String) = apply { this.fileId = fileId } + + /** The tools to add this file to. */ + fun tools(tools: List) = apply { this.tools = tools.toMutableList() } + + /** The tools to add this file to. */ + fun addTool(tool: Tool) = apply { + tools = (tools ?: mutableListOf()).apply { add(tool) } + } + + 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) + } + + fun build(): Attachment = + Attachment( + fileId, + tools?.toImmutable(), + additionalProperties.toImmutable(), + ) + } + + @JsonDeserialize(using = Tool.Deserializer::class) + @JsonSerialize(using = Tool.Serializer::class) + class Tool + private constructor( + private val codeInterpreterTool: CodeInterpreterTool? = null, + private val fileSearch: FileSearch? = null, + private val _json: JsonValue? = null, + ) { + + fun codeInterpreterTool(): Optional = + Optional.ofNullable(codeInterpreterTool) + + fun fileSearch(): Optional = Optional.ofNullable(fileSearch) + + fun isCodeInterpreterTool(): Boolean = codeInterpreterTool != null + + fun isFileSearch(): Boolean = fileSearch != null + + fun asCodeInterpreterTool(): CodeInterpreterTool = + codeInterpreterTool.getOrThrow("codeInterpreterTool") + + fun asFileSearch(): FileSearch = fileSearch.getOrThrow("fileSearch") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + codeInterpreterTool != null -> + visitor.visitCodeInterpreterTool(codeInterpreterTool) + fileSearch != null -> visitor.visitFileSearch(fileSearch) + else -> visitor.unknown(_json) + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Tool && codeInterpreterTool == other.codeInterpreterTool && fileSearch == other.fileSearch /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(codeInterpreterTool, fileSearch) /* spotless:on */ + + override fun toString(): String = + when { + codeInterpreterTool != null -> "Tool{codeInterpreterTool=$codeInterpreterTool}" + fileSearch != null -> "Tool{fileSearch=$fileSearch}" + _json != null -> "Tool{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Tool") + } + + companion object { + + @JvmStatic + fun ofCodeInterpreterTool(codeInterpreterTool: CodeInterpreterTool) = + Tool(codeInterpreterTool = codeInterpreterTool) + + @JvmStatic fun ofFileSearch(fileSearch: FileSearch) = Tool(fileSearch = fileSearch) + } + + interface Visitor { + + fun visitCodeInterpreterTool(codeInterpreterTool: CodeInterpreterTool): T + + fun visitFileSearch(fileSearch: FileSearch): T + + fun unknown(json: JsonValue?): T { + throw OpenAIInvalidDataException("Unknown Tool: $json") + } + } + + class Deserializer : BaseDeserializer(Tool::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Tool { + val json = JsonValue.fromJsonNode(node) + val type = json.asObject().getOrNull()?.get("type")?.asString()?.getOrNull() + + when (type) { + "code_interpreter" -> { + tryDeserialize(node, jacksonTypeRef())?.let { + return Tool(codeInterpreterTool = it, _json = json) + } + } + "file_search" -> { + tryDeserialize(node, jacksonTypeRef())?.let { + return Tool(fileSearch = it, _json = json) + } + } + } + + return Tool(_json = json) + } + } + + class Serializer : BaseSerializer(Tool::class) { + + override fun serialize( + value: Tool, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.codeInterpreterTool != null -> + generator.writeObject(value.codeInterpreterTool) + value.fileSearch != null -> generator.writeObject(value.fileSearch) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Tool") + } + } + } + + @NoAutoDetect + class FileSearch + @JsonCreator + private constructor( + @JsonProperty("type") private val type: Type, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** The type of tool being defined: `file_search` */ + @JsonProperty("type") fun type(): Type = type + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var type: Type? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(fileSearch: FileSearch) = apply { + type = fileSearch.type + additionalProperties = fileSearch.additionalProperties.toMutableMap() + } + + /** The type of tool being defined: `file_search` */ + fun type(type: Type) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + fun build(): FileSearch = + FileSearch( + checkNotNull(type) { "`type` is required but was not set" }, + additionalProperties.toImmutable() + ) + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + companion object { + + @JvmField val FILE_SEARCH = of("file_search") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + FILE_SEARCH, + } + + enum class Value { + FILE_SEARCH, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + FILE_SEARCH -> Value.FILE_SEARCH + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + FILE_SEARCH -> Known.FILE_SEARCH + else -> throw OpenAIInvalidDataException("Unknown Type: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is FileSearch && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(type, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "FileSearch{type=$type, additionalProperties=$additionalProperties}" + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Attachment && fileId == other.fileId && tools == other.tools && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(fileId, tools, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Attachment{fileId=$fileId, tools=$tools, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaThreadMessageCreateParams && threadId == other.threadId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(threadId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "BetaThreadMessageCreateParams{threadId=$threadId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadMessageDeleteParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadMessageDeleteParams.kt new file mode 100644 index 00000000..080ab40c --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadMessageDeleteParams.kt @@ -0,0 +1,220 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models + +import com.openai.core.JsonValue +import com.openai.core.NoAutoDetect +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.core.toImmutable +import java.util.Objects +import java.util.Optional + +class BetaThreadMessageDeleteParams +constructor( + private val threadId: String, + private val messageId: String, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, + private val additionalBodyProperties: Map, +) { + + fun threadId(): String = threadId + + fun messageId(): String = messageId + + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun _additionalBodyProperties(): Map = additionalBodyProperties + + @JvmSynthetic + internal fun getBody(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + + @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams + + fun getPathParam(index: Int): String { + return when (index) { + 0 -> threadId + 1 -> messageId + else -> "" + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + @NoAutoDetect + class Builder { + + private var threadId: String? = null + private var messageId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + private var additionalBodyProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaThreadMessageDeleteParams: BetaThreadMessageDeleteParams) = apply { + threadId = betaThreadMessageDeleteParams.threadId + messageId = betaThreadMessageDeleteParams.messageId + additionalHeaders = betaThreadMessageDeleteParams.additionalHeaders.toBuilder() + additionalQueryParams = betaThreadMessageDeleteParams.additionalQueryParams.toBuilder() + additionalBodyProperties = + betaThreadMessageDeleteParams.additionalBodyProperties.toMutableMap() + } + + fun threadId(threadId: String) = apply { this.threadId = threadId } + + fun messageId(messageId: String) = apply { this.messageId = messageId } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + this.additionalBodyProperties.clear() + putAllAdditionalBodyProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + additionalBodyProperties.put(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + this.additionalBodyProperties.putAll(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { + additionalBodyProperties.remove(key) + } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalBodyProperty) + } + + fun build(): BetaThreadMessageDeleteParams = + BetaThreadMessageDeleteParams( + checkNotNull(threadId) { "`threadId` is required but was not set" }, + checkNotNull(messageId) { "`messageId` is required but was not set" }, + additionalHeaders.build(), + additionalQueryParams.build(), + additionalBodyProperties.toImmutable(), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaThreadMessageDeleteParams && threadId == other.threadId && messageId == other.messageId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(threadId, messageId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ + + override fun toString() = + "BetaThreadMessageDeleteParams{threadId=$threadId, messageId=$messageId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadMessageListPage.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadMessageListPage.kt new file mode 100644 index 00000000..3814d9e6 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadMessageListPage.kt @@ -0,0 +1,171 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.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.NoAutoDetect +import com.openai.core.immutableEmptyMap +import com.openai.core.toImmutable +import com.openai.services.blocking.beta.threads.MessageService +import java.util.Objects +import java.util.Optional +import java.util.stream.Stream +import java.util.stream.StreamSupport + +class BetaThreadMessageListPage +private constructor( + private val messagesService: MessageService, + private val params: BetaThreadMessageListParams, + private val response: Response, +) { + + fun response(): Response = response + + fun data(): List = response().data() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaThreadMessageListPage && 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() = + "BetaThreadMessageListPage{messagesService=$messagesService, params=$params, response=$response}" + + fun hasNextPage(): Boolean { + return !data().isEmpty() + } + + fun getNextPageParams(): Optional { + if (!hasNextPage()) { + return Optional.empty() + } + + return Optional.of( + BetaThreadMessageListParams.builder().from(params).after(data().last().id()).build() + ) + } + + fun getNextPage(): Optional { + return getNextPageParams().map { messagesService.list(it) } + } + + fun autoPager(): AutoPager = AutoPager(this) + + companion object { + + @JvmStatic + fun of( + messagesService: MessageService, + params: BetaThreadMessageListParams, + response: Response + ) = + BetaThreadMessageListPage( + messagesService, + params, + response, + ) + } + + @NoAutoDetect + class Response + @JsonCreator + constructor( + @JsonProperty("data") private val data: JsonField> = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + private var validated: Boolean = false + + fun data(): List = data.getNullable("data") ?: listOf() + + @JsonProperty("data") + fun _data(): Optional>> = Optional.ofNullable(data) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Response = apply { + if (!validated) { + data().map { it.validate() } + validated = true + } + } + + 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 && additionalProperties == other.additionalProperties /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, additionalProperties) /* spotless:on */ + + override fun toString() = "Response{data=$data, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var data: JsonField> = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(page: Response) = apply { + this.data = page.data + this.additionalProperties.putAll(page.additionalProperties) + } + + fun data(data: List) = data(JsonField.of(data)) + + fun data(data: JsonField>) = apply { this.data = data } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun build() = Response(data, additionalProperties.toImmutable()) + } + } + + class AutoPager + constructor( + private val firstPage: BetaThreadMessageListPage, + ) : Iterable { + + override fun iterator(): Iterator = iterator { + var page = firstPage + var index = 0 + while (true) { + while (index < page.data().size) { + yield(page.data()[index++]) + } + page = page.getNextPage().orElse(null) ?: break + index = 0 + } + } + + fun stream(): Stream { + return StreamSupport.stream(spliterator(), false) + } + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadMessageListPageAsync.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadMessageListPageAsync.kt new file mode 100644 index 00000000..a65a4c3e --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadMessageListPageAsync.kt @@ -0,0 +1,181 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.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.NoAutoDetect +import com.openai.core.immutableEmptyMap +import com.openai.core.toImmutable +import com.openai.services.async.beta.threads.MessageServiceAsync +import java.util.Objects +import java.util.Optional +import java.util.concurrent.CompletableFuture +import java.util.concurrent.Executor +import java.util.function.Predicate + +class BetaThreadMessageListPageAsync +private constructor( + private val messagesService: MessageServiceAsync, + private val params: BetaThreadMessageListParams, + private val response: Response, +) { + + fun response(): Response = response + + fun data(): List = response().data() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaThreadMessageListPageAsync && 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() = + "BetaThreadMessageListPageAsync{messagesService=$messagesService, params=$params, response=$response}" + + fun hasNextPage(): Boolean { + return !data().isEmpty() + } + + fun getNextPageParams(): Optional { + if (!hasNextPage()) { + return Optional.empty() + } + + return Optional.of( + BetaThreadMessageListParams.builder().from(params).after(data().last().id()).build() + ) + } + + fun getNextPage(): CompletableFuture> { + return getNextPageParams() + .map { messagesService.list(it).thenApply { Optional.of(it) } } + .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + } + + fun autoPager(): AutoPager = AutoPager(this) + + companion object { + + @JvmStatic + fun of( + messagesService: MessageServiceAsync, + params: BetaThreadMessageListParams, + response: Response + ) = + BetaThreadMessageListPageAsync( + messagesService, + params, + response, + ) + } + + @NoAutoDetect + class Response + @JsonCreator + constructor( + @JsonProperty("data") private val data: JsonField> = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + private var validated: Boolean = false + + fun data(): List = data.getNullable("data") ?: listOf() + + @JsonProperty("data") + fun _data(): Optional>> = Optional.ofNullable(data) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Response = apply { + if (!validated) { + data().map { it.validate() } + validated = true + } + } + + 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 && additionalProperties == other.additionalProperties /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, additionalProperties) /* spotless:on */ + + override fun toString() = "Response{data=$data, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var data: JsonField> = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(page: Response) = apply { + this.data = page.data + this.additionalProperties.putAll(page.additionalProperties) + } + + fun data(data: List) = data(JsonField.of(data)) + + fun data(data: JsonField>) = apply { this.data = data } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun build() = Response(data, additionalProperties.toImmutable()) + } + } + + class AutoPager + constructor( + private val firstPage: BetaThreadMessageListPageAsync, + ) { + + fun forEach(action: Predicate, executor: Executor): CompletableFuture { + fun CompletableFuture>.forEach( + action: (Message) -> Boolean, + executor: Executor + ): CompletableFuture = + thenComposeAsync( + { page -> + page + .filter { it.data().all(action) } + .map { it.getNextPage().forEach(action, executor) } + .orElseGet { CompletableFuture.completedFuture(null) } + }, + executor + ) + return CompletableFuture.completedFuture(Optional.of(firstPage)) + .forEach(action::test, executor) + } + + fun toList(executor: Executor): CompletableFuture> { + val values = mutableListOf() + return forEach(values::add, executor).thenApply { values } + } + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadMessageListParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadMessageListParams.kt new file mode 100644 index 00000000..941b88e4 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadMessageListParams.kt @@ -0,0 +1,327 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models + +import com.fasterxml.jackson.annotation.JsonCreator +import com.openai.core.Enum +import com.openai.core.JsonField +import com.openai.core.NoAutoDetect +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.errors.OpenAIInvalidDataException +import java.util.Objects +import java.util.Optional + +class BetaThreadMessageListParams +constructor( + private val threadId: String, + private val after: String?, + private val before: String?, + private val limit: Long?, + private val order: Order?, + private val runId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) { + + fun threadId(): String = threadId + + /** + * A cursor for use in pagination. `after` is an object ID that defines your place in the list. + * For instance, if you make a list request and receive 100 objects, ending with obj_foo, your + * subsequent call can include after=obj_foo in order to fetch the next page of the list. + */ + fun after(): Optional = Optional.ofNullable(after) + + /** + * A cursor for use in pagination. `before` is an object ID that defines your place in the list. + * For instance, if you make a list request and receive 100 objects, starting with obj_foo, your + * subsequent call can include before=obj_foo in order to fetch the previous page of the list. + */ + fun before(): Optional = Optional.ofNullable(before) + + /** + * A limit on the number of objects to be returned. Limit can range between 1 and 100, and the + * default is 20. + */ + fun limit(): Optional = Optional.ofNullable(limit) + + /** + * Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and `desc` + * for descending order. + */ + fun order(): Optional = Optional.ofNullable(order) + + /** Filter messages by the run ID that generated them. */ + fun runId(): Optional = Optional.ofNullable(runId) + + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + + @JvmSynthetic + internal fun getQueryParams(): QueryParams { + val queryParams = QueryParams.builder() + this.after?.let { queryParams.put("after", listOf(it.toString())) } + this.before?.let { queryParams.put("before", listOf(it.toString())) } + this.limit?.let { queryParams.put("limit", listOf(it.toString())) } + this.order?.let { queryParams.put("order", listOf(it.toString())) } + this.runId?.let { queryParams.put("run_id", listOf(it.toString())) } + queryParams.putAll(additionalQueryParams) + return queryParams.build() + } + + fun getPathParam(index: Int): String { + return when (index) { + 0 -> threadId + else -> "" + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + @NoAutoDetect + class Builder { + + private var threadId: String? = null + private var after: String? = null + private var before: String? = null + private var limit: Long? = null + private var order: Order? = null + private var runId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(betaThreadMessageListParams: BetaThreadMessageListParams) = apply { + threadId = betaThreadMessageListParams.threadId + after = betaThreadMessageListParams.after + before = betaThreadMessageListParams.before + limit = betaThreadMessageListParams.limit + order = betaThreadMessageListParams.order + runId = betaThreadMessageListParams.runId + additionalHeaders = betaThreadMessageListParams.additionalHeaders.toBuilder() + additionalQueryParams = betaThreadMessageListParams.additionalQueryParams.toBuilder() + } + + fun threadId(threadId: String) = apply { this.threadId = threadId } + + /** + * A cursor for use in pagination. `after` is an object ID that defines your place in the + * list. For instance, if you make a list request and receive 100 objects, ending with + * obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page + * of the list. + */ + fun after(after: String) = apply { this.after = after } + + /** + * A cursor for use in pagination. `before` is an object ID that defines your place in the + * list. For instance, if you make a list request and receive 100 objects, starting with + * obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous + * page of the list. + */ + fun before(before: String) = apply { this.before = before } + + /** + * A limit on the number of objects to be returned. Limit can range between 1 and 100, and + * the default is 20. + */ + fun limit(limit: Long) = apply { this.limit = limit } + + /** + * Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and + * `desc` for descending order. + */ + fun order(order: Order) = apply { this.order = order } + + /** Filter messages by the run ID that generated them. */ + fun runId(runId: String) = apply { this.runId = runId } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun build(): BetaThreadMessageListParams = + BetaThreadMessageListParams( + checkNotNull(threadId) { "`threadId` is required but was not set" }, + after, + before, + limit, + order, + runId, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + class Order + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val ASC = of("asc") + + @JvmField val DESC = of("desc") + + @JvmStatic fun of(value: String) = Order(JsonField.of(value)) + } + + enum class Known { + ASC, + DESC, + } + + enum class Value { + ASC, + DESC, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + ASC -> Value.ASC + DESC -> Value.DESC + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + ASC -> Known.ASC + DESC -> Known.DESC + else -> throw OpenAIInvalidDataException("Unknown Order: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Order && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaThreadMessageListParams && threadId == other.threadId && after == other.after && before == other.before && limit == other.limit && order == other.order && runId == other.runId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(threadId, after, before, limit, order, runId, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "BetaThreadMessageListParams{threadId=$threadId, after=$after, before=$before, limit=$limit, order=$order, runId=$runId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadMessageRetrieveParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadMessageRetrieveParams.kt new file mode 100644 index 00000000..5d07ebaa --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadMessageRetrieveParams.kt @@ -0,0 +1,186 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models + +import com.openai.core.NoAutoDetect +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import java.util.Objects + +class BetaThreadMessageRetrieveParams +constructor( + private val threadId: String, + private val messageId: String, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) { + + fun threadId(): String = threadId + + fun messageId(): String = messageId + + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + + @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams + + fun getPathParam(index: Int): String { + return when (index) { + 0 -> threadId + 1 -> messageId + else -> "" + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + @NoAutoDetect + class Builder { + + private var threadId: String? = null + private var messageId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(betaThreadMessageRetrieveParams: BetaThreadMessageRetrieveParams) = + apply { + threadId = betaThreadMessageRetrieveParams.threadId + messageId = betaThreadMessageRetrieveParams.messageId + additionalHeaders = betaThreadMessageRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = + betaThreadMessageRetrieveParams.additionalQueryParams.toBuilder() + } + + fun threadId(threadId: String) = apply { this.threadId = threadId } + + fun messageId(messageId: String) = apply { this.messageId = messageId } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun build(): BetaThreadMessageRetrieveParams = + BetaThreadMessageRetrieveParams( + checkNotNull(threadId) { "`threadId` is required but was not set" }, + checkNotNull(messageId) { "`messageId` is required but was not set" }, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaThreadMessageRetrieveParams && threadId == other.threadId && messageId == other.messageId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(threadId, messageId, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "BetaThreadMessageRetrieveParams{threadId=$threadId, messageId=$messageId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadMessageUpdateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadMessageUpdateParams.kt new file mode 100644 index 00000000..d14346d1 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadMessageUpdateParams.kt @@ -0,0 +1,323 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.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.JsonValue +import com.openai.core.NoAutoDetect +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.core.immutableEmptyMap +import com.openai.core.toImmutable +import java.util.Objects +import java.util.Optional + +class BetaThreadMessageUpdateParams +constructor( + private val threadId: String, + private val messageId: String, + private val body: BetaThreadMessageUpdateBody, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) { + + fun threadId(): String = threadId + + fun messageId(): String = messageId + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for storing + * additional information about the object in a structured format. Keys can be a maximum of 64 + * characters long and values can be a maximum of 512 characters long. + */ + fun metadata(): Optional = body.metadata() + + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun _additionalBodyProperties(): Map = body._additionalProperties() + + @JvmSynthetic internal fun getBody(): BetaThreadMessageUpdateBody = body + + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + + @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams + + fun getPathParam(index: Int): String { + return when (index) { + 0 -> threadId + 1 -> messageId + else -> "" + } + } + + @NoAutoDetect + class BetaThreadMessageUpdateBody + @JsonCreator + internal constructor( + @JsonProperty("metadata") private val metadata: JsonValue?, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format. Keys can be a + * maximum of 64 characters long and values can be a maximum of 512 characters long. + */ + @JsonProperty("metadata") + fun metadata(): Optional = Optional.ofNullable(metadata) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var metadata: JsonValue? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaThreadMessageUpdateBody: BetaThreadMessageUpdateBody) = apply { + metadata = betaThreadMessageUpdateBody.metadata + additionalProperties = + betaThreadMessageUpdateBody.additionalProperties.toMutableMap() + } + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format. Keys can be a + * maximum of 64 characters long and values can be a maximum of 512 characters long. + */ + fun metadata(metadata: JsonValue) = apply { this.metadata = metadata } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + fun build(): BetaThreadMessageUpdateBody = + BetaThreadMessageUpdateBody(metadata, additionalProperties.toImmutable()) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaThreadMessageUpdateBody && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(metadata, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaThreadMessageUpdateBody{metadata=$metadata, additionalProperties=$additionalProperties}" + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + @NoAutoDetect + class Builder { + + private var threadId: String? = null + private var messageId: String? = null + private var body: BetaThreadMessageUpdateBody.Builder = + BetaThreadMessageUpdateBody.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(betaThreadMessageUpdateParams: BetaThreadMessageUpdateParams) = apply { + threadId = betaThreadMessageUpdateParams.threadId + messageId = betaThreadMessageUpdateParams.messageId + body = betaThreadMessageUpdateParams.body.toBuilder() + additionalHeaders = betaThreadMessageUpdateParams.additionalHeaders.toBuilder() + additionalQueryParams = betaThreadMessageUpdateParams.additionalQueryParams.toBuilder() + } + + fun threadId(threadId: String) = apply { this.threadId = threadId } + + fun messageId(messageId: String) = apply { this.messageId = messageId } + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format. Keys can be a + * maximum of 64 characters long and values can be a maximum of 512 characters long. + */ + fun metadata(metadata: JsonValue) = apply { body.metadata(metadata) } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } + + fun build(): BetaThreadMessageUpdateParams = + BetaThreadMessageUpdateParams( + checkNotNull(threadId) { "`threadId` is required but was not set" }, + checkNotNull(messageId) { "`messageId` is required but was not set" }, + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaThreadMessageUpdateParams && threadId == other.threadId && messageId == other.messageId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(threadId, messageId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "BetaThreadMessageUpdateParams{threadId=$threadId, messageId=$messageId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRetrieveParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRetrieveParams.kt new file mode 100644 index 00000000..f923526c --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRetrieveParams.kt @@ -0,0 +1,175 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models + +import com.openai.core.NoAutoDetect +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import java.util.Objects + +class BetaThreadRetrieveParams +constructor( + private val threadId: String, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) { + + fun threadId(): String = threadId + + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + + @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams + + fun getPathParam(index: Int): String { + return when (index) { + 0 -> threadId + else -> "" + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + @NoAutoDetect + class Builder { + + private var threadId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(betaThreadRetrieveParams: BetaThreadRetrieveParams) = apply { + threadId = betaThreadRetrieveParams.threadId + additionalHeaders = betaThreadRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = betaThreadRetrieveParams.additionalQueryParams.toBuilder() + } + + fun threadId(threadId: String) = apply { this.threadId = threadId } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun build(): BetaThreadRetrieveParams = + BetaThreadRetrieveParams( + checkNotNull(threadId) { "`threadId` is required but was not set" }, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaThreadRetrieveParams && threadId == other.threadId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(threadId, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "BetaThreadRetrieveParams{threadId=$threadId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRunCancelParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRunCancelParams.kt new file mode 100644 index 00000000..f5f11d3c --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRunCancelParams.kt @@ -0,0 +1,220 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models + +import com.openai.core.JsonValue +import com.openai.core.NoAutoDetect +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.core.toImmutable +import java.util.Objects +import java.util.Optional + +class BetaThreadRunCancelParams +constructor( + private val threadId: String, + private val runId: String, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, + private val additionalBodyProperties: Map, +) { + + fun threadId(): String = threadId + + fun runId(): String = runId + + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun _additionalBodyProperties(): Map = additionalBodyProperties + + @JvmSynthetic + internal fun getBody(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + + @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams + + fun getPathParam(index: Int): String { + return when (index) { + 0 -> threadId + 1 -> runId + else -> "" + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + @NoAutoDetect + class Builder { + + private var threadId: String? = null + private var runId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + private var additionalBodyProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaThreadRunCancelParams: BetaThreadRunCancelParams) = apply { + threadId = betaThreadRunCancelParams.threadId + runId = betaThreadRunCancelParams.runId + additionalHeaders = betaThreadRunCancelParams.additionalHeaders.toBuilder() + additionalQueryParams = betaThreadRunCancelParams.additionalQueryParams.toBuilder() + additionalBodyProperties = + betaThreadRunCancelParams.additionalBodyProperties.toMutableMap() + } + + fun threadId(threadId: String) = apply { this.threadId = threadId } + + fun runId(runId: String) = apply { this.runId = runId } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + this.additionalBodyProperties.clear() + putAllAdditionalBodyProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + additionalBodyProperties.put(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + this.additionalBodyProperties.putAll(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { + additionalBodyProperties.remove(key) + } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalBodyProperty) + } + + fun build(): BetaThreadRunCancelParams = + BetaThreadRunCancelParams( + checkNotNull(threadId) { "`threadId` is required but was not set" }, + checkNotNull(runId) { "`runId` is required but was not set" }, + additionalHeaders.build(), + additionalQueryParams.build(), + additionalBodyProperties.toImmutable(), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaThreadRunCancelParams && threadId == other.threadId && runId == other.runId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(threadId, runId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ + + override fun toString() = + "BetaThreadRunCancelParams{threadId=$threadId, runId=$runId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRunCreateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRunCreateParams.kt new file mode 100644 index 00000000..5ea21921 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRunCreateParams.kt @@ -0,0 +1,1903 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.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.fasterxml.jackson.core.JsonGenerator +import com.fasterxml.jackson.core.ObjectCodec +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.SerializerProvider +import com.fasterxml.jackson.databind.annotation.JsonDeserialize +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import com.openai.core.BaseDeserializer +import com.openai.core.BaseSerializer +import com.openai.core.Enum +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonValue +import com.openai.core.NoAutoDetect +import com.openai.core.getOrThrow +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.core.immutableEmptyMap +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +class BetaThreadRunCreateParams +constructor( + private val threadId: String, + private val include: List?, + private val body: BetaThreadRunCreateBody, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) { + + fun threadId(): String = threadId + + /** + * A list of additional fields to include in the response. Currently the only supported value is + * `step_details.tool_calls[*].file_search.results[*].content` to fetch the file search result + * content. + * + * See the + * [file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search#customizing-file-search-settings) + * for more information. + */ + fun include(): Optional> = Optional.ofNullable(include) + + /** + * The ID of the [assistant](https://platform.openai.com/docs/api-reference/assistants) to use + * to execute this run. + */ + fun assistantId(): String = body.assistantId() + + /** + * Appends additional instructions at the end of the instructions for the run. This is useful + * for modifying the behavior on a per-run basis without overriding other instructions. + */ + fun additionalInstructions(): Optional = body.additionalInstructions() + + /** Adds additional messages to the thread before creating the run. */ + fun additionalMessages(): Optional> = body.additionalMessages() + + /** + * Overrides the + * [instructions](https://platform.openai.com/docs/api-reference/assistants/createAssistant) of + * the assistant. This is useful for modifying the behavior on a per-run basis. + */ + fun instructions(): Optional = body.instructions() + + /** + * The maximum number of completion tokens that may be used over the course of the run. The run + * will make a best effort to use only the number of completion tokens specified, across + * multiple turns of the run. If the run exceeds the number of completion tokens specified, the + * run will end with status `incomplete`. See `incomplete_details` for more info. + */ + fun maxCompletionTokens(): Optional = body.maxCompletionTokens() + + /** + * The maximum number of prompt tokens that may be used over the course of the run. The run will + * make a best effort to use only the number of prompt tokens specified, across multiple turns + * of the run. If the run exceeds the number of prompt tokens specified, the run will end with + * status `incomplete`. See `incomplete_details` for more info. + */ + fun maxPromptTokens(): Optional = body.maxPromptTokens() + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for storing + * additional information about the object in a structured format. Keys can be a maximum of 64 + * characters long and values can be a maximum of 512 characters long. + */ + fun metadata(): Optional = body.metadata() + + /** + * The ID of the [Model](https://platform.openai.com/docs/api-reference/models) to be used to + * execute this run. If a value is provided here, it will override the model associated with the + * assistant. If not, the model associated with the assistant will be used. + */ + fun model(): Optional = body.model() + + /** + * Whether to enable + * [parallel function calling](https://platform.openai.com/docs/guides/function-calling#configuring-parallel-function-calling) + * during tool use. + */ + fun parallelToolCalls(): Optional = body.parallelToolCalls() + + /** + * Specifies the format that the model must output. Compatible with + * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o), [GPT-4 + * Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4), and all GPT-3.5 Turbo + * models since `gpt-3.5-turbo-1106`. + * + * Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured Outputs which + * ensures the model will match your supplied JSON schema. Learn more in the + * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs). + * + * Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the message the model + * generates is valid JSON. + * + * **Important:** when using JSON mode, you **must** also instruct the model to produce JSON + * yourself via a system or user message. Without this, the model may generate an unending + * stream of whitespace until the generation reaches the token limit, resulting in a + * long-running and seemingly "stuck" request. Also note that the message content may be + * partially cut off if `finish_reason="length"`, which indicates the generation exceeded + * `max_tokens` or the conversation exceeded the max context length. + */ + fun responseFormat(): Optional = body.responseFormat() + + /** + * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the + * output more random, while lower values like 0.2 will make it more focused and deterministic. + */ + fun temperature(): Optional = body.temperature() + + /** + * Controls which (if any) tool is called by the model. `none` means the model will not call any + * tools and instead generates a message. `auto` is the default value and means the model can + * pick between generating a message or calling one or more tools. `required` means the model + * must call one or more tools before responding to the user. Specifying a particular tool like + * `{"type": "file_search"}` or `{"type": "function", "function": {"name": "my_function"}}` + * forces the model to call that tool. + */ + fun toolChoice(): Optional = body.toolChoice() + + /** + * Override the tools the assistant can use for this run. This is useful for modifying the + * behavior on a per-run basis. + */ + fun tools(): Optional> = body.tools() + + /** + * An alternative to sampling with temperature, called nucleus sampling, where the model + * considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens + * comprising the top 10% probability mass are considered. + * + * We generally recommend altering this or temperature but not both. + */ + fun topP(): Optional = body.topP() + + /** + * Controls for how a thread will be truncated prior to the run. Use this to control the intial + * context window of the run. + */ + fun truncationStrategy(): Optional = body.truncationStrategy() + + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun _additionalBodyProperties(): Map = body._additionalProperties() + + @JvmSynthetic internal fun getBody(): BetaThreadRunCreateBody = body + + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + + @JvmSynthetic + internal fun getQueryParams(): QueryParams { + val queryParams = QueryParams.builder() + this.include?.let { queryParams.put("include[]", it.map(Any::toString)) } + queryParams.putAll(additionalQueryParams) + return queryParams.build() + } + + fun getPathParam(index: Int): String { + return when (index) { + 0 -> threadId + else -> "" + } + } + + @NoAutoDetect + class BetaThreadRunCreateBody + @JsonCreator + internal constructor( + @JsonProperty("assistant_id") private val assistantId: String, + @JsonProperty("additional_instructions") private val additionalInstructions: String?, + @JsonProperty("additional_messages") + private val additionalMessages: List?, + @JsonProperty("instructions") private val instructions: String?, + @JsonProperty("max_completion_tokens") private val maxCompletionTokens: Long?, + @JsonProperty("max_prompt_tokens") private val maxPromptTokens: Long?, + @JsonProperty("metadata") private val metadata: JsonValue?, + @JsonProperty("model") private val model: ChatModel?, + @JsonProperty("parallel_tool_calls") private val parallelToolCalls: Boolean?, + @JsonProperty("response_format") private val responseFormat: AssistantResponseFormatOption?, + @JsonProperty("temperature") private val temperature: Double?, + @JsonProperty("tool_choice") private val toolChoice: AssistantToolChoiceOption?, + @JsonProperty("tools") private val tools: List?, + @JsonProperty("top_p") private val topP: Double?, + @JsonProperty("truncation_strategy") private val truncationStrategy: TruncationStrategy?, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** + * The ID of the [assistant](https://platform.openai.com/docs/api-reference/assistants) to + * use to execute this run. + */ + @JsonProperty("assistant_id") fun assistantId(): String = assistantId + + /** + * Appends additional instructions at the end of the instructions for the run. This is + * useful for modifying the behavior on a per-run basis without overriding other + * instructions. + */ + @JsonProperty("additional_instructions") + fun additionalInstructions(): Optional = Optional.ofNullable(additionalInstructions) + + /** Adds additional messages to the thread before creating the run. */ + @JsonProperty("additional_messages") + fun additionalMessages(): Optional> = + Optional.ofNullable(additionalMessages) + + /** + * Overrides the + * [instructions](https://platform.openai.com/docs/api-reference/assistants/createAssistant) + * of the assistant. This is useful for modifying the behavior on a per-run basis. + */ + @JsonProperty("instructions") + fun instructions(): Optional = Optional.ofNullable(instructions) + + /** + * The maximum number of completion tokens that may be used over the course of the run. The + * run will make a best effort to use only the number of completion tokens specified, across + * multiple turns of the run. If the run exceeds the number of completion tokens specified, + * the run will end with status `incomplete`. See `incomplete_details` for more info. + */ + @JsonProperty("max_completion_tokens") + fun maxCompletionTokens(): Optional = Optional.ofNullable(maxCompletionTokens) + + /** + * The maximum number of prompt tokens that may be used over the course of the run. The run + * will make a best effort to use only the number of prompt tokens specified, across + * multiple turns of the run. If the run exceeds the number of prompt tokens specified, the + * run will end with status `incomplete`. See `incomplete_details` for more info. + */ + @JsonProperty("max_prompt_tokens") + fun maxPromptTokens(): Optional = Optional.ofNullable(maxPromptTokens) + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format. Keys can be a + * maximum of 64 characters long and values can be a maximum of 512 characters long. + */ + @JsonProperty("metadata") + fun metadata(): Optional = Optional.ofNullable(metadata) + + /** + * The ID of the [Model](https://platform.openai.com/docs/api-reference/models) to be used + * to execute this run. If a value is provided here, it will override the model associated + * with the assistant. If not, the model associated with the assistant will be used. + */ + @JsonProperty("model") fun model(): Optional = Optional.ofNullable(model) + + /** + * Whether to enable + * [parallel function calling](https://platform.openai.com/docs/guides/function-calling#configuring-parallel-function-calling) + * during tool use. + */ + @JsonProperty("parallel_tool_calls") + fun parallelToolCalls(): Optional = Optional.ofNullable(parallelToolCalls) + + /** + * Specifies the format that the model must output. Compatible with + * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o), [GPT-4 + * Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4), and all GPT-3.5 + * Turbo models since `gpt-3.5-turbo-1106`. + * + * Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured Outputs + * which ensures the model will match your supplied JSON schema. Learn more in the + * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs). + * + * Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the message the + * model generates is valid JSON. + * + * **Important:** when using JSON mode, you **must** also instruct the model to produce JSON + * yourself via a system or user message. Without this, the model may generate an unending + * stream of whitespace until the generation reaches the token limit, resulting in a + * long-running and seemingly "stuck" request. Also note that the message content may be + * partially cut off if `finish_reason="length"`, which indicates the generation exceeded + * `max_tokens` or the conversation exceeded the max context length. + */ + @JsonProperty("response_format") + fun responseFormat(): Optional = + Optional.ofNullable(responseFormat) + + /** + * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the + * output more random, while lower values like 0.2 will make it more focused and + * deterministic. + */ + @JsonProperty("temperature") + fun temperature(): Optional = Optional.ofNullable(temperature) + + /** + * Controls which (if any) tool is called by the model. `none` means the model will not call + * any tools and instead generates a message. `auto` is the default value and means the + * model can pick between generating a message or calling one or more tools. `required` + * means the model must call one or more tools before responding to the user. Specifying a + * particular tool like `{"type": "file_search"}` or `{"type": "function", "function": + * {"name": "my_function"}}` forces the model to call that tool. + */ + @JsonProperty("tool_choice") + fun toolChoice(): Optional = Optional.ofNullable(toolChoice) + + /** + * Override the tools the assistant can use for this run. This is useful for modifying the + * behavior on a per-run basis. + */ + @JsonProperty("tools") + fun tools(): Optional> = Optional.ofNullable(tools) + + /** + * An alternative to sampling with temperature, called nucleus sampling, where the model + * considers the results of the tokens with top_p probability mass. So 0.1 means only the + * tokens comprising the top 10% probability mass are considered. + * + * We generally recommend altering this or temperature but not both. + */ + @JsonProperty("top_p") fun topP(): Optional = Optional.ofNullable(topP) + + /** + * Controls for how a thread will be truncated prior to the run. Use this to control the + * intial context window of the run. + */ + @JsonProperty("truncation_strategy") + fun truncationStrategy(): Optional = + Optional.ofNullable(truncationStrategy) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var assistantId: String? = null + private var additionalInstructions: String? = null + private var additionalMessages: MutableList? = null + private var instructions: String? = null + private var maxCompletionTokens: Long? = null + private var maxPromptTokens: Long? = null + private var metadata: JsonValue? = null + private var model: ChatModel? = null + private var parallelToolCalls: Boolean? = null + private var responseFormat: AssistantResponseFormatOption? = null + private var temperature: Double? = null + private var toolChoice: AssistantToolChoiceOption? = null + private var tools: MutableList? = null + private var topP: Double? = null + private var truncationStrategy: TruncationStrategy? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaThreadRunCreateBody: BetaThreadRunCreateBody) = apply { + assistantId = betaThreadRunCreateBody.assistantId + additionalInstructions = betaThreadRunCreateBody.additionalInstructions + additionalMessages = betaThreadRunCreateBody.additionalMessages?.toMutableList() + instructions = betaThreadRunCreateBody.instructions + maxCompletionTokens = betaThreadRunCreateBody.maxCompletionTokens + maxPromptTokens = betaThreadRunCreateBody.maxPromptTokens + metadata = betaThreadRunCreateBody.metadata + model = betaThreadRunCreateBody.model + parallelToolCalls = betaThreadRunCreateBody.parallelToolCalls + responseFormat = betaThreadRunCreateBody.responseFormat + temperature = betaThreadRunCreateBody.temperature + toolChoice = betaThreadRunCreateBody.toolChoice + tools = betaThreadRunCreateBody.tools?.toMutableList() + topP = betaThreadRunCreateBody.topP + truncationStrategy = betaThreadRunCreateBody.truncationStrategy + additionalProperties = betaThreadRunCreateBody.additionalProperties.toMutableMap() + } + + /** + * The ID of the [assistant](https://platform.openai.com/docs/api-reference/assistants) + * to use to execute this run. + */ + fun assistantId(assistantId: String) = apply { this.assistantId = assistantId } + + /** + * Appends additional instructions at the end of the instructions for the run. This is + * useful for modifying the behavior on a per-run basis without overriding other + * instructions. + */ + fun additionalInstructions(additionalInstructions: String) = apply { + this.additionalInstructions = additionalInstructions + } + + /** Adds additional messages to the thread before creating the run. */ + fun additionalMessages(additionalMessages: List) = apply { + this.additionalMessages = additionalMessages.toMutableList() + } + + /** Adds additional messages to the thread before creating the run. */ + fun addAdditionalMessage(additionalMessage: AdditionalMessage) = apply { + additionalMessages = + (additionalMessages ?: mutableListOf()).apply { add(additionalMessage) } + } + + /** + * Overrides the + * [instructions](https://platform.openai.com/docs/api-reference/assistants/createAssistant) + * of the assistant. This is useful for modifying the behavior on a per-run basis. + */ + fun instructions(instructions: String) = apply { this.instructions = instructions } + + /** + * The maximum number of completion tokens that may be used over the course of the run. + * The run will make a best effort to use only the number of completion tokens + * specified, across multiple turns of the run. If the run exceeds the number of + * completion tokens specified, the run will end with status `incomplete`. See + * `incomplete_details` for more info. + */ + fun maxCompletionTokens(maxCompletionTokens: Long) = apply { + this.maxCompletionTokens = maxCompletionTokens + } + + /** + * The maximum number of prompt tokens that may be used over the course of the run. The + * run will make a best effort to use only the number of prompt tokens specified, across + * multiple turns of the run. If the run exceeds the number of prompt tokens specified, + * the run will end with status `incomplete`. See `incomplete_details` for more info. + */ + fun maxPromptTokens(maxPromptTokens: Long) = apply { + this.maxPromptTokens = maxPromptTokens + } + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format. Keys can be a + * maximum of 64 characters long and values can be a maximum of 512 characters long. + */ + fun metadata(metadata: JsonValue) = apply { this.metadata = metadata } + + /** + * The ID of the [Model](https://platform.openai.com/docs/api-reference/models) to be + * used to execute this run. If a value is provided here, it will override the model + * associated with the assistant. If not, the model associated with the assistant will + * be used. + */ + fun model(model: ChatModel) = apply { this.model = model } + + /** + * The ID of the [Model](https://platform.openai.com/docs/api-reference/models) to be + * used to execute this run. If a value is provided here, it will override the model + * associated with the assistant. If not, the model associated with the assistant will + * be used. + */ + fun model(value: String) = apply { model = ChatModel.of(value) } + + /** + * Whether to enable + * [parallel function calling](https://platform.openai.com/docs/guides/function-calling#configuring-parallel-function-calling) + * during tool use. + */ + fun parallelToolCalls(parallelToolCalls: Boolean) = apply { + this.parallelToolCalls = parallelToolCalls + } + + /** + * Specifies the format that the model must output. Compatible with + * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o), [GPT-4 + * Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4), and all + * GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`. + * + * Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured + * Outputs which ensures the model will match your supplied JSON schema. Learn more in + * the + * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs). + * + * Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the message + * the model generates is valid JSON. + * + * **Important:** when using JSON mode, you **must** also instruct the model to produce + * JSON yourself via a system or user message. Without this, the model may generate an + * unending stream of whitespace until the generation reaches the token limit, resulting + * in a long-running and seemingly "stuck" request. Also note that the message content + * may be partially cut off if `finish_reason="length"`, which indicates the generation + * exceeded `max_tokens` or the conversation exceeded the max context length. + */ + fun responseFormat(responseFormat: AssistantResponseFormatOption) = apply { + this.responseFormat = responseFormat + } + + /** `auto` is the default value */ + fun responseFormat(behavior: AssistantResponseFormatOption.Behavior) = apply { + this.responseFormat = AssistantResponseFormatOption.ofBehavior(behavior) + } + + fun responseFormat(responseFormatText: ResponseFormatText) = apply { + this.responseFormat = + AssistantResponseFormatOption.ofResponseFormatText(responseFormatText) + } + + fun responseFormat(responseFormatJsonObject: ResponseFormatJsonObject) = apply { + this.responseFormat = + AssistantResponseFormatOption.ofResponseFormatJsonObject( + responseFormatJsonObject + ) + } + + fun responseFormat(responseFormatJsonSchema: ResponseFormatJsonSchema) = apply { + this.responseFormat = + AssistantResponseFormatOption.ofResponseFormatJsonSchema( + responseFormatJsonSchema + ) + } + + /** + * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make + * the output more random, while lower values like 0.2 will make it more focused and + * deterministic. + */ + fun temperature(temperature: Double) = apply { this.temperature = temperature } + + /** + * Controls which (if any) tool is called by the model. `none` means the model will not + * call any tools and instead generates a message. `auto` is the default value and means + * the model can pick between generating a message or calling one or more tools. + * `required` means the model must call one or more tools before responding to the user. + * Specifying a particular tool like `{"type": "file_search"}` or `{"type": "function", + * "function": {"name": "my_function"}}` forces the model to call that tool. + */ + fun toolChoice(toolChoice: AssistantToolChoiceOption) = apply { + this.toolChoice = toolChoice + } + + /** + * `none` means the model will not call any tools and instead generates a message. + * `auto` means the model can pick between generating a message or calling one or more + * tools. `required` means the model must call one or more tools before responding to + * the user. + */ + fun toolChoice(behavior: AssistantToolChoiceOption.Behavior) = apply { + this.toolChoice = AssistantToolChoiceOption.ofBehavior(behavior) + } + + /** + * Specifies a tool the model should use. Use to force the model to call a specific + * tool. + */ + fun toolChoice(assistantToolChoice: AssistantToolChoice) = apply { + this.toolChoice = + AssistantToolChoiceOption.ofAssistantToolChoice(assistantToolChoice) + } + + /** + * Override the tools the assistant can use for this run. This is useful for modifying + * the behavior on a per-run basis. + */ + fun tools(tools: List) = apply { this.tools = tools.toMutableList() } + + /** + * Override the tools the assistant can use for this run. This is useful for modifying + * the behavior on a per-run basis. + */ + fun addTool(tool: AssistantTool) = apply { + tools = (tools ?: mutableListOf()).apply { add(tool) } + } + + /** + * An alternative to sampling with temperature, called nucleus sampling, where the model + * considers the results of the tokens with top_p probability mass. So 0.1 means only + * the tokens comprising the top 10% probability mass are considered. + * + * We generally recommend altering this or temperature but not both. + */ + fun topP(topP: Double) = apply { this.topP = topP } + + /** + * Controls for how a thread will be truncated prior to the run. Use this to control the + * intial context window of the run. + */ + fun truncationStrategy(truncationStrategy: TruncationStrategy) = apply { + this.truncationStrategy = truncationStrategy + } + + 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) + } + + fun build(): BetaThreadRunCreateBody = + BetaThreadRunCreateBody( + checkNotNull(assistantId) { "`assistantId` is required but was not set" }, + additionalInstructions, + additionalMessages?.toImmutable(), + instructions, + maxCompletionTokens, + maxPromptTokens, + metadata, + model, + parallelToolCalls, + responseFormat, + temperature, + toolChoice, + tools?.toImmutable(), + topP, + truncationStrategy, + additionalProperties.toImmutable(), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaThreadRunCreateBody && assistantId == other.assistantId && additionalInstructions == other.additionalInstructions && additionalMessages == other.additionalMessages && instructions == other.instructions && maxCompletionTokens == other.maxCompletionTokens && maxPromptTokens == other.maxPromptTokens && metadata == other.metadata && model == other.model && parallelToolCalls == other.parallelToolCalls && responseFormat == other.responseFormat && temperature == other.temperature && toolChoice == other.toolChoice && tools == other.tools && topP == other.topP && truncationStrategy == other.truncationStrategy && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(assistantId, additionalInstructions, additionalMessages, instructions, maxCompletionTokens, maxPromptTokens, metadata, model, parallelToolCalls, responseFormat, temperature, toolChoice, tools, topP, truncationStrategy, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaThreadRunCreateBody{assistantId=$assistantId, additionalInstructions=$additionalInstructions, additionalMessages=$additionalMessages, instructions=$instructions, maxCompletionTokens=$maxCompletionTokens, maxPromptTokens=$maxPromptTokens, metadata=$metadata, model=$model, parallelToolCalls=$parallelToolCalls, responseFormat=$responseFormat, temperature=$temperature, toolChoice=$toolChoice, tools=$tools, topP=$topP, truncationStrategy=$truncationStrategy, additionalProperties=$additionalProperties}" + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + @NoAutoDetect + class Builder { + + private var threadId: String? = null + private var include: MutableList? = null + private var body: BetaThreadRunCreateBody.Builder = BetaThreadRunCreateBody.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(betaThreadRunCreateParams: BetaThreadRunCreateParams) = apply { + threadId = betaThreadRunCreateParams.threadId + include = betaThreadRunCreateParams.include?.toMutableList() + body = betaThreadRunCreateParams.body.toBuilder() + additionalHeaders = betaThreadRunCreateParams.additionalHeaders.toBuilder() + additionalQueryParams = betaThreadRunCreateParams.additionalQueryParams.toBuilder() + } + + fun threadId(threadId: String) = apply { this.threadId = threadId } + + /** + * A list of additional fields to include in the response. Currently the only supported + * value is `step_details.tool_calls[*].file_search.results[*].content` to fetch the file + * search result content. + * + * See the + * [file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search#customizing-file-search-settings) + * for more information. + */ + fun include(include: List) = apply { + this.include = include.toMutableList() + } + + /** + * A list of additional fields to include in the response. Currently the only supported + * value is `step_details.tool_calls[*].file_search.results[*].content` to fetch the file + * search result content. + * + * See the + * [file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search#customizing-file-search-settings) + * for more information. + */ + fun addInclude(include: RunStepInclude) = apply { + this.include = (this.include ?: mutableListOf()).apply { add(include) } + } + + /** + * The ID of the [assistant](https://platform.openai.com/docs/api-reference/assistants) to + * use to execute this run. + */ + fun assistantId(assistantId: String) = apply { body.assistantId(assistantId) } + + /** + * Appends additional instructions at the end of the instructions for the run. This is + * useful for modifying the behavior on a per-run basis without overriding other + * instructions. + */ + fun additionalInstructions(additionalInstructions: String) = apply { + body.additionalInstructions(additionalInstructions) + } + + /** Adds additional messages to the thread before creating the run. */ + fun additionalMessages(additionalMessages: List) = apply { + body.additionalMessages(additionalMessages) + } + + /** Adds additional messages to the thread before creating the run. */ + fun addAdditionalMessage(additionalMessage: AdditionalMessage) = apply { + body.addAdditionalMessage(additionalMessage) + } + + /** + * Overrides the + * [instructions](https://platform.openai.com/docs/api-reference/assistants/createAssistant) + * of the assistant. This is useful for modifying the behavior on a per-run basis. + */ + fun instructions(instructions: String) = apply { body.instructions(instructions) } + + /** + * The maximum number of completion tokens that may be used over the course of the run. The + * run will make a best effort to use only the number of completion tokens specified, across + * multiple turns of the run. If the run exceeds the number of completion tokens specified, + * the run will end with status `incomplete`. See `incomplete_details` for more info. + */ + fun maxCompletionTokens(maxCompletionTokens: Long) = apply { + body.maxCompletionTokens(maxCompletionTokens) + } + + /** + * The maximum number of prompt tokens that may be used over the course of the run. The run + * will make a best effort to use only the number of prompt tokens specified, across + * multiple turns of the run. If the run exceeds the number of prompt tokens specified, the + * run will end with status `incomplete`. See `incomplete_details` for more info. + */ + fun maxPromptTokens(maxPromptTokens: Long) = apply { body.maxPromptTokens(maxPromptTokens) } + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format. Keys can be a + * maximum of 64 characters long and values can be a maximum of 512 characters long. + */ + fun metadata(metadata: JsonValue) = apply { body.metadata(metadata) } + + /** + * The ID of the [Model](https://platform.openai.com/docs/api-reference/models) to be used + * to execute this run. If a value is provided here, it will override the model associated + * with the assistant. If not, the model associated with the assistant will be used. + */ + fun model(model: ChatModel) = apply { body.model(model) } + + /** + * The ID of the [Model](https://platform.openai.com/docs/api-reference/models) to be used + * to execute this run. If a value is provided here, it will override the model associated + * with the assistant. If not, the model associated with the assistant will be used. + */ + fun model(value: String) = apply { body.model(value) } + + /** + * Whether to enable + * [parallel function calling](https://platform.openai.com/docs/guides/function-calling#configuring-parallel-function-calling) + * during tool use. + */ + fun parallelToolCalls(parallelToolCalls: Boolean) = apply { + body.parallelToolCalls(parallelToolCalls) + } + + /** + * Specifies the format that the model must output. Compatible with + * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o), [GPT-4 + * Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4), and all GPT-3.5 + * Turbo models since `gpt-3.5-turbo-1106`. + * + * Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured Outputs + * which ensures the model will match your supplied JSON schema. Learn more in the + * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs). + * + * Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the message the + * model generates is valid JSON. + * + * **Important:** when using JSON mode, you **must** also instruct the model to produce JSON + * yourself via a system or user message. Without this, the model may generate an unending + * stream of whitespace until the generation reaches the token limit, resulting in a + * long-running and seemingly "stuck" request. Also note that the message content may be + * partially cut off if `finish_reason="length"`, which indicates the generation exceeded + * `max_tokens` or the conversation exceeded the max context length. + */ + fun responseFormat(responseFormat: AssistantResponseFormatOption) = apply { + body.responseFormat(responseFormat) + } + + /** `auto` is the default value */ + fun responseFormat(behavior: AssistantResponseFormatOption.Behavior) = apply { + body.responseFormat(behavior) + } + + fun responseFormat(responseFormatText: ResponseFormatText) = apply { + body.responseFormat(responseFormatText) + } + + fun responseFormat(responseFormatJsonObject: ResponseFormatJsonObject) = apply { + body.responseFormat(responseFormatJsonObject) + } + + fun responseFormat(responseFormatJsonSchema: ResponseFormatJsonSchema) = apply { + body.responseFormat(responseFormatJsonSchema) + } + + /** + * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the + * output more random, while lower values like 0.2 will make it more focused and + * deterministic. + */ + fun temperature(temperature: Double) = apply { body.temperature(temperature) } + + /** + * Controls which (if any) tool is called by the model. `none` means the model will not call + * any tools and instead generates a message. `auto` is the default value and means the + * model can pick between generating a message or calling one or more tools. `required` + * means the model must call one or more tools before responding to the user. Specifying a + * particular tool like `{"type": "file_search"}` or `{"type": "function", "function": + * {"name": "my_function"}}` forces the model to call that tool. + */ + fun toolChoice(toolChoice: AssistantToolChoiceOption) = apply { + body.toolChoice(toolChoice) + } + + /** + * `none` means the model will not call any tools and instead generates a message. `auto` + * means the model can pick between generating a message or calling one or more tools. + * `required` means the model must call one or more tools before responding to the user. + */ + fun toolChoice(behavior: AssistantToolChoiceOption.Behavior) = apply { + body.toolChoice(behavior) + } + + /** + * Specifies a tool the model should use. Use to force the model to call a specific tool. + */ + fun toolChoice(assistantToolChoice: AssistantToolChoice) = apply { + body.toolChoice(assistantToolChoice) + } + + /** + * Override the tools the assistant can use for this run. This is useful for modifying the + * behavior on a per-run basis. + */ + fun tools(tools: List) = apply { body.tools(tools) } + + /** + * Override the tools the assistant can use for this run. This is useful for modifying the + * behavior on a per-run basis. + */ + fun addTool(tool: AssistantTool) = apply { body.addTool(tool) } + + /** + * An alternative to sampling with temperature, called nucleus sampling, where the model + * considers the results of the tokens with top_p probability mass. So 0.1 means only the + * tokens comprising the top 10% probability mass are considered. + * + * We generally recommend altering this or temperature but not both. + */ + fun topP(topP: Double) = apply { body.topP(topP) } + + /** + * Controls for how a thread will be truncated prior to the run. Use this to control the + * intial context window of the run. + */ + fun truncationStrategy(truncationStrategy: TruncationStrategy) = apply { + body.truncationStrategy(truncationStrategy) + } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } + + fun build(): BetaThreadRunCreateParams = + BetaThreadRunCreateParams( + checkNotNull(threadId) { "`threadId` is required but was not set" }, + include?.toImmutable(), + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + @NoAutoDetect + class AdditionalMessage + @JsonCreator + private constructor( + @JsonProperty("role") private val role: Role, + @JsonProperty("content") private val content: Content, + @JsonProperty("attachments") private val attachments: List?, + @JsonProperty("metadata") private val metadata: JsonValue?, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** + * The role of the entity that is creating the message. Allowed values include: + * - `user`: Indicates the message is sent by an actual user and should be used in most + * cases to represent user-generated messages. + * - `assistant`: Indicates the message is generated by the assistant. Use this value to + * insert messages from the assistant into the conversation. + */ + @JsonProperty("role") fun role(): Role = role + + /** The text contents of the message. */ + @JsonProperty("content") fun content(): Content = content + + /** A list of files attached to the message, and the tools they should be added to. */ + @JsonProperty("attachments") + fun attachments(): Optional> = Optional.ofNullable(attachments) + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format. Keys can be a + * maximum of 64 characters long and values can be a maximum of 512 characters long. + */ + @JsonProperty("metadata") + fun metadata(): Optional = Optional.ofNullable(metadata) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var role: Role? = null + private var content: Content? = null + private var attachments: MutableList? = null + private var metadata: JsonValue? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(additionalMessage: AdditionalMessage) = apply { + role = additionalMessage.role + content = additionalMessage.content + attachments = additionalMessage.attachments?.toMutableList() + metadata = additionalMessage.metadata + additionalProperties = additionalMessage.additionalProperties.toMutableMap() + } + + /** + * The role of the entity that is creating the message. Allowed values include: + * - `user`: Indicates the message is sent by an actual user and should be used in most + * cases to represent user-generated messages. + * - `assistant`: Indicates the message is generated by the assistant. Use this value to + * insert messages from the assistant into the conversation. + */ + fun role(role: Role) = apply { this.role = role } + + /** The text contents of the message. */ + fun content(content: Content) = apply { this.content = content } + + /** The text contents of the message. */ + fun content(textContent: String) = apply { + this.content = Content.ofTextContent(textContent) + } + + /** + * An array of content parts with a defined type, each can be of type `text` or images + * can be passed with `image_url` or `image_file`. Image types are only supported on + * [Vision-compatible models](https://platform.openai.com/docs/models). + */ + fun contentOfArrayOfContentParts(arrayOfContentParts: List) = + apply { + this.content = Content.ofArrayOfContentParts(arrayOfContentParts) + } + + /** A list of files attached to the message, and the tools they should be added to. */ + fun attachments(attachments: List) = apply { + this.attachments = attachments.toMutableList() + } + + /** A list of files attached to the message, and the tools they should be added to. */ + fun addAttachment(attachment: Attachment) = apply { + attachments = (attachments ?: mutableListOf()).apply { add(attachment) } + } + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format. Keys can be a + * maximum of 64 characters long and values can be a maximum of 512 characters long. + */ + fun metadata(metadata: JsonValue) = apply { this.metadata = metadata } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + fun build(): AdditionalMessage = + AdditionalMessage( + checkNotNull(role) { "`role` is required but was not set" }, + checkNotNull(content) { "`content` is required but was not set" }, + attachments?.toImmutable(), + metadata, + additionalProperties.toImmutable(), + ) + } + + /** The text contents of the message. */ + @JsonDeserialize(using = Content.Deserializer::class) + @JsonSerialize(using = Content.Serializer::class) + class Content + private constructor( + private val textContent: String? = null, + private val arrayOfContentParts: List? = null, + private val _json: JsonValue? = null, + ) { + + /** The text contents of the message. */ + fun textContent(): Optional = Optional.ofNullable(textContent) + /** + * An array of content parts with a defined type, each can be of type `text` or images + * can be passed with `image_url` or `image_file`. Image types are only supported on + * [Vision-compatible models](https://platform.openai.com/docs/models). + */ + fun arrayOfContentParts(): Optional> = + Optional.ofNullable(arrayOfContentParts) + + fun isTextContent(): Boolean = textContent != null + + fun isArrayOfContentParts(): Boolean = arrayOfContentParts != null + + /** The text contents of the message. */ + fun asTextContent(): String = textContent.getOrThrow("textContent") + /** + * An array of content parts with a defined type, each can be of type `text` or images + * can be passed with `image_url` or `image_file`. Image types are only supported on + * [Vision-compatible models](https://platform.openai.com/docs/models). + */ + fun asArrayOfContentParts(): List = + arrayOfContentParts.getOrThrow("arrayOfContentParts") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + textContent != null -> visitor.visitTextContent(textContent) + arrayOfContentParts != null -> + visitor.visitArrayOfContentParts(arrayOfContentParts) + else -> visitor.unknown(_json) + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Content && textContent == other.textContent && arrayOfContentParts == other.arrayOfContentParts /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(textContent, arrayOfContentParts) /* spotless:on */ + + override fun toString(): String = + when { + textContent != null -> "Content{textContent=$textContent}" + arrayOfContentParts != null -> + "Content{arrayOfContentParts=$arrayOfContentParts}" + _json != null -> "Content{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Content") + } + + companion object { + + /** The text contents of the message. */ + @JvmStatic + fun ofTextContent(textContent: String) = Content(textContent = textContent) + + /** + * An array of content parts with a defined type, each can be of type `text` or + * images can be passed with `image_url` or `image_file`. Image types are only + * supported on [Vision-compatible models](https://platform.openai.com/docs/models). + */ + @JvmStatic + fun ofArrayOfContentParts(arrayOfContentParts: List) = + Content(arrayOfContentParts = arrayOfContentParts) + } + + interface Visitor { + + fun visitTextContent(textContent: String): T + + fun visitArrayOfContentParts(arrayOfContentParts: List): T + + fun unknown(json: JsonValue?): T { + throw OpenAIInvalidDataException("Unknown Content: $json") + } + } + + class Deserializer : BaseDeserializer(Content::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Content { + val json = JsonValue.fromJsonNode(node) + + tryDeserialize(node, jacksonTypeRef())?.let { + return Content(textContent = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef>())?.let { + return Content(arrayOfContentParts = it, _json = json) + } + + return Content(_json = json) + } + } + + class Serializer : BaseSerializer(Content::class) { + + override fun serialize( + value: Content, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.textContent != null -> generator.writeObject(value.textContent) + value.arrayOfContentParts != null -> + generator.writeObject(value.arrayOfContentParts) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Content") + } + } + } + } + + class Role + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val USER = of("user") + + @JvmField val ASSISTANT = of("assistant") + + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) + } + + enum class Known { + USER, + ASSISTANT, + } + + enum class Value { + USER, + ASSISTANT, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + USER -> Value.USER + ASSISTANT -> Value.ASSISTANT + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + USER -> Known.USER + ASSISTANT -> Known.ASSISTANT + else -> throw OpenAIInvalidDataException("Unknown Role: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Role && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + @NoAutoDetect + class Attachment + @JsonCreator + private constructor( + @JsonProperty("file_id") private val fileId: String?, + @JsonProperty("tools") private val tools: List?, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** The ID of the file to attach to the message. */ + @JsonProperty("file_id") fun fileId(): Optional = Optional.ofNullable(fileId) + + /** The tools to add this file to. */ + @JsonProperty("tools") fun tools(): Optional> = Optional.ofNullable(tools) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var fileId: String? = null + private var tools: MutableList? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(attachment: Attachment) = apply { + fileId = attachment.fileId + tools = attachment.tools?.toMutableList() + additionalProperties = attachment.additionalProperties.toMutableMap() + } + + /** The ID of the file to attach to the message. */ + fun fileId(fileId: String) = apply { this.fileId = fileId } + + /** The tools to add this file to. */ + fun tools(tools: List) = apply { this.tools = tools.toMutableList() } + + /** The tools to add this file to. */ + fun addTool(tool: Tool) = apply { + tools = (tools ?: mutableListOf()).apply { add(tool) } + } + + 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) + } + + fun build(): Attachment = + Attachment( + fileId, + tools?.toImmutable(), + additionalProperties.toImmutable(), + ) + } + + @JsonDeserialize(using = Tool.Deserializer::class) + @JsonSerialize(using = Tool.Serializer::class) + class Tool + private constructor( + private val codeInterpreterTool: CodeInterpreterTool? = null, + private val fileSearch: FileSearch? = null, + private val _json: JsonValue? = null, + ) { + + fun codeInterpreterTool(): Optional = + Optional.ofNullable(codeInterpreterTool) + + fun fileSearch(): Optional = Optional.ofNullable(fileSearch) + + fun isCodeInterpreterTool(): Boolean = codeInterpreterTool != null + + fun isFileSearch(): Boolean = fileSearch != null + + fun asCodeInterpreterTool(): CodeInterpreterTool = + codeInterpreterTool.getOrThrow("codeInterpreterTool") + + fun asFileSearch(): FileSearch = fileSearch.getOrThrow("fileSearch") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T { + return when { + codeInterpreterTool != null -> + visitor.visitCodeInterpreterTool(codeInterpreterTool) + fileSearch != null -> visitor.visitFileSearch(fileSearch) + else -> visitor.unknown(_json) + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Tool && codeInterpreterTool == other.codeInterpreterTool && fileSearch == other.fileSearch /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(codeInterpreterTool, fileSearch) /* spotless:on */ + + override fun toString(): String = + when { + codeInterpreterTool != null -> + "Tool{codeInterpreterTool=$codeInterpreterTool}" + fileSearch != null -> "Tool{fileSearch=$fileSearch}" + _json != null -> "Tool{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Tool") + } + + companion object { + + @JvmStatic + fun ofCodeInterpreterTool(codeInterpreterTool: CodeInterpreterTool) = + Tool(codeInterpreterTool = codeInterpreterTool) + + @JvmStatic + fun ofFileSearch(fileSearch: FileSearch) = Tool(fileSearch = fileSearch) + } + + interface Visitor { + + fun visitCodeInterpreterTool(codeInterpreterTool: CodeInterpreterTool): T + + fun visitFileSearch(fileSearch: FileSearch): T + + fun unknown(json: JsonValue?): T { + throw OpenAIInvalidDataException("Unknown Tool: $json") + } + } + + class Deserializer : BaseDeserializer(Tool::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Tool { + val json = JsonValue.fromJsonNode(node) + val type = json.asObject().getOrNull()?.get("type")?.asString()?.getOrNull() + + when (type) { + "code_interpreter" -> { + tryDeserialize(node, jacksonTypeRef())?.let { + return Tool(codeInterpreterTool = it, _json = json) + } + } + "file_search" -> { + tryDeserialize(node, jacksonTypeRef())?.let { + return Tool(fileSearch = it, _json = json) + } + } + } + + return Tool(_json = json) + } + } + + class Serializer : BaseSerializer(Tool::class) { + + override fun serialize( + value: Tool, + generator: JsonGenerator, + provider: SerializerProvider + ) { + when { + value.codeInterpreterTool != null -> + generator.writeObject(value.codeInterpreterTool) + value.fileSearch != null -> generator.writeObject(value.fileSearch) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Tool") + } + } + } + + @NoAutoDetect + class FileSearch + @JsonCreator + private constructor( + @JsonProperty("type") private val type: Type, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** The type of tool being defined: `file_search` */ + @JsonProperty("type") fun type(): Type = type + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var type: Type? = null + private var additionalProperties: MutableMap = + mutableMapOf() + + @JvmSynthetic + internal fun from(fileSearch: FileSearch) = apply { + type = fileSearch.type + additionalProperties = fileSearch.additionalProperties.toMutableMap() + } + + /** The type of tool being defined: `file_search` */ + fun type(type: Type) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties( + additionalProperties: Map + ) = apply { this.additionalProperties.putAll(additionalProperties) } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + fun build(): FileSearch = + FileSearch( + checkNotNull(type) { "`type` is required but was not set" }, + additionalProperties.toImmutable() + ) + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue + fun _value(): JsonField = value + + companion object { + + @JvmField val FILE_SEARCH = of("file_search") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + FILE_SEARCH, + } + + enum class Value { + FILE_SEARCH, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + FILE_SEARCH -> Value.FILE_SEARCH + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + FILE_SEARCH -> Known.FILE_SEARCH + else -> throw OpenAIInvalidDataException("Unknown Type: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is FileSearch && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(type, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "FileSearch{type=$type, additionalProperties=$additionalProperties}" + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Attachment && fileId == other.fileId && tools == other.tools && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(fileId, tools, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Attachment{fileId=$fileId, tools=$tools, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is AdditionalMessage && role == other.role && content == other.content && attachments == other.attachments && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(role, content, attachments, metadata, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AdditionalMessage{role=$role, content=$content, attachments=$attachments, metadata=$metadata, additionalProperties=$additionalProperties}" + } + + /** + * Controls for how a thread will be truncated prior to the run. Use this to control the intial + * context window of the run. + */ + @NoAutoDetect + class TruncationStrategy + @JsonCreator + private constructor( + @JsonProperty("type") private val type: Type, + @JsonProperty("last_messages") private val lastMessages: Long?, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** + * The truncation strategy to use for the thread. The default is `auto`. If set to + * `last_messages`, the thread will be truncated to the n most recent messages in the + * thread. When set to `auto`, messages in the middle of the thread will be dropped to fit + * the context length of the model, `max_prompt_tokens`. + */ + @JsonProperty("type") fun type(): Type = type + + /** + * The number of most recent messages from the thread when constructing the context for the + * run. + */ + @JsonProperty("last_messages") + fun lastMessages(): Optional = Optional.ofNullable(lastMessages) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var type: Type? = null + private var lastMessages: Long? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(truncationStrategy: TruncationStrategy) = apply { + type = truncationStrategy.type + lastMessages = truncationStrategy.lastMessages + additionalProperties = truncationStrategy.additionalProperties.toMutableMap() + } + + /** + * The truncation strategy to use for the thread. The default is `auto`. If set to + * `last_messages`, the thread will be truncated to the n most recent messages in the + * thread. When set to `auto`, messages in the middle of the thread will be dropped to + * fit the context length of the model, `max_prompt_tokens`. + */ + fun type(type: Type) = apply { this.type = type } + + /** + * The number of most recent messages from the thread when constructing the context for + * the run. + */ + fun lastMessages(lastMessages: Long) = apply { this.lastMessages = lastMessages } + + 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) + } + + fun build(): TruncationStrategy = + TruncationStrategy( + checkNotNull(type) { "`type` is required but was not set" }, + lastMessages, + additionalProperties.toImmutable(), + ) + } + + class Type + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val AUTO = of("auto") + + @JvmField val LAST_MESSAGES = of("last_messages") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + enum class Known { + AUTO, + LAST_MESSAGES, + } + + enum class Value { + AUTO, + LAST_MESSAGES, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + AUTO -> Value.AUTO + LAST_MESSAGES -> Value.LAST_MESSAGES + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + AUTO -> Known.AUTO + LAST_MESSAGES -> Known.LAST_MESSAGES + else -> throw OpenAIInvalidDataException("Unknown Type: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Type && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is TruncationStrategy && type == other.type && lastMessages == other.lastMessages && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(type, lastMessages, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "TruncationStrategy{type=$type, lastMessages=$lastMessages, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaThreadRunCreateParams && threadId == other.threadId && include == other.include && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(threadId, include, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "BetaThreadRunCreateParams{threadId=$threadId, include=$include, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRunListPage.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRunListPage.kt new file mode 100644 index 00000000..34403cb9 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRunListPage.kt @@ -0,0 +1,167 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.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.NoAutoDetect +import com.openai.core.immutableEmptyMap +import com.openai.core.toImmutable +import com.openai.services.blocking.beta.threads.RunService +import java.util.Objects +import java.util.Optional +import java.util.stream.Stream +import java.util.stream.StreamSupport + +class BetaThreadRunListPage +private constructor( + private val runsService: RunService, + private val params: BetaThreadRunListParams, + private val response: Response, +) { + + fun response(): Response = response + + fun data(): List = response().data() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaThreadRunListPage && 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() = + "BetaThreadRunListPage{runsService=$runsService, params=$params, response=$response}" + + fun hasNextPage(): Boolean { + return !data().isEmpty() + } + + fun getNextPageParams(): Optional { + if (!hasNextPage()) { + return Optional.empty() + } + + return Optional.of( + BetaThreadRunListParams.builder().from(params).after(data().last().id()).build() + ) + } + + fun getNextPage(): Optional { + return getNextPageParams().map { runsService.list(it) } + } + + fun autoPager(): AutoPager = AutoPager(this) + + companion object { + + @JvmStatic + fun of(runsService: RunService, params: BetaThreadRunListParams, response: Response) = + BetaThreadRunListPage( + runsService, + params, + response, + ) + } + + @NoAutoDetect + class Response + @JsonCreator + constructor( + @JsonProperty("data") private val data: JsonField> = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + private var validated: Boolean = false + + fun data(): List = data.getNullable("data") ?: listOf() + + @JsonProperty("data") + fun _data(): Optional>> = Optional.ofNullable(data) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Response = apply { + if (!validated) { + data().map { it.validate() } + validated = true + } + } + + 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 && additionalProperties == other.additionalProperties /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, additionalProperties) /* spotless:on */ + + override fun toString() = "Response{data=$data, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var data: JsonField> = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(page: Response) = apply { + this.data = page.data + this.additionalProperties.putAll(page.additionalProperties) + } + + fun data(data: List) = data(JsonField.of(data)) + + fun data(data: JsonField>) = apply { this.data = data } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun build() = Response(data, additionalProperties.toImmutable()) + } + } + + class AutoPager + constructor( + private val firstPage: BetaThreadRunListPage, + ) : Iterable { + + override fun iterator(): Iterator = iterator { + var page = firstPage + var index = 0 + while (true) { + while (index < page.data().size) { + yield(page.data()[index++]) + } + page = page.getNextPage().orElse(null) ?: break + index = 0 + } + } + + fun stream(): Stream { + return StreamSupport.stream(spliterator(), false) + } + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRunListPageAsync.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRunListPageAsync.kt new file mode 100644 index 00000000..7c37cc93 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRunListPageAsync.kt @@ -0,0 +1,177 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.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.NoAutoDetect +import com.openai.core.immutableEmptyMap +import com.openai.core.toImmutable +import com.openai.services.async.beta.threads.RunServiceAsync +import java.util.Objects +import java.util.Optional +import java.util.concurrent.CompletableFuture +import java.util.concurrent.Executor +import java.util.function.Predicate + +class BetaThreadRunListPageAsync +private constructor( + private val runsService: RunServiceAsync, + private val params: BetaThreadRunListParams, + private val response: Response, +) { + + fun response(): Response = response + + fun data(): List = response().data() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaThreadRunListPageAsync && 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() = + "BetaThreadRunListPageAsync{runsService=$runsService, params=$params, response=$response}" + + fun hasNextPage(): Boolean { + return !data().isEmpty() + } + + fun getNextPageParams(): Optional { + if (!hasNextPage()) { + return Optional.empty() + } + + return Optional.of( + BetaThreadRunListParams.builder().from(params).after(data().last().id()).build() + ) + } + + fun getNextPage(): CompletableFuture> { + return getNextPageParams() + .map { runsService.list(it).thenApply { Optional.of(it) } } + .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + } + + fun autoPager(): AutoPager = AutoPager(this) + + companion object { + + @JvmStatic + fun of(runsService: RunServiceAsync, params: BetaThreadRunListParams, response: Response) = + BetaThreadRunListPageAsync( + runsService, + params, + response, + ) + } + + @NoAutoDetect + class Response + @JsonCreator + constructor( + @JsonProperty("data") private val data: JsonField> = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + private var validated: Boolean = false + + fun data(): List = data.getNullable("data") ?: listOf() + + @JsonProperty("data") + fun _data(): Optional>> = Optional.ofNullable(data) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Response = apply { + if (!validated) { + data().map { it.validate() } + validated = true + } + } + + 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 && additionalProperties == other.additionalProperties /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, additionalProperties) /* spotless:on */ + + override fun toString() = "Response{data=$data, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var data: JsonField> = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(page: Response) = apply { + this.data = page.data + this.additionalProperties.putAll(page.additionalProperties) + } + + fun data(data: List) = data(JsonField.of(data)) + + fun data(data: JsonField>) = apply { this.data = data } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun build() = Response(data, additionalProperties.toImmutable()) + } + } + + class AutoPager + constructor( + private val firstPage: BetaThreadRunListPageAsync, + ) { + + fun forEach(action: Predicate, executor: Executor): CompletableFuture { + fun CompletableFuture>.forEach( + action: (Run) -> Boolean, + executor: Executor + ): CompletableFuture = + thenComposeAsync( + { page -> + page + .filter { it.data().all(action) } + .map { it.getNextPage().forEach(action, executor) } + .orElseGet { CompletableFuture.completedFuture(null) } + }, + executor + ) + return CompletableFuture.completedFuture(Optional.of(firstPage)) + .forEach(action::test, executor) + } + + fun toList(executor: Executor): CompletableFuture> { + val values = mutableListOf() + return forEach(values::add, executor).thenApply { values } + } + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRunListParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRunListParams.kt new file mode 100644 index 00000000..c6319669 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRunListParams.kt @@ -0,0 +1,316 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models + +import com.fasterxml.jackson.annotation.JsonCreator +import com.openai.core.Enum +import com.openai.core.JsonField +import com.openai.core.NoAutoDetect +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.errors.OpenAIInvalidDataException +import java.util.Objects +import java.util.Optional + +class BetaThreadRunListParams +constructor( + private val threadId: String, + private val after: String?, + private val before: String?, + private val limit: Long?, + private val order: Order?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) { + + fun threadId(): String = threadId + + /** + * A cursor for use in pagination. `after` is an object ID that defines your place in the list. + * For instance, if you make a list request and receive 100 objects, ending with obj_foo, your + * subsequent call can include after=obj_foo in order to fetch the next page of the list. + */ + fun after(): Optional = Optional.ofNullable(after) + + /** + * A cursor for use in pagination. `before` is an object ID that defines your place in the list. + * For instance, if you make a list request and receive 100 objects, starting with obj_foo, your + * subsequent call can include before=obj_foo in order to fetch the previous page of the list. + */ + fun before(): Optional = Optional.ofNullable(before) + + /** + * A limit on the number of objects to be returned. Limit can range between 1 and 100, and the + * default is 20. + */ + fun limit(): Optional = Optional.ofNullable(limit) + + /** + * Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and `desc` + * for descending order. + */ + fun order(): Optional = Optional.ofNullable(order) + + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + + @JvmSynthetic + internal fun getQueryParams(): QueryParams { + val queryParams = QueryParams.builder() + this.after?.let { queryParams.put("after", listOf(it.toString())) } + this.before?.let { queryParams.put("before", listOf(it.toString())) } + this.limit?.let { queryParams.put("limit", listOf(it.toString())) } + this.order?.let { queryParams.put("order", listOf(it.toString())) } + queryParams.putAll(additionalQueryParams) + return queryParams.build() + } + + fun getPathParam(index: Int): String { + return when (index) { + 0 -> threadId + else -> "" + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + @NoAutoDetect + class Builder { + + private var threadId: String? = null + private var after: String? = null + private var before: String? = null + private var limit: Long? = null + private var order: Order? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(betaThreadRunListParams: BetaThreadRunListParams) = apply { + threadId = betaThreadRunListParams.threadId + after = betaThreadRunListParams.after + before = betaThreadRunListParams.before + limit = betaThreadRunListParams.limit + order = betaThreadRunListParams.order + additionalHeaders = betaThreadRunListParams.additionalHeaders.toBuilder() + additionalQueryParams = betaThreadRunListParams.additionalQueryParams.toBuilder() + } + + fun threadId(threadId: String) = apply { this.threadId = threadId } + + /** + * A cursor for use in pagination. `after` is an object ID that defines your place in the + * list. For instance, if you make a list request and receive 100 objects, ending with + * obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page + * of the list. + */ + fun after(after: String) = apply { this.after = after } + + /** + * A cursor for use in pagination. `before` is an object ID that defines your place in the + * list. For instance, if you make a list request and receive 100 objects, starting with + * obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous + * page of the list. + */ + fun before(before: String) = apply { this.before = before } + + /** + * A limit on the number of objects to be returned. Limit can range between 1 and 100, and + * the default is 20. + */ + fun limit(limit: Long) = apply { this.limit = limit } + + /** + * Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and + * `desc` for descending order. + */ + fun order(order: Order) = apply { this.order = order } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun build(): BetaThreadRunListParams = + BetaThreadRunListParams( + checkNotNull(threadId) { "`threadId` is required but was not set" }, + after, + before, + limit, + order, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + class Order + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val ASC = of("asc") + + @JvmField val DESC = of("desc") + + @JvmStatic fun of(value: String) = Order(JsonField.of(value)) + } + + enum class Known { + ASC, + DESC, + } + + enum class Value { + ASC, + DESC, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + ASC -> Value.ASC + DESC -> Value.DESC + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + ASC -> Known.ASC + DESC -> Known.DESC + else -> throw OpenAIInvalidDataException("Unknown Order: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Order && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaThreadRunListParams && threadId == other.threadId && after == other.after && before == other.before && limit == other.limit && order == other.order && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(threadId, after, before, limit, order, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "BetaThreadRunListParams{threadId=$threadId, after=$after, before=$before, limit=$limit, order=$order, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRunRetrieveParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRunRetrieveParams.kt new file mode 100644 index 00000000..c42f9547 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRunRetrieveParams.kt @@ -0,0 +1,184 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models + +import com.openai.core.NoAutoDetect +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import java.util.Objects + +class BetaThreadRunRetrieveParams +constructor( + private val threadId: String, + private val runId: String, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) { + + fun threadId(): String = threadId + + fun runId(): String = runId + + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + + @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams + + fun getPathParam(index: Int): String { + return when (index) { + 0 -> threadId + 1 -> runId + else -> "" + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + @NoAutoDetect + class Builder { + + private var threadId: String? = null + private var runId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(betaThreadRunRetrieveParams: BetaThreadRunRetrieveParams) = apply { + threadId = betaThreadRunRetrieveParams.threadId + runId = betaThreadRunRetrieveParams.runId + additionalHeaders = betaThreadRunRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = betaThreadRunRetrieveParams.additionalQueryParams.toBuilder() + } + + fun threadId(threadId: String) = apply { this.threadId = threadId } + + fun runId(runId: String) = apply { this.runId = runId } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun build(): BetaThreadRunRetrieveParams = + BetaThreadRunRetrieveParams( + checkNotNull(threadId) { "`threadId` is required but was not set" }, + checkNotNull(runId) { "`runId` is required but was not set" }, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaThreadRunRetrieveParams && threadId == other.threadId && runId == other.runId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(threadId, runId, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "BetaThreadRunRetrieveParams{threadId=$threadId, runId=$runId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRunStepListPage.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRunStepListPage.kt new file mode 100644 index 00000000..9f56a774 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRunStepListPage.kt @@ -0,0 +1,167 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.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.NoAutoDetect +import com.openai.core.immutableEmptyMap +import com.openai.core.toImmutable +import com.openai.services.blocking.beta.threads.runs.StepService +import java.util.Objects +import java.util.Optional +import java.util.stream.Stream +import java.util.stream.StreamSupport + +class BetaThreadRunStepListPage +private constructor( + private val stepsService: StepService, + private val params: BetaThreadRunStepListParams, + private val response: Response, +) { + + fun response(): Response = response + + fun data(): List = response().data() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaThreadRunStepListPage && 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() = + "BetaThreadRunStepListPage{stepsService=$stepsService, params=$params, response=$response}" + + fun hasNextPage(): Boolean { + return !data().isEmpty() + } + + fun getNextPageParams(): Optional { + if (!hasNextPage()) { + return Optional.empty() + } + + return Optional.of( + BetaThreadRunStepListParams.builder().from(params).after(data().last().id()).build() + ) + } + + fun getNextPage(): Optional { + return getNextPageParams().map { stepsService.list(it) } + } + + fun autoPager(): AutoPager = AutoPager(this) + + companion object { + + @JvmStatic + fun of(stepsService: StepService, params: BetaThreadRunStepListParams, response: Response) = + BetaThreadRunStepListPage( + stepsService, + params, + response, + ) + } + + @NoAutoDetect + class Response + @JsonCreator + constructor( + @JsonProperty("data") private val data: JsonField> = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + private var validated: Boolean = false + + fun data(): List = data.getNullable("data") ?: listOf() + + @JsonProperty("data") + fun _data(): Optional>> = Optional.ofNullable(data) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Response = apply { + if (!validated) { + data().map { it.validate() } + validated = true + } + } + + 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 && additionalProperties == other.additionalProperties /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, additionalProperties) /* spotless:on */ + + override fun toString() = "Response{data=$data, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var data: JsonField> = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(page: Response) = apply { + this.data = page.data + this.additionalProperties.putAll(page.additionalProperties) + } + + fun data(data: List) = data(JsonField.of(data)) + + fun data(data: JsonField>) = apply { this.data = data } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun build() = Response(data, additionalProperties.toImmutable()) + } + } + + class AutoPager + constructor( + private val firstPage: BetaThreadRunStepListPage, + ) : Iterable { + + override fun iterator(): Iterator = iterator { + var page = firstPage + var index = 0 + while (true) { + while (index < page.data().size) { + yield(page.data()[index++]) + } + page = page.getNextPage().orElse(null) ?: break + index = 0 + } + } + + fun stream(): Stream { + return StreamSupport.stream(spliterator(), false) + } + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRunStepListPageAsync.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRunStepListPageAsync.kt new file mode 100644 index 00000000..605f53a8 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRunStepListPageAsync.kt @@ -0,0 +1,181 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.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.NoAutoDetect +import com.openai.core.immutableEmptyMap +import com.openai.core.toImmutable +import com.openai.services.async.beta.threads.runs.StepServiceAsync +import java.util.Objects +import java.util.Optional +import java.util.concurrent.CompletableFuture +import java.util.concurrent.Executor +import java.util.function.Predicate + +class BetaThreadRunStepListPageAsync +private constructor( + private val stepsService: StepServiceAsync, + private val params: BetaThreadRunStepListParams, + private val response: Response, +) { + + fun response(): Response = response + + fun data(): List = response().data() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaThreadRunStepListPageAsync && 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() = + "BetaThreadRunStepListPageAsync{stepsService=$stepsService, params=$params, response=$response}" + + fun hasNextPage(): Boolean { + return !data().isEmpty() + } + + fun getNextPageParams(): Optional { + if (!hasNextPage()) { + return Optional.empty() + } + + return Optional.of( + BetaThreadRunStepListParams.builder().from(params).after(data().last().id()).build() + ) + } + + fun getNextPage(): CompletableFuture> { + return getNextPageParams() + .map { stepsService.list(it).thenApply { Optional.of(it) } } + .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + } + + fun autoPager(): AutoPager = AutoPager(this) + + companion object { + + @JvmStatic + fun of( + stepsService: StepServiceAsync, + params: BetaThreadRunStepListParams, + response: Response + ) = + BetaThreadRunStepListPageAsync( + stepsService, + params, + response, + ) + } + + @NoAutoDetect + class Response + @JsonCreator + constructor( + @JsonProperty("data") private val data: JsonField> = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + private var validated: Boolean = false + + fun data(): List = data.getNullable("data") ?: listOf() + + @JsonProperty("data") + fun _data(): Optional>> = Optional.ofNullable(data) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Response = apply { + if (!validated) { + data().map { it.validate() } + validated = true + } + } + + 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 && additionalProperties == other.additionalProperties /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, additionalProperties) /* spotless:on */ + + override fun toString() = "Response{data=$data, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var data: JsonField> = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(page: Response) = apply { + this.data = page.data + this.additionalProperties.putAll(page.additionalProperties) + } + + fun data(data: List) = data(JsonField.of(data)) + + fun data(data: JsonField>) = apply { this.data = data } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun build() = Response(data, additionalProperties.toImmutable()) + } + } + + class AutoPager + constructor( + private val firstPage: BetaThreadRunStepListPageAsync, + ) { + + fun forEach(action: Predicate, executor: Executor): CompletableFuture { + fun CompletableFuture>.forEach( + action: (RunStep) -> Boolean, + executor: Executor + ): CompletableFuture = + thenComposeAsync( + { page -> + page + .filter { it.data().all(action) } + .map { it.getNextPage().forEach(action, executor) } + .orElseGet { CompletableFuture.completedFuture(null) } + }, + executor + ) + return CompletableFuture.completedFuture(Optional.of(firstPage)) + .forEach(action::test, executor) + } + + fun toList(executor: Executor): CompletableFuture> { + val values = mutableListOf() + return forEach(values::add, executor).thenApply { values } + } + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRunStepListParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRunStepListParams.kt new file mode 100644 index 00000000..104b3682 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRunStepListParams.kt @@ -0,0 +1,368 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models + +import com.fasterxml.jackson.annotation.JsonCreator +import com.openai.core.Enum +import com.openai.core.JsonField +import com.openai.core.NoAutoDetect +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Objects +import java.util.Optional + +class BetaThreadRunStepListParams +constructor( + private val threadId: String, + private val runId: String, + private val after: String?, + private val before: String?, + private val include: List?, + private val limit: Long?, + private val order: Order?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) { + + fun threadId(): String = threadId + + fun runId(): String = runId + + /** + * A cursor for use in pagination. `after` is an object ID that defines your place in the list. + * For instance, if you make a list request and receive 100 objects, ending with obj_foo, your + * subsequent call can include after=obj_foo in order to fetch the next page of the list. + */ + fun after(): Optional = Optional.ofNullable(after) + + /** + * A cursor for use in pagination. `before` is an object ID that defines your place in the list. + * For instance, if you make a list request and receive 100 objects, starting with obj_foo, your + * subsequent call can include before=obj_foo in order to fetch the previous page of the list. + */ + fun before(): Optional = Optional.ofNullable(before) + + /** + * A list of additional fields to include in the response. Currently the only supported value is + * `step_details.tool_calls[*].file_search.results[*].content` to fetch the file search result + * content. + * + * See the + * [file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search#customizing-file-search-settings) + * for more information. + */ + fun include(): Optional> = Optional.ofNullable(include) + + /** + * A limit on the number of objects to be returned. Limit can range between 1 and 100, and the + * default is 20. + */ + fun limit(): Optional = Optional.ofNullable(limit) + + /** + * Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and `desc` + * for descending order. + */ + fun order(): Optional = Optional.ofNullable(order) + + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + + @JvmSynthetic + internal fun getQueryParams(): QueryParams { + val queryParams = QueryParams.builder() + this.after?.let { queryParams.put("after", listOf(it.toString())) } + this.before?.let { queryParams.put("before", listOf(it.toString())) } + this.include?.let { queryParams.put("include[]", it.map(Any::toString)) } + this.limit?.let { queryParams.put("limit", listOf(it.toString())) } + this.order?.let { queryParams.put("order", listOf(it.toString())) } + queryParams.putAll(additionalQueryParams) + return queryParams.build() + } + + fun getPathParam(index: Int): String { + return when (index) { + 0 -> threadId + 1 -> runId + else -> "" + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + @NoAutoDetect + class Builder { + + private var threadId: String? = null + private var runId: String? = null + private var after: String? = null + private var before: String? = null + private var include: MutableList? = null + private var limit: Long? = null + private var order: Order? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(betaThreadRunStepListParams: BetaThreadRunStepListParams) = apply { + threadId = betaThreadRunStepListParams.threadId + runId = betaThreadRunStepListParams.runId + after = betaThreadRunStepListParams.after + before = betaThreadRunStepListParams.before + include = betaThreadRunStepListParams.include?.toMutableList() + limit = betaThreadRunStepListParams.limit + order = betaThreadRunStepListParams.order + additionalHeaders = betaThreadRunStepListParams.additionalHeaders.toBuilder() + additionalQueryParams = betaThreadRunStepListParams.additionalQueryParams.toBuilder() + } + + fun threadId(threadId: String) = apply { this.threadId = threadId } + + fun runId(runId: String) = apply { this.runId = runId } + + /** + * A cursor for use in pagination. `after` is an object ID that defines your place in the + * list. For instance, if you make a list request and receive 100 objects, ending with + * obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page + * of the list. + */ + fun after(after: String) = apply { this.after = after } + + /** + * A cursor for use in pagination. `before` is an object ID that defines your place in the + * list. For instance, if you make a list request and receive 100 objects, starting with + * obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous + * page of the list. + */ + fun before(before: String) = apply { this.before = before } + + /** + * A list of additional fields to include in the response. Currently the only supported + * value is `step_details.tool_calls[*].file_search.results[*].content` to fetch the file + * search result content. + * + * See the + * [file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search#customizing-file-search-settings) + * for more information. + */ + fun include(include: List) = apply { + this.include = include.toMutableList() + } + + /** + * A list of additional fields to include in the response. Currently the only supported + * value is `step_details.tool_calls[*].file_search.results[*].content` to fetch the file + * search result content. + * + * See the + * [file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search#customizing-file-search-settings) + * for more information. + */ + fun addInclude(include: RunStepInclude) = apply { + this.include = (this.include ?: mutableListOf()).apply { add(include) } + } + + /** + * A limit on the number of objects to be returned. Limit can range between 1 and 100, and + * the default is 20. + */ + fun limit(limit: Long) = apply { this.limit = limit } + + /** + * Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and + * `desc` for descending order. + */ + fun order(order: Order) = apply { this.order = order } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun build(): BetaThreadRunStepListParams = + BetaThreadRunStepListParams( + checkNotNull(threadId) { "`threadId` is required but was not set" }, + checkNotNull(runId) { "`runId` is required but was not set" }, + after, + before, + include?.toImmutable(), + limit, + order, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + class Order + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val ASC = of("asc") + + @JvmField val DESC = of("desc") + + @JvmStatic fun of(value: String) = Order(JsonField.of(value)) + } + + enum class Known { + ASC, + DESC, + } + + enum class Value { + ASC, + DESC, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + ASC -> Value.ASC + DESC -> Value.DESC + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + ASC -> Known.ASC + DESC -> Known.DESC + else -> throw OpenAIInvalidDataException("Unknown Order: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Order && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaThreadRunStepListParams && threadId == other.threadId && runId == other.runId && after == other.after && before == other.before && include == other.include && limit == other.limit && order == other.order && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(threadId, runId, after, before, include, limit, order, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "BetaThreadRunStepListParams{threadId=$threadId, runId=$runId, after=$after, before=$before, include=$include, limit=$limit, order=$order, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRunStepRetrieveParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRunStepRetrieveParams.kt new file mode 100644 index 00000000..c9854ada --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRunStepRetrieveParams.kt @@ -0,0 +1,244 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models + +import com.openai.core.NoAutoDetect +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.core.toImmutable +import java.util.Objects +import java.util.Optional + +class BetaThreadRunStepRetrieveParams +constructor( + private val threadId: String, + private val runId: String, + private val stepId: String, + private val include: List?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) { + + fun threadId(): String = threadId + + fun runId(): String = runId + + fun stepId(): String = stepId + + /** + * A list of additional fields to include in the response. Currently the only supported value is + * `step_details.tool_calls[*].file_search.results[*].content` to fetch the file search result + * content. + * + * See the + * [file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search#customizing-file-search-settings) + * for more information. + */ + fun include(): Optional> = Optional.ofNullable(include) + + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + + @JvmSynthetic + internal fun getQueryParams(): QueryParams { + val queryParams = QueryParams.builder() + this.include?.let { queryParams.put("include[]", it.map(Any::toString)) } + queryParams.putAll(additionalQueryParams) + return queryParams.build() + } + + fun getPathParam(index: Int): String { + return when (index) { + 0 -> threadId + 1 -> runId + 2 -> stepId + else -> "" + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + @NoAutoDetect + class Builder { + + private var threadId: String? = null + private var runId: String? = null + private var stepId: String? = null + private var include: MutableList? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(betaThreadRunStepRetrieveParams: BetaThreadRunStepRetrieveParams) = + apply { + threadId = betaThreadRunStepRetrieveParams.threadId + runId = betaThreadRunStepRetrieveParams.runId + stepId = betaThreadRunStepRetrieveParams.stepId + include = betaThreadRunStepRetrieveParams.include?.toMutableList() + additionalHeaders = betaThreadRunStepRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = + betaThreadRunStepRetrieveParams.additionalQueryParams.toBuilder() + } + + fun threadId(threadId: String) = apply { this.threadId = threadId } + + fun runId(runId: String) = apply { this.runId = runId } + + fun stepId(stepId: String) = apply { this.stepId = stepId } + + /** + * A list of additional fields to include in the response. Currently the only supported + * value is `step_details.tool_calls[*].file_search.results[*].content` to fetch the file + * search result content. + * + * See the + * [file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search#customizing-file-search-settings) + * for more information. + */ + fun include(include: List) = apply { + this.include = include.toMutableList() + } + + /** + * A list of additional fields to include in the response. Currently the only supported + * value is `step_details.tool_calls[*].file_search.results[*].content` to fetch the file + * search result content. + * + * See the + * [file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search#customizing-file-search-settings) + * for more information. + */ + fun addInclude(include: RunStepInclude) = apply { + this.include = (this.include ?: mutableListOf()).apply { add(include) } + } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun build(): BetaThreadRunStepRetrieveParams = + BetaThreadRunStepRetrieveParams( + checkNotNull(threadId) { "`threadId` is required but was not set" }, + checkNotNull(runId) { "`runId` is required but was not set" }, + checkNotNull(stepId) { "`stepId` is required but was not set" }, + include?.toImmutable(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaThreadRunStepRetrieveParams && threadId == other.threadId && runId == other.runId && stepId == other.stepId && include == other.include && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(threadId, runId, stepId, include, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "BetaThreadRunStepRetrieveParams{threadId=$threadId, runId=$runId, stepId=$stepId, include=$include, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRunSubmitToolOutputsParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRunSubmitToolOutputsParams.kt new file mode 100644 index 00000000..24d9568b --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRunSubmitToolOutputsParams.kt @@ -0,0 +1,423 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.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.JsonValue +import com.openai.core.NoAutoDetect +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.core.immutableEmptyMap +import com.openai.core.toImmutable +import java.util.Objects +import java.util.Optional + +class BetaThreadRunSubmitToolOutputsParams +constructor( + private val threadId: String, + private val runId: String, + private val body: BetaThreadRunSubmitToolOutputsBody, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) { + + fun threadId(): String = threadId + + fun runId(): String = runId + + /** A list of tools for which the outputs are being submitted. */ + fun toolOutputs(): List = body.toolOutputs() + + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun _additionalBodyProperties(): Map = body._additionalProperties() + + @JvmSynthetic internal fun getBody(): BetaThreadRunSubmitToolOutputsBody = body + + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + + @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams + + fun getPathParam(index: Int): String { + return when (index) { + 0 -> threadId + 1 -> runId + else -> "" + } + } + + @NoAutoDetect + class BetaThreadRunSubmitToolOutputsBody + @JsonCreator + internal constructor( + @JsonProperty("tool_outputs") private val toolOutputs: List, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** A list of tools for which the outputs are being submitted. */ + @JsonProperty("tool_outputs") fun toolOutputs(): List = toolOutputs + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var toolOutputs: MutableList? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + betaThreadRunSubmitToolOutputsBody: BetaThreadRunSubmitToolOutputsBody + ) = apply { + toolOutputs = betaThreadRunSubmitToolOutputsBody.toolOutputs.toMutableList() + additionalProperties = + betaThreadRunSubmitToolOutputsBody.additionalProperties.toMutableMap() + } + + /** A list of tools for which the outputs are being submitted. */ + fun toolOutputs(toolOutputs: List) = apply { + this.toolOutputs = toolOutputs.toMutableList() + } + + /** A list of tools for which the outputs are being submitted. */ + fun addToolOutput(toolOutput: ToolOutput) = apply { + toolOutputs = (toolOutputs ?: mutableListOf()).apply { add(toolOutput) } + } + + 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) + } + + fun build(): BetaThreadRunSubmitToolOutputsBody = + BetaThreadRunSubmitToolOutputsBody( + checkNotNull(toolOutputs) { "`toolOutputs` is required but was not set" } + .toImmutable(), + additionalProperties.toImmutable() + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaThreadRunSubmitToolOutputsBody && toolOutputs == other.toolOutputs && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(toolOutputs, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaThreadRunSubmitToolOutputsBody{toolOutputs=$toolOutputs, additionalProperties=$additionalProperties}" + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + @NoAutoDetect + class Builder { + + private var threadId: String? = null + private var runId: String? = null + private var body: BetaThreadRunSubmitToolOutputsBody.Builder = + BetaThreadRunSubmitToolOutputsBody.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from( + betaThreadRunSubmitToolOutputsParams: BetaThreadRunSubmitToolOutputsParams + ) = apply { + threadId = betaThreadRunSubmitToolOutputsParams.threadId + runId = betaThreadRunSubmitToolOutputsParams.runId + body = betaThreadRunSubmitToolOutputsParams.body.toBuilder() + additionalHeaders = betaThreadRunSubmitToolOutputsParams.additionalHeaders.toBuilder() + additionalQueryParams = + betaThreadRunSubmitToolOutputsParams.additionalQueryParams.toBuilder() + } + + fun threadId(threadId: String) = apply { this.threadId = threadId } + + fun runId(runId: String) = apply { this.runId = runId } + + /** A list of tools for which the outputs are being submitted. */ + fun toolOutputs(toolOutputs: List) = apply { body.toolOutputs(toolOutputs) } + + /** A list of tools for which the outputs are being submitted. */ + fun addToolOutput(toolOutput: ToolOutput) = apply { body.addToolOutput(toolOutput) } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } + + fun build(): BetaThreadRunSubmitToolOutputsParams = + BetaThreadRunSubmitToolOutputsParams( + checkNotNull(threadId) { "`threadId` is required but was not set" }, + checkNotNull(runId) { "`runId` is required but was not set" }, + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + @NoAutoDetect + class ToolOutput + @JsonCreator + private constructor( + @JsonProperty("tool_call_id") private val toolCallId: String?, + @JsonProperty("output") private val output: String?, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** + * The ID of the tool call in the `required_action` object within the run object the output + * is being submitted for. + */ + @JsonProperty("tool_call_id") + fun toolCallId(): Optional = Optional.ofNullable(toolCallId) + + /** The output of the tool call to be submitted to continue the run. */ + @JsonProperty("output") fun output(): Optional = Optional.ofNullable(output) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var toolCallId: String? = null + private var output: String? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(toolOutput: ToolOutput) = apply { + toolCallId = toolOutput.toolCallId + output = toolOutput.output + additionalProperties = toolOutput.additionalProperties.toMutableMap() + } + + /** + * The ID of the tool call in the `required_action` object within the run object the + * output is being submitted for. + */ + fun toolCallId(toolCallId: String) = apply { this.toolCallId = toolCallId } + + /** The output of the tool call to be submitted to continue the run. */ + fun output(output: String) = apply { this.output = output } + + 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) + } + + fun build(): ToolOutput = + ToolOutput( + toolCallId, + output, + additionalProperties.toImmutable(), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ToolOutput && toolCallId == other.toolCallId && output == other.output && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(toolCallId, output, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ToolOutput{toolCallId=$toolCallId, output=$output, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaThreadRunSubmitToolOutputsParams && threadId == other.threadId && runId == other.runId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(threadId, runId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "BetaThreadRunSubmitToolOutputsParams{threadId=$threadId, runId=$runId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRunUpdateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRunUpdateParams.kt new file mode 100644 index 00000000..24f5d23b --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadRunUpdateParams.kt @@ -0,0 +1,321 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.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.JsonValue +import com.openai.core.NoAutoDetect +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.core.immutableEmptyMap +import com.openai.core.toImmutable +import java.util.Objects +import java.util.Optional + +class BetaThreadRunUpdateParams +constructor( + private val threadId: String, + private val runId: String, + private val body: BetaThreadRunUpdateBody, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) { + + fun threadId(): String = threadId + + fun runId(): String = runId + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for storing + * additional information about the object in a structured format. Keys can be a maximum of 64 + * characters long and values can be a maximum of 512 characters long. + */ + fun metadata(): Optional = body.metadata() + + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun _additionalBodyProperties(): Map = body._additionalProperties() + + @JvmSynthetic internal fun getBody(): BetaThreadRunUpdateBody = body + + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + + @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams + + fun getPathParam(index: Int): String { + return when (index) { + 0 -> threadId + 1 -> runId + else -> "" + } + } + + @NoAutoDetect + class BetaThreadRunUpdateBody + @JsonCreator + internal constructor( + @JsonProperty("metadata") private val metadata: JsonValue?, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format. Keys can be a + * maximum of 64 characters long and values can be a maximum of 512 characters long. + */ + @JsonProperty("metadata") + fun metadata(): Optional = Optional.ofNullable(metadata) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var metadata: JsonValue? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaThreadRunUpdateBody: BetaThreadRunUpdateBody) = apply { + metadata = betaThreadRunUpdateBody.metadata + additionalProperties = betaThreadRunUpdateBody.additionalProperties.toMutableMap() + } + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format. Keys can be a + * maximum of 64 characters long and values can be a maximum of 512 characters long. + */ + fun metadata(metadata: JsonValue) = apply { this.metadata = metadata } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + fun build(): BetaThreadRunUpdateBody = + BetaThreadRunUpdateBody(metadata, additionalProperties.toImmutable()) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaThreadRunUpdateBody && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(metadata, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaThreadRunUpdateBody{metadata=$metadata, additionalProperties=$additionalProperties}" + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + @NoAutoDetect + class Builder { + + private var threadId: String? = null + private var runId: String? = null + private var body: BetaThreadRunUpdateBody.Builder = BetaThreadRunUpdateBody.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(betaThreadRunUpdateParams: BetaThreadRunUpdateParams) = apply { + threadId = betaThreadRunUpdateParams.threadId + runId = betaThreadRunUpdateParams.runId + body = betaThreadRunUpdateParams.body.toBuilder() + additionalHeaders = betaThreadRunUpdateParams.additionalHeaders.toBuilder() + additionalQueryParams = betaThreadRunUpdateParams.additionalQueryParams.toBuilder() + } + + fun threadId(threadId: String) = apply { this.threadId = threadId } + + fun runId(runId: String) = apply { this.runId = runId } + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format. Keys can be a + * maximum of 64 characters long and values can be a maximum of 512 characters long. + */ + fun metadata(metadata: JsonValue) = apply { body.metadata(metadata) } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } + + fun build(): BetaThreadRunUpdateParams = + BetaThreadRunUpdateParams( + checkNotNull(threadId) { "`threadId` is required but was not set" }, + checkNotNull(runId) { "`runId` is required but was not set" }, + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaThreadRunUpdateParams && threadId == other.threadId && runId == other.runId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(threadId, runId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "BetaThreadRunUpdateParams{threadId=$threadId, runId=$runId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadUpdateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadUpdateParams.kt new file mode 100644 index 00000000..aa030853 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaThreadUpdateParams.kt @@ -0,0 +1,657 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.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.JsonValue +import com.openai.core.NoAutoDetect +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.core.immutableEmptyMap +import com.openai.core.toImmutable +import java.util.Objects +import java.util.Optional + +class BetaThreadUpdateParams +constructor( + private val threadId: String, + private val body: BetaThreadUpdateBody, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) { + + fun threadId(): String = threadId + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for storing + * additional information about the object in a structured format. Keys can be a maximum of 64 + * characters long and values can be a maximum of 512 characters long. + */ + fun metadata(): Optional = body.metadata() + + /** + * A set of resources that are made available to the assistant's tools in this thread. The + * resources are specific to the type of tool. For example, the `code_interpreter` tool requires + * a list of file IDs, while the `file_search` tool requires a list of vector store IDs. + */ + fun toolResources(): Optional = body.toolResources() + + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun _additionalBodyProperties(): Map = body._additionalProperties() + + @JvmSynthetic internal fun getBody(): BetaThreadUpdateBody = body + + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + + @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams + + fun getPathParam(index: Int): String { + return when (index) { + 0 -> threadId + else -> "" + } + } + + @NoAutoDetect + class BetaThreadUpdateBody + @JsonCreator + internal constructor( + @JsonProperty("metadata") private val metadata: JsonValue?, + @JsonProperty("tool_resources") private val toolResources: ToolResources?, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format. Keys can be a + * maximum of 64 characters long and values can be a maximum of 512 characters long. + */ + @JsonProperty("metadata") + fun metadata(): Optional = Optional.ofNullable(metadata) + + /** + * A set of resources that are made available to the assistant's tools in this thread. The + * resources are specific to the type of tool. For example, the `code_interpreter` tool + * requires a list of file IDs, while the `file_search` tool requires a list of vector store + * IDs. + */ + @JsonProperty("tool_resources") + fun toolResources(): Optional = Optional.ofNullable(toolResources) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var metadata: JsonValue? = null + private var toolResources: ToolResources? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaThreadUpdateBody: BetaThreadUpdateBody) = apply { + metadata = betaThreadUpdateBody.metadata + toolResources = betaThreadUpdateBody.toolResources + additionalProperties = betaThreadUpdateBody.additionalProperties.toMutableMap() + } + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format. Keys can be a + * maximum of 64 characters long and values can be a maximum of 512 characters long. + */ + fun metadata(metadata: JsonValue) = apply { this.metadata = metadata } + + /** + * A set of resources that are made available to the assistant's tools in this thread. + * The resources are specific to the type of tool. For example, the `code_interpreter` + * tool requires a list of file IDs, while the `file_search` tool requires a list of + * vector store IDs. + */ + fun toolResources(toolResources: ToolResources) = apply { + this.toolResources = toolResources + } + + 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) + } + + fun build(): BetaThreadUpdateBody = + BetaThreadUpdateBody( + metadata, + toolResources, + additionalProperties.toImmutable(), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaThreadUpdateBody && metadata == other.metadata && toolResources == other.toolResources && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(metadata, toolResources, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaThreadUpdateBody{metadata=$metadata, toolResources=$toolResources, additionalProperties=$additionalProperties}" + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + @NoAutoDetect + class Builder { + + private var threadId: String? = null + private var body: BetaThreadUpdateBody.Builder = BetaThreadUpdateBody.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(betaThreadUpdateParams: BetaThreadUpdateParams) = apply { + threadId = betaThreadUpdateParams.threadId + body = betaThreadUpdateParams.body.toBuilder() + additionalHeaders = betaThreadUpdateParams.additionalHeaders.toBuilder() + additionalQueryParams = betaThreadUpdateParams.additionalQueryParams.toBuilder() + } + + fun threadId(threadId: String) = apply { this.threadId = threadId } + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format. Keys can be a + * maximum of 64 characters long and values can be a maximum of 512 characters long. + */ + fun metadata(metadata: JsonValue) = apply { body.metadata(metadata) } + + /** + * A set of resources that are made available to the assistant's tools in this thread. The + * resources are specific to the type of tool. For example, the `code_interpreter` tool + * requires a list of file IDs, while the `file_search` tool requires a list of vector store + * IDs. + */ + fun toolResources(toolResources: ToolResources) = apply { + body.toolResources(toolResources) + } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } + + fun build(): BetaThreadUpdateParams = + BetaThreadUpdateParams( + checkNotNull(threadId) { "`threadId` is required but was not set" }, + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + /** + * A set of resources that are made available to the assistant's tools in this thread. The + * resources are specific to the type of tool. For example, the `code_interpreter` tool requires + * a list of file IDs, while the `file_search` tool requires a list of vector store IDs. + */ + @NoAutoDetect + class ToolResources + @JsonCreator + private constructor( + @JsonProperty("code_interpreter") private val codeInterpreter: CodeInterpreter?, + @JsonProperty("file_search") private val fileSearch: FileSearch?, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + @JsonProperty("code_interpreter") + fun codeInterpreter(): Optional = Optional.ofNullable(codeInterpreter) + + @JsonProperty("file_search") + fun fileSearch(): Optional = Optional.ofNullable(fileSearch) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var codeInterpreter: CodeInterpreter? = null + private var fileSearch: FileSearch? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(toolResources: ToolResources) = apply { + codeInterpreter = toolResources.codeInterpreter + fileSearch = toolResources.fileSearch + additionalProperties = toolResources.additionalProperties.toMutableMap() + } + + fun codeInterpreter(codeInterpreter: CodeInterpreter) = apply { + this.codeInterpreter = codeInterpreter + } + + fun fileSearch(fileSearch: FileSearch) = apply { this.fileSearch = fileSearch } + + 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) + } + + fun build(): ToolResources = + ToolResources( + codeInterpreter, + fileSearch, + additionalProperties.toImmutable(), + ) + } + + @NoAutoDetect + class CodeInterpreter + @JsonCreator + private constructor( + @JsonProperty("file_ids") private val fileIds: List?, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** + * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made + * available to the `code_interpreter` tool. There can be a maximum of 20 files + * associated with the tool. + */ + @JsonProperty("file_ids") + fun fileIds(): Optional> = Optional.ofNullable(fileIds) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var fileIds: MutableList? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(codeInterpreter: CodeInterpreter) = apply { + fileIds = codeInterpreter.fileIds?.toMutableList() + additionalProperties = codeInterpreter.additionalProperties.toMutableMap() + } + + /** + * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made + * available to the `code_interpreter` tool. There can be a maximum of 20 files + * associated with the tool. + */ + fun fileIds(fileIds: List) = apply { + this.fileIds = fileIds.toMutableList() + } + + /** + * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made + * available to the `code_interpreter` tool. There can be a maximum of 20 files + * associated with the tool. + */ + fun addFileId(fileId: String) = apply { + fileIds = (fileIds ?: mutableListOf()).apply { add(fileId) } + } + + 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) + } + + fun build(): CodeInterpreter = + CodeInterpreter(fileIds?.toImmutable(), additionalProperties.toImmutable()) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is CodeInterpreter && fileIds == other.fileIds && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(fileIds, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CodeInterpreter{fileIds=$fileIds, additionalProperties=$additionalProperties}" + } + + @NoAutoDetect + class FileSearch + @JsonCreator + private constructor( + @JsonProperty("vector_store_ids") private val vectorStoreIds: List?, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** + * The + * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object) + * attached to this thread. There can be a maximum of 1 vector store attached to the + * thread. + */ + @JsonProperty("vector_store_ids") + fun vectorStoreIds(): Optional> = Optional.ofNullable(vectorStoreIds) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var vectorStoreIds: MutableList? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(fileSearch: FileSearch) = apply { + vectorStoreIds = fileSearch.vectorStoreIds?.toMutableList() + additionalProperties = fileSearch.additionalProperties.toMutableMap() + } + + /** + * The + * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object) + * attached to this thread. There can be a maximum of 1 vector store attached to the + * thread. + */ + fun vectorStoreIds(vectorStoreIds: List) = apply { + this.vectorStoreIds = vectorStoreIds.toMutableList() + } + + /** + * The + * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object) + * attached to this thread. There can be a maximum of 1 vector store attached to the + * thread. + */ + fun addVectorStoreId(vectorStoreId: String) = apply { + vectorStoreIds = + (vectorStoreIds ?: mutableListOf()).apply { add(vectorStoreId) } + } + + 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) + } + + fun build(): FileSearch = + FileSearch(vectorStoreIds?.toImmutable(), additionalProperties.toImmutable()) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is FileSearch && vectorStoreIds == other.vectorStoreIds && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(vectorStoreIds, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "FileSearch{vectorStoreIds=$vectorStoreIds, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ToolResources && codeInterpreter == other.codeInterpreter && fileSearch == other.fileSearch && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(codeInterpreter, fileSearch, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ToolResources{codeInterpreter=$codeInterpreter, fileSearch=$fileSearch, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaThreadUpdateParams && threadId == other.threadId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(threadId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "BetaThreadUpdateParams{threadId=$threadId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreCreateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreCreateParams.kt new file mode 100644 index 00000000..4cebe525 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreCreateParams.kt @@ -0,0 +1,597 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.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.Enum +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonValue +import com.openai.core.NoAutoDetect +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.core.immutableEmptyMap +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Objects +import java.util.Optional + +class BetaVectorStoreCreateParams +constructor( + private val body: BetaVectorStoreCreateBody, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) { + + /** + * The chunking strategy used to chunk the file(s). If not set, will use the `auto` strategy. + * Only applicable if `file_ids` is non-empty. + */ + fun chunkingStrategy(): Optional = body.chunkingStrategy() + + /** The expiration policy for a vector store. */ + fun expiresAfter(): Optional = body.expiresAfter() + + /** + * A list of [File](https://platform.openai.com/docs/api-reference/files) IDs that the vector + * store should use. Useful for tools like `file_search` that can access files. + */ + fun fileIds(): Optional> = body.fileIds() + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for storing + * additional information about the object in a structured format. Keys can be a maximum of 64 + * characters long and values can be a maximum of 512 characters long. + */ + fun metadata(): Optional = body.metadata() + + /** The name of the vector store. */ + fun name(): Optional = body.name() + + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun _additionalBodyProperties(): Map = body._additionalProperties() + + @JvmSynthetic internal fun getBody(): BetaVectorStoreCreateBody = body + + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + + @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams + + @NoAutoDetect + class BetaVectorStoreCreateBody + @JsonCreator + internal constructor( + @JsonProperty("chunking_strategy") private val chunkingStrategy: FileChunkingStrategyParam?, + @JsonProperty("expires_after") private val expiresAfter: ExpiresAfter?, + @JsonProperty("file_ids") private val fileIds: List?, + @JsonProperty("metadata") private val metadata: JsonValue?, + @JsonProperty("name") private val name: String?, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** + * The chunking strategy used to chunk the file(s). If not set, will use the `auto` + * strategy. Only applicable if `file_ids` is non-empty. + */ + @JsonProperty("chunking_strategy") + fun chunkingStrategy(): Optional = + Optional.ofNullable(chunkingStrategy) + + /** The expiration policy for a vector store. */ + @JsonProperty("expires_after") + fun expiresAfter(): Optional = Optional.ofNullable(expiresAfter) + + /** + * A list of [File](https://platform.openai.com/docs/api-reference/files) IDs that the + * vector store should use. Useful for tools like `file_search` that can access files. + */ + @JsonProperty("file_ids") + fun fileIds(): Optional> = Optional.ofNullable(fileIds) + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format. Keys can be a + * maximum of 64 characters long and values can be a maximum of 512 characters long. + */ + @JsonProperty("metadata") + fun metadata(): Optional = Optional.ofNullable(metadata) + + /** The name of the vector store. */ + @JsonProperty("name") fun name(): Optional = Optional.ofNullable(name) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var chunkingStrategy: FileChunkingStrategyParam? = null + private var expiresAfter: ExpiresAfter? = null + private var fileIds: MutableList? = null + private var metadata: JsonValue? = null + private var name: String? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaVectorStoreCreateBody: BetaVectorStoreCreateBody) = apply { + chunkingStrategy = betaVectorStoreCreateBody.chunkingStrategy + expiresAfter = betaVectorStoreCreateBody.expiresAfter + fileIds = betaVectorStoreCreateBody.fileIds?.toMutableList() + metadata = betaVectorStoreCreateBody.metadata + name = betaVectorStoreCreateBody.name + additionalProperties = betaVectorStoreCreateBody.additionalProperties.toMutableMap() + } + + /** + * The chunking strategy used to chunk the file(s). If not set, will use the `auto` + * strategy. Only applicable if `file_ids` is non-empty. + */ + fun chunkingStrategy(chunkingStrategy: FileChunkingStrategyParam) = apply { + this.chunkingStrategy = chunkingStrategy + } + + /** + * The default strategy. This strategy currently uses a `max_chunk_size_tokens` of `800` + * and `chunk_overlap_tokens` of `400`. + */ + fun chunkingStrategy(autoFileChunkingStrategyParam: AutoFileChunkingStrategyParam) = + apply { + this.chunkingStrategy = + FileChunkingStrategyParam.ofAutoFileChunkingStrategyParam( + autoFileChunkingStrategyParam + ) + } + + fun chunkingStrategy(staticFileChunkingStrategyParam: StaticFileChunkingStrategyParam) = + apply { + this.chunkingStrategy = + FileChunkingStrategyParam.ofStaticFileChunkingStrategyParam( + staticFileChunkingStrategyParam + ) + } + + /** The expiration policy for a vector store. */ + fun expiresAfter(expiresAfter: ExpiresAfter) = apply { + this.expiresAfter = expiresAfter + } + + /** + * A list of [File](https://platform.openai.com/docs/api-reference/files) IDs that the + * vector store should use. Useful for tools like `file_search` that can access files. + */ + fun fileIds(fileIds: List) = apply { this.fileIds = fileIds.toMutableList() } + + /** + * A list of [File](https://platform.openai.com/docs/api-reference/files) IDs that the + * vector store should use. Useful for tools like `file_search` that can access files. + */ + fun addFileId(fileId: String) = apply { + fileIds = (fileIds ?: mutableListOf()).apply { add(fileId) } + } + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format. Keys can be a + * maximum of 64 characters long and values can be a maximum of 512 characters long. + */ + fun metadata(metadata: JsonValue) = apply { this.metadata = metadata } + + /** The name of the vector store. */ + fun name(name: String) = apply { this.name = name } + + 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) + } + + fun build(): BetaVectorStoreCreateBody = + BetaVectorStoreCreateBody( + chunkingStrategy, + expiresAfter, + fileIds?.toImmutable(), + metadata, + name, + additionalProperties.toImmutable(), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaVectorStoreCreateBody && chunkingStrategy == other.chunkingStrategy && expiresAfter == other.expiresAfter && fileIds == other.fileIds && metadata == other.metadata && name == other.name && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(chunkingStrategy, expiresAfter, fileIds, metadata, name, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaVectorStoreCreateBody{chunkingStrategy=$chunkingStrategy, expiresAfter=$expiresAfter, fileIds=$fileIds, metadata=$metadata, name=$name, additionalProperties=$additionalProperties}" + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + @NoAutoDetect + class Builder { + + private var body: BetaVectorStoreCreateBody.Builder = BetaVectorStoreCreateBody.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(betaVectorStoreCreateParams: BetaVectorStoreCreateParams) = apply { + body = betaVectorStoreCreateParams.body.toBuilder() + additionalHeaders = betaVectorStoreCreateParams.additionalHeaders.toBuilder() + additionalQueryParams = betaVectorStoreCreateParams.additionalQueryParams.toBuilder() + } + + /** + * The chunking strategy used to chunk the file(s). If not set, will use the `auto` + * strategy. Only applicable if `file_ids` is non-empty. + */ + fun chunkingStrategy(chunkingStrategy: FileChunkingStrategyParam) = apply { + body.chunkingStrategy(chunkingStrategy) + } + + /** + * The default strategy. This strategy currently uses a `max_chunk_size_tokens` of `800` and + * `chunk_overlap_tokens` of `400`. + */ + fun chunkingStrategy(autoFileChunkingStrategyParam: AutoFileChunkingStrategyParam) = apply { + body.chunkingStrategy(autoFileChunkingStrategyParam) + } + + fun chunkingStrategy(staticFileChunkingStrategyParam: StaticFileChunkingStrategyParam) = + apply { + body.chunkingStrategy(staticFileChunkingStrategyParam) + } + + /** The expiration policy for a vector store. */ + fun expiresAfter(expiresAfter: ExpiresAfter) = apply { body.expiresAfter(expiresAfter) } + + /** + * A list of [File](https://platform.openai.com/docs/api-reference/files) IDs that the + * vector store should use. Useful for tools like `file_search` that can access files. + */ + fun fileIds(fileIds: List) = apply { body.fileIds(fileIds) } + + /** + * A list of [File](https://platform.openai.com/docs/api-reference/files) IDs that the + * vector store should use. Useful for tools like `file_search` that can access files. + */ + fun addFileId(fileId: String) = apply { body.addFileId(fileId) } + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format. Keys can be a + * maximum of 64 characters long and values can be a maximum of 512 characters long. + */ + fun metadata(metadata: JsonValue) = apply { body.metadata(metadata) } + + /** The name of the vector store. */ + fun name(name: String) = apply { body.name(name) } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } + + fun build(): BetaVectorStoreCreateParams = + BetaVectorStoreCreateParams( + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + /** The expiration policy for a vector store. */ + @NoAutoDetect + class ExpiresAfter + @JsonCreator + private constructor( + @JsonProperty("anchor") private val anchor: Anchor, + @JsonProperty("days") private val days: Long, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** + * Anchor timestamp after which the expiration policy applies. Supported anchors: + * `last_active_at`. + */ + @JsonProperty("anchor") fun anchor(): Anchor = anchor + + /** The number of days after the anchor time that the vector store will expire. */ + @JsonProperty("days") fun days(): Long = days + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var anchor: Anchor? = null + private var days: Long? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(expiresAfter: ExpiresAfter) = apply { + anchor = expiresAfter.anchor + days = expiresAfter.days + additionalProperties = expiresAfter.additionalProperties.toMutableMap() + } + + /** + * Anchor timestamp after which the expiration policy applies. Supported anchors: + * `last_active_at`. + */ + fun anchor(anchor: Anchor) = apply { this.anchor = anchor } + + /** The number of days after the anchor time that the vector store will expire. */ + fun days(days: Long) = apply { this.days = days } + + 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) + } + + fun build(): ExpiresAfter = + ExpiresAfter( + checkNotNull(anchor) { "`anchor` is required but was not set" }, + checkNotNull(days) { "`days` is required but was not set" }, + additionalProperties.toImmutable(), + ) + } + + class Anchor + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val LAST_ACTIVE_AT = of("last_active_at") + + @JvmStatic fun of(value: String) = Anchor(JsonField.of(value)) + } + + enum class Known { + LAST_ACTIVE_AT, + } + + enum class Value { + LAST_ACTIVE_AT, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + LAST_ACTIVE_AT -> Value.LAST_ACTIVE_AT + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + LAST_ACTIVE_AT -> Known.LAST_ACTIVE_AT + else -> throw OpenAIInvalidDataException("Unknown Anchor: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Anchor && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ExpiresAfter && anchor == other.anchor && days == other.days && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(anchor, days, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ExpiresAfter{anchor=$anchor, days=$days, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaVectorStoreCreateParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "BetaVectorStoreCreateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreDeleteParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreDeleteParams.kt new file mode 100644 index 00000000..763c5163 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreDeleteParams.kt @@ -0,0 +1,211 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models + +import com.openai.core.JsonValue +import com.openai.core.NoAutoDetect +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.core.toImmutable +import java.util.Objects +import java.util.Optional + +class BetaVectorStoreDeleteParams +constructor( + private val vectorStoreId: String, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, + private val additionalBodyProperties: Map, +) { + + fun vectorStoreId(): String = vectorStoreId + + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun _additionalBodyProperties(): Map = additionalBodyProperties + + @JvmSynthetic + internal fun getBody(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + + @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams + + fun getPathParam(index: Int): String { + return when (index) { + 0 -> vectorStoreId + else -> "" + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + @NoAutoDetect + class Builder { + + private var vectorStoreId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + private var additionalBodyProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaVectorStoreDeleteParams: BetaVectorStoreDeleteParams) = apply { + vectorStoreId = betaVectorStoreDeleteParams.vectorStoreId + additionalHeaders = betaVectorStoreDeleteParams.additionalHeaders.toBuilder() + additionalQueryParams = betaVectorStoreDeleteParams.additionalQueryParams.toBuilder() + additionalBodyProperties = + betaVectorStoreDeleteParams.additionalBodyProperties.toMutableMap() + } + + fun vectorStoreId(vectorStoreId: String) = apply { this.vectorStoreId = vectorStoreId } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + this.additionalBodyProperties.clear() + putAllAdditionalBodyProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + additionalBodyProperties.put(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + this.additionalBodyProperties.putAll(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { + additionalBodyProperties.remove(key) + } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalBodyProperty) + } + + fun build(): BetaVectorStoreDeleteParams = + BetaVectorStoreDeleteParams( + checkNotNull(vectorStoreId) { "`vectorStoreId` is required but was not set" }, + additionalHeaders.build(), + additionalQueryParams.build(), + additionalBodyProperties.toImmutable(), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaVectorStoreDeleteParams && vectorStoreId == other.vectorStoreId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(vectorStoreId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ + + override fun toString() = + "BetaVectorStoreDeleteParams{vectorStoreId=$vectorStoreId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreFileBatchCancelParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreFileBatchCancelParams.kt new file mode 100644 index 00000000..44642737 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreFileBatchCancelParams.kt @@ -0,0 +1,223 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models + +import com.openai.core.JsonValue +import com.openai.core.NoAutoDetect +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.core.toImmutable +import java.util.Objects +import java.util.Optional + +class BetaVectorStoreFileBatchCancelParams +constructor( + private val vectorStoreId: String, + private val batchId: String, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, + private val additionalBodyProperties: Map, +) { + + fun vectorStoreId(): String = vectorStoreId + + fun batchId(): String = batchId + + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun _additionalBodyProperties(): Map = additionalBodyProperties + + @JvmSynthetic + internal fun getBody(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + + @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams + + fun getPathParam(index: Int): String { + return when (index) { + 0 -> vectorStoreId + 1 -> batchId + else -> "" + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + @NoAutoDetect + class Builder { + + private var vectorStoreId: String? = null + private var batchId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + private var additionalBodyProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + betaVectorStoreFileBatchCancelParams: BetaVectorStoreFileBatchCancelParams + ) = apply { + vectorStoreId = betaVectorStoreFileBatchCancelParams.vectorStoreId + batchId = betaVectorStoreFileBatchCancelParams.batchId + additionalHeaders = betaVectorStoreFileBatchCancelParams.additionalHeaders.toBuilder() + additionalQueryParams = + betaVectorStoreFileBatchCancelParams.additionalQueryParams.toBuilder() + additionalBodyProperties = + betaVectorStoreFileBatchCancelParams.additionalBodyProperties.toMutableMap() + } + + fun vectorStoreId(vectorStoreId: String) = apply { this.vectorStoreId = vectorStoreId } + + fun batchId(batchId: String) = apply { this.batchId = batchId } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + this.additionalBodyProperties.clear() + putAllAdditionalBodyProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + additionalBodyProperties.put(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + this.additionalBodyProperties.putAll(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { + additionalBodyProperties.remove(key) + } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalBodyProperty) + } + + fun build(): BetaVectorStoreFileBatchCancelParams = + BetaVectorStoreFileBatchCancelParams( + checkNotNull(vectorStoreId) { "`vectorStoreId` is required but was not set" }, + checkNotNull(batchId) { "`batchId` is required but was not set" }, + additionalHeaders.build(), + additionalQueryParams.build(), + additionalBodyProperties.toImmutable(), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaVectorStoreFileBatchCancelParams && vectorStoreId == other.vectorStoreId && batchId == other.batchId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(vectorStoreId, batchId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ + + override fun toString() = + "BetaVectorStoreFileBatchCancelParams{vectorStoreId=$vectorStoreId, batchId=$batchId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreFileBatchCreateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreFileBatchCreateParams.kt new file mode 100644 index 00000000..0134b5e9 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreFileBatchCreateParams.kt @@ -0,0 +1,398 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.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.JsonValue +import com.openai.core.NoAutoDetect +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.core.immutableEmptyMap +import com.openai.core.toImmutable +import java.util.Objects +import java.util.Optional + +class BetaVectorStoreFileBatchCreateParams +constructor( + private val vectorStoreId: String, + private val body: BetaVectorStoreFileBatchCreateBody, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) { + + fun vectorStoreId(): String = vectorStoreId + + /** + * A list of [File](https://platform.openai.com/docs/api-reference/files) IDs that the vector + * store should use. Useful for tools like `file_search` that can access files. + */ + fun fileIds(): List = body.fileIds() + + /** + * The chunking strategy used to chunk the file(s). If not set, will use the `auto` strategy. + * Only applicable if `file_ids` is non-empty. + */ + fun chunkingStrategy(): Optional = body.chunkingStrategy() + + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun _additionalBodyProperties(): Map = body._additionalProperties() + + @JvmSynthetic internal fun getBody(): BetaVectorStoreFileBatchCreateBody = body + + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + + @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams + + fun getPathParam(index: Int): String { + return when (index) { + 0 -> vectorStoreId + else -> "" + } + } + + @NoAutoDetect + class BetaVectorStoreFileBatchCreateBody + @JsonCreator + internal constructor( + @JsonProperty("file_ids") private val fileIds: List, + @JsonProperty("chunking_strategy") private val chunkingStrategy: FileChunkingStrategyParam?, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** + * A list of [File](https://platform.openai.com/docs/api-reference/files) IDs that the + * vector store should use. Useful for tools like `file_search` that can access files. + */ + @JsonProperty("file_ids") fun fileIds(): List = fileIds + + /** + * The chunking strategy used to chunk the file(s). If not set, will use the `auto` + * strategy. Only applicable if `file_ids` is non-empty. + */ + @JsonProperty("chunking_strategy") + fun chunkingStrategy(): Optional = + Optional.ofNullable(chunkingStrategy) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var fileIds: MutableList? = null + private var chunkingStrategy: FileChunkingStrategyParam? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + betaVectorStoreFileBatchCreateBody: BetaVectorStoreFileBatchCreateBody + ) = apply { + fileIds = betaVectorStoreFileBatchCreateBody.fileIds.toMutableList() + chunkingStrategy = betaVectorStoreFileBatchCreateBody.chunkingStrategy + additionalProperties = + betaVectorStoreFileBatchCreateBody.additionalProperties.toMutableMap() + } + + /** + * A list of [File](https://platform.openai.com/docs/api-reference/files) IDs that the + * vector store should use. Useful for tools like `file_search` that can access files. + */ + fun fileIds(fileIds: List) = apply { this.fileIds = fileIds.toMutableList() } + + /** + * A list of [File](https://platform.openai.com/docs/api-reference/files) IDs that the + * vector store should use. Useful for tools like `file_search` that can access files. + */ + fun addFileId(fileId: String) = apply { + fileIds = (fileIds ?: mutableListOf()).apply { add(fileId) } + } + + /** + * The chunking strategy used to chunk the file(s). If not set, will use the `auto` + * strategy. Only applicable if `file_ids` is non-empty. + */ + fun chunkingStrategy(chunkingStrategy: FileChunkingStrategyParam) = apply { + this.chunkingStrategy = chunkingStrategy + } + + /** + * The default strategy. This strategy currently uses a `max_chunk_size_tokens` of `800` + * and `chunk_overlap_tokens` of `400`. + */ + fun chunkingStrategy(autoFileChunkingStrategyParam: AutoFileChunkingStrategyParam) = + apply { + this.chunkingStrategy = + FileChunkingStrategyParam.ofAutoFileChunkingStrategyParam( + autoFileChunkingStrategyParam + ) + } + + fun chunkingStrategy(staticFileChunkingStrategyParam: StaticFileChunkingStrategyParam) = + apply { + this.chunkingStrategy = + FileChunkingStrategyParam.ofStaticFileChunkingStrategyParam( + staticFileChunkingStrategyParam + ) + } + + 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) + } + + fun build(): BetaVectorStoreFileBatchCreateBody = + BetaVectorStoreFileBatchCreateBody( + checkNotNull(fileIds) { "`fileIds` is required but was not set" }.toImmutable(), + chunkingStrategy, + additionalProperties.toImmutable(), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaVectorStoreFileBatchCreateBody && fileIds == other.fileIds && chunkingStrategy == other.chunkingStrategy && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(fileIds, chunkingStrategy, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaVectorStoreFileBatchCreateBody{fileIds=$fileIds, chunkingStrategy=$chunkingStrategy, additionalProperties=$additionalProperties}" + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + @NoAutoDetect + class Builder { + + private var vectorStoreId: String? = null + private var body: BetaVectorStoreFileBatchCreateBody.Builder = + BetaVectorStoreFileBatchCreateBody.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from( + betaVectorStoreFileBatchCreateParams: BetaVectorStoreFileBatchCreateParams + ) = apply { + vectorStoreId = betaVectorStoreFileBatchCreateParams.vectorStoreId + body = betaVectorStoreFileBatchCreateParams.body.toBuilder() + additionalHeaders = betaVectorStoreFileBatchCreateParams.additionalHeaders.toBuilder() + additionalQueryParams = + betaVectorStoreFileBatchCreateParams.additionalQueryParams.toBuilder() + } + + fun vectorStoreId(vectorStoreId: String) = apply { this.vectorStoreId = vectorStoreId } + + /** + * A list of [File](https://platform.openai.com/docs/api-reference/files) IDs that the + * vector store should use. Useful for tools like `file_search` that can access files. + */ + fun fileIds(fileIds: List) = apply { body.fileIds(fileIds) } + + /** + * A list of [File](https://platform.openai.com/docs/api-reference/files) IDs that the + * vector store should use. Useful for tools like `file_search` that can access files. + */ + fun addFileId(fileId: String) = apply { body.addFileId(fileId) } + + /** + * The chunking strategy used to chunk the file(s). If not set, will use the `auto` + * strategy. Only applicable if `file_ids` is non-empty. + */ + fun chunkingStrategy(chunkingStrategy: FileChunkingStrategyParam) = apply { + body.chunkingStrategy(chunkingStrategy) + } + + /** + * The default strategy. This strategy currently uses a `max_chunk_size_tokens` of `800` and + * `chunk_overlap_tokens` of `400`. + */ + fun chunkingStrategy(autoFileChunkingStrategyParam: AutoFileChunkingStrategyParam) = apply { + body.chunkingStrategy(autoFileChunkingStrategyParam) + } + + fun chunkingStrategy(staticFileChunkingStrategyParam: StaticFileChunkingStrategyParam) = + apply { + body.chunkingStrategy(staticFileChunkingStrategyParam) + } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } + + fun build(): BetaVectorStoreFileBatchCreateParams = + BetaVectorStoreFileBatchCreateParams( + checkNotNull(vectorStoreId) { "`vectorStoreId` is required but was not set" }, + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaVectorStoreFileBatchCreateParams && vectorStoreId == other.vectorStoreId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(vectorStoreId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "BetaVectorStoreFileBatchCreateParams{vectorStoreId=$vectorStoreId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreFileBatchListFilesPage.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreFileBatchListFilesPage.kt new file mode 100644 index 00000000..af32f7bb --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreFileBatchListFilesPage.kt @@ -0,0 +1,174 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.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.NoAutoDetect +import com.openai.core.immutableEmptyMap +import com.openai.core.toImmutable +import com.openai.services.blocking.beta.vectorStores.FileBatchService +import java.util.Objects +import java.util.Optional +import java.util.stream.Stream +import java.util.stream.StreamSupport + +class BetaVectorStoreFileBatchListFilesPage +private constructor( + private val fileBatchesService: FileBatchService, + private val params: BetaVectorStoreFileBatchListFilesParams, + private val response: Response, +) { + + fun response(): Response = response + + fun data(): List = response().data() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaVectorStoreFileBatchListFilesPage && 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() = + "BetaVectorStoreFileBatchListFilesPage{fileBatchesService=$fileBatchesService, params=$params, response=$response}" + + fun hasNextPage(): Boolean { + return !data().isEmpty() + } + + fun getNextPageParams(): Optional { + if (!hasNextPage()) { + return Optional.empty() + } + + return Optional.of( + BetaVectorStoreFileBatchListFilesParams.builder() + .from(params) + .after(data().last().id()) + .build() + ) + } + + fun getNextPage(): Optional { + return getNextPageParams().map { fileBatchesService.listFiles(it) } + } + + fun autoPager(): AutoPager = AutoPager(this) + + companion object { + + @JvmStatic + fun of( + fileBatchesService: FileBatchService, + params: BetaVectorStoreFileBatchListFilesParams, + response: Response + ) = + BetaVectorStoreFileBatchListFilesPage( + fileBatchesService, + params, + response, + ) + } + + @NoAutoDetect + class Response + @JsonCreator + constructor( + @JsonProperty("data") private val data: JsonField> = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + private var validated: Boolean = false + + fun data(): List = data.getNullable("data") ?: listOf() + + @JsonProperty("data") + fun _data(): Optional>> = Optional.ofNullable(data) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Response = apply { + if (!validated) { + data().map { it.validate() } + validated = true + } + } + + 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 && additionalProperties == other.additionalProperties /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, additionalProperties) /* spotless:on */ + + override fun toString() = "Response{data=$data, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var data: JsonField> = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(page: Response) = apply { + this.data = page.data + this.additionalProperties.putAll(page.additionalProperties) + } + + fun data(data: List) = data(JsonField.of(data)) + + fun data(data: JsonField>) = apply { this.data = data } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun build() = Response(data, additionalProperties.toImmutable()) + } + } + + class AutoPager + constructor( + private val firstPage: BetaVectorStoreFileBatchListFilesPage, + ) : Iterable { + + override fun iterator(): Iterator = iterator { + var page = firstPage + var index = 0 + while (true) { + while (index < page.data().size) { + yield(page.data()[index++]) + } + page = page.getNextPage().orElse(null) ?: break + index = 0 + } + } + + fun stream(): Stream { + return StreamSupport.stream(spliterator(), false) + } + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreFileBatchListFilesPageAsync.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreFileBatchListFilesPageAsync.kt new file mode 100644 index 00000000..3158e7b4 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreFileBatchListFilesPageAsync.kt @@ -0,0 +1,187 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.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.NoAutoDetect +import com.openai.core.immutableEmptyMap +import com.openai.core.toImmutable +import com.openai.services.async.beta.vectorStores.FileBatchServiceAsync +import java.util.Objects +import java.util.Optional +import java.util.concurrent.CompletableFuture +import java.util.concurrent.Executor +import java.util.function.Predicate + +class BetaVectorStoreFileBatchListFilesPageAsync +private constructor( + private val fileBatchesService: FileBatchServiceAsync, + private val params: BetaVectorStoreFileBatchListFilesParams, + private val response: Response, +) { + + fun response(): Response = response + + fun data(): List = response().data() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaVectorStoreFileBatchListFilesPageAsync && 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() = + "BetaVectorStoreFileBatchListFilesPageAsync{fileBatchesService=$fileBatchesService, params=$params, response=$response}" + + fun hasNextPage(): Boolean { + return !data().isEmpty() + } + + fun getNextPageParams(): Optional { + if (!hasNextPage()) { + return Optional.empty() + } + + return Optional.of( + BetaVectorStoreFileBatchListFilesParams.builder() + .from(params) + .after(data().last().id()) + .build() + ) + } + + fun getNextPage(): CompletableFuture> { + return getNextPageParams() + .map { fileBatchesService.listFiles(it).thenApply { Optional.of(it) } } + .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + } + + fun autoPager(): AutoPager = AutoPager(this) + + companion object { + + @JvmStatic + fun of( + fileBatchesService: FileBatchServiceAsync, + params: BetaVectorStoreFileBatchListFilesParams, + response: Response + ) = + BetaVectorStoreFileBatchListFilesPageAsync( + fileBatchesService, + params, + response, + ) + } + + @NoAutoDetect + class Response + @JsonCreator + constructor( + @JsonProperty("data") private val data: JsonField> = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + private var validated: Boolean = false + + fun data(): List = data.getNullable("data") ?: listOf() + + @JsonProperty("data") + fun _data(): Optional>> = Optional.ofNullable(data) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Response = apply { + if (!validated) { + data().map { it.validate() } + validated = true + } + } + + 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 && additionalProperties == other.additionalProperties /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, additionalProperties) /* spotless:on */ + + override fun toString() = "Response{data=$data, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var data: JsonField> = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(page: Response) = apply { + this.data = page.data + this.additionalProperties.putAll(page.additionalProperties) + } + + fun data(data: List) = data(JsonField.of(data)) + + fun data(data: JsonField>) = apply { this.data = data } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun build() = Response(data, additionalProperties.toImmutable()) + } + } + + class AutoPager + constructor( + private val firstPage: BetaVectorStoreFileBatchListFilesPageAsync, + ) { + + fun forEach( + action: Predicate, + executor: Executor + ): CompletableFuture { + fun CompletableFuture>.forEach( + action: (VectorStoreFile) -> Boolean, + executor: Executor + ): CompletableFuture = + thenComposeAsync( + { page -> + page + .filter { it.data().all(action) } + .map { it.getNextPage().forEach(action, executor) } + .orElseGet { CompletableFuture.completedFuture(null) } + }, + executor + ) + return CompletableFuture.completedFuture(Optional.of(firstPage)) + .forEach(action::test, executor) + } + + fun toList(executor: Executor): CompletableFuture> { + val values = mutableListOf() + return forEach(values::add, executor).thenApply { values } + } + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreFileBatchListFilesParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreFileBatchListFilesParams.kt new file mode 100644 index 00000000..f7c99e63 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreFileBatchListFilesParams.kt @@ -0,0 +1,409 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models + +import com.fasterxml.jackson.annotation.JsonCreator +import com.openai.core.Enum +import com.openai.core.JsonField +import com.openai.core.NoAutoDetect +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.errors.OpenAIInvalidDataException +import java.util.Objects +import java.util.Optional + +class BetaVectorStoreFileBatchListFilesParams +constructor( + private val vectorStoreId: String, + private val batchId: String, + private val after: String?, + private val before: String?, + private val filter: Filter?, + private val limit: Long?, + private val order: Order?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) { + + fun vectorStoreId(): String = vectorStoreId + + fun batchId(): String = batchId + + /** + * A cursor for use in pagination. `after` is an object ID that defines your place in the list. + * For instance, if you make a list request and receive 100 objects, ending with obj_foo, your + * subsequent call can include after=obj_foo in order to fetch the next page of the list. + */ + fun after(): Optional = Optional.ofNullable(after) + + /** + * A cursor for use in pagination. `before` is an object ID that defines your place in the list. + * For instance, if you make a list request and receive 100 objects, starting with obj_foo, your + * subsequent call can include before=obj_foo in order to fetch the previous page of the list. + */ + fun before(): Optional = Optional.ofNullable(before) + + /** Filter by file status. One of `in_progress`, `completed`, `failed`, `cancelled`. */ + fun filter(): Optional = Optional.ofNullable(filter) + + /** + * A limit on the number of objects to be returned. Limit can range between 1 and 100, and the + * default is 20. + */ + fun limit(): Optional = Optional.ofNullable(limit) + + /** + * Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and `desc` + * for descending order. + */ + fun order(): Optional = Optional.ofNullable(order) + + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + + @JvmSynthetic + internal fun getQueryParams(): QueryParams { + val queryParams = QueryParams.builder() + this.after?.let { queryParams.put("after", listOf(it.toString())) } + this.before?.let { queryParams.put("before", listOf(it.toString())) } + this.filter?.let { queryParams.put("filter", listOf(it.toString())) } + this.limit?.let { queryParams.put("limit", listOf(it.toString())) } + this.order?.let { queryParams.put("order", listOf(it.toString())) } + queryParams.putAll(additionalQueryParams) + return queryParams.build() + } + + fun getPathParam(index: Int): String { + return when (index) { + 0 -> vectorStoreId + 1 -> batchId + else -> "" + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + @NoAutoDetect + class Builder { + + private var vectorStoreId: String? = null + private var batchId: String? = null + private var after: String? = null + private var before: String? = null + private var filter: Filter? = null + private var limit: Long? = null + private var order: Order? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from( + betaVectorStoreFileBatchListFilesParams: BetaVectorStoreFileBatchListFilesParams + ) = apply { + vectorStoreId = betaVectorStoreFileBatchListFilesParams.vectorStoreId + batchId = betaVectorStoreFileBatchListFilesParams.batchId + after = betaVectorStoreFileBatchListFilesParams.after + before = betaVectorStoreFileBatchListFilesParams.before + filter = betaVectorStoreFileBatchListFilesParams.filter + limit = betaVectorStoreFileBatchListFilesParams.limit + order = betaVectorStoreFileBatchListFilesParams.order + additionalHeaders = + betaVectorStoreFileBatchListFilesParams.additionalHeaders.toBuilder() + additionalQueryParams = + betaVectorStoreFileBatchListFilesParams.additionalQueryParams.toBuilder() + } + + fun vectorStoreId(vectorStoreId: String) = apply { this.vectorStoreId = vectorStoreId } + + fun batchId(batchId: String) = apply { this.batchId = batchId } + + /** + * A cursor for use in pagination. `after` is an object ID that defines your place in the + * list. For instance, if you make a list request and receive 100 objects, ending with + * obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page + * of the list. + */ + fun after(after: String) = apply { this.after = after } + + /** + * A cursor for use in pagination. `before` is an object ID that defines your place in the + * list. For instance, if you make a list request and receive 100 objects, starting with + * obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous + * page of the list. + */ + fun before(before: String) = apply { this.before = before } + + /** Filter by file status. One of `in_progress`, `completed`, `failed`, `cancelled`. */ + fun filter(filter: Filter) = apply { this.filter = filter } + + /** + * A limit on the number of objects to be returned. Limit can range between 1 and 100, and + * the default is 20. + */ + fun limit(limit: Long) = apply { this.limit = limit } + + /** + * Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and + * `desc` for descending order. + */ + fun order(order: Order) = apply { this.order = order } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun build(): BetaVectorStoreFileBatchListFilesParams = + BetaVectorStoreFileBatchListFilesParams( + checkNotNull(vectorStoreId) { "`vectorStoreId` is required but was not set" }, + checkNotNull(batchId) { "`batchId` is required but was not set" }, + after, + before, + filter, + limit, + order, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + class Filter + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val IN_PROGRESS = of("in_progress") + + @JvmField val COMPLETED = of("completed") + + @JvmField val FAILED = of("failed") + + @JvmField val CANCELLED = of("cancelled") + + @JvmStatic fun of(value: String) = Filter(JsonField.of(value)) + } + + enum class Known { + IN_PROGRESS, + COMPLETED, + FAILED, + CANCELLED, + } + + enum class Value { + IN_PROGRESS, + COMPLETED, + FAILED, + CANCELLED, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + IN_PROGRESS -> Value.IN_PROGRESS + COMPLETED -> Value.COMPLETED + FAILED -> Value.FAILED + CANCELLED -> Value.CANCELLED + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + IN_PROGRESS -> Known.IN_PROGRESS + COMPLETED -> Known.COMPLETED + FAILED -> Known.FAILED + CANCELLED -> Known.CANCELLED + else -> throw OpenAIInvalidDataException("Unknown Filter: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Filter && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class Order + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val ASC = of("asc") + + @JvmField val DESC = of("desc") + + @JvmStatic fun of(value: String) = Order(JsonField.of(value)) + } + + enum class Known { + ASC, + DESC, + } + + enum class Value { + ASC, + DESC, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + ASC -> Value.ASC + DESC -> Value.DESC + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + ASC -> Known.ASC + DESC -> Known.DESC + else -> throw OpenAIInvalidDataException("Unknown Order: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Order && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaVectorStoreFileBatchListFilesParams && vectorStoreId == other.vectorStoreId && batchId == other.batchId && after == other.after && before == other.before && filter == other.filter && limit == other.limit && order == other.order && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(vectorStoreId, batchId, after, before, filter, limit, order, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "BetaVectorStoreFileBatchListFilesParams{vectorStoreId=$vectorStoreId, batchId=$batchId, after=$after, before=$before, filter=$filter, limit=$limit, order=$order, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreFileBatchRetrieveParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreFileBatchRetrieveParams.kt new file mode 100644 index 00000000..446e22bb --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreFileBatchRetrieveParams.kt @@ -0,0 +1,187 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models + +import com.openai.core.NoAutoDetect +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import java.util.Objects + +class BetaVectorStoreFileBatchRetrieveParams +constructor( + private val vectorStoreId: String, + private val batchId: String, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) { + + fun vectorStoreId(): String = vectorStoreId + + fun batchId(): String = batchId + + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + + @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams + + fun getPathParam(index: Int): String { + return when (index) { + 0 -> vectorStoreId + 1 -> batchId + else -> "" + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + @NoAutoDetect + class Builder { + + private var vectorStoreId: String? = null + private var batchId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from( + betaVectorStoreFileBatchRetrieveParams: BetaVectorStoreFileBatchRetrieveParams + ) = apply { + vectorStoreId = betaVectorStoreFileBatchRetrieveParams.vectorStoreId + batchId = betaVectorStoreFileBatchRetrieveParams.batchId + additionalHeaders = betaVectorStoreFileBatchRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = + betaVectorStoreFileBatchRetrieveParams.additionalQueryParams.toBuilder() + } + + fun vectorStoreId(vectorStoreId: String) = apply { this.vectorStoreId = vectorStoreId } + + fun batchId(batchId: String) = apply { this.batchId = batchId } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun build(): BetaVectorStoreFileBatchRetrieveParams = + BetaVectorStoreFileBatchRetrieveParams( + checkNotNull(vectorStoreId) { "`vectorStoreId` is required but was not set" }, + checkNotNull(batchId) { "`batchId` is required but was not set" }, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaVectorStoreFileBatchRetrieveParams && vectorStoreId == other.vectorStoreId && batchId == other.batchId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(vectorStoreId, batchId, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "BetaVectorStoreFileBatchRetrieveParams{vectorStoreId=$vectorStoreId, batchId=$batchId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreFileCreateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreFileCreateParams.kt new file mode 100644 index 00000000..8fed88c1 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreFileCreateParams.kt @@ -0,0 +1,382 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.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.JsonValue +import com.openai.core.NoAutoDetect +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.core.immutableEmptyMap +import com.openai.core.toImmutable +import java.util.Objects +import java.util.Optional + +class BetaVectorStoreFileCreateParams +constructor( + private val vectorStoreId: String, + private val body: BetaVectorStoreFileCreateBody, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) { + + fun vectorStoreId(): String = vectorStoreId + + /** + * A [File](https://platform.openai.com/docs/api-reference/files) ID that the vector store + * should use. Useful for tools like `file_search` that can access files. + */ + fun fileId(): String = body.fileId() + + /** + * The chunking strategy used to chunk the file(s). If not set, will use the `auto` strategy. + * Only applicable if `file_ids` is non-empty. + */ + fun chunkingStrategy(): Optional = body.chunkingStrategy() + + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun _additionalBodyProperties(): Map = body._additionalProperties() + + @JvmSynthetic internal fun getBody(): BetaVectorStoreFileCreateBody = body + + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + + @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams + + fun getPathParam(index: Int): String { + return when (index) { + 0 -> vectorStoreId + else -> "" + } + } + + @NoAutoDetect + class BetaVectorStoreFileCreateBody + @JsonCreator + internal constructor( + @JsonProperty("file_id") private val fileId: String, + @JsonProperty("chunking_strategy") private val chunkingStrategy: FileChunkingStrategyParam?, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** + * A [File](https://platform.openai.com/docs/api-reference/files) ID that the vector store + * should use. Useful for tools like `file_search` that can access files. + */ + @JsonProperty("file_id") fun fileId(): String = fileId + + /** + * The chunking strategy used to chunk the file(s). If not set, will use the `auto` + * strategy. Only applicable if `file_ids` is non-empty. + */ + @JsonProperty("chunking_strategy") + fun chunkingStrategy(): Optional = + Optional.ofNullable(chunkingStrategy) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var fileId: String? = null + private var chunkingStrategy: FileChunkingStrategyParam? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaVectorStoreFileCreateBody: BetaVectorStoreFileCreateBody) = + apply { + fileId = betaVectorStoreFileCreateBody.fileId + chunkingStrategy = betaVectorStoreFileCreateBody.chunkingStrategy + additionalProperties = + betaVectorStoreFileCreateBody.additionalProperties.toMutableMap() + } + + /** + * A [File](https://platform.openai.com/docs/api-reference/files) ID that the vector + * store should use. Useful for tools like `file_search` that can access files. + */ + fun fileId(fileId: String) = apply { this.fileId = fileId } + + /** + * The chunking strategy used to chunk the file(s). If not set, will use the `auto` + * strategy. Only applicable if `file_ids` is non-empty. + */ + fun chunkingStrategy(chunkingStrategy: FileChunkingStrategyParam) = apply { + this.chunkingStrategy = chunkingStrategy + } + + /** + * The default strategy. This strategy currently uses a `max_chunk_size_tokens` of `800` + * and `chunk_overlap_tokens` of `400`. + */ + fun chunkingStrategy(autoFileChunkingStrategyParam: AutoFileChunkingStrategyParam) = + apply { + this.chunkingStrategy = + FileChunkingStrategyParam.ofAutoFileChunkingStrategyParam( + autoFileChunkingStrategyParam + ) + } + + fun chunkingStrategy(staticFileChunkingStrategyParam: StaticFileChunkingStrategyParam) = + apply { + this.chunkingStrategy = + FileChunkingStrategyParam.ofStaticFileChunkingStrategyParam( + staticFileChunkingStrategyParam + ) + } + + 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) + } + + fun build(): BetaVectorStoreFileCreateBody = + BetaVectorStoreFileCreateBody( + checkNotNull(fileId) { "`fileId` is required but was not set" }, + chunkingStrategy, + additionalProperties.toImmutable(), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaVectorStoreFileCreateBody && fileId == other.fileId && chunkingStrategy == other.chunkingStrategy && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(fileId, chunkingStrategy, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaVectorStoreFileCreateBody{fileId=$fileId, chunkingStrategy=$chunkingStrategy, additionalProperties=$additionalProperties}" + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + @NoAutoDetect + class Builder { + + private var vectorStoreId: String? = null + private var body: BetaVectorStoreFileCreateBody.Builder = + BetaVectorStoreFileCreateBody.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(betaVectorStoreFileCreateParams: BetaVectorStoreFileCreateParams) = + apply { + vectorStoreId = betaVectorStoreFileCreateParams.vectorStoreId + body = betaVectorStoreFileCreateParams.body.toBuilder() + additionalHeaders = betaVectorStoreFileCreateParams.additionalHeaders.toBuilder() + additionalQueryParams = + betaVectorStoreFileCreateParams.additionalQueryParams.toBuilder() + } + + fun vectorStoreId(vectorStoreId: String) = apply { this.vectorStoreId = vectorStoreId } + + /** + * A [File](https://platform.openai.com/docs/api-reference/files) ID that the vector store + * should use. Useful for tools like `file_search` that can access files. + */ + fun fileId(fileId: String) = apply { body.fileId(fileId) } + + /** + * The chunking strategy used to chunk the file(s). If not set, will use the `auto` + * strategy. Only applicable if `file_ids` is non-empty. + */ + fun chunkingStrategy(chunkingStrategy: FileChunkingStrategyParam) = apply { + body.chunkingStrategy(chunkingStrategy) + } + + /** + * The default strategy. This strategy currently uses a `max_chunk_size_tokens` of `800` and + * `chunk_overlap_tokens` of `400`. + */ + fun chunkingStrategy(autoFileChunkingStrategyParam: AutoFileChunkingStrategyParam) = apply { + body.chunkingStrategy(autoFileChunkingStrategyParam) + } + + fun chunkingStrategy(staticFileChunkingStrategyParam: StaticFileChunkingStrategyParam) = + apply { + body.chunkingStrategy(staticFileChunkingStrategyParam) + } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } + + fun build(): BetaVectorStoreFileCreateParams = + BetaVectorStoreFileCreateParams( + checkNotNull(vectorStoreId) { "`vectorStoreId` is required but was not set" }, + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaVectorStoreFileCreateParams && vectorStoreId == other.vectorStoreId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(vectorStoreId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "BetaVectorStoreFileCreateParams{vectorStoreId=$vectorStoreId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreFileDeleteParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreFileDeleteParams.kt new file mode 100644 index 00000000..c04cfbaf --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreFileDeleteParams.kt @@ -0,0 +1,222 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models + +import com.openai.core.JsonValue +import com.openai.core.NoAutoDetect +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.core.toImmutable +import java.util.Objects +import java.util.Optional + +class BetaVectorStoreFileDeleteParams +constructor( + private val vectorStoreId: String, + private val fileId: String, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, + private val additionalBodyProperties: Map, +) { + + fun vectorStoreId(): String = vectorStoreId + + fun fileId(): String = fileId + + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun _additionalBodyProperties(): Map = additionalBodyProperties + + @JvmSynthetic + internal fun getBody(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + + @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams + + fun getPathParam(index: Int): String { + return when (index) { + 0 -> vectorStoreId + 1 -> fileId + else -> "" + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + @NoAutoDetect + class Builder { + + private var vectorStoreId: String? = null + private var fileId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + private var additionalBodyProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaVectorStoreFileDeleteParams: BetaVectorStoreFileDeleteParams) = + apply { + vectorStoreId = betaVectorStoreFileDeleteParams.vectorStoreId + fileId = betaVectorStoreFileDeleteParams.fileId + additionalHeaders = betaVectorStoreFileDeleteParams.additionalHeaders.toBuilder() + additionalQueryParams = + betaVectorStoreFileDeleteParams.additionalQueryParams.toBuilder() + additionalBodyProperties = + betaVectorStoreFileDeleteParams.additionalBodyProperties.toMutableMap() + } + + fun vectorStoreId(vectorStoreId: String) = apply { this.vectorStoreId = vectorStoreId } + + fun fileId(fileId: String) = apply { this.fileId = fileId } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + this.additionalBodyProperties.clear() + putAllAdditionalBodyProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + additionalBodyProperties.put(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + this.additionalBodyProperties.putAll(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { + additionalBodyProperties.remove(key) + } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalBodyProperty) + } + + fun build(): BetaVectorStoreFileDeleteParams = + BetaVectorStoreFileDeleteParams( + checkNotNull(vectorStoreId) { "`vectorStoreId` is required but was not set" }, + checkNotNull(fileId) { "`fileId` is required but was not set" }, + additionalHeaders.build(), + additionalQueryParams.build(), + additionalBodyProperties.toImmutable(), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaVectorStoreFileDeleteParams && vectorStoreId == other.vectorStoreId && fileId == other.fileId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(vectorStoreId, fileId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */ + + override fun toString() = + "BetaVectorStoreFileDeleteParams{vectorStoreId=$vectorStoreId, fileId=$fileId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreFileListPage.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreFileListPage.kt new file mode 100644 index 00000000..5b7f64dd --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreFileListPage.kt @@ -0,0 +1,171 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.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.NoAutoDetect +import com.openai.core.immutableEmptyMap +import com.openai.core.toImmutable +import com.openai.services.blocking.beta.vectorStores.FileService +import java.util.Objects +import java.util.Optional +import java.util.stream.Stream +import java.util.stream.StreamSupport + +class BetaVectorStoreFileListPage +private constructor( + private val filesService: FileService, + private val params: BetaVectorStoreFileListParams, + private val response: Response, +) { + + fun response(): Response = response + + fun data(): List = response().data() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaVectorStoreFileListPage && 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() = + "BetaVectorStoreFileListPage{filesService=$filesService, params=$params, response=$response}" + + fun hasNextPage(): Boolean { + return !data().isEmpty() + } + + fun getNextPageParams(): Optional { + if (!hasNextPage()) { + return Optional.empty() + } + + return Optional.of( + BetaVectorStoreFileListParams.builder().from(params).after(data().last().id()).build() + ) + } + + fun getNextPage(): Optional { + return getNextPageParams().map { filesService.list(it) } + } + + fun autoPager(): AutoPager = AutoPager(this) + + companion object { + + @JvmStatic + fun of( + filesService: FileService, + params: BetaVectorStoreFileListParams, + response: Response + ) = + BetaVectorStoreFileListPage( + filesService, + params, + response, + ) + } + + @NoAutoDetect + class Response + @JsonCreator + constructor( + @JsonProperty("data") private val data: JsonField> = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + private var validated: Boolean = false + + fun data(): List = data.getNullable("data") ?: listOf() + + @JsonProperty("data") + fun _data(): Optional>> = Optional.ofNullable(data) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Response = apply { + if (!validated) { + data().map { it.validate() } + validated = true + } + } + + 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 && additionalProperties == other.additionalProperties /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, additionalProperties) /* spotless:on */ + + override fun toString() = "Response{data=$data, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var data: JsonField> = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(page: Response) = apply { + this.data = page.data + this.additionalProperties.putAll(page.additionalProperties) + } + + fun data(data: List) = data(JsonField.of(data)) + + fun data(data: JsonField>) = apply { this.data = data } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun build() = Response(data, additionalProperties.toImmutable()) + } + } + + class AutoPager + constructor( + private val firstPage: BetaVectorStoreFileListPage, + ) : Iterable { + + override fun iterator(): Iterator = iterator { + var page = firstPage + var index = 0 + while (true) { + while (index < page.data().size) { + yield(page.data()[index++]) + } + page = page.getNextPage().orElse(null) ?: break + index = 0 + } + } + + fun stream(): Stream { + return StreamSupport.stream(spliterator(), false) + } + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreFileListPageAsync.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreFileListPageAsync.kt new file mode 100644 index 00000000..faaef573 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreFileListPageAsync.kt @@ -0,0 +1,184 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.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.NoAutoDetect +import com.openai.core.immutableEmptyMap +import com.openai.core.toImmutable +import com.openai.services.async.beta.vectorStores.FileServiceAsync +import java.util.Objects +import java.util.Optional +import java.util.concurrent.CompletableFuture +import java.util.concurrent.Executor +import java.util.function.Predicate + +class BetaVectorStoreFileListPageAsync +private constructor( + private val filesService: FileServiceAsync, + private val params: BetaVectorStoreFileListParams, + private val response: Response, +) { + + fun response(): Response = response + + fun data(): List = response().data() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaVectorStoreFileListPageAsync && 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() = + "BetaVectorStoreFileListPageAsync{filesService=$filesService, params=$params, response=$response}" + + fun hasNextPage(): Boolean { + return !data().isEmpty() + } + + fun getNextPageParams(): Optional { + if (!hasNextPage()) { + return Optional.empty() + } + + return Optional.of( + BetaVectorStoreFileListParams.builder().from(params).after(data().last().id()).build() + ) + } + + fun getNextPage(): CompletableFuture> { + return getNextPageParams() + .map { filesService.list(it).thenApply { Optional.of(it) } } + .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + } + + fun autoPager(): AutoPager = AutoPager(this) + + companion object { + + @JvmStatic + fun of( + filesService: FileServiceAsync, + params: BetaVectorStoreFileListParams, + response: Response + ) = + BetaVectorStoreFileListPageAsync( + filesService, + params, + response, + ) + } + + @NoAutoDetect + class Response + @JsonCreator + constructor( + @JsonProperty("data") private val data: JsonField> = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + private var validated: Boolean = false + + fun data(): List = data.getNullable("data") ?: listOf() + + @JsonProperty("data") + fun _data(): Optional>> = Optional.ofNullable(data) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Response = apply { + if (!validated) { + data().map { it.validate() } + validated = true + } + } + + 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 && additionalProperties == other.additionalProperties /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, additionalProperties) /* spotless:on */ + + override fun toString() = "Response{data=$data, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var data: JsonField> = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(page: Response) = apply { + this.data = page.data + this.additionalProperties.putAll(page.additionalProperties) + } + + fun data(data: List) = data(JsonField.of(data)) + + fun data(data: JsonField>) = apply { this.data = data } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun build() = Response(data, additionalProperties.toImmutable()) + } + } + + class AutoPager + constructor( + private val firstPage: BetaVectorStoreFileListPageAsync, + ) { + + fun forEach( + action: Predicate, + executor: Executor + ): CompletableFuture { + fun CompletableFuture>.forEach( + action: (VectorStoreFile) -> Boolean, + executor: Executor + ): CompletableFuture = + thenComposeAsync( + { page -> + page + .filter { it.data().all(action) } + .map { it.getNextPage().forEach(action, executor) } + .orElseGet { CompletableFuture.completedFuture(null) } + }, + executor + ) + return CompletableFuture.completedFuture(Optional.of(firstPage)) + .forEach(action::test, executor) + } + + fun toList(executor: Executor): CompletableFuture> { + val values = mutableListOf() + return forEach(values::add, executor).thenApply { values } + } + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreFileListParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreFileListParams.kt new file mode 100644 index 00000000..41f81f6c --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreFileListParams.kt @@ -0,0 +1,396 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models + +import com.fasterxml.jackson.annotation.JsonCreator +import com.openai.core.Enum +import com.openai.core.JsonField +import com.openai.core.NoAutoDetect +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.errors.OpenAIInvalidDataException +import java.util.Objects +import java.util.Optional + +class BetaVectorStoreFileListParams +constructor( + private val vectorStoreId: String, + private val after: String?, + private val before: String?, + private val filter: Filter?, + private val limit: Long?, + private val order: Order?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) { + + fun vectorStoreId(): String = vectorStoreId + + /** + * A cursor for use in pagination. `after` is an object ID that defines your place in the list. + * For instance, if you make a list request and receive 100 objects, ending with obj_foo, your + * subsequent call can include after=obj_foo in order to fetch the next page of the list. + */ + fun after(): Optional = Optional.ofNullable(after) + + /** + * A cursor for use in pagination. `before` is an object ID that defines your place in the list. + * For instance, if you make a list request and receive 100 objects, starting with obj_foo, your + * subsequent call can include before=obj_foo in order to fetch the previous page of the list. + */ + fun before(): Optional = Optional.ofNullable(before) + + /** Filter by file status. One of `in_progress`, `completed`, `failed`, `cancelled`. */ + fun filter(): Optional = Optional.ofNullable(filter) + + /** + * A limit on the number of objects to be returned. Limit can range between 1 and 100, and the + * default is 20. + */ + fun limit(): Optional = Optional.ofNullable(limit) + + /** + * Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and `desc` + * for descending order. + */ + fun order(): Optional = Optional.ofNullable(order) + + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + + @JvmSynthetic + internal fun getQueryParams(): QueryParams { + val queryParams = QueryParams.builder() + this.after?.let { queryParams.put("after", listOf(it.toString())) } + this.before?.let { queryParams.put("before", listOf(it.toString())) } + this.filter?.let { queryParams.put("filter", listOf(it.toString())) } + this.limit?.let { queryParams.put("limit", listOf(it.toString())) } + this.order?.let { queryParams.put("order", listOf(it.toString())) } + queryParams.putAll(additionalQueryParams) + return queryParams.build() + } + + fun getPathParam(index: Int): String { + return when (index) { + 0 -> vectorStoreId + else -> "" + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + @NoAutoDetect + class Builder { + + private var vectorStoreId: String? = null + private var after: String? = null + private var before: String? = null + private var filter: Filter? = null + private var limit: Long? = null + private var order: Order? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(betaVectorStoreFileListParams: BetaVectorStoreFileListParams) = apply { + vectorStoreId = betaVectorStoreFileListParams.vectorStoreId + after = betaVectorStoreFileListParams.after + before = betaVectorStoreFileListParams.before + filter = betaVectorStoreFileListParams.filter + limit = betaVectorStoreFileListParams.limit + order = betaVectorStoreFileListParams.order + additionalHeaders = betaVectorStoreFileListParams.additionalHeaders.toBuilder() + additionalQueryParams = betaVectorStoreFileListParams.additionalQueryParams.toBuilder() + } + + fun vectorStoreId(vectorStoreId: String) = apply { this.vectorStoreId = vectorStoreId } + + /** + * A cursor for use in pagination. `after` is an object ID that defines your place in the + * list. For instance, if you make a list request and receive 100 objects, ending with + * obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page + * of the list. + */ + fun after(after: String) = apply { this.after = after } + + /** + * A cursor for use in pagination. `before` is an object ID that defines your place in the + * list. For instance, if you make a list request and receive 100 objects, starting with + * obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous + * page of the list. + */ + fun before(before: String) = apply { this.before = before } + + /** Filter by file status. One of `in_progress`, `completed`, `failed`, `cancelled`. */ + fun filter(filter: Filter) = apply { this.filter = filter } + + /** + * A limit on the number of objects to be returned. Limit can range between 1 and 100, and + * the default is 20. + */ + fun limit(limit: Long) = apply { this.limit = limit } + + /** + * Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and + * `desc` for descending order. + */ + fun order(order: Order) = apply { this.order = order } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun build(): BetaVectorStoreFileListParams = + BetaVectorStoreFileListParams( + checkNotNull(vectorStoreId) { "`vectorStoreId` is required but was not set" }, + after, + before, + filter, + limit, + order, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + class Filter + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val IN_PROGRESS = of("in_progress") + + @JvmField val COMPLETED = of("completed") + + @JvmField val FAILED = of("failed") + + @JvmField val CANCELLED = of("cancelled") + + @JvmStatic fun of(value: String) = Filter(JsonField.of(value)) + } + + enum class Known { + IN_PROGRESS, + COMPLETED, + FAILED, + CANCELLED, + } + + enum class Value { + IN_PROGRESS, + COMPLETED, + FAILED, + CANCELLED, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + IN_PROGRESS -> Value.IN_PROGRESS + COMPLETED -> Value.COMPLETED + FAILED -> Value.FAILED + CANCELLED -> Value.CANCELLED + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + IN_PROGRESS -> Known.IN_PROGRESS + COMPLETED -> Known.COMPLETED + FAILED -> Known.FAILED + CANCELLED -> Known.CANCELLED + else -> throw OpenAIInvalidDataException("Unknown Filter: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Filter && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class Order + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val ASC = of("asc") + + @JvmField val DESC = of("desc") + + @JvmStatic fun of(value: String) = Order(JsonField.of(value)) + } + + enum class Known { + ASC, + DESC, + } + + enum class Value { + ASC, + DESC, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + ASC -> Value.ASC + DESC -> Value.DESC + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + ASC -> Known.ASC + DESC -> Known.DESC + else -> throw OpenAIInvalidDataException("Unknown Order: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Order && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaVectorStoreFileListParams && vectorStoreId == other.vectorStoreId && after == other.after && before == other.before && filter == other.filter && limit == other.limit && order == other.order && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(vectorStoreId, after, before, filter, limit, order, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "BetaVectorStoreFileListParams{vectorStoreId=$vectorStoreId, after=$after, before=$before, filter=$filter, limit=$limit, order=$order, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreFileRetrieveParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreFileRetrieveParams.kt new file mode 100644 index 00000000..1527b25f --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreFileRetrieveParams.kt @@ -0,0 +1,186 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models + +import com.openai.core.NoAutoDetect +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import java.util.Objects + +class BetaVectorStoreFileRetrieveParams +constructor( + private val vectorStoreId: String, + private val fileId: String, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) { + + fun vectorStoreId(): String = vectorStoreId + + fun fileId(): String = fileId + + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + + @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams + + fun getPathParam(index: Int): String { + return when (index) { + 0 -> vectorStoreId + 1 -> fileId + else -> "" + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + @NoAutoDetect + class Builder { + + private var vectorStoreId: String? = null + private var fileId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(betaVectorStoreFileRetrieveParams: BetaVectorStoreFileRetrieveParams) = + apply { + vectorStoreId = betaVectorStoreFileRetrieveParams.vectorStoreId + fileId = betaVectorStoreFileRetrieveParams.fileId + additionalHeaders = betaVectorStoreFileRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = + betaVectorStoreFileRetrieveParams.additionalQueryParams.toBuilder() + } + + fun vectorStoreId(vectorStoreId: String) = apply { this.vectorStoreId = vectorStoreId } + + fun fileId(fileId: String) = apply { this.fileId = fileId } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun build(): BetaVectorStoreFileRetrieveParams = + BetaVectorStoreFileRetrieveParams( + checkNotNull(vectorStoreId) { "`vectorStoreId` is required but was not set" }, + checkNotNull(fileId) { "`fileId` is required but was not set" }, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaVectorStoreFileRetrieveParams && vectorStoreId == other.vectorStoreId && fileId == other.fileId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(vectorStoreId, fileId, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "BetaVectorStoreFileRetrieveParams{vectorStoreId=$vectorStoreId, fileId=$fileId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreListPage.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreListPage.kt new file mode 100644 index 00000000..63d6614e --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreListPage.kt @@ -0,0 +1,171 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.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.NoAutoDetect +import com.openai.core.immutableEmptyMap +import com.openai.core.toImmutable +import com.openai.services.blocking.beta.VectorStoreService +import java.util.Objects +import java.util.Optional +import java.util.stream.Stream +import java.util.stream.StreamSupport + +class BetaVectorStoreListPage +private constructor( + private val vectorStoresService: VectorStoreService, + private val params: BetaVectorStoreListParams, + private val response: Response, +) { + + fun response(): Response = response + + fun data(): List = response().data() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaVectorStoreListPage && 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() = + "BetaVectorStoreListPage{vectorStoresService=$vectorStoresService, params=$params, response=$response}" + + fun hasNextPage(): Boolean { + return !data().isEmpty() + } + + fun getNextPageParams(): Optional { + if (!hasNextPage()) { + return Optional.empty() + } + + return Optional.of( + BetaVectorStoreListParams.builder().from(params).after(data().last().id()).build() + ) + } + + fun getNextPage(): Optional { + return getNextPageParams().map { vectorStoresService.list(it) } + } + + fun autoPager(): AutoPager = AutoPager(this) + + companion object { + + @JvmStatic + fun of( + vectorStoresService: VectorStoreService, + params: BetaVectorStoreListParams, + response: Response + ) = + BetaVectorStoreListPage( + vectorStoresService, + params, + response, + ) + } + + @NoAutoDetect + class Response + @JsonCreator + constructor( + @JsonProperty("data") private val data: JsonField> = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + private var validated: Boolean = false + + fun data(): List = data.getNullable("data") ?: listOf() + + @JsonProperty("data") + fun _data(): Optional>> = Optional.ofNullable(data) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Response = apply { + if (!validated) { + data().map { it.validate() } + validated = true + } + } + + 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 && additionalProperties == other.additionalProperties /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, additionalProperties) /* spotless:on */ + + override fun toString() = "Response{data=$data, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var data: JsonField> = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(page: Response) = apply { + this.data = page.data + this.additionalProperties.putAll(page.additionalProperties) + } + + fun data(data: List) = data(JsonField.of(data)) + + fun data(data: JsonField>) = apply { this.data = data } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun build() = Response(data, additionalProperties.toImmutable()) + } + } + + class AutoPager + constructor( + private val firstPage: BetaVectorStoreListPage, + ) : Iterable { + + override fun iterator(): Iterator = iterator { + var page = firstPage + var index = 0 + while (true) { + while (index < page.data().size) { + yield(page.data()[index++]) + } + page = page.getNextPage().orElse(null) ?: break + index = 0 + } + } + + fun stream(): Stream { + return StreamSupport.stream(spliterator(), false) + } + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreListPageAsync.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreListPageAsync.kt new file mode 100644 index 00000000..922dd80a --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreListPageAsync.kt @@ -0,0 +1,181 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.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.NoAutoDetect +import com.openai.core.immutableEmptyMap +import com.openai.core.toImmutable +import com.openai.services.async.beta.VectorStoreServiceAsync +import java.util.Objects +import java.util.Optional +import java.util.concurrent.CompletableFuture +import java.util.concurrent.Executor +import java.util.function.Predicate + +class BetaVectorStoreListPageAsync +private constructor( + private val vectorStoresService: VectorStoreServiceAsync, + private val params: BetaVectorStoreListParams, + private val response: Response, +) { + + fun response(): Response = response + + fun data(): List = response().data() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaVectorStoreListPageAsync && 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() = + "BetaVectorStoreListPageAsync{vectorStoresService=$vectorStoresService, params=$params, response=$response}" + + fun hasNextPage(): Boolean { + return !data().isEmpty() + } + + fun getNextPageParams(): Optional { + if (!hasNextPage()) { + return Optional.empty() + } + + return Optional.of( + BetaVectorStoreListParams.builder().from(params).after(data().last().id()).build() + ) + } + + fun getNextPage(): CompletableFuture> { + return getNextPageParams() + .map { vectorStoresService.list(it).thenApply { Optional.of(it) } } + .orElseGet { CompletableFuture.completedFuture(Optional.empty()) } + } + + fun autoPager(): AutoPager = AutoPager(this) + + companion object { + + @JvmStatic + fun of( + vectorStoresService: VectorStoreServiceAsync, + params: BetaVectorStoreListParams, + response: Response + ) = + BetaVectorStoreListPageAsync( + vectorStoresService, + params, + response, + ) + } + + @NoAutoDetect + class Response + @JsonCreator + constructor( + @JsonProperty("data") private val data: JsonField> = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + private var validated: Boolean = false + + fun data(): List = data.getNullable("data") ?: listOf() + + @JsonProperty("data") + fun _data(): Optional>> = Optional.ofNullable(data) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun validate(): Response = apply { + if (!validated) { + data().map { it.validate() } + validated = true + } + } + + 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 && additionalProperties == other.additionalProperties /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, additionalProperties) /* spotless:on */ + + override fun toString() = "Response{data=$data, additionalProperties=$additionalProperties}" + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var data: JsonField> = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(page: Response) = apply { + this.data = page.data + this.additionalProperties.putAll(page.additionalProperties) + } + + fun data(data: List) = data(JsonField.of(data)) + + fun data(data: JsonField>) = apply { this.data = data } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + this.additionalProperties.put(key, value) + } + + fun build() = Response(data, additionalProperties.toImmutable()) + } + } + + class AutoPager + constructor( + private val firstPage: BetaVectorStoreListPageAsync, + ) { + + fun forEach(action: Predicate, executor: Executor): CompletableFuture { + fun CompletableFuture>.forEach( + action: (VectorStore) -> Boolean, + executor: Executor + ): CompletableFuture = + thenComposeAsync( + { page -> + page + .filter { it.data().all(action) } + .map { it.getNextPage().forEach(action, executor) } + .orElseGet { CompletableFuture.completedFuture(null) } + }, + executor + ) + return CompletableFuture.completedFuture(Optional.of(firstPage)) + .forEach(action::test, executor) + } + + fun toList(executor: Executor): CompletableFuture> { + val values = mutableListOf() + return forEach(values::add, executor).thenApply { values } + } + } +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreListParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreListParams.kt new file mode 100644 index 00000000..1a5c1bd8 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreListParams.kt @@ -0,0 +1,301 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models + +import com.fasterxml.jackson.annotation.JsonCreator +import com.openai.core.Enum +import com.openai.core.JsonField +import com.openai.core.NoAutoDetect +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.errors.OpenAIInvalidDataException +import java.util.Objects +import java.util.Optional + +class BetaVectorStoreListParams +constructor( + private val after: String?, + private val before: String?, + private val limit: Long?, + private val order: Order?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) { + + /** + * A cursor for use in pagination. `after` is an object ID that defines your place in the list. + * For instance, if you make a list request and receive 100 objects, ending with obj_foo, your + * subsequent call can include after=obj_foo in order to fetch the next page of the list. + */ + fun after(): Optional = Optional.ofNullable(after) + + /** + * A cursor for use in pagination. `before` is an object ID that defines your place in the list. + * For instance, if you make a list request and receive 100 objects, starting with obj_foo, your + * subsequent call can include before=obj_foo in order to fetch the previous page of the list. + */ + fun before(): Optional = Optional.ofNullable(before) + + /** + * A limit on the number of objects to be returned. Limit can range between 1 and 100, and the + * default is 20. + */ + fun limit(): Optional = Optional.ofNullable(limit) + + /** + * Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and `desc` + * for descending order. + */ + fun order(): Optional = Optional.ofNullable(order) + + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + + @JvmSynthetic + internal fun getQueryParams(): QueryParams { + val queryParams = QueryParams.builder() + this.after?.let { queryParams.put("after", listOf(it.toString())) } + this.before?.let { queryParams.put("before", listOf(it.toString())) } + this.limit?.let { queryParams.put("limit", listOf(it.toString())) } + this.order?.let { queryParams.put("order", listOf(it.toString())) } + queryParams.putAll(additionalQueryParams) + return queryParams.build() + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + @NoAutoDetect + class Builder { + + private var after: String? = null + private var before: String? = null + private var limit: Long? = null + private var order: Order? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(betaVectorStoreListParams: BetaVectorStoreListParams) = apply { + after = betaVectorStoreListParams.after + before = betaVectorStoreListParams.before + limit = betaVectorStoreListParams.limit + order = betaVectorStoreListParams.order + additionalHeaders = betaVectorStoreListParams.additionalHeaders.toBuilder() + additionalQueryParams = betaVectorStoreListParams.additionalQueryParams.toBuilder() + } + + /** + * A cursor for use in pagination. `after` is an object ID that defines your place in the + * list. For instance, if you make a list request and receive 100 objects, ending with + * obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page + * of the list. + */ + fun after(after: String) = apply { this.after = after } + + /** + * A cursor for use in pagination. `before` is an object ID that defines your place in the + * list. For instance, if you make a list request and receive 100 objects, starting with + * obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous + * page of the list. + */ + fun before(before: String) = apply { this.before = before } + + /** + * A limit on the number of objects to be returned. Limit can range between 1 and 100, and + * the default is 20. + */ + fun limit(limit: Long) = apply { this.limit = limit } + + /** + * Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and + * `desc` for descending order. + */ + fun order(order: Order) = apply { this.order = order } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun build(): BetaVectorStoreListParams = + BetaVectorStoreListParams( + after, + before, + limit, + order, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + class Order + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val ASC = of("asc") + + @JvmField val DESC = of("desc") + + @JvmStatic fun of(value: String) = Order(JsonField.of(value)) + } + + enum class Known { + ASC, + DESC, + } + + enum class Value { + ASC, + DESC, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + ASC -> Value.ASC + DESC -> Value.DESC + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + ASC -> Known.ASC + DESC -> Known.DESC + else -> throw OpenAIInvalidDataException("Unknown Order: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Order && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaVectorStoreListParams && after == other.after && before == other.before && limit == other.limit && order == other.order && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(after, before, limit, order, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "BetaVectorStoreListParams{after=$after, before=$before, limit=$limit, order=$order, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreRetrieveParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreRetrieveParams.kt new file mode 100644 index 00000000..19b6ff3a --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreRetrieveParams.kt @@ -0,0 +1,175 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models + +import com.openai.core.NoAutoDetect +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import java.util.Objects + +class BetaVectorStoreRetrieveParams +constructor( + private val vectorStoreId: String, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) { + + fun vectorStoreId(): String = vectorStoreId + + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + + @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams + + fun getPathParam(index: Int): String { + return when (index) { + 0 -> vectorStoreId + else -> "" + } + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + @NoAutoDetect + class Builder { + + private var vectorStoreId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(betaVectorStoreRetrieveParams: BetaVectorStoreRetrieveParams) = apply { + vectorStoreId = betaVectorStoreRetrieveParams.vectorStoreId + additionalHeaders = betaVectorStoreRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = betaVectorStoreRetrieveParams.additionalQueryParams.toBuilder() + } + + fun vectorStoreId(vectorStoreId: String) = apply { this.vectorStoreId = vectorStoreId } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun build(): BetaVectorStoreRetrieveParams = + BetaVectorStoreRetrieveParams( + checkNotNull(vectorStoreId) { "`vectorStoreId` is required but was not set" }, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaVectorStoreRetrieveParams && vectorStoreId == other.vectorStoreId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(vectorStoreId, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "BetaVectorStoreRetrieveParams{vectorStoreId=$vectorStoreId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreUpdateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreUpdateParams.kt new file mode 100644 index 00000000..7e5f30e9 --- /dev/null +++ b/openai-java-core/src/main/kotlin/com/openai/models/BetaVectorStoreUpdateParams.kt @@ -0,0 +1,502 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.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.Enum +import com.openai.core.ExcludeMissing +import com.openai.core.JsonField +import com.openai.core.JsonValue +import com.openai.core.NoAutoDetect +import com.openai.core.http.Headers +import com.openai.core.http.QueryParams +import com.openai.core.immutableEmptyMap +import com.openai.core.toImmutable +import com.openai.errors.OpenAIInvalidDataException +import java.util.Objects +import java.util.Optional + +class BetaVectorStoreUpdateParams +constructor( + private val vectorStoreId: String, + private val body: BetaVectorStoreUpdateBody, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) { + + fun vectorStoreId(): String = vectorStoreId + + /** The expiration policy for a vector store. */ + fun expiresAfter(): Optional = body.expiresAfter() + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for storing + * additional information about the object in a structured format. Keys can be a maximum of 64 + * characters long and values can be a maximum of 512 characters long. + */ + fun metadata(): Optional = body.metadata() + + /** The name of the vector store. */ + fun name(): Optional = body.name() + + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun _additionalBodyProperties(): Map = body._additionalProperties() + + @JvmSynthetic internal fun getBody(): BetaVectorStoreUpdateBody = body + + @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + + @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams + + fun getPathParam(index: Int): String { + return when (index) { + 0 -> vectorStoreId + else -> "" + } + } + + @NoAutoDetect + class BetaVectorStoreUpdateBody + @JsonCreator + internal constructor( + @JsonProperty("expires_after") private val expiresAfter: ExpiresAfter?, + @JsonProperty("metadata") private val metadata: JsonValue?, + @JsonProperty("name") private val name: String?, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** The expiration policy for a vector store. */ + @JsonProperty("expires_after") + fun expiresAfter(): Optional = Optional.ofNullable(expiresAfter) + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format. Keys can be a + * maximum of 64 characters long and values can be a maximum of 512 characters long. + */ + @JsonProperty("metadata") + fun metadata(): Optional = Optional.ofNullable(metadata) + + /** The name of the vector store. */ + @JsonProperty("name") fun name(): Optional = Optional.ofNullable(name) + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var expiresAfter: ExpiresAfter? = null + private var metadata: JsonValue? = null + private var name: String? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaVectorStoreUpdateBody: BetaVectorStoreUpdateBody) = apply { + expiresAfter = betaVectorStoreUpdateBody.expiresAfter + metadata = betaVectorStoreUpdateBody.metadata + name = betaVectorStoreUpdateBody.name + additionalProperties = betaVectorStoreUpdateBody.additionalProperties.toMutableMap() + } + + /** The expiration policy for a vector store. */ + fun expiresAfter(expiresAfter: ExpiresAfter) = apply { + this.expiresAfter = expiresAfter + } + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format. Keys can be a + * maximum of 64 characters long and values can be a maximum of 512 characters long. + */ + fun metadata(metadata: JsonValue) = apply { this.metadata = metadata } + + /** The name of the vector store. */ + fun name(name: String) = apply { this.name = name } + + 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) + } + + fun build(): BetaVectorStoreUpdateBody = + BetaVectorStoreUpdateBody( + expiresAfter, + metadata, + name, + additionalProperties.toImmutable(), + ) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaVectorStoreUpdateBody && expiresAfter == other.expiresAfter && metadata == other.metadata && name == other.name && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(expiresAfter, metadata, name, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaVectorStoreUpdateBody{expiresAfter=$expiresAfter, metadata=$metadata, name=$name, additionalProperties=$additionalProperties}" + } + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + @NoAutoDetect + class Builder { + + private var vectorStoreId: String? = null + private var body: BetaVectorStoreUpdateBody.Builder = BetaVectorStoreUpdateBody.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(betaVectorStoreUpdateParams: BetaVectorStoreUpdateParams) = apply { + vectorStoreId = betaVectorStoreUpdateParams.vectorStoreId + body = betaVectorStoreUpdateParams.body.toBuilder() + additionalHeaders = betaVectorStoreUpdateParams.additionalHeaders.toBuilder() + additionalQueryParams = betaVectorStoreUpdateParams.additionalQueryParams.toBuilder() + } + + fun vectorStoreId(vectorStoreId: String) = apply { this.vectorStoreId = vectorStoreId } + + /** The expiration policy for a vector store. */ + fun expiresAfter(expiresAfter: ExpiresAfter) = apply { body.expiresAfter(expiresAfter) } + + /** + * Set of 16 key-value pairs that can be attached to an object. This can be useful for + * storing additional information about the object in a structured format. Keys can be a + * maximum of 64 characters long and values can be a maximum of 512 characters long. + */ + fun metadata(metadata: JsonValue) = apply { body.metadata(metadata) } + + /** The name of the vector store. */ + fun name(name: String) = apply { body.name(name) } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } + + fun build(): BetaVectorStoreUpdateParams = + BetaVectorStoreUpdateParams( + checkNotNull(vectorStoreId) { "`vectorStoreId` is required but was not set" }, + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + /** The expiration policy for a vector store. */ + @NoAutoDetect + class ExpiresAfter + @JsonCreator + private constructor( + @JsonProperty("anchor") private val anchor: Anchor, + @JsonProperty("days") private val days: Long, + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** + * Anchor timestamp after which the expiration policy applies. Supported anchors: + * `last_active_at`. + */ + @JsonProperty("anchor") fun anchor(): Anchor = anchor + + /** The number of days after the anchor time that the vector store will expire. */ + @JsonProperty("days") fun days(): Long = days + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun builder() = Builder() + } + + class Builder { + + private var anchor: Anchor? = null + private var days: Long? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(expiresAfter: ExpiresAfter) = apply { + anchor = expiresAfter.anchor + days = expiresAfter.days + additionalProperties = expiresAfter.additionalProperties.toMutableMap() + } + + /** + * Anchor timestamp after which the expiration policy applies. Supported anchors: + * `last_active_at`. + */ + fun anchor(anchor: Anchor) = apply { this.anchor = anchor } + + /** The number of days after the anchor time that the vector store will expire. */ + fun days(days: Long) = apply { this.days = days } + + 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) + } + + fun build(): ExpiresAfter = + ExpiresAfter( + checkNotNull(anchor) { "`anchor` is required but was not set" }, + checkNotNull(days) { "`days` is required but was not set" }, + additionalProperties.toImmutable(), + ) + } + + class Anchor + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { + + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val LAST_ACTIVE_AT = of("last_active_at") + + @JvmStatic fun of(value: String) = Anchor(JsonField.of(value)) + } + + enum class Known { + LAST_ACTIVE_AT, + } + + enum class Value { + LAST_ACTIVE_AT, + _UNKNOWN, + } + + fun value(): Value = + when (this) { + LAST_ACTIVE_AT -> Value.LAST_ACTIVE_AT + else -> Value._UNKNOWN + } + + fun known(): Known = + when (this) { + LAST_ACTIVE_AT -> Known.LAST_ACTIVE_AT + else -> throw OpenAIInvalidDataException("Unknown Anchor: $value") + } + + fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Anchor && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ExpiresAfter && anchor == other.anchor && days == other.days && additionalProperties == other.additionalProperties /* spotless:on */ + } + + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(anchor, days, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ExpiresAfter{anchor=$anchor, days=$days, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BetaVectorStoreUpdateParams && vectorStoreId == other.vectorStoreId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(vectorStoreId, body, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "BetaVectorStoreUpdateParams{vectorStoreId=$vectorStoreId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletion.kt b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletion.kt index 74dace7f..c4badc86 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletion.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletion.kt @@ -6,36 +6,46 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.databind.annotation.JsonDeserialize import com.openai.core.Enum import com.openai.core.ExcludeMissing import com.openai.core.JsonField import com.openai.core.JsonMissing import com.openai.core.JsonValue import com.openai.core.NoAutoDetect +import com.openai.core.immutableEmptyMap import com.openai.core.toImmutable import com.openai.errors.OpenAIInvalidDataException import java.util.Objects import java.util.Optional /** Represents a chat completion response returned by model, based on the provided input. */ -@JsonDeserialize(builder = ChatCompletion.Builder::class) @NoAutoDetect class ChatCompletion +@JsonCreator private constructor( - private val id: JsonField, - private val choices: JsonField>, - private val created: JsonField, - private val model: JsonField, - private val serviceTier: JsonField, - private val systemFingerprint: JsonField, - private val object_: JsonField, - private val usage: JsonField, - private val additionalProperties: Map, + @JsonProperty("id") @ExcludeMissing private val id: JsonField = JsonMissing.of(), + @JsonProperty("choices") + @ExcludeMissing + private val choices: JsonField> = JsonMissing.of(), + @JsonProperty("created") + @ExcludeMissing + private val created: JsonField = JsonMissing.of(), + @JsonProperty("model") @ExcludeMissing private val model: JsonField = JsonMissing.of(), + @JsonProperty("service_tier") + @ExcludeMissing + private val serviceTier: JsonField = JsonMissing.of(), + @JsonProperty("system_fingerprint") + @ExcludeMissing + private val systemFingerprint: JsonField = JsonMissing.of(), + @JsonProperty("object") + @ExcludeMissing + private val object_: JsonField = JsonMissing.of(), + @JsonProperty("usage") + @ExcludeMissing + private val usage: JsonField = JsonMissing.of(), + @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - /** A unique identifier for the chat completion. */ fun id(): String = id.getRequired("id") @@ -106,6 +116,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): ChatCompletion = apply { if (!validated) { id() @@ -141,45 +153,39 @@ private constructor( @JvmSynthetic internal fun from(chatCompletion: ChatCompletion) = apply { - this.id = chatCompletion.id - this.choices = chatCompletion.choices - this.created = chatCompletion.created - this.model = chatCompletion.model - this.serviceTier = chatCompletion.serviceTier - this.systemFingerprint = chatCompletion.systemFingerprint - this.object_ = chatCompletion.object_ - this.usage = chatCompletion.usage - additionalProperties(chatCompletion.additionalProperties) + id = chatCompletion.id + choices = chatCompletion.choices + created = chatCompletion.created + model = chatCompletion.model + serviceTier = chatCompletion.serviceTier + systemFingerprint = chatCompletion.systemFingerprint + object_ = chatCompletion.object_ + usage = chatCompletion.usage + additionalProperties = chatCompletion.additionalProperties.toMutableMap() } /** A unique identifier for the chat completion. */ fun id(id: String) = id(JsonField.of(id)) /** A unique identifier for the chat completion. */ - @JsonProperty("id") @ExcludeMissing fun id(id: JsonField) = apply { this.id = id } + fun id(id: JsonField) = apply { this.id = id } /** A list of chat completion choices. Can be more than one if `n` is greater than 1. */ fun choices(choices: List) = choices(JsonField.of(choices)) /** A list of chat completion choices. Can be more than one if `n` is greater than 1. */ - @JsonProperty("choices") - @ExcludeMissing fun choices(choices: JsonField>) = apply { this.choices = choices } /** The Unix timestamp (in seconds) of when the chat completion was created. */ fun created(created: Long) = created(JsonField.of(created)) /** The Unix timestamp (in seconds) of when the chat completion was created. */ - @JsonProperty("created") - @ExcludeMissing fun created(created: JsonField) = apply { this.created = created } /** The model used for the chat completion. */ fun model(model: String) = model(JsonField.of(model)) /** The model used for the chat completion. */ - @JsonProperty("model") - @ExcludeMissing fun model(model: JsonField) = apply { this.model = model } /** @@ -192,8 +198,6 @@ private constructor( * The service tier used for processing the request. This field is only included if the * `service_tier` parameter is specified in the request. */ - @JsonProperty("service_tier") - @ExcludeMissing fun serviceTier(serviceTier: JsonField) = apply { this.serviceTier = serviceTier } @@ -213,8 +217,6 @@ private constructor( * Can be used in conjunction with the `seed` request parameter to understand when backend * changes have been made that might impact determinism. */ - @JsonProperty("system_fingerprint") - @ExcludeMissing fun systemFingerprint(systemFingerprint: JsonField) = apply { this.systemFingerprint = systemFingerprint } @@ -223,32 +225,33 @@ private constructor( fun object_(object_: Object) = object_(JsonField.of(object_)) /** The object type, which is always `chat.completion`. */ - @JsonProperty("object") - @ExcludeMissing fun object_(object_: JsonField) = apply { this.object_ = object_ } /** Usage statistics for the completion request. */ fun usage(usage: CompletionUsage) = usage(JsonField.of(usage)) /** Usage statistics for the completion request. */ - @JsonProperty("usage") - @ExcludeMissing fun usage(usage: JsonField) = apply { this.usage = usage } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + 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) + } + fun build(): ChatCompletion = ChatCompletion( id, @@ -263,19 +266,26 @@ private constructor( ) } - @JsonDeserialize(builder = Choice.Builder::class) @NoAutoDetect class Choice + @JsonCreator private constructor( - private val finishReason: JsonField, - private val index: JsonField, - private val message: JsonField, - private val logprobs: JsonField, - private val additionalProperties: Map, + @JsonProperty("finish_reason") + @ExcludeMissing + private val finishReason: JsonField = JsonMissing.of(), + @JsonProperty("index") + @ExcludeMissing + private val index: JsonField = JsonMissing.of(), + @JsonProperty("message") + @ExcludeMissing + private val message: JsonField = JsonMissing.of(), + @JsonProperty("logprobs") + @ExcludeMissing + private val logprobs: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - /** * The reason the model stopped generating tokens. This will be `stop` if the model hit a * natural stop point or a provided stop sequence, `length` if the maximum number of tokens @@ -316,6 +326,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Choice = apply { if (!validated) { finishReason() @@ -343,11 +355,11 @@ private constructor( @JvmSynthetic internal fun from(choice: Choice) = apply { - this.finishReason = choice.finishReason - this.index = choice.index - this.message = choice.message - this.logprobs = choice.logprobs - additionalProperties(choice.additionalProperties) + finishReason = choice.finishReason + index = choice.index + message = choice.message + logprobs = choice.logprobs + additionalProperties = choice.additionalProperties.toMutableMap() } /** @@ -366,8 +378,6 @@ private constructor( * due to a flag from our content filters, `tool_calls` if the model called a tool, or * `function_call` (deprecated) if the model called a function. */ - @JsonProperty("finish_reason") - @ExcludeMissing fun finishReason(finishReason: JsonField) = apply { this.finishReason = finishReason } @@ -376,16 +386,12 @@ private constructor( fun index(index: Long) = index(JsonField.of(index)) /** The index of the choice in the list of choices. */ - @JsonProperty("index") - @ExcludeMissing fun index(index: JsonField) = apply { this.index = index } /** A chat completion message generated by the model. */ fun message(message: ChatCompletionMessage) = message(JsonField.of(message)) /** A chat completion message generated by the model. */ - @JsonProperty("message") - @ExcludeMissing fun message(message: JsonField) = apply { this.message = message } @@ -394,24 +400,27 @@ private constructor( fun logprobs(logprobs: Logprobs) = logprobs(JsonField.of(logprobs)) /** Log probability information for the choice. */ - @JsonProperty("logprobs") - @ExcludeMissing fun logprobs(logprobs: JsonField) = apply { this.logprobs = logprobs } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + 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) + } + fun build(): Choice = Choice( finishReason, @@ -498,17 +507,20 @@ private constructor( } /** Log probability information for the choice. */ - @JsonDeserialize(builder = Logprobs.Builder::class) @NoAutoDetect class Logprobs + @JsonCreator private constructor( - private val content: JsonField>, - private val refusal: JsonField>, - private val additionalProperties: Map, + @JsonProperty("content") + @ExcludeMissing + private val content: JsonField> = JsonMissing.of(), + @JsonProperty("refusal") + @ExcludeMissing + private val refusal: JsonField> = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - /** A list of message content tokens with log probability information. */ fun content(): Optional> = Optional.ofNullable(content.getNullable("content")) @@ -527,6 +539,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Logprobs = apply { if (!validated) { content().map { it.forEach { it.validate() } } @@ -550,9 +564,9 @@ private constructor( @JvmSynthetic internal fun from(logprobs: Logprobs) = apply { - this.content = logprobs.content - this.refusal = logprobs.refusal - additionalProperties(logprobs.additionalProperties) + content = logprobs.content + refusal = logprobs.refusal + additionalProperties = logprobs.additionalProperties.toMutableMap() } /** A list of message content tokens with log probability information. */ @@ -560,8 +574,6 @@ private constructor( content(JsonField.of(content)) /** A list of message content tokens with log probability information. */ - @JsonProperty("content") - @ExcludeMissing fun content(content: JsonField>) = apply { this.content = content } @@ -571,20 +583,17 @@ private constructor( refusal(JsonField.of(refusal)) /** A list of message refusal tokens with log probability information. */ - @JsonProperty("refusal") - @ExcludeMissing fun refusal(refusal: JsonField>) = apply { this.refusal = refusal } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -592,6 +601,14 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Logprobs = Logprobs( content.map { it.toImmutable() }, diff --git a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionAssistantMessageParam.kt b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionAssistantMessageParam.kt index b6930684..decbe356 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionAssistantMessageParam.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionAssistantMessageParam.kt @@ -22,6 +22,7 @@ import com.openai.core.JsonMissing import com.openai.core.JsonValue import com.openai.core.NoAutoDetect import com.openai.core.getOrThrow +import com.openai.core.immutableEmptyMap import com.openai.core.toImmutable import com.openai.errors.OpenAIInvalidDataException import java.util.Objects @@ -29,22 +30,28 @@ import java.util.Optional import kotlin.jvm.optionals.getOrNull /** Messages sent by the model in response to user messages. */ -@JsonDeserialize(builder = ChatCompletionAssistantMessageParam.Builder::class) @NoAutoDetect class ChatCompletionAssistantMessageParam +@JsonCreator private constructor( - private val content: JsonField, - private val refusal: JsonField, - private val role: JsonField, - private val name: JsonField, - private val audio: JsonField