All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.com.xebia.functional.openai.generated.model.ChatCompletionRequestSystemMessageContent.kt Maven / Gradle / Ivy

The newest version!
/**
 *
 * 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.ChatCompletionRequestSystemMessageContentPart
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 = ChatCompletionRequestSystemMessageContentSerializer::class)
sealed interface ChatCompletionRequestSystemMessageContent {

  @JvmInline
  @Serializable
  value class CaseString(val value: kotlin.String): ChatCompletionRequestSystemMessageContent
  @JvmInline
  @Serializable
  value class CaseChatCompletionRequestSystemMessageContentParts(val value: kotlin.collections.List): ChatCompletionRequestSystemMessageContent

}

object ChatCompletionRequestSystemMessageContentSerializer : KSerializer {
    @OptIn(InternalSerializationApi::class, ExperimentalSerializationApi::class)
    override val descriptor: SerialDescriptor = buildSerialDescriptor("ChatCompletionRequestSystemMessageContent", PolymorphicKind.SEALED) { 
      element("1", kotlin.String.serializer().descriptor)
      element("2", ListSerializer(ChatCompletionRequestSystemMessageContentPart.serializer()).descriptor)
    }

    override fun deserialize(decoder: Decoder): ChatCompletionRequestSystemMessageContent {
      val jsonSerde = Json { ignoreUnknownKeys = true }
      val json = decoder.decodeSerializableValue(JsonElement.serializer())
      return attemptDeserialize(json, 
        Pair(ChatCompletionRequestSystemMessageContent.CaseString::class) {
          ChatCompletionRequestSystemMessageContent.CaseString(jsonSerde.decodeFromJsonElement(kotlin.String.serializer(), json))
      },
        Pair(ChatCompletionRequestSystemMessageContent.CaseChatCompletionRequestSystemMessageContentParts::class) {
          ChatCompletionRequestSystemMessageContent.CaseChatCompletionRequestSystemMessageContentParts(jsonSerde.decodeFromJsonElement(ListSerializer(ChatCompletionRequestSystemMessageContentPart.serializer()), json))
      })
    }

    override fun serialize(encoder: Encoder, value: ChatCompletionRequestSystemMessageContent) =
      when(value) { 
        is ChatCompletionRequestSystemMessageContent.CaseString ->
        encoder.encodeSerializableValue(kotlin.String.serializer(), value.value)

        is ChatCompletionRequestSystemMessageContent.CaseChatCompletionRequestSystemMessageContentParts ->
        encoder.encodeSerializableValue(ListSerializer(ChatCompletionRequestSystemMessageContentPart.serializer()), value.value)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy