use derive_builder::Builder;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Default, Builder, Clone, PartialEq)]
#[builder(name = "ModerationParametersBuilder")]
#[builder(setter(into, strip_option), default)]
pub struct ModerationParameters {
pub input: ModerationInput,
pub model: String,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[serde(untagged)]
pub enum ModerationInput {
Text(String),
Array(Vec<String>),
MultiModal(Vec<ModerationObject>),
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[serde(untagged)]
pub enum ModerationObject {
Text {
r#type: String,
text: String,
},
ImageUrl {
r#type: String,
image_url: ModerationImageUrl,
},
}
impl ModerationObject {
pub fn text(text: &str) -> Self {
ModerationObject::Text {
r#type: "text".to_string(),
text: text.to_string(),
}
}
pub fn image_url(url: &str) -> Self {
ModerationObject::ImageUrl {
r#type: "image_url".to_string(),
image_url: ModerationImageUrl {
url: url.to_string(),
},
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct ModerationImageUrl {
pub url: String,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct ModerationResponse {
pub id: String,
pub model: String,
pub results: Vec<Results>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct Results {
pub flagged: bool,
pub categories: Categories,
pub category_scores: CategoryScores,
pub category_applied_input_types: CategoryAppliedInputTypes,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct Categories {
pub hate: bool,
#[serde(rename = "hate/threatening")]
pub hate_threatening: bool,
pub harassment: bool,
#[serde(rename = "harassment/threatening")]
pub harassment_threatening: bool,
pub illicit: bool,
#[serde(rename = "illicit/violent")]
pub illicit_violent: bool,
#[serde(rename = "self-harm")]
pub self_harm: bool,
#[serde(rename = "self-harm/intent")]
pub self_harm_intent: bool,
#[serde(rename = "self-harm/instructions")]
pub self_harm_instructions: bool,
pub sexual: bool,
#[serde(rename = "sexual/minors")]
pub sexual_minors: bool,
pub violence: bool,
#[serde(rename = "violence/graphic")]
pub violence_graphic: bool,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct CategoryScores {
pub hate: f64,
#[serde(rename = "hate/threatening")]
pub hate_threatening: f64,
pub harassment: f64,
#[serde(rename = "harassment/threatening")]
pub harassment_threatening: f64,
pub illicit: f64,
#[serde(rename = "illicit/violent")]
pub illicit_violent: f64,
#[serde(rename = "self-harm")]
pub self_harm: f64,
#[serde(rename = "self-harm/intent")]
pub self_harm_intent: f64,
#[serde(rename = "self-harm/instructions")]
pub self_harm_instructions: f64,
pub sexual: f64,
#[serde(rename = "sexual/minors")]
pub sexual_minors: f64,
pub violence: f64,
#[serde(rename = "violence/graphic")]
pub violence_graphic: f64,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct CategoryAppliedInputTypes {
pub hate: Vec<String>,
#[serde(rename = "hate/threatening")]
pub hate_threatening: Vec<String>,
pub harassment: Vec<String>,
#[serde(rename = "harassment/threatening")]
pub harassment_threatening: Vec<String>,
pub illicit: Vec<String>,
#[serde(rename = "illicit/violent")]
pub illicit_violent: Vec<String>,
#[serde(rename = "self-harm")]
pub self_harm: Vec<String>,
#[serde(rename = "self-harm/intent")]
pub self_harm_intent: Vec<String>,
#[serde(rename = "self-harm/instructions")]
pub self_harm_instructions: Vec<String>,
pub sexual: Vec<String>,
#[serde(rename = "sexual/minors")]
pub sexual_minors: Vec<String>,
pub violence: Vec<String>,
#[serde(rename = "violence/graphic")]
pub violence_graphic: Vec<String>,
}
impl Default for ModerationInput {
fn default() -> Self {
ModerationInput::Text("".to_string())
}
}