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

commonMain.com.xebia.functional.openai.generated.model.ChatCompletionToolChoiceOption.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.ChatCompletionNamedToolChoice
import com.xebia.functional.openai.generated.model.ChatCompletionNamedToolChoiceFunction
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 = ChatCompletionToolChoiceOptionSerializer::class)
sealed interface ChatCompletionToolChoiceOption {

  @JvmInline
  @Serializable
  value class CaseChatCompletionNamedToolChoice(val value: ChatCompletionNamedToolChoice): ChatCompletionToolChoiceOption
  @JvmInline
  @Serializable
  value class CaseString(val value: kotlin.String): ChatCompletionToolChoiceOption

}

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

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

    override fun serialize(encoder: Encoder, value: ChatCompletionToolChoiceOption) =
      when(value) { 
        is ChatCompletionToolChoiceOption.CaseChatCompletionNamedToolChoice ->
        encoder.encodeSerializableValue(ChatCompletionNamedToolChoice.serializer(), value.value)

        is ChatCompletionToolChoiceOption.CaseString ->
        encoder.encodeSerializableValue(kotlin.String.serializer(), value.value)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy