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

/// 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 GPT image models, or when `response_format` is set to `b64_json` for models that support that parameter.
    #[serde(rename = "b64_json", skip_serializing_if = "Option::is_none")]
    pub b64_json: Option<String>,
    /// The URL of the generated image when `response_format` is set to `url` for models that support that parameter. Unsupported for GPT image models.
    #[serde(rename = "url", skip_serializing_if = "Option::is_none")]
    pub url: Option<String>,
    /// The revised prompt used to generate the image, for models that support prompt revision. Not returned by GPT image models.
    #[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),
        }
    }
}