From 4e9c3eb9351f308ed3d842bd4aa2d860c23d568e Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 2 Jan 2025 18:11:12 +0000 Subject: [PATCH 1/7] refactor(client)!: switch query params objects to use `QueryParams` (#64) feat(client): add methods for removing additional properties chore(internal): remove unnecessary validation methods chore(internal): swap params body getters to use optionals chore(internal): remove unnecessary nullable annotations style(internal): minor changes to code ordering and syntax # Migration If you were accessing `_additionalProperties()` on a query params object, then previously it returned `Map>`. Now it returns a dedicated `QueryParams` object. The `QueryParams` class is better suited for mapping a key to multiple values and has similar methods to `Map`. --- .../client/okhttp/OpenAIOkHttpClient.kt | 4 +- .../client/okhttp/OpenAIOkHttpClientAsync.kt | 4 +- .../kotlin/com/openai/core/ClientOptions.kt | 4 +- .../kotlin/com/openai/errors/OpenAIError.kt | 2 + .../main/kotlin/com/openai/models/Batch.kt | 76 ++-- .../com/openai/models/BatchCreateParams.kt | 46 ++- .../kotlin/com/openai/models/BatchError.kt | 24 +- .../com/openai/models/BatchRequestCounts.kt | 22 +- .../com/openai/models/ChatCompletion.kt | 78 ++-- .../ChatCompletionAssistantMessageParam.kt | 69 ++-- .../com/openai/models/ChatCompletionAudio.kt | 24 +- .../openai/models/ChatCompletionAudioParam.kt | 20 +- .../com/openai/models/ChatCompletionChunk.kt | 176 ++++++--- .../models/ChatCompletionContentPartImage.kt | 41 +- .../ChatCompletionContentPartInputAudio.kt | 41 +- .../ChatCompletionContentPartRefusal.kt | 21 +- .../models/ChatCompletionContentPartText.kt | 20 +- .../models/ChatCompletionCreateParams.kt | 273 +++++++------ .../ChatCompletionDeveloperMessageParam.kt | 23 +- .../ChatCompletionFunctionCallOption.kt | 19 +- .../ChatCompletionFunctionMessageParam.kt | 23 +- .../openai/models/ChatCompletionMessage.kt | 48 ++- .../models/ChatCompletionMessageToolCall.kt | 42 +- .../models/ChatCompletionNamedToolChoice.kt | 38 +- .../models/ChatCompletionPredictionContent.kt | 21 +- .../models/ChatCompletionStreamOptions.kt | 18 +- .../ChatCompletionSystemMessageParam.kt | 23 +- .../models/ChatCompletionTokenLogprob.kt | 46 ++- .../com/openai/models/ChatCompletionTool.kt | 20 +- .../models/ChatCompletionToolMessageParam.kt | 23 +- .../models/ChatCompletionUserMessageParam.kt | 23 +- .../kotlin/com/openai/models/Completion.kt | 30 +- .../com/openai/models/CompletionChoice.kt | 66 ++-- .../openai/models/CompletionCreateParams.kt | 126 +++--- .../com/openai/models/CompletionUsage.kt | 70 ++-- .../openai/models/CreateEmbeddingResponse.kt | 44 ++- .../kotlin/com/openai/models/Embedding.kt | 20 +- .../openai/models/EmbeddingCreateParams.kt | 54 ++- .../kotlin/com/openai/models/ErrorObject.kt | 24 +- .../kotlin/com/openai/models/FileDeleted.kt | 22 +- .../kotlin/com/openai/models/FileObject.kt | 32 +- .../kotlin/com/openai/models/FineTuningJob.kt | 208 ++++++---- .../openai/models/FineTuningJobCheckpoint.kt | 60 +-- .../models/FineTuningJobCreateParams.kt | 370 ++++++++---------- .../com/openai/models/FineTuningJobEvent.kt | 30 +- .../models/FineTuningJobWandbIntegration.kt | 24 +- .../FineTuningJobWandbIntegrationObject.kt | 21 +- .../com/openai/models/FunctionDefinition.kt | 24 +- .../com/openai/models/FunctionParameters.kt | 16 +- .../main/kotlin/com/openai/models/Image.kt | 22 +- .../com/openai/models/ImageGenerateParams.kt | 47 ++- .../com/openai/models/ImagesResponse.kt | 20 +- .../main/kotlin/com/openai/models/Model.kt | 24 +- .../kotlin/com/openai/models/ModelDeleted.kt | 22 +- .../kotlin/com/openai/models/Moderation.kt | 150 ++++--- .../openai/models/ModerationCreateParams.kt | 33 +- .../openai/models/ModerationCreateResponse.kt | 22 +- .../openai/models/ModerationImageUrlInput.kt | 38 +- .../com/openai/models/ModerationTextInput.kt | 20 +- .../openai/models/ResponseFormatJsonObject.kt | 18 +- .../openai/models/ResponseFormatJsonSchema.kt | 62 ++- .../com/openai/models/ResponseFormatText.kt | 18 +- .../main/kotlin/com/openai/models/Upload.kt | 34 +- .../com/openai/models/UploadCompleteParams.kt | 22 +- .../com/openai/models/UploadCreateParams.kt | 36 +- .../kotlin/com/openai/models/UploadPart.kt | 24 +- .../openai/models/BatchCreateParamsTest.kt | 2 +- .../models/ChatCompletionCreateParamsTest.kt | 54 +-- .../models/CompletionCreateParamsTest.kt | 32 +- .../models/EmbeddingCreateParamsTest.kt | 6 +- .../models/FineTuningJobCreateParamsTest.kt | 12 +- .../openai/models/ImageGenerateParamsTest.kt | 14 +- .../models/ModerationCreateParamsTest.kt | 2 +- .../openai/models/UploadCompleteParamsTest.kt | 2 +- 74 files changed, 1914 insertions(+), 1375 deletions(-) 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/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/errors/OpenAIError.kt b/openai-java-core/src/main/kotlin/com/openai/errors/OpenAIError.kt index ca3ce740..aefc716c 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 @@ -5,6 +5,7 @@ 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.openai.core.ExcludeMissing import com.openai.core.JsonValue import com.openai.core.NoAutoDetect import com.openai.core.toImmutable @@ -15,6 +16,7 @@ import java.util.Objects class OpenAIError private constructor( @JsonAnyGetter + @ExcludeMissing @get:JvmName("additionalProperties") val additionalProperties: Map, ) { 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..df7d101c 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 @@ -45,8 +45,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - fun id(): String = id.getRequired("id") /** The object type, which is always `batch`. */ @@ -174,6 +172,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Batch = apply { if (!validated) { id() @@ -232,27 +232,27 @@ 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)) @@ -420,18 +420,24 @@ private constructor( 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, @@ -611,8 +617,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** The object type, which is always `list`. */ fun object_(): Optional = Optional.ofNullable(object_.getNullable("object")) @@ -627,6 +631,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Errors = apply { if (!validated) { object_() @@ -650,9 +656,9 @@ 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`. */ @@ -671,18 +677,24 @@ private constructor( 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/BatchCreateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/BatchCreateParams.kt index a2ba22b5..9f678964 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 @@ -63,9 +63,9 @@ constructor( @NoAutoDetect class BatchCreateBody internal constructor( - private val completionWindow: CompletionWindow?, - private val endpoint: Endpoint?, - private val inputFileId: String?, + private val completionWindow: CompletionWindow, + private val endpoint: Endpoint, + private val inputFileId: String, private val metadata: Metadata?, private val additionalProperties: Map, ) { @@ -75,7 +75,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 +83,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 +96,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,11 +122,11 @@ 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() } /** @@ -167,18 +167,24 @@ constructor( 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) { @@ -541,23 +547,29 @@ 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()) } 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..d3aa859b 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 @@ -26,8 +26,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** An error code identifying the error type. */ fun code(): Optional = Optional.ofNullable(code.getNullable("code")) @@ -56,6 +54,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): BatchError = apply { if (!validated) { code() @@ -83,11 +83,11 @@ 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. */ @@ -124,18 +124,24 @@ private constructor( 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/BatchRequestCounts.kt b/openai-java-core/src/main/kotlin/com/openai/models/BatchRequestCounts.kt index 9b5d4b69..f544db79 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 @@ -25,8 +25,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** Total number of requests in the batch. */ fun total(): Long = total.getRequired("total") @@ -49,6 +47,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): BatchRequestCounts = apply { if (!validated) { total() @@ -74,10 +74,10 @@ 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. */ @@ -106,18 +106,24 @@ private constructor( 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/ChatCompletion.kt b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletion.kt index 74dace7f..17eadabc 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 @@ -34,8 +34,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** A unique identifier for the chat completion. */ fun id(): String = id.getRequired("id") @@ -106,6 +104,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): ChatCompletion = apply { if (!validated) { id() @@ -141,15 +141,15 @@ 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. */ @@ -237,18 +237,24 @@ private constructor( 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, @@ -274,8 +280,6 @@ private constructor( private val additionalProperties: Map, ) { - 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 +320,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Choice = apply { if (!validated) { finishReason() @@ -343,11 +349,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() } /** @@ -400,18 +406,24 @@ private constructor( 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, @@ -507,8 +519,6 @@ private constructor( private val additionalProperties: Map, ) { - 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 +537,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 +562,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. */ @@ -579,12 +591,12 @@ private constructor( 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 +604,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..f2f3ed12 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 @@ -43,8 +43,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** * The contents of the assistant message. Required unless `tool_calls` or `function_call` is * specified. @@ -117,6 +115,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): ChatCompletionAssistantMessageParam = apply { if (!validated) { content() @@ -152,14 +152,15 @@ private constructor( internal fun from( chatCompletionAssistantMessageParam: ChatCompletionAssistantMessageParam ) = apply { - this.content = chatCompletionAssistantMessageParam.content - this.refusal = chatCompletionAssistantMessageParam.refusal - this.role = chatCompletionAssistantMessageParam.role - this.name = chatCompletionAssistantMessageParam.name - this.audio = chatCompletionAssistantMessageParam.audio - this.toolCalls = chatCompletionAssistantMessageParam.toolCalls - this.functionCall = chatCompletionAssistantMessageParam.functionCall - additionalProperties(chatCompletionAssistantMessageParam.additionalProperties) + content = chatCompletionAssistantMessageParam.content + refusal = chatCompletionAssistantMessageParam.refusal + role = chatCompletionAssistantMessageParam.role + name = chatCompletionAssistantMessageParam.name + audio = chatCompletionAssistantMessageParam.audio + toolCalls = chatCompletionAssistantMessageParam.toolCalls + functionCall = chatCompletionAssistantMessageParam.functionCall + additionalProperties = + chatCompletionAssistantMessageParam.additionalProperties.toMutableMap() } /** @@ -249,18 +250,24 @@ private constructor( 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(): ChatCompletionAssistantMessageParam = ChatCompletionAssistantMessageParam( content, @@ -337,8 +344,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** Unique identifier for a previous audio response from the model. */ fun id(): String = id.getRequired("id") @@ -349,6 +354,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Audio = apply { if (!validated) { id() @@ -370,8 +377,8 @@ private constructor( @JvmSynthetic internal fun from(audio: Audio) = apply { - this.id = audio.id - additionalProperties(audio.additionalProperties) + id = audio.id + additionalProperties = audio.additionalProperties.toMutableMap() } /** Unique identifier for a previous audio response from the model. */ @@ -384,18 +391,24 @@ private constructor( 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(): Audio = Audio(id, additionalProperties.toImmutable()) } @@ -749,8 +762,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** * The arguments to call the function with, as generated by the model in JSON format. Note * that the model does not always generate valid JSON, and may hallucinate parameters not @@ -777,6 +788,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): FunctionCall = apply { if (!validated) { arguments() @@ -800,9 +813,9 @@ private constructor( @JvmSynthetic internal fun from(functionCall: FunctionCall) = apply { - this.arguments = functionCall.arguments - this.name = functionCall.name - additionalProperties(functionCall.additionalProperties) + arguments = functionCall.arguments + name = functionCall.name + additionalProperties = functionCall.additionalProperties.toMutableMap() } /** @@ -833,18 +846,24 @@ private constructor( 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(): FunctionCall = FunctionCall( arguments, diff --git a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionAudio.kt b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionAudio.kt index 7efacfe1..3f934537 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionAudio.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionAudio.kt @@ -29,8 +29,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** Unique identifier for this audio response. */ fun id(): String = id.getRequired("id") @@ -69,6 +67,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): ChatCompletionAudio = apply { if (!validated) { id() @@ -96,11 +96,11 @@ private constructor( @JvmSynthetic internal fun from(chatCompletionAudio: ChatCompletionAudio) = apply { - this.id = chatCompletionAudio.id - this.expiresAt = chatCompletionAudio.expiresAt - this.data = chatCompletionAudio.data - this.transcript = chatCompletionAudio.transcript - additionalProperties(chatCompletionAudio.additionalProperties) + id = chatCompletionAudio.id + expiresAt = chatCompletionAudio.expiresAt + data = chatCompletionAudio.data + transcript = chatCompletionAudio.transcript + additionalProperties = chatCompletionAudio.additionalProperties.toMutableMap() } /** Unique identifier for this audio response. */ @@ -147,18 +147,24 @@ private constructor( 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(): ChatCompletionAudio = ChatCompletionAudio( id, diff --git a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionAudioParam.kt b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionAudioParam.kt index 55434c73..7db28342 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionAudioParam.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionAudioParam.kt @@ -30,8 +30,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** * The voice the model uses to respond. Supported voices are `ash`, `ballad`, `coral`, `sage`, * and `verse` (also supported but not recommended are `alloy`, `echo`, and `shimmer`; these @@ -60,6 +58,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): ChatCompletionAudioParam = apply { if (!validated) { voice() @@ -83,9 +83,9 @@ private constructor( @JvmSynthetic internal fun from(chatCompletionAudioParam: ChatCompletionAudioParam) = apply { - this.voice = chatCompletionAudioParam.voice - this.format = chatCompletionAudioParam.format - additionalProperties(chatCompletionAudioParam.additionalProperties) + voice = chatCompletionAudioParam.voice + format = chatCompletionAudioParam.format + additionalProperties = chatCompletionAudioParam.additionalProperties.toMutableMap() } /** @@ -120,18 +120,24 @@ private constructor( 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(): ChatCompletionAudioParam = ChatCompletionAudioParam( voice, diff --git a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionChunk.kt b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionChunk.kt index f6547d92..e239905c 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionChunk.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionChunk.kt @@ -37,8 +37,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** A unique identifier for the chat completion. Each chunk has the same ID. */ fun id(): String = id.getRequired("id") @@ -129,6 +127,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): ChatCompletionChunk = apply { if (!validated) { id() @@ -164,15 +164,15 @@ private constructor( @JvmSynthetic internal fun from(chatCompletionChunk: ChatCompletionChunk) = apply { - this.id = chatCompletionChunk.id - this.choices = chatCompletionChunk.choices - this.created = chatCompletionChunk.created - this.model = chatCompletionChunk.model - this.serviceTier = chatCompletionChunk.serviceTier - this.systemFingerprint = chatCompletionChunk.systemFingerprint - this.object_ = chatCompletionChunk.object_ - this.usage = chatCompletionChunk.usage - additionalProperties(chatCompletionChunk.additionalProperties) + id = chatCompletionChunk.id + choices = chatCompletionChunk.choices + created = chatCompletionChunk.created + model = chatCompletionChunk.model + serviceTier = chatCompletionChunk.serviceTier + systemFingerprint = chatCompletionChunk.systemFingerprint + object_ = chatCompletionChunk.object_ + usage = chatCompletionChunk.usage + additionalProperties = chatCompletionChunk.additionalProperties.toMutableMap() } /** A unique identifier for the chat completion. Each chunk has the same ID. */ @@ -280,18 +280,24 @@ private constructor( 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(): ChatCompletionChunk = ChatCompletionChunk( id, @@ -317,8 +323,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** A chat completion delta generated by streamed model responses. */ fun delta(): Delta = delta.getRequired("delta") @@ -360,6 +364,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Choice = apply { if (!validated) { delta().validate() @@ -387,11 +393,11 @@ private constructor( @JvmSynthetic internal fun from(choice: Choice) = apply { - this.delta = choice.delta - this.logprobs = choice.logprobs - this.finishReason = choice.finishReason - this.index = choice.index - additionalProperties(choice.additionalProperties) + delta = choice.delta + logprobs = choice.logprobs + finishReason = choice.finishReason + index = choice.index + additionalProperties = choice.additionalProperties.toMutableMap() } /** A chat completion delta generated by streamed model responses. */ @@ -442,18 +448,24 @@ private constructor( 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( delta, @@ -477,8 +489,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** The contents of the chunk message. */ fun content(): Optional = Optional.ofNullable(content.getNullable("content")) @@ -519,6 +529,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Delta = apply { if (!validated) { content() @@ -548,12 +560,12 @@ private constructor( @JvmSynthetic internal fun from(delta: Delta) = apply { - this.content = delta.content - this.functionCall = delta.functionCall - this.toolCalls = delta.toolCalls - this.role = delta.role - this.refusal = delta.refusal - additionalProperties(delta.additionalProperties) + content = delta.content + functionCall = delta.functionCall + toolCalls = delta.toolCalls + role = delta.role + refusal = delta.refusal + additionalProperties = delta.additionalProperties.toMutableMap() } /** The contents of the chunk message. */ @@ -607,12 +619,12 @@ private constructor( 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) = @@ -620,6 +632,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(): Delta = Delta( content, @@ -644,8 +664,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** * The arguments to call the function with, as generated by the model in JSON * format. Note that the model does not always generate valid JSON, and may @@ -673,6 +691,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): FunctionCall = apply { if (!validated) { arguments() @@ -696,9 +716,9 @@ private constructor( @JvmSynthetic internal fun from(functionCall: FunctionCall) = apply { - this.arguments = functionCall.arguments - this.name = functionCall.name - additionalProperties(functionCall.additionalProperties) + arguments = functionCall.arguments + name = functionCall.name + additionalProperties = functionCall.additionalProperties.toMutableMap() } /** @@ -731,12 +751,12 @@ private constructor( 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) = @@ -744,6 +764,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(): FunctionCall = FunctionCall( arguments, @@ -850,8 +878,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - fun index(): Long = index.getRequired("index") /** The ID of the tool call. */ @@ -877,6 +903,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): ToolCall = apply { if (!validated) { index() @@ -904,11 +932,11 @@ private constructor( @JvmSynthetic internal fun from(toolCall: ToolCall) = apply { - this.index = toolCall.index - this.id = toolCall.id - this.type = toolCall.type - this.function = toolCall.function - additionalProperties(toolCall.additionalProperties) + index = toolCall.index + id = toolCall.id + type = toolCall.type + function = toolCall.function + additionalProperties = toolCall.additionalProperties.toMutableMap() } fun index(index: Long) = index(JsonField.of(index)) @@ -941,12 +969,12 @@ private constructor( 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) = @@ -954,6 +982,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(): ToolCall = ToolCall( index, @@ -973,8 +1009,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** The name of the function to call. */ fun name(): Optional = Optional.ofNullable(name.getNullable("name")) @@ -1002,6 +1036,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Function = apply { if (!validated) { name() @@ -1026,9 +1062,9 @@ private constructor( @JvmSynthetic internal fun from(function: Function) = apply { - this.name = function.name - this.arguments = function.arguments - additionalProperties(function.additionalProperties) + name = function.name + arguments = function.arguments + additionalProperties = function.additionalProperties.toMutableMap() } /** The name of the function to call. */ @@ -1062,18 +1098,26 @@ private constructor( 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(): Function = Function( name, @@ -1273,8 +1317,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** A list of message content tokens with log probability information. */ fun content(): Optional> = Optional.ofNullable(content.getNullable("content")) @@ -1293,6 +1335,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() } } @@ -1316,9 +1360,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. */ @@ -1345,12 +1389,12 @@ private constructor( 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) = @@ -1358,6 +1402,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/ChatCompletionContentPartImage.kt b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionContentPartImage.kt index b4fd1f25..8469667b 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionContentPartImage.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionContentPartImage.kt @@ -28,8 +28,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** The type of the content part. */ fun type(): Type = type.getRequired("type") @@ -44,6 +42,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): ChatCompletionContentPartImage = apply { if (!validated) { type() @@ -67,9 +67,10 @@ private constructor( @JvmSynthetic internal fun from(chatCompletionContentPartImage: ChatCompletionContentPartImage) = apply { - this.type = chatCompletionContentPartImage.type - this.imageUrl = chatCompletionContentPartImage.imageUrl - additionalProperties(chatCompletionContentPartImage.additionalProperties) + type = chatCompletionContentPartImage.type + imageUrl = chatCompletionContentPartImage.imageUrl + additionalProperties = + chatCompletionContentPartImage.additionalProperties.toMutableMap() } /** The type of the content part. */ @@ -88,18 +89,24 @@ private constructor( 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(): ChatCompletionContentPartImage = ChatCompletionContentPartImage( type, @@ -117,8 +124,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** Either a URL of the image or the base64 encoded image data. */ fun url(): String = url.getRequired("url") @@ -141,6 +146,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): ImageUrl = apply { if (!validated) { url() @@ -164,9 +171,9 @@ private constructor( @JvmSynthetic internal fun from(imageUrl: ImageUrl) = apply { - this.url = imageUrl.url - this.detail = imageUrl.detail - additionalProperties(imageUrl.additionalProperties) + url = imageUrl.url + detail = imageUrl.detail + additionalProperties = imageUrl.additionalProperties.toMutableMap() } /** Either a URL of the image or the base64 encoded image data. */ @@ -193,18 +200,24 @@ private constructor( 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(): ImageUrl = ImageUrl( url, diff --git a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionContentPartInputAudio.kt b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionContentPartInputAudio.kt index d38fd276..3b0dd216 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionContentPartInputAudio.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionContentPartInputAudio.kt @@ -27,8 +27,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** The type of the content part. Always `input_audio`. */ fun type(): Type = type.getRequired("type") @@ -43,6 +41,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): ChatCompletionContentPartInputAudio = apply { if (!validated) { type() @@ -68,9 +68,10 @@ private constructor( internal fun from( chatCompletionContentPartInputAudio: ChatCompletionContentPartInputAudio ) = apply { - this.type = chatCompletionContentPartInputAudio.type - this.inputAudio = chatCompletionContentPartInputAudio.inputAudio - additionalProperties(chatCompletionContentPartInputAudio.additionalProperties) + type = chatCompletionContentPartInputAudio.type + inputAudio = chatCompletionContentPartInputAudio.inputAudio + additionalProperties = + chatCompletionContentPartInputAudio.additionalProperties.toMutableMap() } /** The type of the content part. Always `input_audio`. */ @@ -89,18 +90,24 @@ private constructor( 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(): ChatCompletionContentPartInputAudio = ChatCompletionContentPartInputAudio( type, @@ -118,8 +125,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** Base64 encoded audio data. */ fun data(): String = data.getRequired("data") @@ -136,6 +141,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): InputAudio = apply { if (!validated) { data() @@ -159,9 +166,9 @@ private constructor( @JvmSynthetic internal fun from(inputAudio: InputAudio) = apply { - this.data = inputAudio.data - this.format = inputAudio.format - additionalProperties(inputAudio.additionalProperties) + data = inputAudio.data + format = inputAudio.format + additionalProperties = inputAudio.additionalProperties.toMutableMap() } /** Base64 encoded audio data. */ @@ -182,18 +189,24 @@ private constructor( 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(): InputAudio = InputAudio( data, diff --git a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionContentPartRefusal.kt b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionContentPartRefusal.kt index de3eadd3..d981f028 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionContentPartRefusal.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionContentPartRefusal.kt @@ -26,8 +26,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** The type of the content part. */ fun type(): Type = type.getRequired("type") @@ -44,6 +42,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): ChatCompletionContentPartRefusal = apply { if (!validated) { type() @@ -68,9 +68,10 @@ private constructor( @JvmSynthetic internal fun from(chatCompletionContentPartRefusal: ChatCompletionContentPartRefusal) = apply { - this.type = chatCompletionContentPartRefusal.type - this.refusal = chatCompletionContentPartRefusal.refusal - additionalProperties(chatCompletionContentPartRefusal.additionalProperties) + type = chatCompletionContentPartRefusal.type + refusal = chatCompletionContentPartRefusal.refusal + additionalProperties = + chatCompletionContentPartRefusal.additionalProperties.toMutableMap() } /** The type of the content part. */ @@ -91,18 +92,24 @@ private constructor( 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(): ChatCompletionContentPartRefusal = ChatCompletionContentPartRefusal( type, diff --git a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionContentPartText.kt b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionContentPartText.kt index b20c390c..31362c31 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionContentPartText.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionContentPartText.kt @@ -27,8 +27,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** The type of the content part. */ fun type(): Type = type.getRequired("type") @@ -45,6 +43,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): ChatCompletionContentPartText = apply { if (!validated) { type() @@ -68,9 +68,9 @@ private constructor( @JvmSynthetic internal fun from(chatCompletionContentPartText: ChatCompletionContentPartText) = apply { - this.type = chatCompletionContentPartText.type - this.text = chatCompletionContentPartText.text - additionalProperties(chatCompletionContentPartText.additionalProperties) + type = chatCompletionContentPartText.type + text = chatCompletionContentPartText.text + additionalProperties = chatCompletionContentPartText.additionalProperties.toMutableMap() } /** The type of the content part. */ @@ -91,18 +91,24 @@ private constructor( 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(): ChatCompletionContentPartText = ChatCompletionContentPartText( type, diff --git a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionCreateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionCreateParams.kt index c72f280e..a559b170 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionCreateParams.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionCreateParams.kt @@ -173,8 +173,8 @@ constructor( @NoAutoDetect class ChatCompletionCreateBody internal constructor( - private val messages: List?, - private val model: ChatModel?, + private val messages: List, + private val model: ChatModel, private val audio: ChatCompletionAudioParam?, private val frequencyPenalty: Double?, private val functionCall: FunctionCall?, @@ -213,27 +213,29 @@ constructor( * [images](https://platform.openai.com/docs/guides/vision), and * [audio](https://platform.openai.com/docs/guides/audio). */ - @JsonProperty("messages") fun messages(): List? = messages + @JsonProperty("messages") fun messages(): List = messages /** * ID of the model to use. See the * [model endpoint compatibility](https://platform.openai.com/docs/models#model-endpoint-compatibility) * table for details on which models work with the Chat API. */ - @JsonProperty("model") fun model(): ChatModel? = model + @JsonProperty("model") fun model(): ChatModel = model /** * Parameters for audio output. Required when audio output is requested with `modalities: * ["audio"]`. [Learn more](https://platform.openai.com/docs/guides/audio). */ - @JsonProperty("audio") fun audio(): ChatCompletionAudioParam? = audio + @JsonProperty("audio") + fun audio(): Optional = Optional.ofNullable(audio) /** * Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing * frequency in the text so far, decreasing the model's likelihood to repeat the same line * verbatim. */ - @JsonProperty("frequency_penalty") fun frequencyPenalty(): Double? = frequencyPenalty + @JsonProperty("frequency_penalty") + fun frequencyPenalty(): Optional = Optional.ofNullable(frequencyPenalty) /** * Deprecated in favor of `tool_choice`. @@ -250,14 +252,16 @@ constructor( * `none` is the default when no functions are present. `auto` is the default if functions * are present. */ - @JsonProperty("function_call") fun functionCall(): FunctionCall? = functionCall + @JsonProperty("function_call") + fun functionCall(): Optional = Optional.ofNullable(functionCall) /** * Deprecated in favor of `tools`. * * A list of functions the model may generate JSON inputs for. */ - @JsonProperty("functions") fun functions(): List? = functions + @JsonProperty("functions") + fun functions(): Optional> = Optional.ofNullable(functions) /** * Modify the likelihood of specified tokens appearing in the completion. @@ -268,13 +272,14 @@ constructor( * but values between -1 and 1 should decrease or increase likelihood of selection; values * like -100 or 100 should result in a ban or exclusive selection of the relevant token. */ - @JsonProperty("logit_bias") fun logitBias(): LogitBias? = logitBias + @JsonProperty("logit_bias") + fun logitBias(): Optional = Optional.ofNullable(logitBias) /** * Whether to return log probabilities of the output tokens or not. If true, returns the log * probabilities of each output token returned in the `content` of `message`. */ - @JsonProperty("logprobs") fun logprobs(): Boolean? = logprobs + @JsonProperty("logprobs") fun logprobs(): Optional = Optional.ofNullable(logprobs) /** * An upper bound for the number of tokens that can be generated for a completion, including @@ -282,7 +287,7 @@ constructor( * [reasoning tokens](https://platform.openai.com/docs/guides/reasoning). */ @JsonProperty("max_completion_tokens") - fun maxCompletionTokens(): Long? = maxCompletionTokens + fun maxCompletionTokens(): Optional = Optional.ofNullable(maxCompletionTokens) /** * The maximum number of [tokens](/tokenizer) that can be generated in the chat completion. @@ -292,13 +297,13 @@ constructor( * This value is now deprecated in favor of `max_completion_tokens`, and is not compatible * with [o1 series models](https://platform.openai.com/docs/guides/reasoning). */ - @JsonProperty("max_tokens") fun maxTokens(): Long? = maxTokens + @JsonProperty("max_tokens") fun maxTokens(): Optional = Optional.ofNullable(maxTokens) /** * Developer-defined tags and values used for filtering completions in the * [dashboard](https://platform.openai.com/chat-completions). */ - @JsonProperty("metadata") fun metadata(): Metadata? = metadata + @JsonProperty("metadata") fun metadata(): Optional = Optional.ofNullable(metadata) /** * Output types that you would like the model to generate for this request. Most models are @@ -312,33 +317,38 @@ constructor( * * `["text", "audio"]` */ - @JsonProperty("modalities") fun modalities(): List? = modalities + @JsonProperty("modalities") + fun modalities(): Optional> = Optional.ofNullable(modalities) /** * How many chat completion choices to generate for each input message. Note that you will * be charged based on the number of generated tokens across all of the choices. Keep `n` as * `1` to minimize costs. */ - @JsonProperty("n") fun n(): Long? = n + @JsonProperty("n") fun n(): Optional = Optional.ofNullable(n) /** * 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(): Boolean? = parallelToolCalls + @JsonProperty("parallel_tool_calls") + fun parallelToolCalls(): Optional = Optional.ofNullable(parallelToolCalls) /** * Static predicted output content, such as the content of a text file that is being * regenerated. */ - @JsonProperty("prediction") fun prediction(): ChatCompletionPredictionContent? = prediction + @JsonProperty("prediction") + fun prediction(): Optional = + Optional.ofNullable(prediction) /** * Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they * appear in the text so far, increasing the model's likelihood to talk about new topics. */ - @JsonProperty("presence_penalty") fun presencePenalty(): Double? = presencePenalty + @JsonProperty("presence_penalty") + fun presencePenalty(): Optional = Optional.ofNullable(presencePenalty) /** * **o1 models only** @@ -349,7 +359,8 @@ constructor( * faster responses and fewer tokens used on reasoning in a response. */ @JsonProperty("reasoning_effort") - fun reasoningEffort(): ChatCompletionReasoningEffort? = reasoningEffort + fun reasoningEffort(): Optional = + Optional.ofNullable(reasoningEffort) /** * An object specifying the format that the model must output. @@ -368,7 +379,8 @@ constructor( * 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(): ResponseFormat? = responseFormat + @JsonProperty("response_format") + fun responseFormat(): Optional = Optional.ofNullable(responseFormat) /** * This feature is in Beta. If specified, our system will make a best effort to sample @@ -376,7 +388,7 @@ constructor( * return the same result. Determinism is not guaranteed, and you should refer to the * `system_fingerprint` response parameter to monitor changes in the backend. */ - @JsonProperty("seed") fun seed(): Long? = seed + @JsonProperty("seed") fun seed(): Optional = Optional.ofNullable(seed) /** * Specifies the latency tier to use for processing the request. This parameter is relevant @@ -392,28 +404,31 @@ constructor( * * When this parameter is set, the response body will include the `service_tier` utilized. */ - @JsonProperty("service_tier") fun serviceTier(): ServiceTier? = serviceTier + @JsonProperty("service_tier") + fun serviceTier(): Optional = Optional.ofNullable(serviceTier) /** Up to 4 sequences where the API will stop generating further tokens. */ - @JsonProperty("stop") fun stop(): Stop? = stop + @JsonProperty("stop") fun stop(): Optional = Optional.ofNullable(stop) /** * Whether or not to store the output of this chat completion request for use in our * [model distillation](https://platform.openai.com/docs/guides/distillation) or * [evals](https://platform.openai.com/docs/guides/evals) products. */ - @JsonProperty("store") fun store(): Boolean? = store + @JsonProperty("store") fun store(): Optional = Optional.ofNullable(store) /** Options for streaming response. Only set this when you set `stream: true`. */ @JsonProperty("stream_options") - fun streamOptions(): ChatCompletionStreamOptions? = streamOptions + fun streamOptions(): Optional = + Optional.ofNullable(streamOptions) /** * 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. We generally recommend altering this or `top_p` but not both. */ - @JsonProperty("temperature") fun temperature(): Double? = temperature + @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 @@ -425,21 +440,24 @@ constructor( * `none` is the default when no tools are present. `auto` is the default if tools are * present. */ - @JsonProperty("tool_choice") fun toolChoice(): ChatCompletionToolChoiceOption? = toolChoice + @JsonProperty("tool_choice") + fun toolChoice(): Optional = Optional.ofNullable(toolChoice) /** * A list of tools the model may call. Currently, only functions are supported as a tool. * Use this to provide a list of functions the model may generate JSON inputs for. A max of * 128 functions are supported. */ - @JsonProperty("tools") fun tools(): List? = tools + @JsonProperty("tools") + fun tools(): Optional> = Optional.ofNullable(tools) /** * An integer between 0 and 20 specifying the number of most likely tokens to return at each * token position, each with an associated log probability. `logprobs` must be set to `true` * if this parameter is used. */ - @JsonProperty("top_logprobs") fun topLogprobs(): Long? = topLogprobs + @JsonProperty("top_logprobs") + fun topLogprobs(): Optional = Optional.ofNullable(topLogprobs) /** * An alternative to sampling with temperature, called nucleus sampling, where the model @@ -448,14 +466,14 @@ constructor( * * We generally recommend altering this or `temperature` but not both. */ - @JsonProperty("top_p") fun topP(): Double? = topP + @JsonProperty("top_p") fun topP(): Optional = Optional.ofNullable(topP) /** * A unique identifier representing your end-user, which can help OpenAI to monitor and * detect abuse. * [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#end-user-ids). */ - @JsonProperty("user") fun user(): String? = user + @JsonProperty("user") fun user(): Optional = Optional.ofNullable(user) @JsonAnyGetter @ExcludeMissing @@ -503,36 +521,36 @@ constructor( @JvmSynthetic internal fun from(chatCompletionCreateBody: ChatCompletionCreateBody) = apply { - this.messages = chatCompletionCreateBody.messages - this.model = chatCompletionCreateBody.model - this.audio = chatCompletionCreateBody.audio - this.frequencyPenalty = chatCompletionCreateBody.frequencyPenalty - this.functionCall = chatCompletionCreateBody.functionCall - this.functions = chatCompletionCreateBody.functions - this.logitBias = chatCompletionCreateBody.logitBias - this.logprobs = chatCompletionCreateBody.logprobs - this.maxCompletionTokens = chatCompletionCreateBody.maxCompletionTokens - this.maxTokens = chatCompletionCreateBody.maxTokens - this.metadata = chatCompletionCreateBody.metadata - this.modalities = chatCompletionCreateBody.modalities - this.n = chatCompletionCreateBody.n - this.parallelToolCalls = chatCompletionCreateBody.parallelToolCalls - this.prediction = chatCompletionCreateBody.prediction - this.presencePenalty = chatCompletionCreateBody.presencePenalty - this.reasoningEffort = chatCompletionCreateBody.reasoningEffort - this.responseFormat = chatCompletionCreateBody.responseFormat - this.seed = chatCompletionCreateBody.seed - this.serviceTier = chatCompletionCreateBody.serviceTier - this.stop = chatCompletionCreateBody.stop - this.store = chatCompletionCreateBody.store - this.streamOptions = chatCompletionCreateBody.streamOptions - this.temperature = chatCompletionCreateBody.temperature - this.toolChoice = chatCompletionCreateBody.toolChoice - this.tools = chatCompletionCreateBody.tools - this.topLogprobs = chatCompletionCreateBody.topLogprobs - this.topP = chatCompletionCreateBody.topP - this.user = chatCompletionCreateBody.user - additionalProperties(chatCompletionCreateBody.additionalProperties) + messages = chatCompletionCreateBody.messages.toMutableList() + model = chatCompletionCreateBody.model + audio = chatCompletionCreateBody.audio + frequencyPenalty = chatCompletionCreateBody.frequencyPenalty + functionCall = chatCompletionCreateBody.functionCall + functions = chatCompletionCreateBody.functions?.toMutableList() + logitBias = chatCompletionCreateBody.logitBias + logprobs = chatCompletionCreateBody.logprobs + maxCompletionTokens = chatCompletionCreateBody.maxCompletionTokens + maxTokens = chatCompletionCreateBody.maxTokens + metadata = chatCompletionCreateBody.metadata + modalities = chatCompletionCreateBody.modalities?.toMutableList() + n = chatCompletionCreateBody.n + parallelToolCalls = chatCompletionCreateBody.parallelToolCalls + prediction = chatCompletionCreateBody.prediction + presencePenalty = chatCompletionCreateBody.presencePenalty + reasoningEffort = chatCompletionCreateBody.reasoningEffort + responseFormat = chatCompletionCreateBody.responseFormat + seed = chatCompletionCreateBody.seed + serviceTier = chatCompletionCreateBody.serviceTier + stop = chatCompletionCreateBody.stop + store = chatCompletionCreateBody.store + streamOptions = chatCompletionCreateBody.streamOptions + temperature = chatCompletionCreateBody.temperature + toolChoice = chatCompletionCreateBody.toolChoice + tools = chatCompletionCreateBody.tools?.toMutableList() + topLogprobs = chatCompletionCreateBody.topLogprobs + topP = chatCompletionCreateBody.topP + user = chatCompletionCreateBody.user + additionalProperties = chatCompletionCreateBody.additionalProperties.toMutableMap() } /** @@ -837,18 +855,24 @@ constructor( 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(): ChatCompletionCreateBody = ChatCompletionCreateBody( checkNotNull(messages) { "`messages` is required but was not set" } @@ -1613,8 +1637,6 @@ constructor( private val _json: JsonValue? = null, ) { - private var validated: Boolean = false - /** * `none` means the model will not call a function and instead generates a message. `auto` * means the model can pick between generating a message or calling a function. @@ -1646,16 +1668,6 @@ constructor( } } - fun validate(): FunctionCall = apply { - if (!validated) { - if (behavior == null && functionCallOption == null) { - throw OpenAIInvalidDataException("Unknown FunctionCall: $_json") - } - functionCallOption?.validate() - validated = true - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1702,12 +1714,9 @@ constructor( tryDeserialize(node, jacksonTypeRef())?.let { return FunctionCall(behavior = it, _json = json) } - tryDeserialize(node, jacksonTypeRef()) { - it.validate() - } - ?.let { - return FunctionCall(functionCallOption = it, _json = json) - } + tryDeserialize(node, jacksonTypeRef())?.let { + return FunctionCall(functionCallOption = it, _json = json) + } return FunctionCall(_json = json) } @@ -1793,7 +1802,7 @@ constructor( class Function private constructor( private val description: String?, - private val name: String?, + private val name: String, private val parameters: FunctionParameters?, private val additionalProperties: Map, ) { @@ -1802,13 +1811,14 @@ constructor( * A description of what the function does, used by the model to choose when and how to call * the function. */ - @JsonProperty("description") fun description(): String? = description + @JsonProperty("description") + fun description(): Optional = Optional.ofNullable(description) /** * The name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and * dashes, with a maximum length of 64. */ - @JsonProperty("name") fun name(): String? = name + @JsonProperty("name") fun name(): String = name /** * The parameters the functions accepts, described as a JSON Schema object. See the @@ -1818,7 +1828,8 @@ constructor( * * Omitting `parameters` defines a function with an empty parameter list. */ - @JsonProperty("parameters") fun parameters(): FunctionParameters? = parameters + @JsonProperty("parameters") + fun parameters(): Optional = Optional.ofNullable(parameters) @JsonAnyGetter @ExcludeMissing @@ -1840,10 +1851,10 @@ constructor( @JvmSynthetic internal fun from(function: Function) = apply { - this.description = function.description - this.name = function.name - this.parameters = function.parameters - additionalProperties(function.additionalProperties) + description = function.description + name = function.name + parameters = function.parameters + additionalProperties = function.additionalProperties.toMutableMap() } /** @@ -1872,18 +1883,24 @@ constructor( 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(): Function = Function( description, @@ -1944,23 +1961,29 @@ constructor( @JvmSynthetic internal fun from(logitBias: LogitBias) = apply { - additionalProperties(logitBias.additionalProperties) + additionalProperties = logitBias.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(): LogitBias = LogitBias(additionalProperties.toImmutable()) } @@ -2009,23 +2032,29 @@ 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()) } @@ -2056,8 +2085,6 @@ constructor( private val _json: JsonValue? = null, ) { - private var validated: Boolean = false - fun responseFormatText(): Optional = Optional.ofNullable(responseFormatText) @@ -2095,22 +2122,6 @@ constructor( } } - fun validate(): ResponseFormat = apply { - if (!validated) { - if ( - responseFormatText == null && - responseFormatJsonObject == null && - responseFormatJsonSchema == null - ) { - throw OpenAIInvalidDataException("Unknown ResponseFormat: $_json") - } - responseFormatText?.validate() - responseFormatJsonObject?.validate() - responseFormatJsonSchema?.validate() - validated = true - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -2166,18 +2177,15 @@ constructor( override fun ObjectCodec.deserialize(node: JsonNode): ResponseFormat { val json = JsonValue.fromJsonNode(node) - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return ResponseFormat(responseFormatText = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return ResponseFormat(responseFormatJsonObject = it, _json = json) - } - tryDeserialize(node, jacksonTypeRef()) { it.validate() } - ?.let { - return ResponseFormat(responseFormatJsonSchema = it, _json = json) - } + tryDeserialize(node, jacksonTypeRef())?.let { + return ResponseFormat(responseFormatText = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef())?.let { + return ResponseFormat(responseFormatJsonObject = it, _json = json) + } + tryDeserialize(node, jacksonTypeRef())?.let { + return ResponseFormat(responseFormatJsonSchema = it, _json = json) + } return ResponseFormat(_json = json) } @@ -2270,8 +2278,6 @@ constructor( private val _json: JsonValue? = null, ) { - private var validated: Boolean = false - fun string(): Optional = Optional.ofNullable(string) fun strings(): Optional> = Optional.ofNullable(strings) @@ -2294,15 +2300,6 @@ constructor( } } - fun validate(): Stop = apply { - if (!validated) { - if (string == null && strings == null) { - throw OpenAIInvalidDataException("Unknown Stop: $_json") - } - validated = true - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionDeveloperMessageParam.kt b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionDeveloperMessageParam.kt index fb190a1c..f73c25fb 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionDeveloperMessageParam.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionDeveloperMessageParam.kt @@ -41,8 +41,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** The contents of the developer message. */ fun content(): Content = content.getRequired("content") @@ -71,6 +69,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): ChatCompletionDeveloperMessageParam = apply { if (!validated) { content() @@ -98,10 +98,11 @@ private constructor( internal fun from( chatCompletionDeveloperMessageParam: ChatCompletionDeveloperMessageParam ) = apply { - this.content = chatCompletionDeveloperMessageParam.content - this.role = chatCompletionDeveloperMessageParam.role - this.name = chatCompletionDeveloperMessageParam.name - additionalProperties(chatCompletionDeveloperMessageParam.additionalProperties) + content = chatCompletionDeveloperMessageParam.content + role = chatCompletionDeveloperMessageParam.role + name = chatCompletionDeveloperMessageParam.name + additionalProperties = + chatCompletionDeveloperMessageParam.additionalProperties.toMutableMap() } /** The contents of the developer message. */ @@ -136,18 +137,24 @@ private constructor( 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(): ChatCompletionDeveloperMessageParam = ChatCompletionDeveloperMessageParam( content, diff --git a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionFunctionCallOption.kt b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionFunctionCallOption.kt index 7535abbf..98ebfa62 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionFunctionCallOption.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionFunctionCallOption.kt @@ -26,8 +26,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** The name of the function to call. */ fun name(): String = name.getRequired("name") @@ -38,6 +36,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): ChatCompletionFunctionCallOption = apply { if (!validated) { name() @@ -60,8 +60,9 @@ private constructor( @JvmSynthetic internal fun from(chatCompletionFunctionCallOption: ChatCompletionFunctionCallOption) = apply { - this.name = chatCompletionFunctionCallOption.name - additionalProperties(chatCompletionFunctionCallOption.additionalProperties) + name = chatCompletionFunctionCallOption.name + additionalProperties = + chatCompletionFunctionCallOption.additionalProperties.toMutableMap() } /** The name of the function to call. */ @@ -74,18 +75,24 @@ private constructor( 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(): ChatCompletionFunctionCallOption = ChatCompletionFunctionCallOption(name, additionalProperties.toImmutable()) } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionFunctionMessageParam.kt b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionFunctionMessageParam.kt index b8582701..87f4e7c8 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionFunctionMessageParam.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionFunctionMessageParam.kt @@ -28,8 +28,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** The role of the messages author, in this case `function`. */ fun role(): Role = role.getRequired("role") @@ -52,6 +50,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): ChatCompletionFunctionMessageParam = apply { if (!validated) { role() @@ -78,10 +78,11 @@ private constructor( @JvmSynthetic internal fun from(chatCompletionFunctionMessageParam: ChatCompletionFunctionMessageParam) = apply { - this.role = chatCompletionFunctionMessageParam.role - this.content = chatCompletionFunctionMessageParam.content - this.name = chatCompletionFunctionMessageParam.name - additionalProperties(chatCompletionFunctionMessageParam.additionalProperties) + role = chatCompletionFunctionMessageParam.role + content = chatCompletionFunctionMessageParam.content + name = chatCompletionFunctionMessageParam.name + additionalProperties = + chatCompletionFunctionMessageParam.additionalProperties.toMutableMap() } /** The role of the messages author, in this case `function`. */ @@ -110,18 +111,24 @@ private constructor( 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(): ChatCompletionFunctionMessageParam = ChatCompletionFunctionMessageParam( role, diff --git a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionMessage.kt b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionMessage.kt index 84e48d67..641c28cf 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionMessage.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionMessage.kt @@ -32,8 +32,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** The contents of the message. */ fun content(): Optional = Optional.ofNullable(content.getNullable("content")) @@ -88,6 +86,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): ChatCompletionMessage = apply { if (!validated) { content() @@ -119,13 +119,13 @@ private constructor( @JvmSynthetic internal fun from(chatCompletionMessage: ChatCompletionMessage) = apply { - this.content = chatCompletionMessage.content - this.refusal = chatCompletionMessage.refusal - this.toolCalls = chatCompletionMessage.toolCalls - this.role = chatCompletionMessage.role - this.functionCall = chatCompletionMessage.functionCall - this.audio = chatCompletionMessage.audio - additionalProperties(chatCompletionMessage.additionalProperties) + content = chatCompletionMessage.content + refusal = chatCompletionMessage.refusal + toolCalls = chatCompletionMessage.toolCalls + role = chatCompletionMessage.role + functionCall = chatCompletionMessage.functionCall + audio = chatCompletionMessage.audio + additionalProperties = chatCompletionMessage.additionalProperties.toMutableMap() } /** The contents of the message. */ @@ -195,18 +195,24 @@ private constructor( 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(): ChatCompletionMessage = ChatCompletionMessage( content, @@ -283,8 +289,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** * The arguments to call the function with, as generated by the model in JSON format. Note * that the model does not always generate valid JSON, and may hallucinate parameters not @@ -311,6 +315,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): FunctionCall = apply { if (!validated) { arguments() @@ -334,9 +340,9 @@ private constructor( @JvmSynthetic internal fun from(functionCall: FunctionCall) = apply { - this.arguments = functionCall.arguments - this.name = functionCall.name - additionalProperties(functionCall.additionalProperties) + arguments = functionCall.arguments + name = functionCall.name + additionalProperties = functionCall.additionalProperties.toMutableMap() } /** @@ -367,18 +373,24 @@ private constructor( 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(): FunctionCall = FunctionCall( arguments, diff --git a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionMessageToolCall.kt b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionMessageToolCall.kt index 87e15127..cb15680b 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionMessageToolCall.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionMessageToolCall.kt @@ -27,8 +27,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** The ID of the tool call. */ fun id(): String = id.getRequired("id") @@ -51,6 +49,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): ChatCompletionMessageToolCall = apply { if (!validated) { id() @@ -76,10 +76,10 @@ private constructor( @JvmSynthetic internal fun from(chatCompletionMessageToolCall: ChatCompletionMessageToolCall) = apply { - this.id = chatCompletionMessageToolCall.id - this.type = chatCompletionMessageToolCall.type - this.function = chatCompletionMessageToolCall.function - additionalProperties(chatCompletionMessageToolCall.additionalProperties) + id = chatCompletionMessageToolCall.id + type = chatCompletionMessageToolCall.type + function = chatCompletionMessageToolCall.function + additionalProperties = chatCompletionMessageToolCall.additionalProperties.toMutableMap() } /** The ID of the tool call. */ @@ -106,18 +106,24 @@ private constructor( 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(): ChatCompletionMessageToolCall = ChatCompletionMessageToolCall( id, @@ -137,8 +143,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** The name of the function to call. */ fun name(): String = name.getRequired("name") @@ -165,6 +169,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Function = apply { if (!validated) { name() @@ -188,9 +194,9 @@ private constructor( @JvmSynthetic internal fun from(function: Function) = apply { - this.name = function.name - this.arguments = function.arguments - additionalProperties(function.additionalProperties) + name = function.name + arguments = function.arguments + additionalProperties = function.additionalProperties.toMutableMap() } /** The name of the function to call. */ @@ -221,18 +227,24 @@ private constructor( 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(): Function = Function( name, diff --git a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionNamedToolChoice.kt b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionNamedToolChoice.kt index ca3b88e1..77194577 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionNamedToolChoice.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionNamedToolChoice.kt @@ -27,8 +27,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** The type of the tool. Currently, only `function` is supported. */ fun type(): Type = type.getRequired("type") @@ -43,6 +41,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): ChatCompletionNamedToolChoice = apply { if (!validated) { type() @@ -66,9 +66,9 @@ private constructor( @JvmSynthetic internal fun from(chatCompletionNamedToolChoice: ChatCompletionNamedToolChoice) = apply { - this.type = chatCompletionNamedToolChoice.type - this.function = chatCompletionNamedToolChoice.function - additionalProperties(chatCompletionNamedToolChoice.additionalProperties) + type = chatCompletionNamedToolChoice.type + function = chatCompletionNamedToolChoice.function + additionalProperties = chatCompletionNamedToolChoice.additionalProperties.toMutableMap() } /** The type of the tool. Currently, only `function` is supported. */ @@ -87,18 +87,24 @@ private constructor( 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(): ChatCompletionNamedToolChoice = ChatCompletionNamedToolChoice( type, @@ -115,8 +121,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** The name of the function to call. */ fun name(): String = name.getRequired("name") @@ -127,6 +131,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Function = apply { if (!validated) { name() @@ -148,8 +154,8 @@ private constructor( @JvmSynthetic internal fun from(function: Function) = apply { - this.name = function.name - additionalProperties(function.additionalProperties) + name = function.name + additionalProperties = function.additionalProperties.toMutableMap() } /** The name of the function to call. */ @@ -162,18 +168,24 @@ private constructor( 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(): Function = Function(name, additionalProperties.toImmutable()) } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionPredictionContent.kt b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionPredictionContent.kt index 6c588848..8bd54ecf 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionPredictionContent.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionPredictionContent.kt @@ -39,8 +39,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** * The type of the predicted content you want to provide. This type is currently always * `content`. @@ -69,6 +67,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): ChatCompletionPredictionContent = apply { if (!validated) { type() @@ -93,9 +93,10 @@ private constructor( @JvmSynthetic internal fun from(chatCompletionPredictionContent: ChatCompletionPredictionContent) = apply { - this.type = chatCompletionPredictionContent.type - this.content = chatCompletionPredictionContent.content - additionalProperties(chatCompletionPredictionContent.additionalProperties) + type = chatCompletionPredictionContent.type + content = chatCompletionPredictionContent.content + additionalProperties = + chatCompletionPredictionContent.additionalProperties.toMutableMap() } /** @@ -128,18 +129,24 @@ private constructor( 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(): ChatCompletionPredictionContent = ChatCompletionPredictionContent( type, diff --git a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionStreamOptions.kt b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionStreamOptions.kt index ff1c5506..213de4c2 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionStreamOptions.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionStreamOptions.kt @@ -24,8 +24,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** * If set, an additional chunk will be streamed before the `data: [DONE]` message. The `usage` * field on this chunk shows the token usage statistics for the entire request, and the @@ -47,6 +45,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): ChatCompletionStreamOptions = apply { if (!validated) { includeUsage() @@ -68,8 +68,8 @@ private constructor( @JvmSynthetic internal fun from(chatCompletionStreamOptions: ChatCompletionStreamOptions) = apply { - this.includeUsage = chatCompletionStreamOptions.includeUsage - additionalProperties(chatCompletionStreamOptions.additionalProperties) + includeUsage = chatCompletionStreamOptions.includeUsage + additionalProperties = chatCompletionStreamOptions.additionalProperties.toMutableMap() } /** @@ -94,18 +94,24 @@ private constructor( 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(): ChatCompletionStreamOptions = ChatCompletionStreamOptions(includeUsage, additionalProperties.toImmutable()) } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionSystemMessageParam.kt b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionSystemMessageParam.kt index 098f4323..29ba0e2d 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionSystemMessageParam.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionSystemMessageParam.kt @@ -41,8 +41,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** The contents of the system message. */ fun content(): Content = content.getRequired("content") @@ -71,6 +69,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): ChatCompletionSystemMessageParam = apply { if (!validated) { content() @@ -97,10 +97,11 @@ private constructor( @JvmSynthetic internal fun from(chatCompletionSystemMessageParam: ChatCompletionSystemMessageParam) = apply { - this.content = chatCompletionSystemMessageParam.content - this.role = chatCompletionSystemMessageParam.role - this.name = chatCompletionSystemMessageParam.name - additionalProperties(chatCompletionSystemMessageParam.additionalProperties) + content = chatCompletionSystemMessageParam.content + role = chatCompletionSystemMessageParam.role + name = chatCompletionSystemMessageParam.name + additionalProperties = + chatCompletionSystemMessageParam.additionalProperties.toMutableMap() } /** The contents of the system message. */ @@ -135,18 +136,24 @@ private constructor( 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(): ChatCompletionSystemMessageParam = ChatCompletionSystemMessageParam( content, diff --git a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionTokenLogprob.kt b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionTokenLogprob.kt index ee476074..82401e11 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionTokenLogprob.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionTokenLogprob.kt @@ -26,8 +26,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** The token. */ fun token(): String = token.getRequired("token") @@ -78,6 +76,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): ChatCompletionTokenLogprob = apply { if (!validated) { token() @@ -105,11 +105,11 @@ private constructor( @JvmSynthetic internal fun from(chatCompletionTokenLogprob: ChatCompletionTokenLogprob) = apply { - this.token = chatCompletionTokenLogprob.token - this.logprob = chatCompletionTokenLogprob.logprob - this.bytes = chatCompletionTokenLogprob.bytes - this.topLogprobs = chatCompletionTokenLogprob.topLogprobs - additionalProperties(chatCompletionTokenLogprob.additionalProperties) + token = chatCompletionTokenLogprob.token + logprob = chatCompletionTokenLogprob.logprob + bytes = chatCompletionTokenLogprob.bytes + topLogprobs = chatCompletionTokenLogprob.topLogprobs + additionalProperties = chatCompletionTokenLogprob.additionalProperties.toMutableMap() } /** The token. */ @@ -170,18 +170,24 @@ private constructor( 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(): ChatCompletionTokenLogprob = ChatCompletionTokenLogprob( token, @@ -202,8 +208,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** The token. */ fun token(): String = token.getRequired("token") @@ -242,6 +246,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): TopLogprob = apply { if (!validated) { token() @@ -267,10 +273,10 @@ private constructor( @JvmSynthetic internal fun from(topLogprob: TopLogprob) = apply { - this.token = topLogprob.token - this.logprob = topLogprob.logprob - this.bytes = topLogprob.bytes - additionalProperties(topLogprob.additionalProperties) + token = topLogprob.token + logprob = topLogprob.logprob + bytes = topLogprob.bytes + additionalProperties = topLogprob.additionalProperties.toMutableMap() } /** The token. */ @@ -315,18 +321,24 @@ private constructor( 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(): TopLogprob = TopLogprob( token, diff --git a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionTool.kt b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionTool.kt index f1e1f3f6..401cd4e2 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionTool.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionTool.kt @@ -26,8 +26,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** The type of the tool. Currently, only `function` is supported. */ fun type(): Type = type.getRequired("type") @@ -42,6 +40,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): ChatCompletionTool = apply { if (!validated) { type() @@ -65,9 +65,9 @@ private constructor( @JvmSynthetic internal fun from(chatCompletionTool: ChatCompletionTool) = apply { - this.type = chatCompletionTool.type - this.function = chatCompletionTool.function - additionalProperties(chatCompletionTool.additionalProperties) + type = chatCompletionTool.type + function = chatCompletionTool.function + additionalProperties = chatCompletionTool.additionalProperties.toMutableMap() } /** The type of the tool. Currently, only `function` is supported. */ @@ -86,18 +86,24 @@ private constructor( 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(): ChatCompletionTool = ChatCompletionTool( type, diff --git a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionToolMessageParam.kt b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionToolMessageParam.kt index 0106764f..7f763b6f 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionToolMessageParam.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionToolMessageParam.kt @@ -37,8 +37,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** The role of the messages author, in this case `tool`. */ fun role(): Role = role.getRequired("role") @@ -61,6 +59,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): ChatCompletionToolMessageParam = apply { if (!validated) { role() @@ -86,10 +86,11 @@ private constructor( @JvmSynthetic internal fun from(chatCompletionToolMessageParam: ChatCompletionToolMessageParam) = apply { - this.role = chatCompletionToolMessageParam.role - this.content = chatCompletionToolMessageParam.content - this.toolCallId = chatCompletionToolMessageParam.toolCallId - additionalProperties(chatCompletionToolMessageParam.additionalProperties) + role = chatCompletionToolMessageParam.role + content = chatCompletionToolMessageParam.content + toolCallId = chatCompletionToolMessageParam.toolCallId + additionalProperties = + chatCompletionToolMessageParam.additionalProperties.toMutableMap() } /** The role of the messages author, in this case `tool`. */ @@ -118,18 +119,24 @@ private constructor( 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(): ChatCompletionToolMessageParam = ChatCompletionToolMessageParam( role, diff --git a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionUserMessageParam.kt b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionUserMessageParam.kt index 3afa688d..13e75208 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionUserMessageParam.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/ChatCompletionUserMessageParam.kt @@ -38,8 +38,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** The contents of the user message. */ fun content(): Content = content.getRequired("content") @@ -68,6 +66,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): ChatCompletionUserMessageParam = apply { if (!validated) { content() @@ -93,10 +93,11 @@ private constructor( @JvmSynthetic internal fun from(chatCompletionUserMessageParam: ChatCompletionUserMessageParam) = apply { - this.content = chatCompletionUserMessageParam.content - this.role = chatCompletionUserMessageParam.role - this.name = chatCompletionUserMessageParam.name - additionalProperties(chatCompletionUserMessageParam.additionalProperties) + content = chatCompletionUserMessageParam.content + role = chatCompletionUserMessageParam.role + name = chatCompletionUserMessageParam.name + additionalProperties = + chatCompletionUserMessageParam.additionalProperties.toMutableMap() } /** The contents of the user message. */ @@ -131,18 +132,24 @@ private constructor( 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(): ChatCompletionUserMessageParam = ChatCompletionUserMessageParam( content, diff --git a/openai-java-core/src/main/kotlin/com/openai/models/Completion.kt b/openai-java-core/src/main/kotlin/com/openai/models/Completion.kt index e26c7c6e..5ec1fe82 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/Completion.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/Completion.kt @@ -36,8 +36,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** A unique identifier for the completion. */ fun id(): String = id.getRequired("id") @@ -95,6 +93,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Completion = apply { if (!validated) { id() @@ -128,14 +128,14 @@ private constructor( @JvmSynthetic internal fun from(completion: Completion) = apply { - this.id = completion.id - this.choices = completion.choices - this.created = completion.created - this.model = completion.model - this.systemFingerprint = completion.systemFingerprint - this.object_ = completion.object_ - this.usage = completion.usage - additionalProperties(completion.additionalProperties) + id = completion.id + choices = completion.choices + created = completion.created + model = completion.model + systemFingerprint = completion.systemFingerprint + object_ = completion.object_ + usage = completion.usage + additionalProperties = completion.additionalProperties.toMutableMap() } /** A unique identifier for the completion. */ @@ -207,18 +207,24 @@ private constructor( 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(): Completion = Completion( id, diff --git a/openai-java-core/src/main/kotlin/com/openai/models/CompletionChoice.kt b/openai-java-core/src/main/kotlin/com/openai/models/CompletionChoice.kt index 7c7c114d..65dbea67 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/CompletionChoice.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/CompletionChoice.kt @@ -29,8 +29,6 @@ private constructor( private val additionalProperties: Map, ) { - 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 @@ -63,6 +61,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): CompletionChoice = apply { if (!validated) { finishReason() @@ -90,11 +90,11 @@ private constructor( @JvmSynthetic internal fun from(completionChoice: CompletionChoice) = apply { - this.finishReason = completionChoice.finishReason - this.index = completionChoice.index - this.logprobs = completionChoice.logprobs - this.text = completionChoice.text - additionalProperties(completionChoice.additionalProperties) + finishReason = completionChoice.finishReason + index = completionChoice.index + logprobs = completionChoice.logprobs + text = completionChoice.text + additionalProperties = completionChoice.additionalProperties.toMutableMap() } /** @@ -137,18 +137,24 @@ private constructor( 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(): CompletionChoice = CompletionChoice( finishReason, @@ -233,8 +239,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - fun textOffset(): Optional> = Optional.ofNullable(textOffset.getNullable("text_offset")) @@ -258,6 +262,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Logprobs = apply { if (!validated) { textOffset() @@ -285,11 +291,11 @@ private constructor( @JvmSynthetic internal fun from(logprobs: Logprobs) = apply { - this.textOffset = logprobs.textOffset - this.tokenLogprobs = logprobs.tokenLogprobs - this.tokens = logprobs.tokens - this.topLogprobs = logprobs.topLogprobs - additionalProperties(logprobs.additionalProperties) + textOffset = logprobs.textOffset + tokenLogprobs = logprobs.tokenLogprobs + tokens = logprobs.tokens + topLogprobs = logprobs.topLogprobs + additionalProperties = logprobs.additionalProperties.toMutableMap() } fun textOffset(textOffset: List) = textOffset(JsonField.of(textOffset)) @@ -325,18 +331,24 @@ private constructor( 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(): Logprobs = Logprobs( textOffset.map { it.toImmutable() }, @@ -354,12 +366,12 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): TopLogprob = apply { if (!validated) { validated = true @@ -379,17 +391,17 @@ private constructor( @JvmSynthetic internal fun from(topLogprob: TopLogprob) = apply { - additionalProperties(topLogprob.additionalProperties) + additionalProperties = topLogprob.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) = @@ -397,6 +409,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(): TopLogprob = TopLogprob(additionalProperties.toImmutable()) } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/CompletionCreateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/CompletionCreateParams.kt index aca4bc01..d0e56e8a 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/CompletionCreateParams.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/CompletionCreateParams.kt @@ -124,7 +124,7 @@ constructor( @NoAutoDetect class CompletionCreateBody internal constructor( - private val model: Model?, + private val model: Model, private val prompt: Prompt?, private val bestOf: Long?, private val echo: Boolean?, @@ -150,7 +150,7 @@ constructor( * of your available models, or see our * [Model overview](https://platform.openai.com/docs/models) for descriptions of them. */ - @JsonProperty("model") fun model(): Model? = model + @JsonProperty("model") fun model(): Model = model /** * The prompt(s) to generate completions for, encoded as a string, array of strings, array @@ -160,7 +160,7 @@ constructor( * if a prompt is not specified the model will generate as if from the beginning of a new * document. */ - @JsonProperty("prompt") fun prompt(): Prompt? = prompt + @JsonProperty("prompt") fun prompt(): Optional = Optional.ofNullable(prompt) /** * Generates `best_of` completions server-side and returns the "best" (the one with the @@ -173,10 +173,10 @@ constructor( * token quota. Use carefully and ensure that you have reasonable settings for `max_tokens` * and `stop`. */ - @JsonProperty("best_of") fun bestOf(): Long? = bestOf + @JsonProperty("best_of") fun bestOf(): Optional = Optional.ofNullable(bestOf) /** Echo back the prompt in addition to the completion */ - @JsonProperty("echo") fun echo(): Boolean? = echo + @JsonProperty("echo") fun echo(): Optional = Optional.ofNullable(echo) /** * Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing @@ -186,7 +186,8 @@ constructor( * [See more information about frequency and presence * penalties.](https://platform.openai.com/docs/guides/text-generation) */ - @JsonProperty("frequency_penalty") fun frequencyPenalty(): Double? = frequencyPenalty + @JsonProperty("frequency_penalty") + fun frequencyPenalty(): Optional = Optional.ofNullable(frequencyPenalty) /** * Modify the likelihood of specified tokens appearing in the completion. @@ -202,7 +203,8 @@ constructor( * As an example, you can pass `{"50256": -100}` to prevent the <|endoftext|> token from * being generated. */ - @JsonProperty("logit_bias") fun logitBias(): LogitBias? = logitBias + @JsonProperty("logit_bias") + fun logitBias(): Optional = Optional.ofNullable(logitBias) /** * Include the log probabilities on the `logprobs` most likely output tokens, as well the @@ -212,7 +214,7 @@ constructor( * * The maximum value for `logprobs` is 5. */ - @JsonProperty("logprobs") fun logprobs(): Long? = logprobs + @JsonProperty("logprobs") fun logprobs(): Optional = Optional.ofNullable(logprobs) /** * The maximum number of [tokens](/tokenizer) that can be generated in the completion. @@ -222,7 +224,7 @@ constructor( * [Example Python code](https://cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken) * for counting tokens. */ - @JsonProperty("max_tokens") fun maxTokens(): Long? = maxTokens + @JsonProperty("max_tokens") fun maxTokens(): Optional = Optional.ofNullable(maxTokens) /** * How many completions to generate for each prompt. @@ -231,7 +233,7 @@ constructor( * token quota. Use carefully and ensure that you have reasonable settings for `max_tokens` * and `stop`. */ - @JsonProperty("n") fun n(): Long? = n + @JsonProperty("n") fun n(): Optional = Optional.ofNullable(n) /** * Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they @@ -240,7 +242,8 @@ constructor( * [See more information about frequency and presence * penalties.](https://platform.openai.com/docs/guides/text-generation) */ - @JsonProperty("presence_penalty") fun presencePenalty(): Double? = presencePenalty + @JsonProperty("presence_penalty") + fun presencePenalty(): Optional = Optional.ofNullable(presencePenalty) /** * If specified, our system will make a best effort to sample deterministically, such that @@ -249,24 +252,25 @@ constructor( * Determinism is not guaranteed, and you should refer to the `system_fingerprint` response * parameter to monitor changes in the backend. */ - @JsonProperty("seed") fun seed(): Long? = seed + @JsonProperty("seed") fun seed(): Optional = Optional.ofNullable(seed) /** * Up to 4 sequences where the API will stop generating further tokens. The returned text * will not contain the stop sequence. */ - @JsonProperty("stop") fun stop(): Stop? = stop + @JsonProperty("stop") fun stop(): Optional = Optional.ofNullable(stop) /** Options for streaming response. Only set this when you set `stream: true`. */ @JsonProperty("stream_options") - fun streamOptions(): ChatCompletionStreamOptions? = streamOptions + fun streamOptions(): Optional = + Optional.ofNullable(streamOptions) /** * The suffix that comes after a completion of inserted text. * * This parameter is only supported for `gpt-3.5-turbo-instruct`. */ - @JsonProperty("suffix") fun suffix(): String? = suffix + @JsonProperty("suffix") fun suffix(): Optional = Optional.ofNullable(suffix) /** * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the @@ -275,7 +279,8 @@ constructor( * * We generally recommend altering this or `top_p` but not both. */ - @JsonProperty("temperature") fun temperature(): Double? = temperature + @JsonProperty("temperature") + fun temperature(): Optional = Optional.ofNullable(temperature) /** * An alternative to sampling with temperature, called nucleus sampling, where the model @@ -284,14 +289,14 @@ constructor( * * We generally recommend altering this or `temperature` but not both. */ - @JsonProperty("top_p") fun topP(): Double? = topP + @JsonProperty("top_p") fun topP(): Optional = Optional.ofNullable(topP) /** * A unique identifier representing your end-user, which can help OpenAI to monitor and * detect abuse. * [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#end-user-ids). */ - @JsonProperty("user") fun user(): String? = user + @JsonProperty("user") fun user(): Optional = Optional.ofNullable(user) @JsonAnyGetter @ExcludeMissing @@ -327,24 +332,24 @@ constructor( @JvmSynthetic internal fun from(completionCreateBody: CompletionCreateBody) = apply { - this.model = completionCreateBody.model - this.prompt = completionCreateBody.prompt - this.bestOf = completionCreateBody.bestOf - this.echo = completionCreateBody.echo - this.frequencyPenalty = completionCreateBody.frequencyPenalty - this.logitBias = completionCreateBody.logitBias - this.logprobs = completionCreateBody.logprobs - this.maxTokens = completionCreateBody.maxTokens - this.n = completionCreateBody.n - this.presencePenalty = completionCreateBody.presencePenalty - this.seed = completionCreateBody.seed - this.stop = completionCreateBody.stop - this.streamOptions = completionCreateBody.streamOptions - this.suffix = completionCreateBody.suffix - this.temperature = completionCreateBody.temperature - this.topP = completionCreateBody.topP - this.user = completionCreateBody.user - additionalProperties(completionCreateBody.additionalProperties) + model = completionCreateBody.model + prompt = completionCreateBody.prompt + bestOf = completionCreateBody.bestOf + echo = completionCreateBody.echo + frequencyPenalty = completionCreateBody.frequencyPenalty + logitBias = completionCreateBody.logitBias + logprobs = completionCreateBody.logprobs + maxTokens = completionCreateBody.maxTokens + n = completionCreateBody.n + presencePenalty = completionCreateBody.presencePenalty + seed = completionCreateBody.seed + stop = completionCreateBody.stop + streamOptions = completionCreateBody.streamOptions + suffix = completionCreateBody.suffix + temperature = completionCreateBody.temperature + topP = completionCreateBody.topP + user = completionCreateBody.user + additionalProperties = completionCreateBody.additionalProperties.toMutableMap() } /** @@ -512,18 +517,24 @@ constructor( 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(): CompletionCreateBody = CompletionCreateBody( checkNotNull(model) { "`model` is required but was not set" }, @@ -1060,8 +1071,6 @@ constructor( private val _json: JsonValue? = null, ) { - private var validated: Boolean = false - fun string(): Optional = Optional.ofNullable(string) fun arrayOfStrings(): Optional> = Optional.ofNullable(arrayOfStrings) @@ -1100,20 +1109,6 @@ constructor( } } - fun validate(): Prompt = apply { - if (!validated) { - if ( - string == null && - arrayOfStrings == null && - arrayOfTokens == null && - arrayOfTokenArrays == null - ) { - throw OpenAIInvalidDataException("Unknown Prompt: $_json") - } - validated = true - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1244,23 +1239,29 @@ constructor( @JvmSynthetic internal fun from(logitBias: LogitBias) = apply { - additionalProperties(logitBias.additionalProperties) + additionalProperties = logitBias.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(): LogitBias = LogitBias(additionalProperties.toImmutable()) } @@ -1290,8 +1291,6 @@ constructor( private val _json: JsonValue? = null, ) { - private var validated: Boolean = false - fun string(): Optional = Optional.ofNullable(string) fun strings(): Optional> = Optional.ofNullable(strings) @@ -1314,15 +1313,6 @@ constructor( } } - fun validate(): Stop = apply { - if (!validated) { - if (string == null && strings == null) { - throw OpenAIInvalidDataException("Unknown Stop: $_json") - } - validated = true - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/openai-java-core/src/main/kotlin/com/openai/models/CompletionUsage.kt b/openai-java-core/src/main/kotlin/com/openai/models/CompletionUsage.kt index 922b62fa..dfff2aba 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/CompletionUsage.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/CompletionUsage.kt @@ -28,8 +28,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** Number of tokens in the generated completion. */ fun completionTokens(): Long = completionTokens.getRequired("completion_tokens") @@ -70,6 +68,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): CompletionUsage = apply { if (!validated) { completionTokens() @@ -99,12 +99,12 @@ private constructor( @JvmSynthetic internal fun from(completionUsage: CompletionUsage) = apply { - this.completionTokens = completionUsage.completionTokens - this.promptTokens = completionUsage.promptTokens - this.totalTokens = completionUsage.totalTokens - this.completionTokensDetails = completionUsage.completionTokensDetails - this.promptTokensDetails = completionUsage.promptTokensDetails - additionalProperties(completionUsage.additionalProperties) + completionTokens = completionUsage.completionTokens + promptTokens = completionUsage.promptTokens + totalTokens = completionUsage.totalTokens + completionTokensDetails = completionUsage.completionTokensDetails + promptTokensDetails = completionUsage.promptTokensDetails + additionalProperties = completionUsage.additionalProperties.toMutableMap() } /** Number of tokens in the generated completion. */ @@ -159,18 +159,24 @@ private constructor( 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(): CompletionUsage = CompletionUsage( completionTokens, @@ -194,8 +200,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** * When using Predicted Outputs, the number of tokens in the prediction that appeared in the * completion. @@ -246,6 +250,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): CompletionTokensDetails = apply { if (!validated) { acceptedPredictionTokens() @@ -273,11 +279,11 @@ private constructor( @JvmSynthetic internal fun from(completionTokensDetails: CompletionTokensDetails) = apply { - this.acceptedPredictionTokens = completionTokensDetails.acceptedPredictionTokens - this.audioTokens = completionTokensDetails.audioTokens - this.reasoningTokens = completionTokensDetails.reasoningTokens - this.rejectedPredictionTokens = completionTokensDetails.rejectedPredictionTokens - additionalProperties(completionTokensDetails.additionalProperties) + acceptedPredictionTokens = completionTokensDetails.acceptedPredictionTokens + audioTokens = completionTokensDetails.audioTokens + reasoningTokens = completionTokensDetails.reasoningTokens + rejectedPredictionTokens = completionTokensDetails.rejectedPredictionTokens + additionalProperties = completionTokensDetails.additionalProperties.toMutableMap() } /** @@ -339,18 +345,24 @@ private constructor( 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(): CompletionTokensDetails = CompletionTokensDetails( acceptedPredictionTokens, @@ -389,8 +401,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** Audio input tokens present in the prompt. */ fun audioTokens(): Optional = Optional.ofNullable(audioTokens.getNullable("audio_tokens")) @@ -409,6 +419,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): PromptTokensDetails = apply { if (!validated) { audioTokens() @@ -432,9 +444,9 @@ private constructor( @JvmSynthetic internal fun from(promptTokensDetails: PromptTokensDetails) = apply { - this.audioTokens = promptTokensDetails.audioTokens - this.cachedTokens = promptTokensDetails.cachedTokens - additionalProperties(promptTokensDetails.additionalProperties) + audioTokens = promptTokensDetails.audioTokens + cachedTokens = promptTokensDetails.cachedTokens + additionalProperties = promptTokensDetails.additionalProperties.toMutableMap() } /** Audio input tokens present in the prompt. */ @@ -457,18 +469,24 @@ private constructor( 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(): PromptTokensDetails = PromptTokensDetails( audioTokens, diff --git a/openai-java-core/src/main/kotlin/com/openai/models/CreateEmbeddingResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/CreateEmbeddingResponse.kt index 07697a54..3d2aa2f1 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/CreateEmbeddingResponse.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/CreateEmbeddingResponse.kt @@ -28,8 +28,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** The list of embeddings generated by the model. */ fun data(): List = data.getRequired("data") @@ -58,6 +56,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): CreateEmbeddingResponse = apply { if (!validated) { data().forEach { it.validate() } @@ -85,11 +85,11 @@ private constructor( @JvmSynthetic internal fun from(createEmbeddingResponse: CreateEmbeddingResponse) = apply { - this.data = createEmbeddingResponse.data - this.model = createEmbeddingResponse.model - this.object_ = createEmbeddingResponse.object_ - this.usage = createEmbeddingResponse.usage - additionalProperties(createEmbeddingResponse.additionalProperties) + data = createEmbeddingResponse.data + model = createEmbeddingResponse.model + object_ = createEmbeddingResponse.object_ + usage = createEmbeddingResponse.usage + additionalProperties = createEmbeddingResponse.additionalProperties.toMutableMap() } /** The list of embeddings generated by the model. */ @@ -126,18 +126,24 @@ private constructor( 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(): CreateEmbeddingResponse = CreateEmbeddingResponse( data.map { it.toImmutable() }, @@ -209,8 +215,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** The number of tokens used by the prompt. */ fun promptTokens(): Long = promptTokens.getRequired("prompt_tokens") @@ -227,6 +231,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Usage = apply { if (!validated) { promptTokens() @@ -250,9 +256,9 @@ private constructor( @JvmSynthetic internal fun from(usage: Usage) = apply { - this.promptTokens = usage.promptTokens - this.totalTokens = usage.totalTokens - additionalProperties(usage.additionalProperties) + promptTokens = usage.promptTokens + totalTokens = usage.totalTokens + additionalProperties = usage.additionalProperties.toMutableMap() } /** The number of tokens used by the prompt. */ @@ -275,18 +281,24 @@ private constructor( 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(): Usage = Usage( promptTokens, diff --git a/openai-java-core/src/main/kotlin/com/openai/models/Embedding.kt b/openai-java-core/src/main/kotlin/com/openai/models/Embedding.kt index d50f0960..0a9560bf 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/Embedding.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/Embedding.kt @@ -28,8 +28,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** The index of the embedding in the list of embeddings. */ fun index(): Long = index.getRequired("index") @@ -58,6 +56,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Embedding = apply { if (!validated) { index() @@ -83,10 +83,10 @@ private constructor( @JvmSynthetic internal fun from(embedding: Embedding) = apply { - this.index = embedding.index + index = embedding.index this.embedding = embedding.embedding - this.object_ = embedding.object_ - additionalProperties(embedding.additionalProperties) + object_ = embedding.object_ + additionalProperties = embedding.additionalProperties.toMutableMap() } /** The index of the embedding in the list of embeddings. */ @@ -123,18 +123,24 @@ private constructor( 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(): Embedding = Embedding( index, diff --git a/openai-java-core/src/main/kotlin/com/openai/models/EmbeddingCreateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/EmbeddingCreateParams.kt index f3b27071..2d0b95a7 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/EmbeddingCreateParams.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/EmbeddingCreateParams.kt @@ -76,8 +76,8 @@ constructor( @NoAutoDetect class EmbeddingCreateBody internal constructor( - private val input: Input?, - private val model: EmbeddingModel?, + private val input: Input, + private val model: EmbeddingModel, private val dimensions: Long?, private val encodingFormat: EncodingFormat?, private val user: String?, @@ -92,7 +92,7 @@ constructor( * [Example Python code](https://cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken) * for counting tokens. */ - @JsonProperty("input") fun input(): Input? = input + @JsonProperty("input") fun input(): Input = input /** * ID of the model to use. You can use the @@ -100,26 +100,28 @@ constructor( * of your available models, or see our * [Model overview](https://platform.openai.com/docs/models) for descriptions of them. */ - @JsonProperty("model") fun model(): EmbeddingModel? = model + @JsonProperty("model") fun model(): EmbeddingModel = model /** * The number of dimensions the resulting output embeddings should have. Only supported in * `text-embedding-3` and later models. */ - @JsonProperty("dimensions") fun dimensions(): Long? = dimensions + @JsonProperty("dimensions") + fun dimensions(): Optional = Optional.ofNullable(dimensions) /** * The format to return the embeddings in. Can be either `float` or * [`base64`](https://pypi.org/project/pybase64/). */ - @JsonProperty("encoding_format") fun encodingFormat(): EncodingFormat? = encodingFormat + @JsonProperty("encoding_format") + fun encodingFormat(): Optional = Optional.ofNullable(encodingFormat) /** * A unique identifier representing your end-user, which can help OpenAI to monitor and * detect abuse. * [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#end-user-ids). */ - @JsonProperty("user") fun user(): String? = user + @JsonProperty("user") fun user(): Optional = Optional.ofNullable(user) @JsonAnyGetter @ExcludeMissing @@ -143,12 +145,12 @@ constructor( @JvmSynthetic internal fun from(embeddingCreateBody: EmbeddingCreateBody) = apply { - this.input = embeddingCreateBody.input - this.model = embeddingCreateBody.model - this.dimensions = embeddingCreateBody.dimensions - this.encodingFormat = embeddingCreateBody.encodingFormat - this.user = embeddingCreateBody.user - additionalProperties(embeddingCreateBody.additionalProperties) + input = embeddingCreateBody.input + model = embeddingCreateBody.model + dimensions = embeddingCreateBody.dimensions + encodingFormat = embeddingCreateBody.encodingFormat + user = embeddingCreateBody.user + additionalProperties = embeddingCreateBody.additionalProperties.toMutableMap() } /** @@ -195,18 +197,24 @@ constructor( 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(): EmbeddingCreateBody = EmbeddingCreateBody( checkNotNull(input) { "`input` is required but was not set" }, @@ -504,8 +512,6 @@ constructor( private val _json: JsonValue? = null, ) { - private var validated: Boolean = false - /** The string that will be turned into an embedding. */ fun string(): Optional = Optional.ofNullable(string) /** The array of strings that will be turned into an embedding. */ @@ -545,20 +551,6 @@ constructor( } } - fun validate(): Input = apply { - if (!validated) { - if ( - string == null && - arrayOfStrings == null && - arrayOfTokens == null && - arrayOfTokenArrays == null - ) { - throw OpenAIInvalidDataException("Unknown Input: $_json") - } - validated = true - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/openai-java-core/src/main/kotlin/com/openai/models/ErrorObject.kt b/openai-java-core/src/main/kotlin/com/openai/models/ErrorObject.kt index 31ee0d40..988d3e3c 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/ErrorObject.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/ErrorObject.kt @@ -26,8 +26,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - fun code(): Optional = Optional.ofNullable(code.getNullable("code")) fun message(): String = message.getRequired("message") @@ -48,6 +46,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): ErrorObject = apply { if (!validated) { code() @@ -75,11 +75,11 @@ private constructor( @JvmSynthetic internal fun from(errorObject: ErrorObject) = apply { - this.code = errorObject.code - this.message = errorObject.message - this.param = errorObject.param - this.type = errorObject.type - additionalProperties(errorObject.additionalProperties) + code = errorObject.code + message = errorObject.message + param = errorObject.param + type = errorObject.type + additionalProperties = errorObject.additionalProperties.toMutableMap() } fun code(code: String) = code(JsonField.of(code)) @@ -108,18 +108,24 @@ private constructor( 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(): ErrorObject = ErrorObject( code, diff --git a/openai-java-core/src/main/kotlin/com/openai/models/FileDeleted.kt b/openai-java-core/src/main/kotlin/com/openai/models/FileDeleted.kt index 9cb0bcd8..f65cb454 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/FileDeleted.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/FileDeleted.kt @@ -27,8 +27,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - fun id(): String = id.getRequired("id") fun object_(): Object = object_.getRequired("object") @@ -45,6 +43,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): FileDeleted = apply { if (!validated) { id() @@ -70,10 +70,10 @@ private constructor( @JvmSynthetic internal fun from(fileDeleted: FileDeleted) = apply { - this.id = fileDeleted.id - this.object_ = fileDeleted.object_ - this.deleted = fileDeleted.deleted - additionalProperties(fileDeleted.additionalProperties) + id = fileDeleted.id + object_ = fileDeleted.object_ + deleted = fileDeleted.deleted + additionalProperties = fileDeleted.additionalProperties.toMutableMap() } fun id(id: String) = id(JsonField.of(id)) @@ -94,18 +94,24 @@ private constructor( 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(): FileDeleted = FileDeleted( id, diff --git a/openai-java-core/src/main/kotlin/com/openai/models/FileObject.kt b/openai-java-core/src/main/kotlin/com/openai/models/FileObject.kt index ab1fe8ad..28ba0059 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/FileObject.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/FileObject.kt @@ -34,8 +34,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** The file identifier, which can be referenced in the API endpoints. */ fun id(): String = id.getRequired("id") @@ -107,6 +105,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): FileObject = apply { if (!validated) { id() @@ -142,15 +142,15 @@ private constructor( @JvmSynthetic internal fun from(fileObject: FileObject) = apply { - this.id = fileObject.id - this.bytes = fileObject.bytes - this.createdAt = fileObject.createdAt - this.filename = fileObject.filename - this.object_ = fileObject.object_ - this.purpose = fileObject.purpose - this.status = fileObject.status - this.statusDetails = fileObject.statusDetails - additionalProperties(fileObject.additionalProperties) + id = fileObject.id + bytes = fileObject.bytes + createdAt = fileObject.createdAt + filename = fileObject.filename + object_ = fileObject.object_ + purpose = fileObject.purpose + status = fileObject.status + statusDetails = fileObject.statusDetails + additionalProperties = fileObject.additionalProperties.toMutableMap() } /** The file identifier, which can be referenced in the API endpoints. */ @@ -237,18 +237,24 @@ private constructor( 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(): FileObject = FileObject( id, diff --git a/openai-java-core/src/main/kotlin/com/openai/models/FineTuningJob.kt b/openai-java-core/src/main/kotlin/com/openai/models/FineTuningJob.kt index 5fac9a76..256edccb 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/FineTuningJob.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/FineTuningJob.kt @@ -55,8 +55,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** The object identifier, which can be referenced in the API endpoints. */ fun id(): String = id.getRequired("id") @@ -234,6 +232,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): FineTuningJob = apply { if (!validated) { id() @@ -290,25 +290,25 @@ private constructor( @JvmSynthetic internal fun from(fineTuningJob: FineTuningJob) = apply { - this.id = fineTuningJob.id - this.createdAt = fineTuningJob.createdAt - this.error = fineTuningJob.error - this.fineTunedModel = fineTuningJob.fineTunedModel - this.finishedAt = fineTuningJob.finishedAt - this.hyperparameters = fineTuningJob.hyperparameters - this.model = fineTuningJob.model - this.object_ = fineTuningJob.object_ - this.organizationId = fineTuningJob.organizationId - this.resultFiles = fineTuningJob.resultFiles - this.status = fineTuningJob.status - this.trainedTokens = fineTuningJob.trainedTokens - this.trainingFile = fineTuningJob.trainingFile - this.validationFile = fineTuningJob.validationFile - this.integrations = fineTuningJob.integrations - this.seed = fineTuningJob.seed - this.estimatedFinish = fineTuningJob.estimatedFinish - this.method = fineTuningJob.method - additionalProperties(fineTuningJob.additionalProperties) + id = fineTuningJob.id + createdAt = fineTuningJob.createdAt + error = fineTuningJob.error + fineTunedModel = fineTuningJob.fineTunedModel + finishedAt = fineTuningJob.finishedAt + hyperparameters = fineTuningJob.hyperparameters + model = fineTuningJob.model + object_ = fineTuningJob.object_ + organizationId = fineTuningJob.organizationId + resultFiles = fineTuningJob.resultFiles + status = fineTuningJob.status + trainedTokens = fineTuningJob.trainedTokens + trainingFile = fineTuningJob.trainingFile + validationFile = fineTuningJob.validationFile + integrations = fineTuningJob.integrations + seed = fineTuningJob.seed + estimatedFinish = fineTuningJob.estimatedFinish + method = fineTuningJob.method + additionalProperties = fineTuningJob.additionalProperties.toMutableMap() } /** The object identifier, which can be referenced in the API endpoints. */ @@ -538,18 +538,24 @@ private constructor( 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(): FineTuningJob = FineTuningJob( id, @@ -588,8 +594,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** A machine-readable error code. */ fun code(): String = code.getRequired("code") @@ -618,6 +622,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Error = apply { if (!validated) { code() @@ -643,10 +649,10 @@ private constructor( @JvmSynthetic internal fun from(error: Error) = apply { - this.code = error.code - this.message = error.message - this.param = error.param - additionalProperties(error.additionalProperties) + code = error.code + message = error.message + param = error.param + additionalProperties = error.additionalProperties.toMutableMap() } /** A machine-readable error code. */ @@ -681,18 +687,24 @@ private constructor( 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(): Error = Error( code, @@ -734,8 +746,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** * Number of examples in each batch. A larger batch size means that model parameters are * updated less frequently, but with lower variance. @@ -780,6 +790,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Hyperparameters = apply { if (!validated) { batchSize() @@ -805,10 +817,10 @@ private constructor( @JvmSynthetic internal fun from(hyperparameters: Hyperparameters) = apply { - this.batchSize = hyperparameters.batchSize - this.learningRateMultiplier = hyperparameters.learningRateMultiplier - this.nEpochs = hyperparameters.nEpochs - additionalProperties(hyperparameters.additionalProperties) + batchSize = hyperparameters.batchSize + learningRateMultiplier = hyperparameters.learningRateMultiplier + nEpochs = hyperparameters.nEpochs + additionalProperties = hyperparameters.additionalProperties.toMutableMap() } /** @@ -859,18 +871,24 @@ private constructor( 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(): Hyperparameters = Hyperparameters( batchSize, @@ -1529,8 +1547,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** The type of method. Is either `supervised` or `dpo`. */ fun type(): Optional = Optional.ofNullable(type.getNullable("type")) @@ -1554,6 +1570,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Method = apply { if (!validated) { type() @@ -1579,10 +1597,10 @@ private constructor( @JvmSynthetic internal fun from(method: Method) = apply { - this.type = method.type - this.supervised = method.supervised - this.dpo = method.dpo - additionalProperties(method.additionalProperties) + type = method.type + supervised = method.supervised + dpo = method.dpo + additionalProperties = method.additionalProperties.toMutableMap() } /** The type of method. Is either `supervised` or `dpo`. */ @@ -1613,18 +1631,24 @@ private constructor( 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(): Method = Method( type, @@ -1643,8 +1667,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** The hyperparameters used for the fine-tuning job. */ fun hyperparameters(): Optional = Optional.ofNullable(hyperparameters.getNullable("hyperparameters")) @@ -1658,6 +1680,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Dpo = apply { if (!validated) { hyperparameters().map { it.validate() } @@ -1679,8 +1703,8 @@ private constructor( @JvmSynthetic internal fun from(dpo: Dpo) = apply { - this.hyperparameters = dpo.hyperparameters - additionalProperties(dpo.additionalProperties) + hyperparameters = dpo.hyperparameters + additionalProperties = dpo.additionalProperties.toMutableMap() } /** The hyperparameters used for the fine-tuning job. */ @@ -1696,12 +1720,12 @@ private constructor( 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) = @@ -1709,6 +1733,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(): Dpo = Dpo(hyperparameters, additionalProperties.toImmutable()) } @@ -1724,8 +1756,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** * The beta value for the DPO method. A higher beta value will increase the weight * of the penalty between the policy and reference model. @@ -1785,6 +1815,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Hyperparameters = apply { if (!validated) { beta() @@ -1813,11 +1845,11 @@ private constructor( @JvmSynthetic internal fun from(hyperparameters: Hyperparameters) = apply { - this.beta = hyperparameters.beta - this.batchSize = hyperparameters.batchSize - this.learningRateMultiplier = hyperparameters.learningRateMultiplier - this.nEpochs = hyperparameters.nEpochs - additionalProperties(hyperparameters.additionalProperties) + beta = hyperparameters.beta + batchSize = hyperparameters.batchSize + learningRateMultiplier = hyperparameters.learningRateMultiplier + nEpochs = hyperparameters.nEpochs + additionalProperties = hyperparameters.additionalProperties.toMutableMap() } /** @@ -1883,12 +1915,12 @@ private constructor( 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) = @@ -1896,6 +1928,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(): Hyperparameters = Hyperparameters( beta, @@ -2613,8 +2653,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** The hyperparameters used for the fine-tuning job. */ fun hyperparameters(): Optional = Optional.ofNullable(hyperparameters.getNullable("hyperparameters")) @@ -2628,6 +2666,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Supervised = apply { if (!validated) { hyperparameters().map { it.validate() } @@ -2649,8 +2689,8 @@ private constructor( @JvmSynthetic internal fun from(supervised: Supervised) = apply { - this.hyperparameters = supervised.hyperparameters - additionalProperties(supervised.additionalProperties) + hyperparameters = supervised.hyperparameters + additionalProperties = supervised.additionalProperties.toMutableMap() } /** The hyperparameters used for the fine-tuning job. */ @@ -2666,12 +2706,12 @@ private constructor( 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) = @@ -2679,6 +2719,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(): Supervised = Supervised(hyperparameters, additionalProperties.toImmutable()) } @@ -2694,8 +2742,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** * Number of examples in each batch. A larger batch size means that model parameters * are updated less frequently, but with lower variance. @@ -2743,6 +2789,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Hyperparameters = apply { if (!validated) { batchSize() @@ -2769,10 +2817,10 @@ private constructor( @JvmSynthetic internal fun from(hyperparameters: Hyperparameters) = apply { - this.batchSize = hyperparameters.batchSize - this.learningRateMultiplier = hyperparameters.learningRateMultiplier - this.nEpochs = hyperparameters.nEpochs - additionalProperties(hyperparameters.additionalProperties) + batchSize = hyperparameters.batchSize + learningRateMultiplier = hyperparameters.learningRateMultiplier + nEpochs = hyperparameters.nEpochs + additionalProperties = hyperparameters.additionalProperties.toMutableMap() } /** @@ -2824,12 +2872,12 @@ private constructor( 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) = @@ -2837,6 +2885,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(): Hyperparameters = Hyperparameters( batchSize, diff --git a/openai-java-core/src/main/kotlin/com/openai/models/FineTuningJobCheckpoint.kt b/openai-java-core/src/main/kotlin/com/openai/models/FineTuningJobCheckpoint.kt index 80a2b112..c2463e97 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/FineTuningJobCheckpoint.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/FineTuningJobCheckpoint.kt @@ -36,8 +36,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** The checkpoint identifier, which can be referenced in the API endpoints. */ fun id(): String = id.getRequired("id") @@ -87,6 +85,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): FineTuningJobCheckpoint = apply { if (!validated) { id() @@ -120,14 +120,14 @@ private constructor( @JvmSynthetic internal fun from(fineTuningJobCheckpoint: FineTuningJobCheckpoint) = apply { - this.id = fineTuningJobCheckpoint.id - this.createdAt = fineTuningJobCheckpoint.createdAt - this.fineTunedModelCheckpoint = fineTuningJobCheckpoint.fineTunedModelCheckpoint - this.stepNumber = fineTuningJobCheckpoint.stepNumber - this.metrics = fineTuningJobCheckpoint.metrics - this.fineTuningJobId = fineTuningJobCheckpoint.fineTuningJobId - this.object_ = fineTuningJobCheckpoint.object_ - additionalProperties(fineTuningJobCheckpoint.additionalProperties) + id = fineTuningJobCheckpoint.id + createdAt = fineTuningJobCheckpoint.createdAt + fineTunedModelCheckpoint = fineTuningJobCheckpoint.fineTunedModelCheckpoint + stepNumber = fineTuningJobCheckpoint.stepNumber + metrics = fineTuningJobCheckpoint.metrics + fineTuningJobId = fineTuningJobCheckpoint.fineTuningJobId + object_ = fineTuningJobCheckpoint.object_ + additionalProperties = fineTuningJobCheckpoint.additionalProperties.toMutableMap() } /** The checkpoint identifier, which can be referenced in the API endpoints. */ @@ -192,18 +192,24 @@ private constructor( 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(): FineTuningJobCheckpoint = FineTuningJobCheckpoint( id, @@ -232,8 +238,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - fun step(): Optional = Optional.ofNullable(step.getNullable("step")) fun trainLoss(): Optional = Optional.ofNullable(trainLoss.getNullable("train_loss")) @@ -278,6 +282,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Metrics = apply { if (!validated) { step() @@ -311,14 +317,14 @@ private constructor( @JvmSynthetic internal fun from(metrics: Metrics) = apply { - this.step = metrics.step - this.trainLoss = metrics.trainLoss - this.trainMeanTokenAccuracy = metrics.trainMeanTokenAccuracy - this.validLoss = metrics.validLoss - this.validMeanTokenAccuracy = metrics.validMeanTokenAccuracy - this.fullValidLoss = metrics.fullValidLoss - this.fullValidMeanTokenAccuracy = metrics.fullValidMeanTokenAccuracy - additionalProperties(metrics.additionalProperties) + step = metrics.step + trainLoss = metrics.trainLoss + trainMeanTokenAccuracy = metrics.trainMeanTokenAccuracy + validLoss = metrics.validLoss + validMeanTokenAccuracy = metrics.validMeanTokenAccuracy + fullValidLoss = metrics.fullValidLoss + fullValidMeanTokenAccuracy = metrics.fullValidMeanTokenAccuracy + additionalProperties = metrics.additionalProperties.toMutableMap() } fun step(step: Double) = step(JsonField.of(step)) @@ -376,18 +382,24 @@ private constructor( 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(): Metrics = Metrics( step, diff --git a/openai-java-core/src/main/kotlin/com/openai/models/FineTuningJobCreateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/FineTuningJobCreateParams.kt index e1f29ab8..4628d0cf 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/FineTuningJobCreateParams.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/FineTuningJobCreateParams.kt @@ -88,8 +88,8 @@ constructor( @NoAutoDetect class FineTuningJobCreateBody internal constructor( - private val model: Model?, - private val trainingFile: String?, + private val model: Model, + private val trainingFile: String, private val hyperparameters: Hyperparameters?, private val integrations: List?, private val method: Method?, @@ -103,7 +103,7 @@ constructor( * The name of the model to fine-tune. You can select one of the * [supported models](https://platform.openai.com/docs/guides/fine-tuning#which-models-can-be-fine-tuned). */ - @JsonProperty("model") fun model(): Model? = model + @JsonProperty("model") fun model(): Model = model /** * The ID of an uploaded file that contains training data. @@ -124,26 +124,28 @@ constructor( * See the [fine-tuning guide](https://platform.openai.com/docs/guides/fine-tuning) for more * details. */ - @JsonProperty("training_file") fun trainingFile(): String? = trainingFile + @JsonProperty("training_file") fun trainingFile(): String = trainingFile /** * The hyperparameters used for the fine-tuning job. This value is now deprecated in favor * of `method`, and should be passed in under the `method` parameter. */ - @JsonProperty("hyperparameters") fun hyperparameters(): Hyperparameters? = hyperparameters + @JsonProperty("hyperparameters") + fun hyperparameters(): Optional = Optional.ofNullable(hyperparameters) /** A list of integrations to enable for your fine-tuning job. */ - @JsonProperty("integrations") fun integrations(): List? = integrations + @JsonProperty("integrations") + fun integrations(): Optional> = Optional.ofNullable(integrations) /** The method used for fine-tuning. */ - @JsonProperty("method") fun method(): Method? = method + @JsonProperty("method") fun method(): Optional = Optional.ofNullable(method) /** * The seed controls the reproducibility of the job. Passing in the same seed and job * parameters should produce the same results, but may differ in rare cases. If a seed is * not specified, one will be generated for you. */ - @JsonProperty("seed") fun seed(): Long? = seed + @JsonProperty("seed") fun seed(): Optional = Optional.ofNullable(seed) /** * A string of up to 64 characters that will be added to your fine-tuned model name. @@ -151,7 +153,7 @@ constructor( * For example, a `suffix` of "custom-model-name" would produce a model name like * `ft:gpt-4o-mini:openai:custom-model-name:7p4lURel`. */ - @JsonProperty("suffix") fun suffix(): String? = suffix + @JsonProperty("suffix") fun suffix(): Optional = Optional.ofNullable(suffix) /** * The ID of an uploaded file that contains validation data. @@ -166,7 +168,8 @@ constructor( * See the [fine-tuning guide](https://platform.openai.com/docs/guides/fine-tuning) for more * details. */ - @JsonProperty("validation_file") fun validationFile(): String? = validationFile + @JsonProperty("validation_file") + fun validationFile(): Optional = Optional.ofNullable(validationFile) @JsonAnyGetter @ExcludeMissing @@ -193,15 +196,15 @@ constructor( @JvmSynthetic internal fun from(fineTuningJobCreateBody: FineTuningJobCreateBody) = apply { - this.model = fineTuningJobCreateBody.model - this.trainingFile = fineTuningJobCreateBody.trainingFile - this.hyperparameters = fineTuningJobCreateBody.hyperparameters - this.integrations = fineTuningJobCreateBody.integrations - this.method = fineTuningJobCreateBody.method - this.seed = fineTuningJobCreateBody.seed - this.suffix = fineTuningJobCreateBody.suffix - this.validationFile = fineTuningJobCreateBody.validationFile - additionalProperties(fineTuningJobCreateBody.additionalProperties) + model = fineTuningJobCreateBody.model + trainingFile = fineTuningJobCreateBody.trainingFile + hyperparameters = fineTuningJobCreateBody.hyperparameters + integrations = fineTuningJobCreateBody.integrations?.toMutableList() + method = fineTuningJobCreateBody.method + seed = fineTuningJobCreateBody.seed + suffix = fineTuningJobCreateBody.suffix + validationFile = fineTuningJobCreateBody.validationFile + additionalProperties = fineTuningJobCreateBody.additionalProperties.toMutableMap() } /** @@ -285,18 +288,24 @@ constructor( 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(): FineTuningJobCreateBody = FineTuningJobCreateBody( checkNotNull(model) { "`model` is required but was not set" }, @@ -674,20 +683,22 @@ constructor( * Number of examples in each batch. A larger batch size means that model parameters are * updated less frequently, but with lower variance. */ - @JsonProperty("batch_size") fun batchSize(): BatchSize? = batchSize + @JsonProperty("batch_size") + fun batchSize(): Optional = Optional.ofNullable(batchSize) /** * Scaling factor for the learning rate. A smaller learning rate may be useful to avoid * overfitting. */ @JsonProperty("learning_rate_multiplier") - fun learningRateMultiplier(): LearningRateMultiplier? = learningRateMultiplier + fun learningRateMultiplier(): Optional = + Optional.ofNullable(learningRateMultiplier) /** * The number of epochs to train the model for. An epoch refers to one full cycle through * the training dataset. */ - @JsonProperty("n_epochs") fun nEpochs(): NEpochs? = nEpochs + @JsonProperty("n_epochs") fun nEpochs(): Optional = Optional.ofNullable(nEpochs) @JsonAnyGetter @ExcludeMissing @@ -709,10 +720,10 @@ constructor( @JvmSynthetic internal fun from(hyperparameters: Hyperparameters) = apply { - this.batchSize = hyperparameters.batchSize - this.learningRateMultiplier = hyperparameters.learningRateMultiplier - this.nEpochs = hyperparameters.nEpochs - additionalProperties(hyperparameters.additionalProperties) + batchSize = hyperparameters.batchSize + learningRateMultiplier = hyperparameters.learningRateMultiplier + nEpochs = hyperparameters.nEpochs + additionalProperties = hyperparameters.additionalProperties.toMutableMap() } /** @@ -740,18 +751,24 @@ constructor( 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(): Hyperparameters = Hyperparameters( batchSize, @@ -770,8 +787,6 @@ constructor( private val _json: JsonValue? = null, ) { - private var validated: Boolean = false - fun behavior(): Optional = Optional.ofNullable(behavior) fun integer(): Optional = Optional.ofNullable(integer) @@ -794,15 +809,6 @@ constructor( } } - fun validate(): BatchSize = apply { - if (!validated) { - if (behavior == null && integer == null) { - throw OpenAIInvalidDataException("Unknown BatchSize: $_json") - } - validated = true - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -932,8 +938,6 @@ constructor( private val _json: JsonValue? = null, ) { - private var validated: Boolean = false - fun behavior(): Optional = Optional.ofNullable(behavior) fun number(): Optional = Optional.ofNullable(number) @@ -956,15 +960,6 @@ constructor( } } - fun validate(): LearningRateMultiplier = apply { - if (!validated) { - if (behavior == null && number == null) { - throw OpenAIInvalidDataException("Unknown LearningRateMultiplier: $_json") - } - validated = true - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1097,8 +1092,6 @@ constructor( private val _json: JsonValue? = null, ) { - private var validated: Boolean = false - fun behavior(): Optional = Optional.ofNullable(behavior) fun integer(): Optional = Optional.ofNullable(integer) @@ -1121,15 +1114,6 @@ constructor( } } - fun validate(): NEpochs = apply { - if (!validated) { - if (behavior == null && integer == null) { - throw OpenAIInvalidDataException("Unknown NEpochs: $_json") - } - validated = true - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1272,8 +1256,8 @@ constructor( @NoAutoDetect class Integration private constructor( - private val type: Type?, - private val wandb: Wandb?, + private val type: Type, + private val wandb: Wandb, private val additionalProperties: Map, ) { @@ -1281,7 +1265,7 @@ constructor( * The type of integration to enable. Currently, only "wandb" (Weights and Biases) is * supported. */ - @JsonProperty("type") fun type(): Type? = type + @JsonProperty("type") fun type(): Type = type /** * The settings for your integration with Weights and Biases. This payload specifies the @@ -1289,7 +1273,7 @@ constructor( * for your run, add tags to your run, and set a default entity (team, username, etc) to be * associated with your run. */ - @JsonProperty("wandb") fun wandb(): Wandb? = wandb + @JsonProperty("wandb") fun wandb(): Wandb = wandb @JsonAnyGetter @ExcludeMissing @@ -1310,9 +1294,9 @@ constructor( @JvmSynthetic internal fun from(integration: Integration) = apply { - this.type = integration.type - this.wandb = integration.wandb - additionalProperties(integration.additionalProperties) + type = integration.type + wandb = integration.wandb + additionalProperties = integration.additionalProperties.toMutableMap() } /** @@ -1331,18 +1315,24 @@ constructor( 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(): Integration = Integration( checkNotNull(type) { "`type` is required but was not set" }, @@ -1412,7 +1402,7 @@ constructor( @NoAutoDetect class Wandb private constructor( - private val project: String?, + private val project: String, private val name: String?, private val entity: String?, private val tags: List?, @@ -1420,26 +1410,26 @@ constructor( ) { /** The name of the project that the new run will be created under. */ - @JsonProperty("project") fun project(): String? = project + @JsonProperty("project") fun project(): String = project /** * A display name to set for the run. If not set, we will use the Job ID as the name. */ - @JsonProperty("name") fun name(): String? = name + @JsonProperty("name") fun name(): Optional = Optional.ofNullable(name) /** * The entity to use for the run. This allows you to set the team or username of the * WandB user that you would like associated with the run. If not set, the default * entity for the registered WandB API key is used. */ - @JsonProperty("entity") fun entity(): String? = entity + @JsonProperty("entity") fun entity(): Optional = Optional.ofNullable(entity) /** * A list of tags to be attached to the newly created run. These tags are passed through * directly to WandB. Some default tags are generated by OpenAI: "openai/finetune", * "openai/{base-model}", "openai/{ftjob-abcdef}". */ - @JsonProperty("tags") fun tags(): List? = tags + @JsonProperty("tags") fun tags(): Optional> = Optional.ofNullable(tags) @JsonAnyGetter @ExcludeMissing @@ -1462,11 +1452,11 @@ constructor( @JvmSynthetic internal fun from(wandb: Wandb) = apply { - this.project = wandb.project - this.name = wandb.name - this.entity = wandb.entity - this.tags = wandb.tags - additionalProperties(wandb.additionalProperties) + project = wandb.project + name = wandb.name + entity = wandb.entity + tags = wandb.tags?.toMutableList() + additionalProperties = wandb.additionalProperties.toMutableMap() } /** The name of the project that the new run will be created under. */ @@ -1495,12 +1485,12 @@ constructor( 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) = @@ -1508,6 +1498,14 @@ constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Wandb = Wandb( checkNotNull(project) { "`project` is required but was not set" }, @@ -1566,13 +1564,14 @@ constructor( ) { /** The type of method. Is either `supervised` or `dpo`. */ - @JsonProperty("type") fun type(): Type? = type + @JsonProperty("type") fun type(): Optional = Optional.ofNullable(type) /** Configuration for the supervised fine-tuning method. */ - @JsonProperty("supervised") fun supervised(): Supervised? = supervised + @JsonProperty("supervised") + fun supervised(): Optional = Optional.ofNullable(supervised) /** Configuration for the DPO fine-tuning method. */ - @JsonProperty("dpo") fun dpo(): Dpo? = dpo + @JsonProperty("dpo") fun dpo(): Optional = Optional.ofNullable(dpo) @JsonAnyGetter @ExcludeMissing @@ -1594,10 +1593,10 @@ constructor( @JvmSynthetic internal fun from(method: Method) = apply { - this.type = method.type - this.supervised = method.supervised - this.dpo = method.dpo - additionalProperties(method.additionalProperties) + type = method.type + supervised = method.supervised + dpo = method.dpo + additionalProperties = method.additionalProperties.toMutableMap() } /** The type of method. Is either `supervised` or `dpo`. */ @@ -1612,18 +1611,24 @@ constructor( 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(): Method = Method( type, @@ -1644,7 +1649,7 @@ constructor( /** The hyperparameters used for the fine-tuning job. */ @JsonProperty("hyperparameters") - fun hyperparameters(): Hyperparameters? = hyperparameters + fun hyperparameters(): Optional = Optional.ofNullable(hyperparameters) @JsonAnyGetter @ExcludeMissing @@ -1664,8 +1669,8 @@ constructor( @JvmSynthetic internal fun from(dpo: Dpo) = apply { - this.hyperparameters = dpo.hyperparameters - additionalProperties(dpo.additionalProperties) + hyperparameters = dpo.hyperparameters + additionalProperties = dpo.additionalProperties.toMutableMap() } /** The hyperparameters used for the fine-tuning job. */ @@ -1676,12 +1681,12 @@ constructor( 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) = @@ -1689,6 +1694,14 @@ constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Dpo = Dpo(hyperparameters, additionalProperties.toImmutable()) } @@ -1708,26 +1721,29 @@ constructor( * The beta value for the DPO method. A higher beta value will increase the weight * of the penalty between the policy and reference model. */ - @JsonProperty("beta") fun beta(): Beta? = beta + @JsonProperty("beta") fun beta(): Optional = Optional.ofNullable(beta) /** * Number of examples in each batch. A larger batch size means that model parameters * are updated less frequently, but with lower variance. */ - @JsonProperty("batch_size") fun batchSize(): BatchSize? = batchSize + @JsonProperty("batch_size") + fun batchSize(): Optional = Optional.ofNullable(batchSize) /** * Scaling factor for the learning rate. A smaller learning rate may be useful to * avoid overfitting. */ @JsonProperty("learning_rate_multiplier") - fun learningRateMultiplier(): LearningRateMultiplier? = learningRateMultiplier + fun learningRateMultiplier(): Optional = + Optional.ofNullable(learningRateMultiplier) /** * The number of epochs to train the model for. An epoch refers to one full cycle * through the training dataset. */ - @JsonProperty("n_epochs") fun nEpochs(): NEpochs? = nEpochs + @JsonProperty("n_epochs") + fun nEpochs(): Optional = Optional.ofNullable(nEpochs) @JsonAnyGetter @ExcludeMissing @@ -1750,11 +1766,11 @@ constructor( @JvmSynthetic internal fun from(hyperparameters: Hyperparameters) = apply { - this.beta = hyperparameters.beta - this.batchSize = hyperparameters.batchSize - this.learningRateMultiplier = hyperparameters.learningRateMultiplier - this.nEpochs = hyperparameters.nEpochs - additionalProperties(hyperparameters.additionalProperties) + beta = hyperparameters.beta + batchSize = hyperparameters.batchSize + learningRateMultiplier = hyperparameters.learningRateMultiplier + nEpochs = hyperparameters.nEpochs + additionalProperties = hyperparameters.additionalProperties.toMutableMap() } /** @@ -1789,12 +1805,12 @@ constructor( 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) = @@ -1802,6 +1818,14 @@ constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Hyperparameters = Hyperparameters( beta, @@ -1821,8 +1845,6 @@ constructor( private val _json: JsonValue? = null, ) { - private var validated: Boolean = false - fun auto(): Optional = Optional.ofNullable(auto) fun manual(): Optional = Optional.ofNullable(manual) @@ -1845,15 +1867,6 @@ constructor( } } - fun validate(): BatchSize = apply { - if (!validated) { - if (auto == null && manual == null) { - throw OpenAIInvalidDataException("Unknown BatchSize: $_json") - } - validated = true - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -1984,8 +1997,6 @@ constructor( private val _json: JsonValue? = null, ) { - private var validated: Boolean = false - fun auto(): Optional = Optional.ofNullable(auto) fun manual(): Optional = Optional.ofNullable(manual) @@ -2008,15 +2019,6 @@ constructor( } } - fun validate(): Beta = apply { - if (!validated) { - if (auto == null && manual == null) { - throw OpenAIInvalidDataException("Unknown Beta: $_json") - } - validated = true - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -2147,8 +2149,6 @@ constructor( private val _json: JsonValue? = null, ) { - private var validated: Boolean = false - fun auto(): Optional = Optional.ofNullable(auto) fun manual(): Optional = Optional.ofNullable(manual) @@ -2171,17 +2171,6 @@ constructor( } } - fun validate(): LearningRateMultiplier = apply { - if (!validated) { - if (auto == null && manual == null) { - throw OpenAIInvalidDataException( - "Unknown LearningRateMultiplier: $_json" - ) - } - validated = true - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -2320,8 +2309,6 @@ constructor( private val _json: JsonValue? = null, ) { - private var validated: Boolean = false - fun auto(): Optional = Optional.ofNullable(auto) fun manual(): Optional = Optional.ofNullable(manual) @@ -2344,15 +2331,6 @@ constructor( } } - fun validate(): NEpochs = apply { - if (!validated) { - if (auto == null && manual == null) { - throw OpenAIInvalidDataException("Unknown NEpochs: $_json") - } - validated = true - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -2521,7 +2499,7 @@ constructor( /** The hyperparameters used for the fine-tuning job. */ @JsonProperty("hyperparameters") - fun hyperparameters(): Hyperparameters? = hyperparameters + fun hyperparameters(): Optional = Optional.ofNullable(hyperparameters) @JsonAnyGetter @ExcludeMissing @@ -2541,8 +2519,8 @@ constructor( @JvmSynthetic internal fun from(supervised: Supervised) = apply { - this.hyperparameters = supervised.hyperparameters - additionalProperties(supervised.additionalProperties) + hyperparameters = supervised.hyperparameters + additionalProperties = supervised.additionalProperties.toMutableMap() } /** The hyperparameters used for the fine-tuning job. */ @@ -2553,12 +2531,12 @@ constructor( 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) = @@ -2566,6 +2544,14 @@ constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Supervised = Supervised(hyperparameters, additionalProperties.toImmutable()) } @@ -2585,20 +2571,23 @@ constructor( * Number of examples in each batch. A larger batch size means that model parameters * are updated less frequently, but with lower variance. */ - @JsonProperty("batch_size") fun batchSize(): BatchSize? = batchSize + @JsonProperty("batch_size") + fun batchSize(): Optional = Optional.ofNullable(batchSize) /** * Scaling factor for the learning rate. A smaller learning rate may be useful to * avoid overfitting. */ @JsonProperty("learning_rate_multiplier") - fun learningRateMultiplier(): LearningRateMultiplier? = learningRateMultiplier + fun learningRateMultiplier(): Optional = + Optional.ofNullable(learningRateMultiplier) /** * The number of epochs to train the model for. An epoch refers to one full cycle * through the training dataset. */ - @JsonProperty("n_epochs") fun nEpochs(): NEpochs? = nEpochs + @JsonProperty("n_epochs") + fun nEpochs(): Optional = Optional.ofNullable(nEpochs) @JsonAnyGetter @ExcludeMissing @@ -2620,10 +2609,10 @@ constructor( @JvmSynthetic internal fun from(hyperparameters: Hyperparameters) = apply { - this.batchSize = hyperparameters.batchSize - this.learningRateMultiplier = hyperparameters.learningRateMultiplier - this.nEpochs = hyperparameters.nEpochs - additionalProperties(hyperparameters.additionalProperties) + batchSize = hyperparameters.batchSize + learningRateMultiplier = hyperparameters.learningRateMultiplier + nEpochs = hyperparameters.nEpochs + additionalProperties = hyperparameters.additionalProperties.toMutableMap() } /** @@ -2652,12 +2641,12 @@ constructor( 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) = @@ -2665,6 +2654,14 @@ constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Hyperparameters = Hyperparameters( batchSize, @@ -2683,8 +2680,6 @@ constructor( private val _json: JsonValue? = null, ) { - private var validated: Boolean = false - fun auto(): Optional = Optional.ofNullable(auto) fun manual(): Optional = Optional.ofNullable(manual) @@ -2707,15 +2702,6 @@ constructor( } } - fun validate(): BatchSize = apply { - if (!validated) { - if (auto == null && manual == null) { - throw OpenAIInvalidDataException("Unknown BatchSize: $_json") - } - validated = true - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -2846,8 +2832,6 @@ constructor( private val _json: JsonValue? = null, ) { - private var validated: Boolean = false - fun auto(): Optional = Optional.ofNullable(auto) fun manual(): Optional = Optional.ofNullable(manual) @@ -2870,17 +2854,6 @@ constructor( } } - fun validate(): LearningRateMultiplier = apply { - if (!validated) { - if (auto == null && manual == null) { - throw OpenAIInvalidDataException( - "Unknown LearningRateMultiplier: $_json" - ) - } - validated = true - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -3019,8 +2992,6 @@ constructor( private val _json: JsonValue? = null, ) { - private var validated: Boolean = false - fun auto(): Optional = Optional.ofNullable(auto) fun manual(): Optional = Optional.ofNullable(manual) @@ -3043,15 +3014,6 @@ constructor( } } - fun validate(): NEpochs = apply { - if (!validated) { - if (auto == null && manual == null) { - throw OpenAIInvalidDataException("Unknown NEpochs: $_json") - } - validated = true - } - } - override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/openai-java-core/src/main/kotlin/com/openai/models/FineTuningJobEvent.kt b/openai-java-core/src/main/kotlin/com/openai/models/FineTuningJobEvent.kt index 24910412..7f2d3bb0 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/FineTuningJobEvent.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/FineTuningJobEvent.kt @@ -33,8 +33,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** The object type, which is always "fine_tuning.job.event". */ fun object_(): Object = object_.getRequired("object") @@ -78,6 +76,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): FineTuningJobEvent = apply { if (!validated) { object_() @@ -110,14 +110,14 @@ private constructor( @JvmSynthetic internal fun from(fineTuningJobEvent: FineTuningJobEvent) = apply { - this.object_ = fineTuningJobEvent.object_ - this.id = fineTuningJobEvent.id - this.createdAt = fineTuningJobEvent.createdAt - this.level = fineTuningJobEvent.level - this.message = fineTuningJobEvent.message - this.type = fineTuningJobEvent.type - this.data = fineTuningJobEvent.data - additionalProperties(fineTuningJobEvent.additionalProperties) + object_ = fineTuningJobEvent.object_ + id = fineTuningJobEvent.id + createdAt = fineTuningJobEvent.createdAt + level = fineTuningJobEvent.level + message = fineTuningJobEvent.message + type = fineTuningJobEvent.type + data = fineTuningJobEvent.data + additionalProperties = fineTuningJobEvent.additionalProperties.toMutableMap() } /** The object type, which is always "fine_tuning.job.event". */ @@ -171,18 +171,24 @@ private constructor( 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(): FineTuningJobEvent = FineTuningJobEvent( object_, diff --git a/openai-java-core/src/main/kotlin/com/openai/models/FineTuningJobWandbIntegration.kt b/openai-java-core/src/main/kotlin/com/openai/models/FineTuningJobWandbIntegration.kt index 4a975dbc..d5f1d648 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/FineTuningJobWandbIntegration.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/FineTuningJobWandbIntegration.kt @@ -31,8 +31,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** The name of the project that the new run will be created under. */ fun project(): String = project.getRequired("project") @@ -77,6 +75,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): FineTuningJobWandbIntegration = apply { if (!validated) { project() @@ -104,11 +104,11 @@ private constructor( @JvmSynthetic internal fun from(fineTuningJobWandbIntegration: FineTuningJobWandbIntegration) = apply { - this.project = fineTuningJobWandbIntegration.project - this.name = fineTuningJobWandbIntegration.name - this.entity = fineTuningJobWandbIntegration.entity - this.tags = fineTuningJobWandbIntegration.tags - additionalProperties(fineTuningJobWandbIntegration.additionalProperties) + project = fineTuningJobWandbIntegration.project + name = fineTuningJobWandbIntegration.name + entity = fineTuningJobWandbIntegration.entity + tags = fineTuningJobWandbIntegration.tags + additionalProperties = fineTuningJobWandbIntegration.additionalProperties.toMutableMap() } /** The name of the project that the new run will be created under. */ @@ -161,18 +161,24 @@ private constructor( 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(): FineTuningJobWandbIntegration = FineTuningJobWandbIntegration( project, diff --git a/openai-java-core/src/main/kotlin/com/openai/models/FineTuningJobWandbIntegrationObject.kt b/openai-java-core/src/main/kotlin/com/openai/models/FineTuningJobWandbIntegrationObject.kt index e1ff04b9..ece0f00b 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/FineTuningJobWandbIntegrationObject.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/FineTuningJobWandbIntegrationObject.kt @@ -26,8 +26,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** The type of the integration being enabled for the fine-tuning job */ fun type(): Type = type.getRequired("type") @@ -54,6 +52,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): FineTuningJobWandbIntegrationObject = apply { if (!validated) { type() @@ -79,9 +79,10 @@ private constructor( internal fun from( fineTuningJobWandbIntegrationObject: FineTuningJobWandbIntegrationObject ) = apply { - this.type = fineTuningJobWandbIntegrationObject.type - this.wandb = fineTuningJobWandbIntegrationObject.wandb - additionalProperties(fineTuningJobWandbIntegrationObject.additionalProperties) + type = fineTuningJobWandbIntegrationObject.type + wandb = fineTuningJobWandbIntegrationObject.wandb + additionalProperties = + fineTuningJobWandbIntegrationObject.additionalProperties.toMutableMap() } /** The type of the integration being enabled for the fine-tuning job */ @@ -112,18 +113,24 @@ private constructor( 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(): FineTuningJobWandbIntegrationObject = FineTuningJobWandbIntegrationObject( type, diff --git a/openai-java-core/src/main/kotlin/com/openai/models/FunctionDefinition.kt b/openai-java-core/src/main/kotlin/com/openai/models/FunctionDefinition.kt index 3f7f29b4..7c41ed30 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/FunctionDefinition.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/FunctionDefinition.kt @@ -26,8 +26,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** * A description of what the function does, used by the model to choose when and how to call the * function. @@ -94,6 +92,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): FunctionDefinition = apply { if (!validated) { description() @@ -121,11 +121,11 @@ private constructor( @JvmSynthetic internal fun from(functionDefinition: FunctionDefinition) = apply { - this.description = functionDefinition.description - this.name = functionDefinition.name - this.parameters = functionDefinition.parameters - this.strict = functionDefinition.strict - additionalProperties(functionDefinition.additionalProperties) + description = functionDefinition.description + name = functionDefinition.name + parameters = functionDefinition.parameters + strict = functionDefinition.strict + additionalProperties = functionDefinition.additionalProperties.toMutableMap() } /** @@ -200,18 +200,24 @@ private constructor( 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(): FunctionDefinition = FunctionDefinition( description, diff --git a/openai-java-core/src/main/kotlin/com/openai/models/FunctionParameters.kt b/openai-java-core/src/main/kotlin/com/openai/models/FunctionParameters.kt index 99616c8c..c152be93 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/FunctionParameters.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/FunctionParameters.kt @@ -26,12 +26,12 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): FunctionParameters = apply { if (!validated) { validated = true @@ -51,23 +51,29 @@ private constructor( @JvmSynthetic internal fun from(functionParameters: FunctionParameters) = apply { - additionalProperties(functionParameters.additionalProperties) + additionalProperties = functionParameters.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(): FunctionParameters = FunctionParameters(additionalProperties.toImmutable()) } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/Image.kt b/openai-java-core/src/main/kotlin/com/openai/models/Image.kt index 73693ef0..d73ee3a0 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/Image.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/Image.kt @@ -26,8 +26,6 @@ private constructor( private val additionalProperties: Map, ) { - private var validated: Boolean = false - /** The base64-encoded JSON of the generated image, if `response_format` is `b64_json`. */ fun b64Json(): Optional = Optional.ofNullable(b64Json.getNullable("b64_json")) @@ -51,6 +49,8 @@ private constructor( @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Image = apply { if (!validated) { b64Json() @@ -76,10 +76,10 @@ private constructor( @JvmSynthetic internal fun from(image: Image) = apply { - this.b64Json = image.b64Json - this.url = image.url - this.revisedPrompt = image.revisedPrompt - additionalProperties(image.additionalProperties) + b64Json = image.b64Json + url = image.url + revisedPrompt = image.revisedPrompt + additionalProperties = image.additionalProperties.toMutableMap() } /** The base64-encoded JSON of the generated image, if `response_format` is `b64_json`. */ @@ -114,18 +114,24 @@ private constructor( 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(): Image = Image( b64Json, diff --git a/openai-java-core/src/main/kotlin/com/openai/models/ImageGenerateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/ImageGenerateParams.kt index 3fca4269..db8e5fdc 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/ImageGenerateParams.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/ImageGenerateParams.kt @@ -79,7 +79,7 @@ constructor( @NoAutoDetect class ImageGenerateBody internal constructor( - private val prompt: String?, + private val prompt: String, private val model: ImageModel?, private val n: Long?, private val quality: Quality?, @@ -94,35 +94,36 @@ constructor( * A text description of the desired image(s). The maximum length is 1000 characters for * `dall-e-2` and 4000 characters for `dall-e-3`. */ - @JsonProperty("prompt") fun prompt(): String? = prompt + @JsonProperty("prompt") fun prompt(): String = prompt /** The model to use for image generation. */ - @JsonProperty("model") fun model(): ImageModel? = model + @JsonProperty("model") fun model(): Optional = Optional.ofNullable(model) /** * The number of images to generate. Must be between 1 and 10. For `dall-e-3`, only `n=1` is * supported. */ - @JsonProperty("n") fun n(): Long? = n + @JsonProperty("n") fun n(): Optional = Optional.ofNullable(n) /** * The quality of the image that will be generated. `hd` creates images with finer details * and greater consistency across the image. This param is only supported for `dall-e-3`. */ - @JsonProperty("quality") fun quality(): Quality? = quality + @JsonProperty("quality") fun quality(): Optional = Optional.ofNullable(quality) /** * The format in which the generated images are returned. Must be one of `url` or * `b64_json`. URLs are only valid for 60 minutes after the image has been generated. */ - @JsonProperty("response_format") fun responseFormat(): ResponseFormat? = responseFormat + @JsonProperty("response_format") + fun responseFormat(): Optional = Optional.ofNullable(responseFormat) /** * The size of the generated images. Must be one of `256x256`, `512x512`, or `1024x1024` for * `dall-e-2`. Must be one of `1024x1024`, `1792x1024`, or `1024x1792` for `dall-e-3` * models. */ - @JsonProperty("size") fun size(): Size? = size + @JsonProperty("size") fun size(): Optional = Optional.ofNullable(size) /** * The style of the generated images. Must be one of `vivid` or `natural`. Vivid causes the @@ -130,14 +131,14 @@ constructor( * to produce more natural, less hyper-real looking images. This param is only supported for * `dall-e-3`. */ - @JsonProperty("style") fun style(): Style? = style + @JsonProperty("style") fun style(): Optional