openai-client-base 0.14.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};

/// ModerationResultBody : A moderation result produced for the response input or output.
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize, bon::Builder)]
pub struct ModerationResultBody {
    /// The object type, which was always `moderation_result` for successful moderation results.
    #[serde(rename = "type")]
    pub r#type: Type,
    /// The moderation model that produced this result.
    #[serde(rename = "model")]
    pub model: String,
    /// A boolean indicating whether the content was flagged by any category.
    #[serde(rename = "flagged")]
    pub flagged: bool,
    /// A dictionary of moderation categories to booleans, True if the input is flagged under this category.
    #[serde(rename = "categories")]
    pub categories: std::collections::HashMap<String, bool>,
    /// A dictionary of moderation categories to scores.
    #[serde(rename = "category_scores")]
    pub category_scores: std::collections::HashMap<String, f64>,
    /// Which modalities of input are reflected by the score for each category.
    #[serde(rename = "category_applied_input_types")]
    pub category_applied_input_types:
        std::collections::HashMap<String, Vec<models::ModerationInputType>>,
}

impl ModerationResultBody {
    /// A moderation result produced for the response input or output.
    pub fn new(
        r#type: Type,
        model: String,
        flagged: bool,
        categories: std::collections::HashMap<String, bool>,
        category_scores: std::collections::HashMap<String, f64>,
        category_applied_input_types: std::collections::HashMap<
            String,
            Vec<models::ModerationInputType>,
        >,
    ) -> ModerationResultBody {
        ModerationResultBody {
            r#type,
            model,
            flagged,
            categories,
            category_scores,
            category_applied_input_types,
        }
    }
}
/// The object type, which was always `moderation_result` for successful moderation results.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum Type {
    #[serde(rename = "moderation_result")]
    ModerationResult,
}

impl Default for Type {
    fn default() -> Type {
        Self::ModerationResult
    }
}

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