packages feed

openai-1.2.0 / src / OpenAI / V1 / Message.hs

-- | The `Message` typemodule OpenAI.V1.Message    ( -- * Main types      Message(..)      -- * Other types    , ImageFile(..)    , ImageURL(..)    , Content(..)    , Attachment(..)    ) whereimport OpenAI.Preludeimport OpenAI.V1.AutoOrimport OpenAI.V1.Files (FileID)import OpenAI.V1.Tool-- | References an image File in the content of a messagedata ImageFile = ImageFile{ file_id :: FileID, detail :: Maybe (AutoOr Text) }    deriving stock (Generic, Show)    deriving anyclass (FromJSON, ToJSON)-- | References an image URL in the content of a messagedata ImageURL = ImageURL    { image_url :: Text    , detail :: Maybe (AutoOr Text)    } deriving stock (Generic, Show)      deriving anyclass (FromJSON, ToJSON)-- | Message contentdata Content text    = Image_File{ image_file :: ImageFile }    | Image_URL{ image_url :: ImageURL }    | Text{ text :: text }    deriving stock (Generic, Show)contentOptions :: OptionscontentOptions = aesonOptions    { sumEncoding =        TaggedObject{ tagFieldName = "type", contentsFieldName = "" }    , tagSingleConstructors = True    }instance FromJSON text => FromJSON (Content text) where    parseJSON = genericParseJSON contentOptionsinstance ToJSON text => ToJSON (Content text) where    toJSON = genericToJSON contentOptionsinstance IsString text => IsString (Content text) where    fromString string = Text{ text = fromString string }-- | A file attached to the message, and the tools it should be added todata Attachment = Attachment{ file_id :: FileID, tools :: Maybe (Vector Tool) }    deriving stock (Generic, Show)    deriving anyclass (FromJSON, ToJSON)-- | A messagedata Message    = User        { content :: Vector (Content Text)        , attachments :: Maybe (Vector Attachment)        , metadata :: Maybe (Map Text Text)        }    | Assistant        { content :: Vector (Content Text)        , attachments :: Maybe (Vector Attachment)        , metadata :: Maybe (Map Text Text)        }    deriving stock (Generic, Show)messageOptions :: OptionsmessageOptions =    aesonOptions        { sumEncoding =            TaggedObject{ tagFieldName = "role", contentsFieldName = "" }        , tagSingleConstructors = True        }instance FromJSON Message where    parseJSON = genericParseJSON  messageOptionsinstance ToJSON Message where    toJSON = genericToJSON  messageOptions