packages feed

openai-3.0.0 / src / OpenAI / V1 / Decisions.hs

-- | @\/v1\/decisions@module OpenAI.V1.Decisions    ( -- * Main types      CreateDecision(..)    , _CreateDecision    , Decision(..)      -- * Other types    , InputItem(..)    , Role(..)    , Phase(..)    , Status(..)    , ContentPart(..)    , ImageDetail(..)    , PromptCacheBreakpoint(..)    , PromptCacheBreakpointMode(..)    , Question(..)    , Choice(..)    , ChoiceValue(..)    , Level(..)    , Answer(..)    , ChoiceProbability(..)    , LevelProbability(..)    , Usage(..)    , InputTokensDetails(..)    , OutputTokensDetails(..)    , PromptCacheOptions(..)    , PromptCacheMode(..)    , PromptCacheTTL(..)      -- * Servant    , API    ) whereimport OpenAI.Prelude hiding (Input(..), input)import OpenAI.V1.Models (Model)-- | Image detail leveldata ImageDetail    = ImageDetail_Low    | ImageDetail_High    | ImageDetail_Auto    | ImageDetail_Original    deriving stock (Eq, Generic, Show)imageDetailOptions :: OptionsimageDetailOptions =    aesonOptions        { constructorTagModifier = stripPrefix "ImageDetail_" }instance FromJSON ImageDetail where    parseJSON = genericParseJSON imageDetailOptionsinstance ToJSON ImageDetail where    toJSON = genericToJSON imageDetailOptions-- | Mode of an explicit prompt cache breakpointdata PromptCacheBreakpointMode = PromptCacheBreakpointMode_Explicit    deriving stock (Eq, Generic, Show)promptCacheBreakpointModeOptions :: OptionspromptCacheBreakpointModeOptions =    aesonOptions        { constructorTagModifier = stripPrefix "PromptCacheBreakpointMode_"        , tagSingleConstructors = True        }instance FromJSON PromptCacheBreakpointMode where    parseJSON = genericParseJSON promptCacheBreakpointModeOptionsinstance ToJSON PromptCacheBreakpointMode where    toJSON = genericToJSON promptCacheBreakpointModeOptions-- | Marks the end of a reusable prompt prefixdata PromptCacheBreakpoint = PromptCacheBreakpoint    { mode :: PromptCacheBreakpointMode    } deriving stock (Eq, Generic, Show)instance FromJSON PromptCacheBreakpoint where    parseJSON = genericParseJSON aesonOptionsinstance ToJSON PromptCacheBreakpoint where    toJSON = genericToJSON aesonOptions-- | Content parts for input items and question instructions---- User messages accept @Input_Text@, @Input_Image@, and @Input_JSON@.-- Developer and system messages accept only @Input_Text@.  Assistant messages-- accept @Output_Text@ and @Refusal@.  Tool call outputs accept @Input_Text@-- and @Input_Image@.  Question instructions accept @Input_Text@,-- @Input_Image@, and @Input_JSON@, without prompt cache breakpoints.data ContentPart    = Input_Text        { text :: Text        , prompt_cache_breakpoint :: Maybe PromptCacheBreakpoint        }    | Input_Image        { image_url :: Text        , detail :: Maybe ImageDetail        , prompt_cache_breakpoint :: Maybe PromptCacheBreakpoint        }    | Input_JSON        { data_ :: Value        }    | Output_Text        { text :: Text        }    | Refusal        { refusal :: Text        }    deriving stock (Eq, Generic, Show)contentPartOptions :: OptionscontentPartOptions =    aesonOptions        { sumEncoding = TaggedObject{ tagFieldName = "type", contentsFieldName = "" }        , tagSingleConstructors = True        }instance FromJSON ContentPart where    parseJSON = genericParseJSON contentPartOptionsinstance ToJSON ContentPart where    toJSON = genericToJSON contentPartOptionsinstance IsString ContentPart where    fromString string =        Input_Text{ text = fromString string, prompt_cache_breakpoint = Nothing }-- | Role of an input messagedata Role = User | Developer | System | Assistant    deriving stock (Eq, Generic, Show)instance FromJSON Role where    parseJSON = genericParseJSON aesonOptionsinstance ToJSON Role where    toJSON = genericToJSON aesonOptions-- | Phase of an assistant messagedata Phase = Phase_Commentary | Phase_Final_Answer    deriving stock (Eq, Generic, Show)phaseOptions :: OptionsphaseOptions = aesonOptions{ constructorTagModifier = stripPrefix "Phase_" }instance FromJSON Phase where    parseJSON = genericParseJSON phaseOptionsinstance ToJSON Phase where    toJSON = genericToJSON phaseOptions-- | Status of a tool call or tool call outputdata Status = Status_In_Progress | Status_Completed | Status_Incomplete    deriving stock (Eq, Generic, Show)statusOptions :: OptionsstatusOptions = aesonOptions{ constructorTagModifier = stripPrefix "Status_" }instance FromJSON Status where    parseJSON = genericParseJSON statusOptionsinstance ToJSON Status where    toJSON = genericToJSON statusOptions-- | An item of shared evidence for every questiondata InputItem    = Item_Message        { role :: Role        , content :: Vector ContentPart        , phase :: Maybe Phase        }    | Item_Function_Call        { id :: Maybe Text        , call_id :: Text        , namespace :: Maybe Text        , name :: Text        , arguments :: Text        , status :: Maybe Status        }    | Item_Function_Call_Output        { id :: Maybe Text        , call_id :: Text        , output :: Vector ContentPart        , status :: Maybe Status        }    | Item_Custom_Tool_Call        { id :: Maybe Text        , call_id :: Text        , namespace :: Maybe Text        , name :: Text        , input :: Text        , status :: Maybe Status        }    | Item_Custom_Tool_Call_Output        { id :: Maybe Text        , call_id :: Text        , output :: Vector ContentPart        , status :: Maybe Status        }    deriving stock (Eq, Generic, Show)inputItemOptions :: OptionsinputItemOptions =    aesonOptions        { sumEncoding = TaggedObject{ tagFieldName = "type", contentsFieldName = "" }        , tagSingleConstructors = True        , constructorTagModifier = stripPrefix "Item_"        }instance FromJSON InputItem where    parseJSON = genericParseJSON inputItemOptionsinstance ToJSON InputItem where    toJSON = genericToJSON inputItemOptions-- | A value a choice question can selectdata ChoiceValue = ChoiceValue_Text Text | ChoiceValue_Bool Bool    deriving stock (Eq, Generic, Show)instance FromJSON ChoiceValue where    parseJSON (Bool bool) = pure (ChoiceValue_Bool bool)    parseJSON value = fmap ChoiceValue_Text (parseJSON value)instance ToJSON ChoiceValue where    toJSON (ChoiceValue_Text text) = toJSON text    toJSON (ChoiceValue_Bool bool) = toJSON boolinstance IsString ChoiceValue where    fromString string = ChoiceValue_Text (fromString string)-- | An option for a choice questiondata Choice = Choice    { value :: ChoiceValue    , description :: Maybe Text    } deriving stock (Eq, Generic, Show)instance FromJSON Choice where    parseJSON = genericParseJSON aesonOptionsinstance ToJSON Choice where    toJSON = genericToJSON aesonOptions-- | A level of a score question, ordered from lowest to highestdata Level = Level    { label :: Text    , description :: Maybe Text    } deriving stock (Eq, Generic, Show)instance FromJSON Level where    parseJSON = genericParseJSON aesonOptionsinstance ToJSON Level where    toJSON = genericToJSON aesonOptions-- | A question about the inputdata Question    = Question_Predicate        { name :: Maybe Text        , instructions :: Vector ContentPart        }    | Question_Choice        { name :: Maybe Text        , instructions :: Vector ContentPart        , choices :: Vector Choice        }    | Question_Score        { name :: Maybe Text        , instructions :: Vector ContentPart        , levels :: Vector Level        }    deriving stock (Eq, Generic, Show)questionOptions :: OptionsquestionOptions =    aesonOptions        { sumEncoding = TaggedObject{ tagFieldName = "type", contentsFieldName = "" }        , tagSingleConstructors = True        , constructorTagModifier = stripPrefix "Question_"        }instance FromJSON Question where    parseJSON = genericParseJSON questionOptionsinstance ToJSON Question where    toJSON = genericToJSON questionOptions-- | Probability of one choicedata ChoiceProbability = ChoiceProbability    { probability :: Double    , value :: ChoiceValue    } deriving stock (Eq, Generic, Show)instance FromJSON ChoiceProbability where    parseJSON = genericParseJSON aesonOptionsinstance ToJSON ChoiceProbability where    toJSON = genericToJSON aesonOptions-- | Probability of one score leveldata LevelProbability = LevelProbability    { label :: Text    , probability :: Double    , value :: Natural    -- ^ Index of the level    } deriving stock (Eq, Generic, Show)instance FromJSON LevelProbability where    parseJSON = genericParseJSON aesonOptionsinstance ToJSON LevelProbability where    toJSON = genericToJSON aesonOptions-- | The answer to one questiondata Answer    = Answer_Predicate        { name :: Maybe Text        , probability :: Double        }    | Answer_Choice        { name :: Maybe Text        , choice :: ChoiceValue        , confidence :: Double        , choice_probabilities :: Vector ChoiceProbability        }    | Answer_Score        { name :: Maybe Text        , score :: Double        , confidence :: Double        , score_probabilities :: Vector LevelProbability        }    | Answer_Refusal        { name :: Maybe Text        }    deriving stock (Eq, Generic, Show)answerOptions :: OptionsanswerOptions =    aesonOptions        { sumEncoding = TaggedObject{ tagFieldName = "type", contentsFieldName = "" }        , tagSingleConstructors = True        , constructorTagModifier = stripPrefix "Answer_"        , fieldLabelModifier = stripPrefix "choice_" . stripPrefix "score_"        }instance FromJSON Answer where    parseJSON = genericParseJSON answerOptionsinstance ToJSON Answer where    toJSON = genericToJSON answerOptions-- | Input token detailsdata InputTokensDetails = InputTokensDetails    { cached_tokens :: Natural    , cache_write_tokens :: Natural    } deriving stock (Eq, Generic, Show)instance FromJSON InputTokensDetails where    parseJSON = genericParseJSON aesonOptionsinstance ToJSON InputTokensDetails where    toJSON = genericToJSON aesonOptions-- | Output token detailsdata OutputTokensDetails = OutputTokensDetails    { reasoning_tokens :: Natural    } deriving stock (Eq, Generic, Show)instance FromJSON OutputTokensDetails where    parseJSON = genericParseJSON aesonOptionsinstance ToJSON OutputTokensDetails where    toJSON = genericToJSON aesonOptions-- | Token usage for a decision requestdata Usage = Usage    { input_tokens :: Natural    , input_tokens_details :: InputTokensDetails    , output_tokens :: Natural    , output_tokens_details :: OutputTokensDetails    , total_tokens :: Natural    } deriving stock (Eq, Generic, Show)instance FromJSON Usage where    parseJSON = genericParseJSON aesonOptionsinstance ToJSON Usage where    toJSON = genericToJSON aesonOptions-- | Whether OpenAI creates an implicit prompt cache breakpointdata PromptCacheMode = PromptCacheMode_Implicit | PromptCacheMode_Explicit    deriving stock (Eq, Generic, Show)promptCacheModeOptions :: OptionspromptCacheModeOptions =    aesonOptions{ constructorTagModifier = stripPrefix "PromptCacheMode_" }instance FromJSON PromptCacheMode where    parseJSON = genericParseJSON promptCacheModeOptionsinstance ToJSON PromptCacheMode where    toJSON = genericToJSON promptCacheModeOptions-- | Minimum lifetime of prompt cache breakpointsdata PromptCacheTTL = PromptCacheTTL_30m    deriving stock (Eq, Generic, Show)promptCacheTTLOptions :: OptionspromptCacheTTLOptions =    aesonOptions        { constructorTagModifier = stripPrefix "PromptCacheTTL_"        , tagSingleConstructors = True        }instance FromJSON PromptCacheTTL where    parseJSON = genericParseJSON promptCacheTTLOptionsinstance ToJSON PromptCacheTTL where    toJSON = genericToJSON promptCacheTTLOptions-- | Prompt caching optionsdata PromptCacheOptions = PromptCacheOptions    { mode :: Maybe PromptCacheMode    , ttl :: Maybe PromptCacheTTL    } deriving stock (Eq, Generic, Show)instance FromJSON PromptCacheOptions where    parseJSON = genericParseJSON aesonOptionsinstance ToJSON PromptCacheOptions where    toJSON = genericToJSON aesonOptions-- | Request body for @\/v1\/decisions@data CreateDecision = CreateDecision    { model :: Model    , input :: Vector InputItem    , questions :: Vector Question    , prompt_cache_key :: Maybe Text    , prompt_cache_options :: Maybe PromptCacheOptions    , safety_identifier :: Maybe Text    } deriving stock (Generic, Show)instance FromJSON CreateDecision where    parseJSON = genericParseJSON aesonOptionsinstance ToJSON CreateDecision where    toJSON = genericToJSON aesonOptions-- | Default `CreateDecision`_CreateDecision :: CreateDecision_CreateDecision = CreateDecision    { prompt_cache_key = Nothing    , prompt_cache_options = Nothing    , safety_identifier = Nothing    }-- | Response body for @\/v1\/decisions@data Decision = Decision    { answers :: Vector Answer    -- ^ Answers in question order    , model :: Model    , usage :: Usage    } deriving stock (Generic, Show)instance FromJSON Decision where    parseJSON = genericParseJSON aesonOptionsinstance ToJSON Decision where    toJSON = genericToJSON aesonOptions-- | Servant APItype API =        "decisions"    :>  ReqBody '[JSON] CreateDecision    :>  Post '[JSON] Decision