-- | The `Tool` type module OpenAI.V1.Tool ( -- * Types Tool(..) , RankingOptions(..) , FileSearch(..) , Function(..) , ToolChoice(..) ) where import OpenAI.Prelude -- | The ranking options for the file search data RankingOptions = RankingOptions { ranker :: Maybe Text , score_threshold :: Double } deriving stock (Generic, Show) deriving anyclass (FromJSON, ToJSON) -- | Overrides for the file search tool data FileSearch = FileSearch { max_num_results :: Maybe Natural , ranking_options :: Maybe RankingOptions } deriving stock (Generic, Show) deriving anyclass (FromJSON, ToJSON) -- | The Function tool data Function = Function { description :: Maybe Text , name :: Text , parameters :: Maybe Value , strict :: Maybe Bool } deriving stock (Generic, Show) deriving anyclass (FromJSON, ToJSON) -- | A tool enabled on the assistant data Tool = Tool_Code_Interpreter | Tool_File_Search{ file_search :: FileSearch } | Tool_Function{ function :: Function } deriving stock (Generic, Show) toolOptions :: Options toolOptions = aesonOptions { sumEncoding = TaggedObject{ tagFieldName = "type", contentsFieldName = "" } , tagSingleConstructors = True , constructorTagModifier = stripPrefix "Tool_" } instance FromJSON Tool where parseJSON = genericParseJSON toolOptions instance ToJSON Tool where toJSON = genericToJSON toolOptions -- | Controls which (if any) tool is called by the model data ToolChoice = ToolChoiceNone | ToolChoiceAuto | ToolChoiceRequired | ToolChoiceTool Tool deriving stock (Generic, Show) instance FromJSON ToolChoice where parseJSON "none" = pure ToolChoiceNone parseJSON "auto" = pure ToolChoiceAuto parseJSON "required" = pure ToolChoiceRequired parseJSON other = fmap ToolChoiceTool (parseJSON other) instance ToJSON ToolChoice where toJSON ToolChoiceNone = "none" toJSON ToolChoiceAuto = "auto" toJSON ToolChoiceRequired = "required" toJSON (ToolChoiceTool tool) = toJSON tool