commonMain.com.xebia.functional.openai.generated.model.MessageObjectContentInner.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xef-openai-client-jvm Show documentation
Show all versions of xef-openai-client-jvm Show documentation
Building applications with LLMs through composability in Kotlin
/**
*
* Please note:
* This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* Do not edit this file manually.
*
*/
@file:Suppress(
"ArrayInDataClass",
"EnumEntryName",
"RemoveRedundantQualifierName",
"UnusedImport"
)
package com.xebia.functional.openai.generated.model
import com.xebia.functional.openai.generated.model.MessageContentImageFileObject
import com.xebia.functional.openai.generated.model.MessageContentImageFileObjectImageFile
import com.xebia.functional.openai.generated.model.MessageContentImageUrlObject
import com.xebia.functional.openai.generated.model.MessageContentImageUrlObjectImageUrl
import com.xebia.functional.openai.generated.model.MessageContentRefusalObject
import com.xebia.functional.openai.generated.model.MessageContentTextObject
import com.xebia.functional.openai.generated.model.MessageContentTextObjectText
import com.xebia.functional.openai.attemptDeserialize
import kotlin.jvm.JvmInline
import kotlinx.serialization.*
import kotlinx.serialization.builtins.*
import kotlinx.serialization.descriptors.*
import kotlinx.serialization.encoding.*
import kotlinx.serialization.json.*
@Serializable(with = MessageObjectContentInnerSerializer::class)
sealed interface MessageObjectContentInner {
@JvmInline
@Serializable
value class CaseMessageContentImageFileObject(val value: MessageContentImageFileObject): MessageObjectContentInner
@JvmInline
@Serializable
value class CaseMessageContentImageUrlObject(val value: MessageContentImageUrlObject): MessageObjectContentInner
@JvmInline
@Serializable
value class CaseMessageContentRefusalObject(val value: MessageContentRefusalObject): MessageObjectContentInner
@JvmInline
@Serializable
value class CaseMessageContentTextObject(val value: MessageContentTextObject): MessageObjectContentInner
}
object MessageObjectContentInnerSerializer : KSerializer {
@OptIn(InternalSerializationApi::class, ExperimentalSerializationApi::class)
override val descriptor: SerialDescriptor = buildSerialDescriptor("MessageObjectContentInner", PolymorphicKind.SEALED) {
element("1", MessageContentImageFileObject.serializer().descriptor)
element("2", MessageContentImageUrlObject.serializer().descriptor)
element("3", MessageContentRefusalObject.serializer().descriptor)
element("4", MessageContentTextObject.serializer().descriptor)
}
override fun deserialize(decoder: Decoder): MessageObjectContentInner {
val jsonSerde = Json { ignoreUnknownKeys = true }
val json = decoder.decodeSerializableValue(JsonElement.serializer())
return attemptDeserialize(json,
Pair(MessageObjectContentInner.CaseMessageContentImageFileObject::class) {
MessageObjectContentInner.CaseMessageContentImageFileObject(jsonSerde.decodeFromJsonElement(MessageContentImageFileObject.serializer(), json))
},
Pair(MessageObjectContentInner.CaseMessageContentImageUrlObject::class) {
MessageObjectContentInner.CaseMessageContentImageUrlObject(jsonSerde.decodeFromJsonElement(MessageContentImageUrlObject.serializer(), json))
},
Pair(MessageObjectContentInner.CaseMessageContentRefusalObject::class) {
MessageObjectContentInner.CaseMessageContentRefusalObject(jsonSerde.decodeFromJsonElement(MessageContentRefusalObject.serializer(), json))
},
Pair(MessageObjectContentInner.CaseMessageContentTextObject::class) {
MessageObjectContentInner.CaseMessageContentTextObject(jsonSerde.decodeFromJsonElement(MessageContentTextObject.serializer(), json))
})
}
override fun serialize(encoder: Encoder, value: MessageObjectContentInner) =
when(value) {
is MessageObjectContentInner.CaseMessageContentImageFileObject ->
encoder.encodeSerializableValue(MessageContentImageFileObject.serializer(), value.value)
is MessageObjectContentInner.CaseMessageContentImageUrlObject ->
encoder.encodeSerializableValue(MessageContentImageUrlObject.serializer(), value.value)
is MessageObjectContentInner.CaseMessageContentRefusalObject ->
encoder.encodeSerializableValue(MessageContentRefusalObject.serializer(), value.value)
is MessageObjectContentInner.CaseMessageContentTextObject ->
encoder.encodeSerializableValue(MessageContentTextObject.serializer(), value.value)
}
}