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

#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize, bon::Builder)]
pub struct RunGraderResponseMetadata {
    #[serde(rename = "name")]
    pub name: String,
    #[serde(rename = "type")]
    pub r#type: String,
    #[serde(rename = "errors")]
    pub errors: Box<models::RunGraderResponseMetadataErrors>,
    #[serde(rename = "execution_time")]
    pub execution_time: f64,
    #[serde(rename = "scores")]
    pub scores: std::collections::HashMap<String, serde_json::Value>,
    #[serde(rename = "token_usage", deserialize_with = "Option::deserialize")]
    pub token_usage: Option<i32>,
    #[serde(
        rename = "sampled_model_name",
        deserialize_with = "Option::deserialize"
    )]
    pub sampled_model_name: Option<String>,
}

impl RunGraderResponseMetadata {
    pub fn new(
        name: String,
        r#type: String,
        errors: models::RunGraderResponseMetadataErrors,
        execution_time: f64,
        scores: std::collections::HashMap<String, serde_json::Value>,
        token_usage: Option<i32>,
        sampled_model_name: Option<String>,
    ) -> RunGraderResponseMetadata {
        RunGraderResponseMetadata {
            name,
            r#type,
            errors: Box::new(errors),
            execution_time,
            scores,
            token_usage,
            sampled_model_name,
        }
    }
}

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