-- | @\/v1\/threads@
module OpenAI.V1.Threads
    ( -- Main types
      ThreadID(..)
    , Thread(..)
    , _Thread
    , ModifyThread(..)
    , _ModifyThread
    , Message(..)
    , Content(..)
    , ThreadObject(..)

      -- * Other types
    , ImageURL(..)
    , ImageFile(..)
    , Attachment(..)

      -- * Servant
    , API
    ) where

import OpenAI.Prelude
import OpenAI.V1.DeletionStatus
import OpenAI.V1.Message
import OpenAI.V1.ToolResources

-- | Thread ID
newtype ThreadID = ThreadID{ ThreadID -> Text
text :: Text }
    deriving newtype (Maybe ThreadID
Value -> Parser [ThreadID]
Value -> Parser ThreadID
(Value -> Parser ThreadID)
-> (Value -> Parser [ThreadID])
-> Maybe ThreadID
-> FromJSON ThreadID
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser ThreadID
parseJSON :: Value -> Parser ThreadID
$cparseJSONList :: Value -> Parser [ThreadID]
parseJSONList :: Value -> Parser [ThreadID]
$comittedField :: Maybe ThreadID
omittedField :: Maybe ThreadID
FromJSON, String -> ThreadID
(String -> ThreadID) -> IsString ThreadID
forall a. (String -> a) -> IsString a
$cfromString :: String -> ThreadID
fromString :: String -> ThreadID
IsString, Int -> ThreadID -> ShowS
[ThreadID] -> ShowS
ThreadID -> String
(Int -> ThreadID -> ShowS)
-> (ThreadID -> String) -> ([ThreadID] -> ShowS) -> Show ThreadID
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ThreadID -> ShowS
showsPrec :: Int -> ThreadID -> ShowS
$cshow :: ThreadID -> String
show :: ThreadID -> String
$cshowList :: [ThreadID] -> ShowS
showList :: [ThreadID] -> ShowS
Show, ThreadID -> Text
ThreadID -> ByteString
ThreadID -> Builder
(ThreadID -> Text)
-> (ThreadID -> Builder)
-> (ThreadID -> ByteString)
-> (ThreadID -> Text)
-> (ThreadID -> Builder)
-> ToHttpApiData ThreadID
forall a.
(a -> Text)
-> (a -> Builder)
-> (a -> ByteString)
-> (a -> Text)
-> (a -> Builder)
-> ToHttpApiData a
$ctoUrlPiece :: ThreadID -> Text
toUrlPiece :: ThreadID -> Text
$ctoEncodedUrlPiece :: ThreadID -> Builder
toEncodedUrlPiece :: ThreadID -> Builder
$ctoHeader :: ThreadID -> ByteString
toHeader :: ThreadID -> ByteString
$ctoQueryParam :: ThreadID -> Text
toQueryParam :: ThreadID -> Text
$ctoEncodedQueryParam :: ThreadID -> Builder
toEncodedQueryParam :: ThreadID -> Builder
ToHttpApiData, [ThreadID] -> Value
[ThreadID] -> Encoding
ThreadID -> Bool
ThreadID -> Value
ThreadID -> Encoding
(ThreadID -> Value)
-> (ThreadID -> Encoding)
-> ([ThreadID] -> Value)
-> ([ThreadID] -> Encoding)
-> (ThreadID -> Bool)
-> ToJSON ThreadID
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: ThreadID -> Value
toJSON :: ThreadID -> Value
$ctoEncoding :: ThreadID -> Encoding
toEncoding :: ThreadID -> Encoding
$ctoJSONList :: [ThreadID] -> Value
toJSONList :: [ThreadID] -> Value
$ctoEncodingList :: [ThreadID] -> Encoding
toEncodingList :: [ThreadID] -> Encoding
$comitField :: ThreadID -> Bool
omitField :: ThreadID -> Bool
ToJSON)

-- | Request body for @\/v1\/threads@
data Thread = Thread
    { Thread -> Maybe (Vector Message)
messages :: Maybe (Vector Message)
    , Thread -> Maybe ToolResources
tool_resources :: Maybe ToolResources
    , Thread -> Maybe (Map Text Text)
metadata :: Maybe (Map Text Text)
    } deriving stock ((forall x. Thread -> Rep Thread x)
-> (forall x. Rep Thread x -> Thread) -> Generic Thread
forall x. Rep Thread x -> Thread
forall x. Thread -> Rep Thread x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Thread -> Rep Thread x
from :: forall x. Thread -> Rep Thread x
$cto :: forall x. Rep Thread x -> Thread
to :: forall x. Rep Thread x -> Thread
Generic, Int -> Thread -> ShowS
[Thread] -> ShowS
Thread -> String
(Int -> Thread -> ShowS)
-> (Thread -> String) -> ([Thread] -> ShowS) -> Show Thread
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Thread -> ShowS
showsPrec :: Int -> Thread -> ShowS
$cshow :: Thread -> String
show :: Thread -> String
$cshowList :: [Thread] -> ShowS
showList :: [Thread] -> ShowS
Show)
      deriving anyclass ([Thread] -> Value
[Thread] -> Encoding
Thread -> Bool
Thread -> Value
Thread -> Encoding
(Thread -> Value)
-> (Thread -> Encoding)
-> ([Thread] -> Value)
-> ([Thread] -> Encoding)
-> (Thread -> Bool)
-> ToJSON Thread
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: Thread -> Value
toJSON :: Thread -> Value
$ctoEncoding :: Thread -> Encoding
toEncoding :: Thread -> Encoding
$ctoJSONList :: [Thread] -> Value
toJSONList :: [Thread] -> Value
$ctoEncodingList :: [Thread] -> Encoding
toEncodingList :: [Thread] -> Encoding
$comitField :: Thread -> Bool
omitField :: Thread -> Bool
ToJSON)

