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

commonMain.com.xebia.functional.openai.generated.model.CreateChatCompletionRequestResponseFormat.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.ResponseFormatJsonObject
import com.xebia.functional.openai.generated.model.ResponseFormatJsonSchema
import com.xebia.functional.openai.generated.model.ResponseFormatJsonSchemaJsonSchema
import com.xebia.functional.openai.generated.model.ResponseFormatText
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 = CreateChatCompletionRequestResponseFormatSerializer::class)
sealed interface CreateChatCompletionRequestResponseFormat {

  @JvmInline
  @Serializable
  value class CaseResponseFormatJsonObject(val value: ResponseFormatJsonObject): CreateChatCompletionRequestResponseFormat
  @JvmInline
  @Serializable
  value class CaseResponseFormatJsonSchema(val value: ResponseFormatJsonSchema): CreateChatCompletionRequestResponseFormat
  @JvmInline
  @Serializable
  value class CaseResponseFormatText(val value: ResponseFormatText): CreateChatCompletionRequestResponseFormat

}

object CreateChatCompletionRequestResponseFormatSerializer : KSerializer {
    @OptIn(InternalSerializationApi::class, ExperimentalSerializationApi::class)
    override val descriptor: SerialDescriptor = buildSerialDescriptor("CreateChatCompletionRequestResponseFormat", PolymorphicKind.SEALED) { 
      element("1", ResponseFormatJsonObject.serializer().descriptor)
      element("2", ResponseFormatJsonSchema.serializer().descriptor)
      element("3", ResponseFormatText.serializer().descriptor)
    }

    override fun deserialize(decoder: Decoder): CreateChatCompletionRequestResponseFormat {
      val jsonSerde = Json { ignoreUnknownKeys = true }
      val json = decoder.decodeSerializableValue(JsonElement.serializer())
      return attemptDeserialize(json, 
        Pair(CreateChatCompletionRequestResponseFormat.CaseResponseFormatJsonObject::class) {
          CreateChatCompletionRequestResponseFormat.CaseResponseFormatJsonObject(jsonSerde.decodeFromJsonElement(ResponseFormatJsonObject.serializer(), json))
      },
        Pair(CreateChatCompletionRequestResponseFormat.CaseResponseFormatJsonSchema::class) {
          CreateChatCompletionRequestResponseFormat.CaseResponseFormatJsonSchema(jsonSerde.decodeFromJsonElement(ResponseFormatJsonSchema.serializer(), json))
      },
        Pair(CreateChatCompletionRequestResponseFormat.CaseResponseFormatText::class) {
          CreateChatCompletionRequestResponseFormat.CaseResponseFormatText(jsonSerde.decodeFromJsonElement(ResponseFormatText.serializer(), json))
      })
    }

    override fun serialize(encoder: Encoder, value: CreateChatCompletionRequestResponseFormat) =
      when(value) { 
        is CreateChatCompletionRequestResponseFormat.CaseResponseFormatJsonObject ->
        encoder.encodeSerializableValue(ResponseFormatJsonObject.serializer(), value.value)

        is CreateChatCompletionRequestResponseFormat.CaseResponseFormatJsonSchema ->
        encoder.encodeSerializableValue(ResponseFormatJsonSchema.serializer(), value.value)

        is CreateChatCompletionRequestResponseFormat.CaseResponseFormatText ->
        encoder.encodeSerializableValue(ResponseFormatText.serializer(), value.value)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy