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

/// ImagesUsage : For the GPT image models only, the token usage information for the image generation.
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize, bon::Builder)]
pub struct ImagesUsage {
    /// The total number of tokens (images and text) used for the image generation.
    #[serde(rename = "total_tokens")]
    pub total_tokens: i32,
    /// The number of tokens (images and text) in the input prompt.
    #[serde(rename = "input_tokens")]
    pub input_tokens: i32,
    /// The number of image tokens in the output image.
    #[serde(rename = "output_tokens")]
    pub output_tokens: i32,
    #[serde(rename = "input_tokens_details")]
    pub input_tokens_details: Box<models::ImagesUsageInputTokensDetails>,
}

impl ImagesUsage {
    /// For the GPT image models only, the token usage information for the image generation.
    pub fn new(
        total_tokens: i32,
        input_tokens: i32,
        output_tokens: i32,
        input_tokens_details: models::ImagesUsageInputTokensDetails,
    ) -> ImagesUsage {
        ImagesUsage {
            total_tokens,
            input_tokens,
            output_tokens,
            input_tokens_details: Box::new(input_tokens_details),
        }
    }
}

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