|
| 1 | +// File generated from our OpenAPI spec by Stainless. |
| 2 | + |
| 3 | +package com.openai.models.realtime |
| 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.Enum |
| 10 | +import com.openai.core.ExcludeMissing |
| 11 | +import com.openai.core.JsonField |
| 12 | +import com.openai.core.JsonMissing |
| 13 | +import com.openai.core.JsonValue |
| 14 | +import com.openai.errors.OpenAIInvalidDataException |
| 15 | +import java.util.Collections |
| 16 | +import java.util.Objects |
| 17 | +import java.util.Optional |
| 18 | +import kotlin.jvm.optionals.getOrNull |
| 19 | + |
| 20 | +class AudioTranscription |
| 21 | +private constructor( |
| 22 | + private val language: JsonField<String>, |
| 23 | + private val model: JsonField<Model>, |
| 24 | + private val prompt: JsonField<String>, |
| 25 | + private val additionalProperties: MutableMap<String, JsonValue>, |
| 26 | +) { |
| 27 | + |
| 28 | + @JsonCreator |
| 29 | + private constructor( |
| 30 | + @JsonProperty("language") @ExcludeMissing language: JsonField<String> = JsonMissing.of(), |
| 31 | + @JsonProperty("model") @ExcludeMissing model: JsonField<Model> = JsonMissing.of(), |
| 32 | + @JsonProperty("prompt") @ExcludeMissing prompt: JsonField<String> = JsonMissing.of(), |
| 33 | + ) : this(language, model, prompt, mutableMapOf()) |
| 34 | + |
| 35 | + /** |
| 36 | + * The language of the input audio. Supplying the input language in |
| 37 | + * [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) (e.g. `en`) format will |
| 38 | + * improve accuracy and latency. |
| 39 | + * |
| 40 | + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the |
| 41 | + * server responded with an unexpected value). |
| 42 | + */ |
| 43 | + fun language(): Optional<String> = language.getOptional("language") |
| 44 | + |
| 45 | + /** |
| 46 | + * The model to use for transcription. Current options are `whisper-1`, |
| 47 | + * `gpt-4o-transcribe-latest`, `gpt-4o-mini-transcribe`, and `gpt-4o-transcribe`. |
| 48 | + * |
| 49 | + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the |
| 50 | + * server responded with an unexpected value). |
| 51 | + */ |
| 52 | + fun model(): Optional<Model> = model.getOptional("model") |
| 53 | + |
| 54 | + /** |
| 55 | + * An optional text to guide the model's style or continue a previous audio segment. For |
| 56 | + * `whisper-1`, the |
| 57 | + * [prompt is a list of keywords](https://platform.openai.com/docs/guides/speech-to-text#prompting). |
| 58 | + * For `gpt-4o-transcribe` models, the prompt is a free text string, for example "expect words |
| 59 | + * related to technology". |
| 60 | + * |
| 61 | + * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the |
| 62 | + * server responded with an unexpected value). |
| 63 | + */ |
| 64 | + fun prompt(): Optional<String> = prompt.getOptional("prompt") |
| 65 | + |
| 66 | + /** |
| 67 | + * Returns the raw JSON value of [language]. |
| 68 | + * |
| 69 | + * Unlike [language], this method doesn't throw if the JSON field has an unexpected type. |
| 70 | + */ |
| 71 | + @JsonProperty("language") @ExcludeMissing fun _language(): JsonField<String> = language |
| 72 | + |
| 73 | + /** |
| 74 | + * Returns the raw JSON value of [model]. |
| 75 | + * |
| 76 | + * Unlike [model], this method doesn't throw if the JSON field has an unexpected type. |
| 77 | + */ |
| 78 | + @JsonProperty("model") @ExcludeMissing fun _model(): JsonField<Model> = model |
| 79 | + |
| 80 | + /** |
| 81 | + * Returns the raw JSON value of [prompt]. |
| 82 | + * |
| 83 | + * Unlike [prompt], this method doesn't throw if the JSON field has an unexpected type. |
| 84 | + */ |
| 85 | + @JsonProperty("prompt") @ExcludeMissing fun _prompt(): JsonField<String> = prompt |
| 86 | + |
| 87 | + @JsonAnySetter |
| 88 | + private fun putAdditionalProperty(key: String, value: JsonValue) { |
| 89 | + additionalProperties.put(key, value) |
| 90 | + } |
| 91 | + |
| 92 | + @JsonAnyGetter |
| 93 | + @ExcludeMissing |
| 94 | + fun _additionalProperties(): Map<String, JsonValue> = |
| 95 | + Collections.unmodifiableMap(additionalProperties) |
| 96 | + |
| 97 | + fun toBuilder() = Builder().from(this) |
| 98 | + |
| 99 | + companion object { |
| 100 | + |
| 101 | + /** Returns a mutable builder for constructing an instance of [AudioTranscription]. */ |
| 102 | + @JvmStatic fun builder() = Builder() |
| 103 | + } |
| 104 | + |
| 105 | + /** A builder for [AudioTranscription]. */ |
| 106 | + class Builder internal constructor() { |
| 107 | + |
| 108 | + private var language: JsonField<String> = JsonMissing.of() |
| 109 | + private var model: JsonField<Model> = JsonMissing.of() |
| 110 | + private var prompt: JsonField<String> = JsonMissing.of() |
| 111 | + private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf() |
| 112 | + |
| 113 | + @JvmSynthetic |
| 114 | + internal fun from(audioTranscription: AudioTranscription) = apply { |
| 115 | + language = audioTranscription.language |
| 116 | + model = audioTranscription.model |
| 117 | + prompt = audioTranscription.prompt |
| 118 | + additionalProperties = audioTranscription.additionalProperties.toMutableMap() |
| 119 | + } |
| 120 | + |
| 121 | + /** |
| 122 | + * The language of the input audio. Supplying the input language in |
| 123 | + * [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) (e.g. `en`) format |
| 124 | + * will improve accuracy and latency. |
| 125 | + */ |
| 126 | + fun language(language: String) = language(JsonField.of(language)) |
| 127 | + |
| 128 | + /** |
| 129 | + * Sets [Builder.language] to an arbitrary JSON value. |
| 130 | + * |
| 131 | + * You should usually call [Builder.language] with a well-typed [String] value instead. This |
| 132 | + * method is primarily for setting the field to an undocumented or not yet supported value. |
| 133 | + */ |
| 134 | + fun language(language: JsonField<String>) = apply { this.language = language } |
| 135 | + |
| 136 | + /** |
| 137 | + * The model to use for transcription. Current options are `whisper-1`, |
| 138 | + * `gpt-4o-transcribe-latest`, `gpt-4o-mini-transcribe`, and `gpt-4o-transcribe`. |
| 139 | + */ |
| 140 | + fun model(model: Model) = model(JsonField.of(model)) |
| 141 | + |
| 142 | + /** |
| 143 | + * Sets [Builder.model] to an arbitrary JSON value. |
| 144 | + * |
| 145 | + * You should usually call [Builder.model] with a well-typed [Model] value instead. This |
| 146 | + * method is primarily for setting the field to an undocumented or not yet supported value. |
| 147 | + */ |
| 148 | + fun model(model: JsonField<Model>) = apply { this.model = model } |
| 149 | + |
| 150 | + /** |
| 151 | + * An optional text to guide the model's style or continue a previous audio segment. For |
| 152 | + * `whisper-1`, the |
| 153 | + * [prompt is a list of keywords](https://platform.openai.com/docs/guides/speech-to-text#prompting). |
| 154 | + * For `gpt-4o-transcribe` models, the prompt is a free text string, for example "expect |
| 155 | + * words related to technology". |
| 156 | + */ |
| 157 | + fun prompt(prompt: String) = prompt(JsonField.of(prompt)) |
| 158 | + |
| 159 | + /** |
| 160 | + * Sets [Builder.prompt] to an arbitrary JSON value. |
| 161 | + * |
| 162 | + * You should usually call [Builder.prompt] with a well-typed [String] value instead. This |
| 163 | + * method is primarily for setting the field to an undocumented or not yet supported value. |
| 164 | + */ |
| 165 | + fun prompt(prompt: JsonField<String>) = apply { this.prompt = prompt } |
| 166 | + |
| 167 | + fun additionalProperties(additionalProperties: Map<String, JsonValue>) = apply { |
| 168 | + this.additionalProperties.clear() |
| 169 | + putAllAdditionalProperties(additionalProperties) |
| 170 | + } |
| 171 | + |
| 172 | + fun putAdditionalProperty(key: String, value: JsonValue) = apply { |
| 173 | + additionalProperties.put(key, value) |
| 174 | + } |
| 175 | + |
| 176 | + fun putAllAdditionalProperties(additionalProperties: Map<String, JsonValue>) = apply { |
| 177 | + this.additionalProperties.putAll(additionalProperties) |
| 178 | + } |
| 179 | + |
| 180 | + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } |
| 181 | + |
| 182 | + fun removeAllAdditionalProperties(keys: Set<String>) = apply { |
| 183 | + keys.forEach(::removeAdditionalProperty) |
| 184 | + } |
| 185 | + |
| 186 | + /** |
| 187 | + * Returns an immutable instance of [AudioTranscription]. |
| 188 | + * |
| 189 | + * Further updates to this [Builder] will not mutate the returned instance. |
| 190 | + */ |
| 191 | + fun build(): AudioTranscription = |
| 192 | + AudioTranscription(language, model, prompt, additionalProperties.toMutableMap()) |
| 193 | + } |
| 194 | + |
| 195 | + private var validated: Boolean = false |
| 196 | + |
| 197 | + fun validate(): AudioTranscription = apply { |
| 198 | + if (validated) { |
| 199 | + return@apply |
| 200 | + } |
| 201 | + |
| 202 | + language() |
| 203 | + model().ifPresent { it.validate() } |
| 204 | + prompt() |
| 205 | + validated = true |
| 206 | + } |
| 207 | + |
| 208 | + fun isValid(): Boolean = |
| 209 | + try { |
| 210 | + validate() |
| 211 | + true |
| 212 | + } catch (e: OpenAIInvalidDataException) { |
| 213 | + false |
| 214 | + } |
| 215 | + |
| 216 | + /** |
| 217 | + * Returns a score indicating how many valid values are contained in this object recursively. |
| 218 | + * |
| 219 | + * Used for best match union deserialization. |
| 220 | + */ |
| 221 | + @JvmSynthetic |
| 222 | + internal fun validity(): Int = |
| 223 | + (if (language.asKnown().isPresent) 1 else 0) + |
| 224 | + (model.asKnown().getOrNull()?.validity() ?: 0) + |
| 225 | + (if (prompt.asKnown().isPresent) 1 else 0) |
| 226 | + |
| 227 | + /** |
| 228 | + * The model to use for transcription. Current options are `whisper-1`, |
| 229 | + * `gpt-4o-transcribe-latest`, `gpt-4o-mini-transcribe`, and `gpt-4o-transcribe`. |
| 230 | + */ |
| 231 | + class Model @JsonCreator private constructor(private val value: JsonField<String>) : Enum { |
| 232 | + |
| 233 | + /** |
| 234 | + * Returns this class instance's raw value. |
| 235 | + * |
| 236 | + * This is usually only useful if this instance was deserialized from data that doesn't |
| 237 | + * match any known member, and you want to know that value. For example, if the SDK is on an |
| 238 | + * older version than the API, then the API may respond with new members that the SDK is |
| 239 | + * unaware of. |
| 240 | + */ |
| 241 | + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField<String> = value |
| 242 | + |
| 243 | + companion object { |
| 244 | + |
| 245 | + @JvmField val WHISPER_1 = of("whisper-1") |
| 246 | + |
| 247 | + @JvmField val GPT_4O_TRANSCRIBE_LATEST = of("gpt-4o-transcribe-latest") |
| 248 | + |
| 249 | + @JvmField val GPT_4O_MINI_TRANSCRIBE = of("gpt-4o-mini-transcribe") |
| 250 | + |
| 251 | + @JvmField val GPT_4O_TRANSCRIBE = of("gpt-4o-transcribe") |
| 252 | + |
| 253 | + @JvmStatic fun of(value: String) = Model(JsonField.of(value)) |
| 254 | + } |
| 255 | + |
| 256 | + /** An enum containing [Model]'s known values. */ |
| 257 | + enum class Known { |
| 258 | + WHISPER_1, |
| 259 | + GPT_4O_TRANSCRIBE_LATEST, |
| 260 | + GPT_4O_MINI_TRANSCRIBE, |
| 261 | + GPT_4O_TRANSCRIBE, |
| 262 | + } |
| 263 | + |
| 264 | + /** |
| 265 | + * An enum containing [Model]'s known values, as well as an [_UNKNOWN] member. |
| 266 | + * |
| 267 | + * An instance of [Model] can contain an unknown value in a couple of cases: |
| 268 | + * - It was deserialized from data that doesn't match any known member. For example, if the |
| 269 | + * SDK is on an older version than the API, then the API may respond with new members that |
| 270 | + * the SDK is unaware of. |
| 271 | + * - It was constructed with an arbitrary value using the [of] method. |
| 272 | + */ |
| 273 | + enum class Value { |
| 274 | + WHISPER_1, |
| 275 | + GPT_4O_TRANSCRIBE_LATEST, |
| 276 | + GPT_4O_MINI_TRANSCRIBE, |
| 277 | + GPT_4O_TRANSCRIBE, |
| 278 | + /** An enum member indicating that [Model] was instantiated with an unknown value. */ |
| 279 | + _UNKNOWN, |
| 280 | + } |
| 281 | + |
| 282 | + /** |
| 283 | + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] |
| 284 | + * if the class was instantiated with an unknown value. |
| 285 | + * |
| 286 | + * Use the [known] method instead if you're certain the value is always known or if you want |
| 287 | + * to throw for the unknown case. |
| 288 | + */ |
| 289 | + fun value(): Value = |
| 290 | + when (this) { |
| 291 | + WHISPER_1 -> Value.WHISPER_1 |
| 292 | + GPT_4O_TRANSCRIBE_LATEST -> Value.GPT_4O_TRANSCRIBE_LATEST |
| 293 | + GPT_4O_MINI_TRANSCRIBE -> Value.GPT_4O_MINI_TRANSCRIBE |
| 294 | + GPT_4O_TRANSCRIBE -> Value.GPT_4O_TRANSCRIBE |
| 295 | + else -> Value._UNKNOWN |
| 296 | + } |
| 297 | + |
| 298 | + /** |
| 299 | + * Returns an enum member corresponding to this class instance's value. |
| 300 | + * |
| 301 | + * Use the [value] method instead if you're uncertain the value is always known and don't |
| 302 | + * want to throw for the unknown case. |
| 303 | + * |
| 304 | + * @throws OpenAIInvalidDataException if this class instance's value is a not a known |
| 305 | + * member. |
| 306 | + */ |
| 307 | + fun known(): Known = |
| 308 | + when (this) { |
| 309 | + WHISPER_1 -> Known.WHISPER_1 |
| 310 | + GPT_4O_TRANSCRIBE_LATEST -> Known.GPT_4O_TRANSCRIBE_LATEST |
| 311 | + GPT_4O_MINI_TRANSCRIBE -> Known.GPT_4O_MINI_TRANSCRIBE |
| 312 | + GPT_4O_TRANSCRIBE -> Known.GPT_4O_TRANSCRIBE |
| 313 | + else -> throw OpenAIInvalidDataException("Unknown Model: $value") |
| 314 | + } |
| 315 | + |
| 316 | + /** |
| 317 | + * Returns this class instance's primitive wire representation. |
| 318 | + * |
| 319 | + * This differs from the [toString] method because that method is primarily for debugging |
| 320 | + * and generally doesn't throw. |
| 321 | + * |
| 322 | + * @throws OpenAIInvalidDataException if this class instance's value does not have the |
| 323 | + * expected primitive type. |
| 324 | + */ |
| 325 | + fun asString(): String = |
| 326 | + _value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") } |
| 327 | + |
| 328 | + private var validated: Boolean = false |
| 329 | + |
| 330 | + fun validate(): Model = apply { |
| 331 | + if (validated) { |
| 332 | + return@apply |
| 333 | + } |
| 334 | + |
| 335 | + known() |
| 336 | + validated = true |
| 337 | + } |
| 338 | + |
| 339 | + fun isValid(): Boolean = |
| 340 | + try { |
| 341 | + validate() |
| 342 | + true |
| 343 | + } catch (e: OpenAIInvalidDataException) { |
| 344 | + false |
| 345 | + } |
| 346 | + |
| 347 | + /** |
| 348 | + * Returns a score indicating how many valid values are contained in this object |
| 349 | + * recursively. |
| 350 | + * |
| 351 | + * Used for best match union deserialization. |
| 352 | + */ |
| 353 | + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 |
| 354 | + |
| 355 | + override fun equals(other: Any?): Boolean { |
| 356 | + if (this === other) { |
| 357 | + return true |
| 358 | + } |
| 359 | + |
| 360 | + return other is Model && value == other.value |
| 361 | + } |
| 362 | + |
| 363 | + override fun hashCode() = value.hashCode() |
| 364 | + |
| 365 | + override fun toString() = value.toString() |
| 366 | + } |
| 367 | + |
| 368 | + override fun equals(other: Any?): Boolean { |
| 369 | + if (this === other) { |
| 370 | + return true |
| 371 | + } |
| 372 | + |
| 373 | + return other is AudioTranscription && |
| 374 | + language == other.language && |
| 375 | + model == other.model && |
| 376 | + prompt == other.prompt && |
| 377 | + additionalProperties == other.additionalProperties |
| 378 | + } |
| 379 | + |
| 380 | + private val hashCode: Int by lazy { |
| 381 | + Objects.hash(language, model, prompt, additionalProperties) |
| 382 | + } |
| 383 | + |
| 384 | + override fun hashCode(): Int = hashCode |
| 385 | + |
| 386 | + override fun toString() = |
| 387 | + "AudioTranscription{language=$language, model=$model, prompt=$prompt, additionalProperties=$additionalProperties}" |
| 388 | +} |
0 commit comments