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

commonMain.com.xebia.functional.openai.generated.model.ChatCompletionRequestMessage.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.ChatCompletionMessageToolCall
import com.xebia.functional.openai.generated.model.ChatCompletionRequestAssistantMessage
import com.xebia.functional.openai.generated.model.ChatCompletionRequestAssistantMessageFunctionCall
import com.xebia.functional.openai.generated.model.ChatCompletionRequestFunctionMessage
import com.xebia.functional.openai.generated.model.ChatCompletionRequestSystemMessage
import com.xebia.functional.openai.generated.model.ChatCompletionRequestToolMessage
import com.xebia.functional.openai.generated.model.ChatCompletionRequestUserMessage
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 = ChatCompletionRequestMessageSerializer::class)
sealed interface ChatCompletionRequestMessage {

  @JvmInline
  @Serializable
  value class CaseChatCompletionRequestAssistantMessage(val value: ChatCompletionRequestAssistantMessage): ChatCompletionRequestMessage
  @JvmInline
  @Serializable
  value class CaseChatCompletionRequestFunctionMessage(val value: ChatCompletionRequestFunctionMessage): ChatCompletionRequestMessage
  @JvmInline
  @Serializable
  value class CaseChatCompletionRequestSystemMessage(val value: ChatCompletionRequestSystemMessage): ChatCompletionRequestMessage
  @JvmInline
  @Serializable
  value class CaseChatCompletionRequestToolMessage(val value: ChatCompletionRequestToolMessage): ChatCompletionRequestMessage
  @JvmInline
  @Serializable
  value class CaseChatCompletionRequestUserMessage(val value: ChatCompletionRequestUserMessage): ChatCompletionRequestMessage

}

object ChatCompletionRequestMessageSerializer : KSerializer {
    @OptIn(InternalSerializationApi::class, ExperimentalSerializationApi::class)
    override val descriptor: SerialDescriptor = buildSerialDescriptor("ChatCompletionRequestMessage", PolymorphicKind.SEALED) { 
      element("1", ChatCompletionRequestAssistantMessage.serializer().descriptor)
      element("2", ChatCompletionRequestFunctionMessage.serializer().descriptor)
      element("3", ChatCompletionRequestSystemMessage.serializer().descriptor)
      element("4", ChatCompletionRequestToolMessage.serializer().descriptor)
      element("5", ChatCompletionRequestUserMessage.serializer().descriptor)
    }

    override fun deserialize(decoder: Decoder): ChatCompletionRequestMessage {
      val jsonSerde = Json { ignoreUnknownKeys = true }
      val json = decoder.decodeSerializableValue(JsonElement.serializer())
      return attemptDeserialize(json, 
        Pair(ChatCompletionRequestMessage.CaseChatCompletionRequestAssistantMessage::class) {
          ChatCompletionRequestMessage.CaseChatCompletionRequestAssistantMessage(jsonSerde.decodeFromJsonElement(ChatCompletionRequestAssistantMessage.serializer(), json))
      },
        Pair(ChatCompletionRequestMessage.CaseChatCompletionRequestFunctionMessage::class) {
          ChatCompletionRequestMessage.CaseChatCompletionRequestFunctionMessage(jsonSerde.decodeFromJsonElement(ChatCompletionRequestFunctionMessage.serializer(), json))
      },
        Pair(ChatCompletionRequestMessage.CaseChatCompletionRequestSystemMessage::class) {
          ChatCompletionRequestMessage.CaseChatCompletionRequestSystemMessage(jsonSerde.decodeFromJsonElement(ChatCompletionRequestSystemMessage.serializer(), json))
      },
        Pair(ChatCompletionRequestMessage.CaseChatCompletionRequestToolMessage::class) {
          ChatCompletionRequestMessage.CaseChatCompletionRequestToolMessage(jsonSerde.decodeFromJsonElement(ChatCompletionRequestToolMessage.serializer(), json))
      },
        Pair(ChatCompletionRequestMessage.CaseChatCompletionRequestUserMessage::class) {
          ChatCompletionRequestMessage.CaseChatCompletionRequestUserMessage(jsonSerde.decodeFromJsonElement(ChatCompletionRequestUserMessage.serializer(), json))
      })
    }

    override fun serialize(encoder: Encoder, value: ChatCompletionRequestMessage) =
      when(value) { 
        is ChatCompletionRequestMessage.CaseChatCompletionRequestAssistantMessage ->
        encoder.encodeSerializableValue(ChatCompletionRequestAssistantMessage.serializer(), value.value)

        is ChatCompletionRequestMessage.CaseChatCompletionRequestFunctionMessage ->
        encoder.encodeSerializableValue(ChatCompletionRequestFunctionMessage.serializer(), value.value)

        is ChatCompletionRequestMessage.CaseChatCompletionRequestSystemMessage ->
        encoder.encodeSerializableValue(ChatCompletionRequestSystemMessage.serializer(), value.value)

        is ChatCompletionRequestMessage.CaseChatCompletionRequestToolMessage ->
        encoder.encodeSerializableValue(ChatCompletionRequestToolMessage.serializer(), value.value)

        is ChatCompletionRequestMessage.CaseChatCompletionRequestUserMessage ->
        encoder.encodeSerializableValue(ChatCompletionRequestUserMessage.serializer(), value.value)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy