|
| 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 | + * Developer-provided instructions that the model should follow, regardless of messages sent by the |
| 32 | + * user. With o1 models and newer, `developer` messages replace the previous `system` messages. |
| 33 | + */ |
| 34 | +@JsonDeserialize(builder = ChatCompletionDeveloperMessageParam.Builder::class) |
| 35 | +@NoAutoDetect |
| 36 | +class ChatCompletionDeveloperMessageParam |
| 37 | +private constructor( |
| 38 | + private val content: JsonField<Content>, |
| 39 | + private val role: JsonField<Role>, |
| 40 | + private val name: JsonField<String>, |
| 41 | + private val additionalProperties: Map<String, JsonValue>, |
| 42 | +) { |
| 43 | + |
| 44 | + private var validated: Boolean = false |
| 45 | + |
| 46 | + /** The contents of the developer message. */ |
| 47 | + fun content(): Content = content.getRequired("content") |
| 48 | + |
| 49 | + /** The role of the messages author, in this case `developer`. */ |
| 50 | + fun role(): Role = role.getRequired("role") |
| 51 | + |
| 52 | + /** |
| 53 | + * An optional name for the participant. Provides the model information to differentiate between |
| 54 | + * participants of the same role. |
| 55 | + */ |
| 56 | + fun name(): Optional<String> = Optional.ofNullable(name.getNullable("name")) |
| 57 | + |
| 58 | + /** The contents of the developer message. */ |
| 59 | + @JsonProperty("content") @ExcludeMissing fun _content() = content |
| 60 | + |
| 61 | + /** The role of the messages author, in this case `developer`. */ |
| 62 | + @JsonProperty("role") @ExcludeMissing fun _role() = role |
| 63 | + |
| 64 | + /** |
| 65 | + * An optional name for the participant. Provides the model information to differentiate between |
| 66 | + * participants of the same role. |
| 67 | + */ |
| 68 | + @JsonProperty("name") @ExcludeMissing fun _name() = name |
| 69 | + |
| 70 | + @JsonAnyGetter |
| 71 | + @ExcludeMissing |
| 72 | + fun _additionalProperties(): Map<String, JsonValue> = additionalProperties |
| 73 | + |
| 74 | + fun validate(): ChatCompletionDeveloperMessageParam = apply { |
| 75 | + if (!validated) { |
| 76 | + content() |
| 77 | + role() |
| 78 | + name() |
| 79 | + validated = true |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + fun toBuilder() = Builder().from(this) |
| 84 | + |
| 85 | + companion object { |
| 86 | + |
| 87 | + @JvmStatic fun builder() = Builder() |
| 88 | + } |
| 89 | + |
| 90 | + class Builder { |
| 91 | + |
| 92 | + private var content: JsonField<Content> = JsonMissing.of() |
| 93 | + private var role: JsonField<Role> = JsonMissing.of() |
| 94 | + private var name: JsonField<String> = JsonMissing.of() |
| 95 | + private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf() |
| 96 | + |
| 97 | + @JvmSynthetic |
| 98 | + internal fun from( |
| 99 | + chatCompletionDeveloperMessageParam: ChatCompletionDeveloperMessageParam |
| 100 | + ) = apply { |
| 101 | + this.content = chatCompletionDeveloperMessageParam.content |
| 102 | + this.role = chatCompletionDeveloperMessageParam.role |
| 103 | + this.name = chatCompletionDeveloperMessageParam.name |
| 104 | + additionalProperties(chatCompletionDeveloperMessageParam.additionalProperties) |
| 105 | + } |
| 106 | + |
| 107 | + /** The contents of the developer message. */ |
| 108 | + fun content(content: Content) = content(JsonField.of(content)) |
| 109 | + |
| 110 | + /** The contents of the developer message. */ |
| 111 | + @JsonProperty("content") |
| 112 | + @ExcludeMissing |
| 113 | + fun content(content: JsonField<Content>) = apply { this.content = content } |
| 114 | + |
| 115 | + /** The role of the messages author, in this case `developer`. */ |
| 116 | + fun role(role: Role) = role(JsonField.of(role)) |
| 117 | + |
| 118 | + /** The role of the messages author, in this case `developer`. */ |
| 119 | + @JsonProperty("role") |
| 120 | + @ExcludeMissing |
| 121 | + fun role(role: JsonField<Role>) = apply { this.role = role } |
| 122 | + |
| 123 | + /** |
| 124 | + * An optional name for the participant. Provides the model information to differentiate |
| 125 | + * between participants of the same role. |
| 126 | + */ |
| 127 | + fun name(name: String) = name(JsonField.of(name)) |
| 128 | + |
| 129 | + /** |
| 130 | + * An optional name for the participant. Provides the model information to differentiate |
| 131 | + * between participants of the same role. |
| 132 | + */ |
| 133 | + @JsonProperty("name") |
| 134 | + @ExcludeMissing |
| 135 | + fun name(name: JsonField<String>) = apply { this.name = name } |
| 136 | + |
| 137 | + fun additionalProperties(additionalProperties: Map<String, JsonValue>) = apply { |
| 138 | + this.additionalProperties.clear() |
| 139 | + this.additionalProperties.putAll(additionalProperties) |
| 140 | + } |
| 141 | + |
| 142 | + @JsonAnySetter |
| 143 | + fun putAdditionalProperty(key: String, value: JsonValue) = apply { |
| 144 | + this.additionalProperties.put(key, value) |
| 145 | + } |
| 146 | + |
| 147 | + fun putAllAdditionalProperties(additionalProperties: Map<String, JsonValue>) = apply { |
| 148 | + this.additionalProperties.putAll(additionalProperties) |
| 149 | + } |
| 150 | + |
| 151 | + fun build(): ChatCompletionDeveloperMessageParam = |
| 152 | + ChatCompletionDeveloperMessageParam( |
| 153 | + content, |
| 154 | + role, |
| 155 | + name, |
| 156 | + additionalProperties.toImmutable(), |
| 157 | + ) |
| 158 | + } |
| 159 | + |
| 160 | + @JsonDeserialize(using = Content.Deserializer::class) |
| 161 | + @JsonSerialize(using = Content.Serializer::class) |
| 162 | + class Content |
| 163 | + private constructor( |
| 164 | + private val textContent: String? = null, |
| 165 | + private val arrayOfContentParts: List<ChatCompletionContentPartText>? = null, |
| 166 | + private val _json: JsonValue? = null, |
| 167 | + ) { |
| 168 | + |
| 169 | + private var validated: Boolean = false |
| 170 | + |
| 171 | + /** The contents of the developer message. */ |
| 172 | + fun textContent(): Optional<String> = Optional.ofNullable(textContent) |
| 173 | + /** |
| 174 | + * An array of content parts with a defined type. For developer messages, only type `text` |
| 175 | + * is supported. |
| 176 | + */ |
| 177 | + fun arrayOfContentParts(): Optional<List<ChatCompletionContentPartText>> = |
| 178 | + Optional.ofNullable(arrayOfContentParts) |
| 179 | + |
| 180 | + fun isTextContent(): Boolean = textContent != null |
| 181 | + |
| 182 | + fun isArrayOfContentParts(): Boolean = arrayOfContentParts != null |
| 183 | + |
| 184 | + fun asTextContent(): String = textContent.getOrThrow("textContent") |
| 185 | + |
| 186 | + fun asArrayOfContentParts(): List<ChatCompletionContentPartText> = |
| 187 | + arrayOfContentParts.getOrThrow("arrayOfContentParts") |
| 188 | + |
| 189 | + fun _json(): Optional<JsonValue> = Optional.ofNullable(_json) |
| 190 | + |
| 191 | + fun <T> accept(visitor: Visitor<T>): T { |
| 192 | + return when { |
| 193 | + textContent != null -> visitor.visitTextContent(textContent) |
| 194 | + arrayOfContentParts != null -> visitor.visitArrayOfContentParts(arrayOfContentParts) |
| 195 | + else -> visitor.unknown(_json) |
| 196 | + } |
| 197 | + } |
| 198 | + |
| 199 | + fun validate(): Content = apply { |
| 200 | + if (!validated) { |
| 201 | + if (textContent == null && arrayOfContentParts == null) { |
| 202 | + throw OpenAIInvalidDataException("Unknown Content: $_json") |
| 203 | + } |
| 204 | + arrayOfContentParts?.forEach { it.validate() } |
| 205 | + validated = true |
| 206 | + } |
| 207 | + } |
| 208 | + |
| 209 | + override fun equals(other: Any?): Boolean { |
| 210 | + if (this === other) { |
| 211 | + return true |
| 212 | + } |
| 213 | + |
| 214 | + return /* spotless:off */ other is Content && textContent == other.textContent && arrayOfContentParts == other.arrayOfContentParts /* spotless:on */ |
| 215 | + } |
| 216 | + |
| 217 | + override fun hashCode(): Int = /* spotless:off */ Objects.hash(textContent, arrayOfContentParts) /* spotless:on */ |
| 218 | + |
| 219 | + override fun toString(): String = |
| 220 | + when { |
| 221 | + textContent != null -> "Content{textContent=$textContent}" |
| 222 | + arrayOfContentParts != null -> "Content{arrayOfContentParts=$arrayOfContentParts}" |
| 223 | + _json != null -> "Content{_unknown=$_json}" |
| 224 | + else -> throw IllegalStateException("Invalid Content") |
| 225 | + } |
| 226 | + |
| 227 | + companion object { |
| 228 | + |
| 229 | + @JvmStatic fun ofTextContent(textContent: String) = Content(textContent = textContent) |
| 230 | + |
| 231 | + @JvmStatic |
| 232 | + fun ofArrayOfContentParts(arrayOfContentParts: List<ChatCompletionContentPartText>) = |
| 233 | + Content(arrayOfContentParts = arrayOfContentParts) |
| 234 | + } |
| 235 | + |
| 236 | + interface Visitor<out T> { |
| 237 | + |
| 238 | + fun visitTextContent(textContent: String): T |
| 239 | + |
| 240 | + fun visitArrayOfContentParts( |
| 241 | + arrayOfContentParts: List<ChatCompletionContentPartText> |
| 242 | + ): T |
| 243 | + |
| 244 | + fun unknown(json: JsonValue?): T { |
| 245 | + throw OpenAIInvalidDataException("Unknown Content: $json") |
| 246 | + } |
| 247 | + } |
| 248 | + |
| 249 | + class Deserializer : BaseDeserializer<Content>(Content::class) { |
| 250 | + |
| 251 | + override fun ObjectCodec.deserialize(node: JsonNode): Content { |
| 252 | + val json = JsonValue.fromJsonNode(node) |
| 253 | + |
| 254 | + tryDeserialize(node, jacksonTypeRef<String>())?.let { |
| 255 | + return Content(textContent = it, _json = json) |
| 256 | + } |
| 257 | + tryDeserialize(node, jacksonTypeRef<List<ChatCompletionContentPartText>>()) { |
| 258 | + it.forEach { it.validate() } |
| 259 | + } |
| 260 | + ?.let { |
| 261 | + return Content(arrayOfContentParts = it, _json = json) |
| 262 | + } |
| 263 | + |
| 264 | + return Content(_json = json) |
| 265 | + } |
| 266 | + } |
| 267 | + |
| 268 | + class Serializer : BaseSerializer<Content>(Content::class) { |
| 269 | + |
| 270 | + override fun serialize( |
| 271 | + value: Content, |
| 272 | + generator: JsonGenerator, |
| 273 | + provider: SerializerProvider |
| 274 | + ) { |
| 275 | + when { |
| 276 | + value.textContent != null -> generator.writeObject(value.textContent) |
| 277 | + value.arrayOfContentParts != null -> |
| 278 | + generator.writeObject(value.arrayOfContentParts) |
| 279 | + value._json != null -> generator.writeObject(value._json) |
| 280 | + else -> throw IllegalStateException("Invalid Content") |
| 281 | + } |
| 282 | + } |
| 283 | + } |
| 284 | + } |
| 285 | + |
| 286 | + class Role |
| 287 | + @JsonCreator |
| 288 | + private constructor( |
| 289 | + private val value: JsonField<String>, |
| 290 | + ) : Enum { |
| 291 | + |
| 292 | + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField<String> = value |
| 293 | + |
| 294 | + companion object { |
| 295 | + |
| 296 | + @JvmField val DEVELOPER = of("developer") |
| 297 | + |
| 298 | + @JvmStatic fun of(value: String) = Role(JsonField.of(value)) |
| 299 | + } |
| 300 | + |
| 301 | + enum class Known { |
| 302 | + DEVELOPER, |
| 303 | + } |
| 304 | + |
| 305 | + enum class Value { |
| 306 | + DEVELOPER, |
| 307 | + _UNKNOWN, |
| 308 | + } |
| 309 | + |
| 310 | + fun value(): Value = |
| 311 | + when (this) { |
| 312 | + DEVELOPER -> Value.DEVELOPER |
| 313 | + else -> Value._UNKNOWN |
| 314 | + } |
| 315 | + |
| 316 | + fun known(): Known = |
| 317 | + when (this) { |
| 318 | + DEVELOPER -> Known.DEVELOPER |
| 319 | + else -> throw OpenAIInvalidDataException("Unknown Role: $value") |
| 320 | + } |
| 321 | + |
| 322 | + fun asString(): String = _value().asStringOrThrow() |
| 323 | + |
| 324 | + override fun equals(other: Any?): Boolean { |
| 325 | + if (this === other) { |
| 326 | + return true |
| 327 | + } |
| 328 | + |
| 329 | + return /* spotless:off */ other is Role && value == other.value /* spotless:on */ |
| 330 | + } |
| 331 | + |
| 332 | + override fun hashCode() = value.hashCode() |
| 333 | + |
| 334 | + override fun toString() = value.toString() |
| 335 | + } |
| 336 | + |
| 337 | + override fun equals(other: Any?): Boolean { |
| 338 | + if (this === other) { |
| 339 | + return true |
| 340 | + } |
| 341 | + |
| 342 | + return /* spotless:off */ other is ChatCompletionDeveloperMessageParam && content == other.content && role == other.role && name == other.name && additionalProperties == other.additionalProperties /* spotless:on */ |
| 343 | + } |
| 344 | + |
| 345 | + /* spotless:off */ |
| 346 | + private val hashCode: Int by lazy { Objects.hash(content, role, name, additionalProperties) } |
| 347 | + /* spotless:on */ |
| 348 | + |
| 349 | + override fun hashCode(): Int = hashCode |
| 350 | + |
| 351 | + override fun toString() = |
| 352 | + "ChatCompletionDeveloperMessageParam{content=$content, role=$role, name=$name, additionalProperties=$additionalProperties}" |
| 353 | +} |
0 commit comments