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

commonMain.com.xebia.functional.openai.generated.model.AssistantStreamEvent.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.DoneEvent
import com.xebia.functional.openai.generated.model.ErrorEvent
import com.xebia.functional.openai.generated.model.MessageStreamEvent
import com.xebia.functional.openai.generated.model.RunStepStreamEvent
import com.xebia.functional.openai.generated.model.RunStreamEvent
import com.xebia.functional.openai.generated.model.ThreadStreamEvent
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 = AssistantStreamEventSerializer::class)
sealed interface AssistantStreamEvent {

  @JvmInline
  @Serializable
  value class CaseDoneEvent(val value: DoneEvent): AssistantStreamEvent
  @JvmInline
  @Serializable
  value class CaseErrorEvent(val value: ErrorEvent): AssistantStreamEvent
  @JvmInline
  @Serializable
  value class CaseMessageStreamEvent(val value: MessageStreamEvent): AssistantStreamEvent
  @JvmInline
  @Serializable
  value class CaseRunStepStreamEvent(val value: RunStepStreamEvent): AssistantStreamEvent
  @JvmInline
  @Serializable
  value class CaseRunStreamEvent(val value: RunStreamEvent): AssistantStreamEvent
  @JvmInline
  @Serializable
  value class CaseThreadStreamEvent(val value: ThreadStreamEvent): AssistantStreamEvent

}

object AssistantStreamEventSerializer : KSerializer {
    @OptIn(InternalSerializationApi::class, ExperimentalSerializationApi::class)
    override val descriptor: SerialDescriptor = buildSerialDescriptor("AssistantStreamEvent", PolymorphicKind.SEALED) { 
      element("1", DoneEvent.serializer().descriptor)
      element("2", ErrorEvent.serializer().descriptor)
      element("3", MessageStreamEvent.serializer().descriptor)
      element("4", RunStepStreamEvent.serializer().descriptor)
      element("5", RunStreamEvent.serializer().descriptor)
      element("6", ThreadStreamEvent.serializer().descriptor)
    }

    override fun deserialize(decoder: Decoder): AssistantStreamEvent {
      val jsonSerde = Json { ignoreUnknownKeys = true }
      val json = decoder.decodeSerializableValue(JsonElement.serializer())
      return attemptDeserialize(json, 
        Pair(AssistantStreamEvent.CaseDoneEvent::class) {
          AssistantStreamEvent.CaseDoneEvent(jsonSerde.decodeFromJsonElement(DoneEvent.serializer(), json))
      },
        Pair(AssistantStreamEvent.CaseErrorEvent::class) {
          AssistantStreamEvent.CaseErrorEvent(jsonSerde.decodeFromJsonElement(ErrorEvent.serializer(), json))
      },
        Pair(AssistantStreamEvent.CaseMessageStreamEvent::class) {
          AssistantStreamEvent.CaseMessageStreamEvent(jsonSerde.decodeFromJsonElement(MessageStreamEvent.serializer(), json))
      },
        Pair(AssistantStreamEvent.CaseRunStepStreamEvent::class) {
          AssistantStreamEvent.CaseRunStepStreamEvent(jsonSerde.decodeFromJsonElement(RunStepStreamEvent.serializer(), json))
      },
        Pair(AssistantStreamEvent.CaseRunStreamEvent::class) {
          AssistantStreamEvent.CaseRunStreamEvent(jsonSerde.decodeFromJsonElement(RunStreamEvent.serializer(), json))
      },
        Pair(AssistantStreamEvent.CaseThreadStreamEvent::class) {
          AssistantStreamEvent.CaseThreadStreamEvent(jsonSerde.decodeFromJsonElement(ThreadStreamEvent.serializer(), json))
      })
    }

    override fun serialize(encoder: Encoder, value: AssistantStreamEvent) =
      when(value) { 
        is AssistantStreamEvent.CaseDoneEvent ->
        encoder.encodeSerializableValue(DoneEvent.serializer(), value.value)

        is AssistantStreamEvent.CaseErrorEvent ->
        encoder.encodeSerializableValue(ErrorEvent.serializer(), value.value)

        is AssistantStreamEvent.CaseMessageStreamEvent ->
        encoder.encodeSerializableValue(MessageStreamEvent.serializer(), value.value)

        is AssistantStreamEvent.CaseRunStepStreamEvent ->
        encoder.encodeSerializableValue(RunStepStreamEvent.serializer(), value.value)

        is AssistantStreamEvent.CaseRunStreamEvent ->
        encoder.encodeSerializableValue(RunStreamEvent.serializer(), value.value)

        is AssistantStreamEvent.CaseThreadStreamEvent ->
        encoder.encodeSerializableValue(ThreadStreamEvent.serializer(), value.value)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy