|
| 1 | +// File generated from our OpenAPI spec by Stainless. |
| 2 | + |
| 3 | +package com.openai.models.responses.inputtokens |
| 4 | + |
| 5 | +import com.fasterxml.jackson.annotation.JsonAnyGetter |
| 6 | +import com.fasterxml.jackson.annotation.JsonAnySetter |
| 7 | +import com.fasterxml.jackson.annotation.JsonCreator |
| 8 | +import com.fasterxml.jackson.annotation.JsonProperty |
| 9 | +import com.openai.core.ExcludeMissing |
| 10 | +import com.openai.core.JsonField |
| 11 | +import com.openai.core.JsonMissing |
| 12 | +import com.openai.core.JsonValue |
| 13 | +import com.openai.core.checkRequired |
| 14 | +import com.openai.errors.OpenAIInvalidDataException |
| 15 | +import java.util.Collections |
| 16 | +import java.util.Objects |
| 17 | + |
| 18 | +class InputTokenCountResponse |
| 19 | +@JsonCreator(mode = JsonCreator.Mode.DISABLED) |
| 20 | +private constructor( |
| 21 | + private val inputTokens: JsonField<Long>, |
| 22 | + private val object_: JsonValue, |
| 23 | + private val additionalProperties: MutableMap<String, JsonValue>, |
| 24 | +) { |
| 25 | + |
| 26 | + @JsonCreator |
| 27 | + private constructor( |
| 28 | + @JsonProperty("input_tokens") |
| 29 | + @ExcludeMissing |
| 30 | + inputTokens: JsonField<Long> = JsonMissing.of(), |
| 31 | + @JsonProperty("object") @ExcludeMissing object_: JsonValue = JsonMissing.of(), |
| 32 | + ) : this(inputTokens, object_, mutableMapOf()) |
| 33 | + |
| 34 | + /** |
| 35 | + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is |
| 36 | + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). |
| 37 | + */ |
| 38 | + fun inputTokens(): Long = inputTokens.getRequired("input_tokens") |
| 39 | + |
| 40 | + /** |
| 41 | + * Expected to always return the following: |
| 42 | + * ```java |
| 43 | + * JsonValue.from("response.input_tokens") |
| 44 | + * ``` |
| 45 | + * |
| 46 | + * However, this method can be useful for debugging and logging (e.g. if the server responded |
| 47 | + * with an unexpected value). |
| 48 | + */ |
| 49 | + @JsonProperty("object") @ExcludeMissing fun _object_(): JsonValue = object_ |
| 50 | + |
| 51 | + /** |
| 52 | + * Returns the raw JSON value of [inputTokens]. |
| 53 | + * |
| 54 | + * Unlike [inputTokens], this method doesn't throw if the JSON field has an unexpected type. |
| 55 | + */ |
| 56 | + @JsonProperty("input_tokens") @ExcludeMissing fun _inputTokens(): JsonField<Long> = inputTokens |
| 57 | + |
| 58 | + @JsonAnySetter |
| 59 | + private fun putAdditionalProperty(key: String, value: JsonValue) { |
| 60 | + additionalProperties.put(key, value) |
| 61 | + } |
| 62 | + |
| 63 | + @JsonAnyGetter |
| 64 | + @ExcludeMissing |
| 65 | + fun _additionalProperties(): Map<String, JsonValue> = |
| 66 | + Collections.unmodifiableMap(additionalProperties) |
| 67 | + |
| 68 | + fun toBuilder() = Builder().from(this) |
| 69 | + |
| 70 | + companion object { |
| 71 | + |
| 72 | + /** |
| 73 | + * Returns a mutable builder for constructing an instance of [InputTokenCountResponse]. |
| 74 | + * |
| 75 | + * The following fields are required: |
| 76 | + * ```java |
| 77 | + * .inputTokens() |
| 78 | + * ``` |
| 79 | + */ |
| 80 | + @JvmStatic fun builder() = Builder() |
| 81 | + } |
| 82 | + |
| 83 | + /** A builder for [InputTokenCountResponse]. */ |
| 84 | + class Builder internal constructor() { |
| 85 | + |
| 86 | + private var inputTokens: JsonField<Long>? = null |
| 87 | + private var object_: JsonValue = JsonValue.from("response.input_tokens") |
| 88 | + private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf() |
| 89 | + |
| 90 | + @JvmSynthetic |
| 91 | + internal fun from(inputTokenCountResponse: InputTokenCountResponse) = apply { |
| 92 | + inputTokens = inputTokenCountResponse.inputTokens |
| 93 | + object_ = inputTokenCountResponse.object_ |
| 94 | + additionalProperties = inputTokenCountResponse.additionalProperties.toMutableMap() |
| 95 | + } |
| 96 | + |
| 97 | + fun inputTokens(inputTokens: Long) = inputTokens(JsonField.of(inputTokens)) |
| 98 | + |
| 99 | + /** |
| 100 | + * Sets [Builder.inputTokens] to an arbitrary JSON value. |
| 101 | + * |
| 102 | + * You should usually call [Builder.inputTokens] with a well-typed [Long] value instead. |
| 103 | + * This method is primarily for setting the field to an undocumented or not yet supported |
| 104 | + * value. |
| 105 | + */ |
| 106 | + fun inputTokens(inputTokens: JsonField<Long>) = apply { this.inputTokens = inputTokens } |
| 107 | + |
| 108 | + /** |
| 109 | + * Sets the field to an arbitrary JSON value. |
| 110 | + * |
| 111 | + * It is usually unnecessary to call this method because the field defaults to the |
| 112 | + * following: |
| 113 | + * ```java |
| 114 | + * JsonValue.from("response.input_tokens") |
| 115 | + * ``` |
| 116 | + * |
| 117 | + * This method is primarily for setting the field to an undocumented or not yet supported |
| 118 | + * value. |
| 119 | + */ |
| 120 | + fun object_(object_: JsonValue) = apply { this.object_ = object_ } |
| 121 | + |
| 122 | + fun additionalProperties(additionalProperties: Map<String, JsonValue>) = apply { |
| 123 | + this.additionalProperties.clear() |
| 124 | + putAllAdditionalProperties(additionalProperties) |
| 125 | + } |
| 126 | + |
| 127 | + fun putAdditionalProperty(key: String, value: JsonValue) = apply { |
| 128 | + additionalProperties.put(key, value) |
| 129 | + } |
| 130 | + |
| 131 | + fun putAllAdditionalProperties(additionalProperties: Map<String, JsonValue>) = apply { |
| 132 | + this.additionalProperties.putAll(additionalProperties) |
| 133 | + } |
| 134 | + |
| 135 | + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } |
| 136 | + |
| 137 | + fun removeAllAdditionalProperties(keys: Set<String>) = apply { |
| 138 | + keys.forEach(::removeAdditionalProperty) |
| 139 | + } |
| 140 | + |
| 141 | + /** |
| 142 | + * Returns an immutable instance of [InputTokenCountResponse]. |
| 143 | + * |
| 144 | + * Further updates to this [Builder] will not mutate the returned instance. |
| 145 | + * |
| 146 | + * The following fields are required: |
| 147 | + * ```java |
| 148 | + * .inputTokens() |
| 149 | + * ``` |
| 150 | + * |
| 151 | + * @throws IllegalStateException if any required field is unset. |
| 152 | + */ |
| 153 | + fun build(): InputTokenCountResponse = |
| 154 | + InputTokenCountResponse( |
| 155 | + checkRequired("inputTokens", inputTokens), |
| 156 | + object_, |
| 157 | + additionalProperties.toMutableMap(), |
| 158 | + ) |
| 159 | + } |
| 160 | + |
| 161 | + private var validated: Boolean = false |
| 162 | + |
| 163 | + fun validate(): InputTokenCountResponse = apply { |
| 164 | + if (validated) { |
| 165 | + return@apply |
| 166 | + } |
| 167 | + |
| 168 | + inputTokens() |
| 169 | + _object_().let { |
| 170 | + if (it != JsonValue.from("response.input_tokens")) { |
| 171 | + throw OpenAIInvalidDataException("'object_' is invalid, received $it") |
| 172 | + } |
| 173 | + } |
| 174 | + validated = true |
| 175 | + } |
| 176 | + |
| 177 | + fun isValid(): Boolean = |
| 178 | + try { |
| 179 | + validate() |
| 180 | + true |
| 181 | + } catch (e: OpenAIInvalidDataException) { |
| 182 | + false |
| 183 | + } |
| 184 | + |
| 185 | + /** |
| 186 | + * Returns a score indicating how many valid values are contained in this object recursively. |
| 187 | + * |
| 188 | + * Used for best match union deserialization. |
| 189 | + */ |
| 190 | + @JvmSynthetic |
| 191 | + internal fun validity(): Int = |
| 192 | + (if (inputTokens.asKnown().isPresent) 1 else 0) + |
| 193 | + object_.let { if (it == JsonValue.from("response.input_tokens")) 1 else 0 } |
| 194 | + |
| 195 | + override fun equals(other: Any?): Boolean { |
| 196 | + if (this === other) { |
| 197 | + return true |
| 198 | + } |
| 199 | + |
| 200 | + return other is InputTokenCountResponse && |
| 201 | + inputTokens == other.inputTokens && |
| 202 | + object_ == other.object_ && |
| 203 | + additionalProperties == other.additionalProperties |
| 204 | + } |
| 205 | + |
| 206 | + private val hashCode: Int by lazy { Objects.hash(inputTokens, object_, additionalProperties) } |
| 207 | + |
| 208 | + override fun hashCode(): Int = hashCode |
| 209 | + |
| 210 | + override fun toString() = |
| 211 | + "InputTokenCountResponse{inputTokens=$inputTokens, object_=$object_, additionalProperties=$additionalProperties}" |
| 212 | +} |
0 commit comments