packages feed

openai-2.2.1 / src / OpenAI / V1 / Moderations.hs

-- | @\/v1\/moderations@module OpenAI.V1.Moderations    ( -- * Main types      CreateModeration(..)    , _CreateModeration    , Moderation(..)      -- * Other types    , InputType(..)    , Result(..)      -- * Servant    , API    ) whereimport OpenAI.Preludeimport OpenAI.V1.Models (Model)-- | Request body for @\/v1\/moderations@data CreateModeration = CreateModeration    { input :: Text    , model :: Maybe Model    } deriving stock (Generic, Show)      deriving anyclass (FromJSON, ToJSON)-- | Default `CreateModeration`_CreateModeration :: CreateModeration_CreateModeration = CreateModeration    { model = Nothing    }-- | The input type that the score applies todata InputType = Text | Image    deriving stock (Generic, Show)instance FromJSON InputType where    parseJSON = genericParseJSON aesonOptionsinstance ToJSON InputType where    toJSON = genericToJSON aesonOptions-- | A moderation resultdata Result = Result    { flagged :: Bool    , categories :: Map Text Bool    , category_scores :: Map Text Double    , category_applied_input_types :: Maybe (Map Text [InputType])    -- According to the OpenAPI spec the `category_applied_input_types`    -- field is required but their actual implementation omits this field.    -- Note: Each category maps to a list of input types (e.g., ["text"], ["image"])    } deriving stock (Generic, Show)      deriving anyclass (FromJSON, ToJSON)-- | Represents if a given text input is potentially harmful.data Moderation = Moderation    { id :: Text    , model :: Model    , results :: Vector Result    } deriving stock (Generic, Show)      deriving anyclass (FromJSON, ToJSON)-- | Servant APItype API =    "moderations" :> ReqBody '[JSON] CreateModeration :> Post '[JSON] Moderation