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

commonMain.com.xebia.functional.openai.generated.model.ChunkingStrategyRequestParam.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.AutoChunkingStrategyRequestParam
import com.xebia.functional.openai.generated.model.StaticChunkingStrategy
import com.xebia.functional.openai.generated.model.StaticChunkingStrategyRequestParam
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 = ChunkingStrategyRequestParamSerializer::class)
sealed interface ChunkingStrategyRequestParam {

  @JvmInline
  @Serializable
  value class CaseAutoChunkingStrategyRequestParam(val value: AutoChunkingStrategyRequestParam): ChunkingStrategyRequestParam
  @JvmInline
  @Serializable
  value class CaseStaticChunkingStrategyRequestParam(val value: StaticChunkingStrategyRequestParam): ChunkingStrategyRequestParam

}

object ChunkingStrategyRequestParamSerializer : KSerializer {
    @OptIn(InternalSerializationApi::class, ExperimentalSerializationApi::class)
    override val descriptor: SerialDescriptor = buildSerialDescriptor("ChunkingStrategyRequestParam", PolymorphicKind.SEALED) { 
      element("1", AutoChunkingStrategyRequestParam.serializer().descriptor)
      element("2", StaticChunkingStrategyRequestParam.serializer().descriptor)
    }

    override fun deserialize(decoder: Decoder): ChunkingStrategyRequestParam {
      val jsonSerde = Json { ignoreUnknownKeys = true }
      val json = decoder.decodeSerializableValue(JsonElement.serializer())
      return attemptDeserialize(json, 
        Pair(ChunkingStrategyRequestParam.CaseAutoChunkingStrategyRequestParam::class) {
          ChunkingStrategyRequestParam.CaseAutoChunkingStrategyRequestParam(jsonSerde.decodeFromJsonElement(AutoChunkingStrategyRequestParam.serializer(), json))
      },
        Pair(ChunkingStrategyRequestParam.CaseStaticChunkingStrategyRequestParam::class) {
          ChunkingStrategyRequestParam.CaseStaticChunkingStrategyRequestParam(jsonSerde.decodeFromJsonElement(StaticChunkingStrategyRequestParam.serializer(), json))
      })
    }

    override fun serialize(encoder: Encoder, value: ChunkingStrategyRequestParam) =
      when(value) { 
        is ChunkingStrategyRequestParam.CaseAutoChunkingStrategyRequestParam ->
        encoder.encodeSerializableValue(AutoChunkingStrategyRequestParam.serializer(), value.value)

        is ChunkingStrategyRequestParam.CaseStaticChunkingStrategyRequestParam ->
        encoder.encodeSerializableValue(StaticChunkingStrategyRequestParam.serializer(), value.value)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy