1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use serde::{Deserialize, Serialize};

use crate::impl_builder_methods;

#[derive(Debug, Serialize, Clone)]
pub struct CreateModerationRequest {
    pub input: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub model: Option<String>,
}

impl CreateModerationRequest {
    pub fn new(input: String) -> Self {
        Self { input, model: None }
    }
}

impl_builder_methods!(
    CreateModerationRequest,
    model: String
);

#[derive(Debug, Deserialize)]
pub struct CreateModerationResponse {
    pub id: String,
    pub model: String,
    pub results: Vec<ModerationResult>,
}

#[derive(Debug, Deserialize)]
pub struct ModerationResult {
    pub categories: ModerationCategories,
    pub category_scores: ModerationCategoryScores,
    pub flagged: bool,
}

#[derive(Debug, Deserialize)]
pub struct ModerationCategories {
    #[serde(rename = "hate")]
    pub is_hate: bool,
    #[serde(rename = "hate/threatening")]
    pub is_hate_threatening: bool,
    #[serde(rename = "self-harm")]
    pub is_self_harm: bool,
    pub sexual: bool,
    #[serde(rename = "sexual/minors")]
    pub is_sexual_minors: bool,
    pub violence: bool,
    #[serde(rename = "violence/graphic")]
    pub is_violence_graphic: bool,
}

#[derive(Debug, Deserialize)]
pub struct ModerationCategoryScores {
    #[serde(rename = "hate")]
    pub hate_score: f64,
    #[serde(rename = "hate/threatening")]
    pub hate_threatening_score: f64,
    #[serde(rename = "self-harm")]
    pub self_harm_score: f64,
    pub sexual: f64,
    #[serde(rename = "sexual/minors")]
    pub sexual_minors_score: f64,
    pub violence: f64,
    #[serde(rename = "violence/graphic")]
    pub violence_graphic_score: f64,
}