|
| 1 | +// File generated from our OpenAPI spec by Stainless. |
| 2 | + |
| 3 | +package com.openai.models |
| 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.fasterxml.jackson.core.JsonGenerator |
| 10 | +import com.fasterxml.jackson.core.ObjectCodec |
| 11 | +import com.fasterxml.jackson.databind.JsonNode |
| 12 | +import com.fasterxml.jackson.databind.SerializerProvider |
| 13 | +import com.fasterxml.jackson.databind.annotation.JsonDeserialize |
| 14 | +import com.fasterxml.jackson.databind.annotation.JsonSerialize |
| 15 | +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef |
| 16 | +import com.openai.core.BaseDeserializer |
| 17 | +import com.openai.core.BaseSerializer |
| 18 | +import com.openai.core.Enum |
| 19 | +import com.openai.core.ExcludeMissing |
| 20 | +import com.openai.core.JsonField |
| 21 | +import com.openai.core.JsonMissing |
| 22 | +import com.openai.core.JsonValue |
| 23 | +import com.openai.core.NoAutoDetect |
| 24 | +import com.openai.core.getOrThrow |
| 25 | +import com.openai.core.toImmutable |
| 26 | +import com.openai.errors.OpenAIInvalidDataException |
| 27 | +import java.util.Objects |
| 28 | +import java.util.Optional |
| 29 | + |
| 30 | +/** |
| 31 | + * Static predicted output content, such as the content of a text file that is being regenerated. |
| 32 | + */ |
| 33 | +@JsonDeserialize(builder = ChatCompletionPredictionContent.Builder::class) |
| 34 | +@NoAutoDetect |
| 35 | +class ChatCompletionPredictionContent |
| 36 | +private constructor( |
| 37 | + private val type: JsonField<Type>, |
| 38 | + private val content: JsonField<Content>, |
| 39 | + private val additionalProperties: Map<String, JsonValue>, |
| 40 | +) { |
| 41 | + |
| 42 | + private var validated: Boolean = false |
| 43 | + |
| 44 | + /** |
| 45 | + * The type of the predicted content you want to provide. This type is currently always |
| 46 | + * `content`. |
| 47 | + */ |
| 48 | + fun type(): Type = type.getRequired("type") |
| 49 | + |
| 50 | + /** |
| 51 | + * The content that should be matched when generating a model response. If generated tokens |
| 52 | + * would match this content, the entire model response can be returned much more quickly. |
| 53 | + */ |
| 54 | + fun content(): Content = content.getRequired("content") |
| 55 | + |
| 56 | + /** |
| 57 | + * The type of the predicted content you want to provide. This type is currently always |
| 58 | + * `content`. |
| 59 | + */ |
| 60 | + @JsonProperty("type") @ExcludeMissing fun _type() = type |
| 61 | + |
| 62 | + /** |
| 63 | + * The content that should be matched when generating a model response. If generated tokens |
| 64 | + * would match this content, the entire model response can be returned much more quickly. |
| 65 | + */ |
| 66 | + @JsonProperty("content") @ExcludeMissing fun _content() = content |
| 67 | + |
| 68 | + @JsonAnyGetter |
| 69 | + @ExcludeMissing |
| 70 | + fun _additionalProperties(): Map<String, JsonValue> = additionalProperties |
| 71 | + |
| 72 | + fun validate(): ChatCompletionPredictionContent = apply { |
| 73 | + if (!validated) { |
| 74 | + type() |
| 75 | + content() |
| 76 | + validated = true |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + fun toBuilder() = Builder().from(this) |
| 81 | + |
| 82 | + companion object { |
| 83 | + |
| 84 | + @JvmStatic fun builder() = Builder() |
| 85 | + } |
| 86 | + |
| 87 | + class Builder { |
| 88 | + |
| 89 | + private var type: JsonField<Type> = JsonMissing.of() |
| 90 | + private var content: JsonField<Content> = JsonMissing.of() |
| 91 | + private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf() |
| 92 | + |
| 93 | + @JvmSynthetic |
| 94 | + internal fun from(chatCompletionPredictionContent: ChatCompletionPredictionContent) = |
| 95 | + apply { |
| 96 | + this.type = chatCompletionPredictionContent.type |
| 97 | + this.content = chatCompletionPredictionContent.content |
| 98 | + additionalProperties(chatCompletionPredictionContent.additionalProperties) |
| 99 | + } |
| 100 | + |
| 101 | + /** |
| 102 | + * The type of the predicted content you want to provide. This type is currently always |
| 103 | + * `content`. |
| 104 | + */ |
| 105 | + fun type(type: Type) = type(JsonField.of(type)) |
| 106 | + |
| 107 | + /** |
| 108 | + * The type of the predicted content you want to provide. This type is currently always |
| 109 | + * `content`. |
| 110 | + */ |
| 111 | + @JsonProperty("type") |
| 112 | + @ExcludeMissing |
| 113 | + fun type(type: JsonField<Type>) = apply { this.type = type } |
| 114 | + |
| 115 | + /** |
| 116 | + * The content that should be matched when generating a model response. If generated tokens |
| 117 | + * would match this content, the entire model response can be returned much more quickly. |
| 118 | + */ |
| 119 | + fun content(content: Content) = content(JsonField.of(content)) |
| 120 | + |
| 121 | + /** |
| 122 | + * The content that should be matched when generating a model response. If generated tokens |
| 123 | + * would match this content, the entire model response can be returned much more quickly. |
| 124 | + */ |
| 125 | + @JsonProperty("content") |
| 126 | + @ExcludeMissing |
| 127 | + fun content(content: JsonField<Content>) = apply { this.content = content } |
| 128 | + |
| 129 | + fun additionalProperties(additionalProperties: Map<String, JsonValue>) = apply { |
| 130 | + this.additionalProperties.clear() |
| 131 | + this.additionalProperties.putAll(additionalProperties) |
| 132 | + } |
| 133 | + |
| 134 | + @JsonAnySetter |
| 135 | + fun putAdditionalProperty(key: String, value: JsonValue) = apply { |
| 136 | + this.additionalProperties.put(key, value) |
| 137 | + } |
| 138 | + |
| 139 | + fun putAllAdditionalProperties(additionalProperties: Map<String, JsonValue>) = apply { |
| 140 | + this.additionalProperties.putAll(additionalProperties) |
| 141 | + } |
| 142 | + |
| 143 | + fun build(): ChatCompletionPredictionContent = |
| 144 | + ChatCompletionPredictionContent( |
| 145 | + type, |
| 146 | + content, |
| 147 | + additionalProperties.toImmutable(), |
| 148 | + ) |
| 149 | + } |
| 150 | + |
| 151 | + @JsonDeserialize(using = Content.Deserializer::class) |
| 152 | + @JsonSerialize(using = Content.Serializer::class) |
| 153 | + class Content |
| 154 | + private constructor( |
| 155 | + private val textContent: String? = null, |
| 156 | + private val arrayOfContentParts: List<ChatCompletionContentPartText>? = null, |
| 157 | + private val _json: JsonValue? = null, |
| 158 | + ) { |
| 159 | + |
| 160 | + private var validated: Boolean = false |
| 161 | + |
| 162 | + /** |
| 163 | + * The content used for a Predicted Output. This is often the text of a file you are |
| 164 | + * regenerating with minor changes. |
| 165 | + */ |
| 166 | + fun textContent(): Optional<String> = Optional.ofNullable(textContent) |
| 167 | + /** |
| 168 | + * An array of content parts with a defined type. Supported options differ based on the |
| 169 | + * [model](https://platform.openai.com/docs/models) being used to generate the response. Can |
| 170 | + * contain text inputs. |
| 171 | + */ |
| 172 | + fun arrayOfContentParts(): Optional<List<ChatCompletionContentPartText>> = |
| 173 | + Optional.ofNullable(arrayOfContentParts) |
| 174 | + |
| 175 | + fun isTextContent(): Boolean = textContent != null |
| 176 | + |
| 177 | + fun isArrayOfContentParts(): Boolean = arrayOfContentParts != null |
| 178 | + |
| 179 | + fun asTextContent(): String = textContent.getOrThrow("textContent") |
| 180 | + |
| 181 | + fun asArrayOfContentParts(): List<ChatCompletionContentPartText> = |
| 182 | + arrayOfContentParts.getOrThrow("arrayOfContentParts") |
| 183 | + |
| 184 | + fun _json(): Optional<JsonValue> = Optional.ofNullable(_json) |
| 185 | + |
| 186 | + fun <T> accept(visitor: Visitor<T>): T { |
| 187 | + return when { |
| 188 | + textContent != null -> visitor.visitTextContent(textContent) |
| 189 | + arrayOfContentParts != null -> visitor.visitArrayOfContentParts(arrayOfContentParts) |
| 190 | + else -> visitor.unknown(_json) |
| 191 | + } |
| 192 | + } |
| 193 | + |
| 194 | + fun validate(): Content = apply { |
| 195 | + if (!validated) { |
| 196 | + if (textContent == null && arrayOfContentParts == null) { |
| 197 | + throw OpenAIInvalidDataException("Unknown Content: $_json") |
| 198 | + } |
| 199 | + arrayOfContentParts?.forEach { it.validate() } |
| 200 | + validated = true |
| 201 | + } |
| 202 | + } |
| 203 | + |
| 204 | + override fun equals(other: Any?): Boolean { |
| 205 | + if (this === other) { |
| 206 | + return true |
| 207 | + } |
| 208 | + |
| 209 | + return /* spotless:off */ other is Content && this.textContent == other.textContent && this.arrayOfContentParts == other.arrayOfContentParts /* spotless:on */ |
| 210 | + } |
| 211 | + |
| 212 | + override fun hashCode(): Int { |
| 213 | + return /* spotless:off */ Objects.hash(textContent, arrayOfContentParts) /* spotless:on */ |
| 214 | + } |
| 215 | + |
| 216 | + override fun toString(): String { |
| 217 | + return when { |
| 218 | + textContent != null -> "Content{textContent=$textContent}" |
| 219 | + arrayOfContentParts != null -> "Content{arrayOfContentParts=$arrayOfContentParts}" |
| 220 | + _json != null -> "Content{_unknown=$_json}" |
| 221 | + else -> throw IllegalStateException("Invalid Content") |
| 222 | + } |
| 223 | + } |
| 224 | + |
| 225 | + companion object { |
| 226 | + |
| 227 | + @JvmStatic fun ofTextContent(textContent: String) = Content(textContent = textContent) |
| 228 | + |
| 229 | + @JvmStatic |
| 230 | + fun ofArrayOfContentParts(arrayOfContentParts: List<ChatCompletionContentPartText>) = |
| 231 | + Content(arrayOfContentParts = arrayOfContentParts) |
| 232 | + } |
| 233 | + |
| 234 | + interface Visitor<out T> { |
| 235 | + |
| 236 | + fun visitTextContent(textContent: String): T |
| 237 | + |
| 238 | + fun visitArrayOfContentParts( |
| 239 | + arrayOfContentParts: List<ChatCompletionContentPartText> |
| 240 | + ): T |
| 241 | + |
| 242 | + fun unknown(json: JsonValue?): T { |
| 243 | + throw OpenAIInvalidDataException("Unknown Content: $json") |
| 244 | + } |
| 245 | + } |
| 246 | + |
| 247 | + class Deserializer : BaseDeserializer<Content>(Content::class) { |
| 248 | + |
| 249 | + override fun ObjectCodec.deserialize(node: JsonNode): Content { |
| 250 | + val json = JsonValue.fromJsonNode(node) |
| 251 | + |
| 252 | + tryDeserialize(node, jacksonTypeRef<String>())?.let { |
| 253 | + return Content(textContent = it, _json = json) |
| 254 | + } |
| 255 | + tryDeserialize(node, jacksonTypeRef<List<ChatCompletionContentPartText>>()) { |
| 256 | + it.forEach { it.validate() } |
| 257 | + } |
| 258 | + ?.let { |
| 259 | + return Content(arrayOfContentParts = it, _json = json) |
| 260 | + } |
| 261 | + |
| 262 | + return Content(_json = json) |
| 263 | + } |
| 264 | + } |
| 265 | + |
| 266 | + class Serializer : BaseSerializer<Content>(Content::class) { |
| 267 | + |
| 268 | + override fun serialize( |
| 269 | + value: Content, |
| 270 | + generator: JsonGenerator, |
| 271 | + provider: SerializerProvider |
| 272 | + ) { |
| 273 | + when { |
| 274 | + value.textContent != null -> generator.writeObject(value.textContent) |
| 275 | + value.arrayOfContentParts != null -> |
| 276 | + generator.writeObject(value.arrayOfContentParts) |
| 277 | + value._json != null -> generator.writeObject(value._json) |
| 278 | + else -> throw IllegalStateException("Invalid Content") |
| 279 | + } |
| 280 | + } |
| 281 | + } |
| 282 | + } |
| 283 | + |
| 284 | + class Type |
| 285 | + @JsonCreator |
| 286 | + private constructor( |
| 287 | + private val value: JsonField<String>, |
| 288 | + ) : Enum { |
| 289 | + |
| 290 | + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField<String> = value |
| 291 | + |
| 292 | + override fun equals(other: Any?): Boolean { |
| 293 | + if (this === other) { |
| 294 | + return true |
| 295 | + } |
| 296 | + |
| 297 | + return /* spotless:off */ other is Type && this.value == other.value /* spotless:on */ |
| 298 | + } |
| 299 | + |
| 300 | + override fun hashCode() = value.hashCode() |
| 301 | + |
| 302 | + override fun toString() = value.toString() |
| 303 | + |
| 304 | + companion object { |
| 305 | + |
| 306 | + @JvmField val CONTENT = Type(JsonField.of("content")) |
| 307 | + |
| 308 | + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) |
| 309 | + } |
| 310 | + |
| 311 | + enum class Known { |
| 312 | + CONTENT, |
| 313 | + } |
| 314 | + |
| 315 | + enum class Value { |
| 316 | + CONTENT, |
| 317 | + _UNKNOWN, |
| 318 | + } |
| 319 | + |
| 320 | + fun value(): Value = |
| 321 | + when (this) { |
| 322 | + CONTENT -> Value.CONTENT |
| 323 | + else -> Value._UNKNOWN |
| 324 | + } |
| 325 | + |
| 326 | + fun known(): Known = |
| 327 | + when (this) { |
| 328 | + CONTENT -> Known.CONTENT |
| 329 | + else -> throw OpenAIInvalidDataException("Unknown Type: $value") |
| 330 | + } |
| 331 | + |
| 332 | + fun asString(): String = _value().asStringOrThrow() |
| 333 | + } |
| 334 | + |
| 335 | + override fun equals(other: Any?): Boolean { |
| 336 | + if (this === other) { |
| 337 | + return true |
| 338 | + } |
| 339 | + |
| 340 | + return /* spotless:off */ other is ChatCompletionPredictionContent && this.type == other.type && this.content == other.content && this.additionalProperties == other.additionalProperties /* spotless:on */ |
| 341 | + } |
| 342 | + |
| 343 | + private var hashCode: Int = 0 |
| 344 | + |
| 345 | + override fun hashCode(): Int { |
| 346 | + if (hashCode == 0) { |
| 347 | + hashCode = /* spotless:off */ Objects.hash(type, content, additionalProperties) /* spotless:on */ |
| 348 | + } |
| 349 | + return hashCode |
| 350 | + } |
| 351 | + |
| 352 | + override fun toString() = |
| 353 | + "ChatCompletionPredictionContent{type=$type, content=$content, additionalProperties=$additionalProperties}" |
| 354 | +} |
0 commit comments