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

/// Image : Represents the content or the URL of an image generated by the OpenAI API.
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize, bon::Builder)]
pub struct Image {
    /// The base64-encoded JSON of the generated image. Returned by default for the GPT image models, and only present if `response_format` is set to `b64_json` for `dall-e-2` and `dall-e-3`.
    #[serde(rename = "b64_json", skip_serializing_if = "Option::is_none")]
    pub b64_json: Option<String>,
    /// When using `dall-e-2` or `dall-e-3`, the URL of the generated image if `response_format` is set to `url` (default value). Unsupported for the GPT image models.
    #[serde(rename = "url", skip_serializing_if = "Option::is_none")]
    pub url: Option<String>,
    /// For `dall-e-3` only, the revised prompt that was used to generate the image.
    #[serde(rename = "revised_prompt", skip_serializing_if = "Option::is_none")]
    pub revised_prompt: Option<String>,
}

impl Image {
    /// Represents the content or the URL of an image generated by the OpenAI API.
    pub fn new() -> Image {
        Image {
            b64_json: None,
            url: None,
            revised_prompt: None,
        }
    }
}

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