openai-client-base 0.12.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};

/// ResponseErrorEvent : Emitted when an error occurs.
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize, bon::Builder)]
pub struct ResponseErrorEvent {
    /// The type of the event. Always `error`.
    #[serde(rename = "type")]
    pub r#type: Type,
    /// The error code.
    #[serde(rename = "code", deserialize_with = "Option::deserialize")]
    pub code: Option<String>,
    /// The error message.
    #[serde(rename = "message")]
    pub message: String,
    /// The error parameter.
    #[serde(rename = "param", deserialize_with = "Option::deserialize")]
    pub param: Option<String>,
    /// The sequence number of this event.
    #[serde(rename = "sequence_number")]
    pub sequence_number: i32,
}

impl ResponseErrorEvent {
    /// Emitted when an error occurs.
    pub fn new(
        r#type: Type,
        code: Option<String>,
        message: String,
        param: Option<String>,
        sequence_number: i32,
    ) -> ResponseErrorEvent {
        ResponseErrorEvent {
            r#type,
            code,
            message,
            param,
            sequence_number,
        }
    }
}
/// The type of the event. 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 ResponseErrorEvent {
    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),
        }
    }
}