-- | Default `Thread`
_Thread :: Thread
_Thread :: Thread
_Thread = Thread
    { $sel:messages:Thread :: Maybe (Vector Message)
messages = Maybe (Vector Message)
forall a. Maybe a
Nothing
    , $sel:tool_resources:Thread :: Maybe ToolResources
tool_resources = Maybe ToolResources
forall a. Maybe a
Nothing
    , $sel:metadata:Thread :: Maybe (Map Text Text)
metadata = Maybe (Map Text Text)
forall a. Maybe a
Nothing
    }

-- | Request body for @\/v1\/threads\/:thread_id@
data ModifyThread = ModifyThread
    { ModifyThread -> Maybe ToolResources
tool_resources :: Maybe ToolResources
    , ModifyThread -> Maybe (Map Text Text)
metadata :: Maybe (Map Text Text)
    } deriving stock ((forall x. ModifyThread -> Rep ModifyThread x)
-> (forall x. Rep ModifyThread x -> ModifyThread)
-> Generic ModifyThread
forall x. Rep ModifyThread x -> ModifyThread
forall x. ModifyThread -> Rep ModifyThread x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ModifyThread -> Rep ModifyThread x
from :: forall x. ModifyThread -> Rep ModifyThread x
$cto :: forall x. Rep ModifyThread x -> ModifyThread
to :: forall x. Rep ModifyThread x -> ModifyThread
Generic, Int -> ModifyThread -> ShowS
[ModifyThread] -> ShowS
ModifyThread -> String
(Int -> ModifyThread -> ShowS)
-> (ModifyThread -> String)
-> ([ModifyThread] -> ShowS)
-> Show ModifyThread
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ModifyThread -> ShowS
showsPrec :: Int -> ModifyThread -> ShowS
$cshow :: ModifyThread -> String
show :: ModifyThread -> String
$cshowList :: [ModifyThread] -> ShowS
showList :: [ModifyThread] -> ShowS
Show)

instance ToJSON ModifyThread where
    toJSON :: ModifyThread -> Value
toJSON = Options -> ModifyThread -> Value
forall a.
(Generic a, GToJSON' Value Zero (Rep a)) =>
Options -> a -> Value
genericToJSON Options
aesonOptions

-- | Default `ModifyThread`
_ModifyThread :: ModifyThread
_ModifyThread :: ModifyThread
_ModifyThread = ModifyThread
    { $sel:tool_resources:ModifyThread :: Maybe ToolResources
tool_resources = Maybe ToolResources
forall a. Maybe a
Nothing
    , $sel:metadata:ModifyThread :: Maybe (Map Text Text)
metadata = Maybe (Map Text Text)
forall a. Maybe a
Nothing
    }

-- | Represents a thread that contains messages
data ThreadObject = ThreadObject
    { ThreadObject -> ThreadID
id :: ThreadID
    , ThreadObject -> Text
object :: Text
    , ThreadObject -> POSIXTime
created_at :: POSIXTime
    , ThreadObject -> Maybe ToolResources
tool_resources :: Maybe ToolResources
    , ThreadObject -> Maybe (Map Text Text)
metadata :: Maybe (Map Text Text)
    } deriving stock ((forall x. ThreadObject -> Rep ThreadObject x)
-> (forall x. Rep ThreadObject x -> ThreadObject)
-> Generic ThreadObject
forall x. Rep ThreadObject x -> ThreadObject
forall x. ThreadObject -> Rep ThreadObject x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ThreadObject -> Rep ThreadObject x
from :: forall x. ThreadObject -> Rep ThreadObject x
$cto :: forall x. Rep ThreadObject x -> ThreadObject
to :: forall x. Rep ThreadObject x -> ThreadObject
Generic, Int -> ThreadObject -> ShowS
[ThreadObject] -> ShowS
ThreadObject -> String
(Int -> ThreadObject -> ShowS)
-> (ThreadObject -> String)
-> ([ThreadObject] -> ShowS)
-> Show ThreadObject
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ThreadObject -> ShowS
showsPrec :: Int -> ThreadObject -> ShowS
$cshow :: ThreadObject -> String
show :: ThreadObject -> String
$cshowList :: [ThreadObject] -> ShowS
showList :: [ThreadObject] -> ShowS
Show)
      deriving anyclass (Maybe ThreadObject
Value -> Parser [ThreadObject]
Value -> Parser ThreadObject
(Value -> Parser ThreadObject)
-> (Value -> Parser [ThreadObject])
-> Maybe ThreadObject
-> FromJSON ThreadObject
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser ThreadObject
parseJSON :: Value -> Parser ThreadObject
$cparseJSONList :: Value -> Parser [ThreadObject]
parseJSONList :: Value -> Parser [ThreadObject]
$comittedField :: Maybe ThreadObject
omittedField :: Maybe ThreadObject
FromJSON)

-- | Servant API
type API =
        "threads"
    :>  Header' '[Required, Strict] "OpenAI-Beta" Text
    :>  (         ReqBody '[JSON] Thread
              :>  Post '[JSON] ThreadObject
        :<|>      Capture "thread_id" ThreadID
              :>  Get '[JSON] ThreadObject
        :<|>      Capture "thread_id" ThreadID
              :>  ReqBody '[JSON] ModifyThread
              :>  Post '[JSON] ThreadObject
        :<|>      Capture "thread_id" ThreadID
              :>  Delete '[JSON] DeletionStatus
        )