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

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

There is a newer version: 0.0.5-alpha.119
Show 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.ChatCompletionRequestMessageContentPartImage
import com.xebia.functional.openai.generated.model.ChatCompletionRequestMessageContentPartImageImageUrl
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 = ChatCompletionRequestUserMessageContentPartSerializer::class)
sealed interface ChatCompletionRequestUserMessageContentPart {

  @JvmInline
  @Serializable
  value class CaseChatCompletionRequestMessageContentPartImage(val value: ChatCompletionRequestMessageContentPartImage): ChatCompletionRequestUserMessageContentPart
  @JvmInline
  @Serializable
  value class CaseChatCompletionRequestMessageContentPartText(val value: ChatCompletionRequestMessageContentPartText): ChatCompletionRequestUserMessageContentPart

}

object ChatCompletionRequestUserMessageContentPartSerializer : KSerializer {
    @OptIn(InternalSerializationApi::class, ExperimentalSerializationApi::class)
    override val descriptor: SerialDescriptor = buildSerialDescriptor("ChatCompletionRequestUserMessageContentPart", PolymorphicKind.SEALED) { 
      element("1", ChatCompletionRequestMessageContentPartImage.serializer().descriptor)
      element("2", ChatCompletionRequestMessageContentPartText.serializer().descriptor)
    }

    override fun deserialize(decoder: Decoder): ChatCompletionRequestUserMessageContentPart {
      val jsonSerde = Json { ignoreUnknownKeys = true }
      val json = decoder.decodeSerializableValue(JsonElement.serializer())
      return attemptDeserialize(json, 
        Pair(ChatCompletionRequestUserMessageContentPart.CaseChatCompletionRequestMessageContentPartImage::class) {
          ChatCompletionRequestUserMessageContentPart.CaseChatCompletionRequestMessageContentPartImage(jsonSerde.decodeFromJsonElement(ChatCompletionRequestMessageContentPartImage.serializer(), json))
      },
        Pair(ChatCompletionRequestUserMessageContentPart.CaseChatCompletionRequestMessageContentPartText::class) {
          ChatCompletionRequestUserMessageContentPart.CaseChatCompletionRequestMessageContentPartText(jsonSerde.decodeFromJsonElement(ChatCompletionRequestMessageContentPartText.serializer(), json))
      })
    }

    override fun serialize(encoder: Encoder, value: ChatCompletionRequestUserMessageContentPart) =
      when(value) { 
        is ChatCompletionRequestUserMessageContentPart.CaseChatCompletionRequestMessageContentPartImage ->
        encoder.encodeSerializableValue(ChatCompletionRequestMessageContentPartImage.serializer(), value.value)

        is ChatCompletionRequestUserMessageContentPart.CaseChatCompletionRequestMessageContentPartText ->
        encoder.encodeSerializableValue(ChatCompletionRequestMessageContentPartText.serializer(), value.value)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy