commonMain.com.xebia.functional.openai.generated.model.AssistantsApiResponseFormatOption.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xef-openai-client-jvm Show documentation
Show all versions of xef-openai-client-jvm Show documentation
Building applications with LLMs through composability in Kotlin
/**
*
* 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 = AssistantsApiResponseFormatOptionSerializer::class)
sealed interface AssistantsApiResponseFormatOption {
@JvmInline
@Serializable
value class CaseResponseFormatJsonObject(val value: ResponseFormatJsonObject): AssistantsApiResponseFormatOption
@JvmInline
@Serializable
value class CaseResponseFormatJsonSchema(val value: ResponseFormatJsonSchema): AssistantsApiResponseFormatOption
@JvmInline
@Serializable
value class CaseResponseFormatText(val value: ResponseFormatText): AssistantsApiResponseFormatOption
@JvmInline
@Serializable
value class CaseString(val value: kotlin.String): AssistantsApiResponseFormatOption
}
object AssistantsApiResponseFormatOptionSerializer : KSerializer {
@OptIn(InternalSerializationApi::class, ExperimentalSerializationApi::class)
override val descriptor: SerialDescriptor = buildSerialDescriptor("AssistantsApiResponseFormatOption", PolymorphicKind.SEALED) {
element("1", ResponseFormatJsonObject.serializer().descriptor)
element("2", ResponseFormatJsonSchema.serializer().descriptor)
element("3", ResponseFormatText.serializer().descriptor)
element("4", kotlin.String.serializer().descriptor)
}
override fun deserialize(decoder: Decoder): AssistantsApiResponseFormatOption {
val jsonSerde = Json { ignoreUnknownKeys = true }
val json = decoder.decodeSerializableValue(JsonElement.serializer())
return attemptDeserialize(json,
Pair(AssistantsApiResponseFormatOption.CaseResponseFormatJsonObject::class) {
AssistantsApiResponseFormatOption.CaseResponseFormatJsonObject(jsonSerde.decodeFromJsonElement(ResponseFormatJsonObject.serializer(), json))
},
Pair(AssistantsApiResponseFormatOption.CaseResponseFormatJsonSchema::class) {
AssistantsApiResponseFormatOption.CaseResponseFormatJsonSchema(jsonSerde.decodeFromJsonElement(ResponseFormatJsonSchema.serializer(), json))
},
Pair(AssistantsApiResponseFormatOption.CaseResponseFormatText::class) {
AssistantsApiResponseFormatOption.CaseResponseFormatText(jsonSerde.decodeFromJsonElement(ResponseFormatText.serializer(), json))
},
Pair(AssistantsApiResponseFormatOption.CaseString::class) {
AssistantsApiResponseFormatOption.CaseString(jsonSerde.decodeFromJsonElement(kotlin.String.serializer(), json))
})
}
override fun serialize(encoder: Encoder, value: AssistantsApiResponseFormatOption) =
when(value) {
is AssistantsApiResponseFormatOption.CaseResponseFormatJsonObject ->
encoder.encodeSerializableValue(ResponseFormatJsonObject.serializer(), value.value)
is AssistantsApiResponseFormatOption.CaseResponseFormatJsonSchema ->
encoder.encodeSerializableValue(ResponseFormatJsonSchema.serializer(), value.value)
is AssistantsApiResponseFormatOption.CaseResponseFormatText ->
encoder.encodeSerializableValue(ResponseFormatText.serializer(), value.value)
is AssistantsApiResponseFormatOption.CaseString ->
encoder.encodeSerializableValue(kotlin.String.serializer(), value.value)
}
}