Skip to main content

async_openai/types/shared/
moderation.rs

1/// The moderation policy for the response input.
2#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq)]
3#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
4#[cfg_attr(feature = "openapi", schema(as = async_openai::ModerationConfigParam))]
5pub struct ModerationConfigParam {
6    pub mode: ModerationMode,
7}
8
9#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq)]
10#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
11#[cfg_attr(feature = "openapi", schema(as = async_openai::ModerationInputType))]
12pub enum ModerationInputType {
13    #[serde(rename = "text")]
14    Text,
15    #[serde(rename = "image")]
16    Image,
17}
18
19#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq)]
20#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
21#[cfg_attr(feature = "openapi", schema(as = async_openai::ModerationMode))]
22pub enum ModerationMode {
23    #[serde(rename = "score")]
24    Score,
25    #[serde(rename = "block")]
26    Block,
27}
28
29/// Configuration for running moderation on the input and output of this response.
30#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq)]
31#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
32#[cfg_attr(feature = "openapi", schema(as = async_openai::ModerationParam))]
33pub struct ModerationParam {
34    /// The moderation model to use for moderated completions, e.g. 'omni-moderation-latest'.
35    pub model: String,
36    #[serde(skip_serializing_if = "Option::is_none")]
37    pub policy: Option<ModerationPolicyParam>,
38}
39
40/// The policy to apply to moderated response input and output.
41#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq)]
42#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
43#[cfg_attr(feature = "openapi", schema(as = async_openai::ModerationPolicyParam))]
44pub struct ModerationPolicyParam {
45    #[serde(skip_serializing_if = "Option::is_none")]
46    pub input: Option<ModerationConfigParam>,
47    #[serde(skip_serializing_if = "Option::is_none")]
48    pub output: Option<ModerationConfigParam>,
49}
50
51/// A moderation result produced for the response input or output.
52#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq)]
53#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
54#[cfg_attr(feature = "openapi", schema(as = async_openai::ModerationResultBody))]
55pub struct ModerationResultBody {
56    /// The moderation model that produced this result.
57    pub model: String,
58    /// A boolean indicating whether the content was flagged by any category.
59    pub flagged: bool,
60    /// A dictionary of moderation categories to booleans, True if the input is flagged under this category.
61    pub categories: std::collections::HashMap<String, bool>,
62    /// A dictionary of moderation categories to scores.
63    pub category_scores: std::collections::HashMap<String, f64>,
64    /// Which modalities of input are reflected by the score for each category.
65    pub category_applied_input_types: std::collections::HashMap<String, Vec<ModerationInputType>>,
66}