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

/// EvalRunOutputItemResult : A single grader result for an evaluation run output item.
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize, bon::Builder)]
pub struct EvalRunOutputItemResult {
    /// The name of the grader.
    #[serde(rename = "name")]
    pub name: String,
    /// The grader type (for example, \"string-check-grader\").
    #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
    pub r#type: Option<String>,
    /// The numeric score produced by the grader.
    #[serde(rename = "score")]
    pub score: f64,
    /// Whether the grader considered the output a pass.
    #[serde(rename = "passed")]
    pub passed: bool,
    #[serde(rename = "sample", skip_serializing_if = "Option::is_none")]
    pub sample: Option<Box<models::EvalRunOutputItemResultSample>>,
}

impl EvalRunOutputItemResult {
    /// A single grader result for an evaluation run output item.
    pub fn new(name: String, score: f64, passed: bool) -> EvalRunOutputItemResult {
        EvalRunOutputItemResult {
            name,
            r#type: None,
            score,
            passed,
            sample: None,
        }
    }
}

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