commonMain.com.xebia.functional.openai.generated.model.ChatCompletionRequestUserMessageContent.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.ChatCompletionRequestUserMessageContentPart
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 = ChatCompletionRequestUserMessageContentSerializer::class)
sealed interface ChatCompletionRequestUserMessageContent {
@JvmInline
@Serializable
value class CaseString(val value: kotlin.String): ChatCompletionRequestUserMessageContent
@JvmInline
@Serializable
value class CaseChatCompletionRequestUserMessageContentParts(val value: kotlin.collections.List): ChatCompletionRequestUserMessageContent
}
object ChatCompletionRequestUserMessageContentSerializer : KSerializer {
@OptIn(InternalSerializationApi::class, ExperimentalSerializationApi::class)
override val descriptor: SerialDescriptor = buildSerialDescriptor("ChatCompletionRequestUserMessageContent", PolymorphicKind.SEALED) {
element("1", kotlin.String.serializer().descriptor)
element("2", ListSerializer(ChatCompletionRequestUserMessageContentPart.serializer()).descriptor)
}
override fun deserialize(decoder: Decoder): ChatCompletionRequestUserMessageContent {
val jsonSerde = Json { ignoreUnknownKeys = true }
val json = decoder.decodeSerializableValue(JsonElement.serializer())
return attemptDeserialize(json,
Pair(ChatCompletionRequestUserMessageContent.CaseString::class) {
ChatCompletionRequestUserMessageContent.CaseString(jsonSerde.decodeFromJsonElement(kotlin.String.serializer(), json))
},
Pair(ChatCompletionRequestUserMessageContent.CaseChatCompletionRequestUserMessageContentParts::class) {
ChatCompletionRequestUserMessageContent.CaseChatCompletionRequestUserMessageContentParts(jsonSerde.decodeFromJsonElement(ListSerializer(ChatCompletionRequestUserMessageContentPart.serializer()), json))
})
}
override fun serialize(encoder: Encoder, value: ChatCompletionRequestUserMessageContent) =
when(value) {
is ChatCompletionRequestUserMessageContent.CaseString ->
encoder.encodeSerializableValue(kotlin.String.serializer(), value.value)
is ChatCompletionRequestUserMessageContent.CaseChatCompletionRequestUserMessageContentParts ->
encoder.encodeSerializableValue(ListSerializer(ChatCompletionRequestUserMessageContentPart.serializer()), value.value)
}
}