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

commonMain.com.xebia.functional.openai.generated.model.ChatCompletionRequestToolMessageContent.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.ChatCompletionRequestToolMessageContentPart
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 = ChatCompletionRequestToolMessageContentSerializer::class)
sealed interface ChatCompletionRequestToolMessageContent {

  @JvmInline
  @Serializable
  value class CaseString(val value: kotlin.String): ChatCompletionRequestToolMessageContent
  @JvmInline
  @Serializable
  value class CaseChatCompletionRequestToolMessageContentParts(val value: kotlin.collections.List): ChatCompletionRequestToolMessageContent

}

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

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

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

        is ChatCompletionRequestToolMessageContent.CaseChatCompletionRequestToolMessageContentParts ->
        encoder.encodeSerializableValue(ListSerializer(ChatCompletionRequestToolMessageContentPart.serializer()), value.value)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy