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};

#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize, bon::Builder)]
pub struct CreateImageRequest {
    /// A text description of the desired image(s). The maximum length is 32000 characters.
    #[serde(rename = "prompt")]
    pub prompt: String,
    #[serde(rename = "model")]
    pub model: String,
    /// The number of images to generate. Must be between 1 and 10.
    #[serde(
        rename = "n",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub n: Option<Option<i32>>,
    #[serde(
        rename = "quality",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub quality: Option<Option<Quality>>,
    /// Legacy response format parameter for retired image models. Unsupported for GPT image models, which always return base64-encoded images.
    #[serde(
        rename = "response_format",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub response_format: Option<Option<ResponseFormat>>,
    #[serde(
        rename = "output_format",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub output_format: Option<Option<OutputFormat>>,
    /// The compression level (0-100%) for the generated images. This parameter is only supported for the GPT image models with the `webp` or `jpeg` output formats, and defaults to 100.
    #[serde(
        rename = "output_compression",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub output_compression: Option<Option<i32>>,
    /// Generate the image in streaming mode. Defaults to `false`. See the [Image generation guide](https://developers.openai.com/api/docs/guides/image-generation) for more information. This parameter is only supported for the GPT image models.
    #[serde(
        rename = "stream",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub stream: Option<Option<bool>>,
    /// The number of partial images to generate. This parameter is used for streaming responses that return partial images. Value must be between 0 and 3. When set to 0, the response will be a single image sent in one streaming event.  Note that the final image may be sent before the full number of partial images are generated if the full image is generated more quickly.
    #[serde(
        rename = "partial_images",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub partial_images: Option<Option<i32>>,
    #[serde(
        rename = "size",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub size: Option<Option<Box<models::CreateImageRequestSize>>>,
    #[serde(
        rename = "moderation",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub moderation: Option<Option<Moderation>>,
    #[serde(
        rename = "background",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub background: Option<Option<Background>>,
    /// Legacy style parameter for retired image models. Unsupported for GPT image models; describe the desired style in the prompt instead.
    #[serde(
        rename = "style",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub style: Option<Option<Style>>,
    /// A stable identifier for an end user in your organization, used for safety monitoring and abuse detection. Hash a username or email address to avoid sending identifying information. A non-empty value takes precedence over the deprecated `user` parameter. If omitted, null, or empty, the API uses `user` when available. [Learn more](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers).
    #[serde(
        rename = "safety_identifier",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub safety_identifier: Option<Option<String>>,
    /// Deprecated: use `safety_identifier` instead. This parameter remains accepted for backward compatibility and is used when `safety_identifier` is omitted, null, or empty. [Learn more](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers).
    #[serde(rename = "user", skip_serializing_if = "Option::is_none")]
    pub user: Option<String>,
}

impl CreateImageRequest {
    pub fn new(prompt: String, model: String) -> CreateImageRequest {
        CreateImageRequest {
            prompt,
            model,
            n: None,
            quality: None,
            response_format: None,
            output_format: None,
            output_compression: None,
            stream: None,
            partial_images: None,
            size: None,
            moderation: None,
            background: None,
            style: None,
            safety_identifier: None,
            user: None,
        }
    }
}
///
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum Quality {
    #[serde(rename = "low")]
    Low,
    #[serde(rename = "medium")]
    Medium,
    #[serde(rename = "high")]
    High,
    #[serde(rename = "xhigh")]
    Xhigh,
    #[serde(rename = "max")]
    Max,
    #[serde(rename = "auto")]
    Auto,
    #[serde(rename = "standard")]
    Standard,
    #[serde(rename = "hd")]
    Hd,
}

impl Default for Quality {
    fn default() -> Quality {
        Self::Low
    }
}
/// Legacy response format parameter for retired image models. Unsupported for GPT image models, which always return base64-encoded images.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum ResponseFormat {
    #[serde(rename = "url")]
    Url,
    #[serde(rename = "b64_json")]
    B64Json,
}

impl Default for ResponseFormat {
    fn default() -> ResponseFormat {
        Self::Url
    }
}
///
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum OutputFormat {
    #[serde(rename = "png")]
    Png,
    #[serde(rename = "jpeg")]
    Jpeg,
    #[serde(rename = "webp")]
    Webp,
}

impl Default for OutputFormat {
    fn default() -> OutputFormat {
        Self::Png
    }
}
///
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum Moderation {
    #[serde(rename = "low")]
    Low,
    #[serde(rename = "auto")]
    Auto,
}

impl Default for Moderation {
    fn default() -> Moderation {
        Self::Low
    }
}
///
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum Background {
    #[serde(rename = "transparent")]
    Transparent,
    #[serde(rename = "opaque")]
    Opaque,
    #[serde(rename = "auto")]
    Auto,
}

impl Default for Background {
    fn default() -> Background {
        Self::Transparent
    }
}
/// Legacy style parameter for retired image models. Unsupported for GPT image models; describe the desired style in the prompt instead.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum Style {
    #[serde(rename = "vivid")]
    Vivid,
    #[serde(rename = "natural")]
    Natural,
}

impl Default for Style {
    fn default() -> Style {
        Self::Vivid
    }
}

impl std::fmt::Display for CreateImageRequest {
    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),
        }
    }
}