commonMain.com.xebia.functional.openai.generated.model.ChatCompletionRequestAssistantMessageContentPart.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 Show documentation
Show all versions of xef-openai-client 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.ChatCompletionRequestMessageContentPartRefusal
import com.xebia.functional.openai.generated.model.ChatCompletionRequestMessageContentPartText
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 = ChatCompletionRequestAssistantMessageContentPartSerializer::class)
sealed interface ChatCompletionRequestAssistantMessageContentPart {
@JvmInline
@Serializable
value class CaseChatCompletionRequestMessageContentPartRefusal(val value: ChatCompletionRequestMessageContentPartRefusal): ChatCompletionRequestAssistantMessageContentPart
@JvmInline
@Serializable
value class CaseChatCompletionRequestMessageContentPartText(val value: ChatCompletionRequestMessageContentPartText): ChatCompletionRequestAssistantMessageContentPart
}
object ChatCompletionRequestAssistantMessageContentPartSerializer : KSerializer {
@OptIn(InternalSerializationApi::class, ExperimentalSerializationApi::class)
override val descriptor: SerialDescriptor = buildSerialDescriptor("ChatCompletionRequestAssistantMessageContentPart", PolymorphicKind.SEALED) {
element("1", ChatCompletionRequestMessageContentPartRefusal.serializer().descriptor)
element("2", ChatCompletionRequestMessageContentPartText.serializer().descriptor)
}
override fun deserialize(decoder: Decoder): ChatCompletionRequestAssistantMessageContentPart {
val jsonSerde = Json { ignoreUnknownKeys = true }
val json = decoder.decodeSerializableValue(JsonElement.serializer())
return attemptDeserialize(json,
Pair(ChatCompletionRequestAssistantMessageContentPart.CaseChatCompletionRequestMessageContentPartRefusal::class) {
ChatCompletionRequestAssistantMessageContentPart.CaseChatCompletionRequestMessageContentPartRefusal(jsonSerde.decodeFromJsonElement(ChatCompletionRequestMessageContentPartRefusal.serializer(), json))
},
Pair(ChatCompletionRequestAssistantMessageContentPart.CaseChatCompletionRequestMessageContentPartText::class) {
ChatCompletionRequestAssistantMessageContentPart.CaseChatCompletionRequestMessageContentPartText(jsonSerde.decodeFromJsonElement(ChatCompletionRequestMessageContentPartText.serializer(), json))
})
}
override fun serialize(encoder: Encoder, value: ChatCompletionRequestAssistantMessageContentPart) =
when(value) {
is ChatCompletionRequestAssistantMessageContentPart.CaseChatCompletionRequestMessageContentPartRefusal ->
encoder.encodeSerializableValue(ChatCompletionRequestMessageContentPartRefusal.serializer(), value.value)
is ChatCompletionRequestAssistantMessageContentPart.CaseChatCompletionRequestMessageContentPartText ->
encoder.encodeSerializableValue(ChatCompletionRequestMessageContentPartText.serializer(), value.value)
}
}