openai-client-base 0.16.0

Auto-generated Rust client for the OpenAI API
/*
 * OpenAI API
 *
 * The OpenAI REST API. Please see https://platform.openai.com/docs/api-reference for more details.
 *
 * The version of the OpenAPI document: 2.3.0
 *
 * Generated by: https://openapi-generator.tech
 */

use crate::models;
use serde::{Deserialize, Serialize};

/// SessionEventError : Emitted when a turn or session fails.
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize, bon::Builder)]
pub struct SessionEventError {
    /// The type of the object. Always `error`.
    #[serde(rename = "type")]
    pub r#type: Type,
    /// The unique ID of the event.
    #[serde(rename = "event_id")]
    pub event_id: String,
    /// The ID of the session associated with the event.
    #[serde(rename = "session_id")]
    pub session_id: String,
    #[serde(rename = "error")]
    pub error: models::SessionErrorResource,
}

impl SessionEventError {
    /// Emitted when a turn or session fails.
    pub fn new(
        r#type: Type,
        event_id: String,
        session_id: String,
        error: models::SessionErrorResource,
    ) -> SessionEventError {
        SessionEventError {
            r#type,
            event_id,
            session_id,
            error,
        }
    }
}
/// The type of the object. Always `error`.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum Type {
    #[serde(rename = "error")]
    Error,
}

impl Default for Type {
    fn default() -> Type {
        Self::Error
    }
}

impl std::fmt::Display for SessionEventError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match serde_json::to_string(self) {
            Ok(s) => write!(f, "{}", s),
            Err(_) => Err(std::fmt::Error),
        }
    }
}