{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
module Data.Ollama.Common.Types
( ModelDetails (..)
, Format (..)
, GenerateResponse (..)
, Message (..)
, Role (..)
, ChatResponse (..)
, HasDone (..)
, ModelOptions (..)
, InputTool (..)
, FunctionDef (..)
, FunctionParameters (..)
, ToolCall (..)
, OutputFunction (..)
, Version (..)
) where
import Data.Aeson
import Data.Map qualified as HM
import Data.Maybe (catMaybes)
import Data.Ollama.Common.SchemaBuilder
import Data.Text (Text)
import Data.Time (UTCTime)
import GHC.Generics
import GHC.Int (Int64)
data ModelDetails = ModelDetails
{ ModelDetails -> Maybe Text
parentModel :: !(Maybe Text)
, ModelDetails -> Text
format :: !Text
, ModelDetails -> Text
family :: !Text
, ModelDetails -> [Text]
families :: ![Text]
, ModelDetails -> Text
parameterSize :: !Text
, ModelDetails -> Text
quantizationLevel :: Text
}
deriving (ModelDetails -> ModelDetails -> Bool
(ModelDetails -> ModelDetails -> Bool)
-> (ModelDetails -> ModelDetails -> Bool) -> Eq ModelDetails
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ModelDetails -> ModelDetails -> Bool
== :: ModelDetails -> ModelDetails -> Bool
$c/= :: ModelDetails -> ModelDetails -> Bool
/= :: ModelDetails -> ModelDetails -> Bool
Eq, Int -> ModelDetails -> ShowS
[ModelDetails] -> ShowS
ModelDetails -> String
(Int -> ModelDetails -> ShowS)
-> (ModelDetails -> String)
-> ([ModelDetails] -> ShowS)
-> Show ModelDetails
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ModelDetails -> ShowS
showsPrec :: Int -> ModelDetails -> ShowS
$cshow :: ModelDetails -> String
show :: ModelDetails -> String
$cshowList :: [ModelDetails] -> ShowS
showList :: [ModelDetails] -> ShowS
Show)
instance FromJSON ModelDetails where
parseJSON :: Value -> Parser ModelDetails
parseJSON = String
-> (Object -> Parser ModelDetails) -> Value -> Parser ModelDetails
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"ModelDetails" ((Object -> Parser ModelDetails) -> Value -> Parser ModelDetails)
-> (Object -> Parser ModelDetails) -> Value -> Parser ModelDetails
forall a b. (a -> b) -> a -> b
$ \Object
v ->
Maybe Text
-> Text -> Text -> [Text] -> Text -> Text -> ModelDetails
ModelDetails
(Maybe Text
-> Text -> Text -> [Text] -> Text -> Text -> ModelDetails)
-> Parser (Maybe Text)
-> Parser (Text -> Text -> [Text] -> Text -> Text -> ModelDetails)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"parent_model"
Parser (Text -> Text -> [Text] -> Text -> Text -> ModelDetails)
-> Parser Text
-> Parser (Text -> [Text] -> Text -> Text -> ModelDetails)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"format"
Parser (Text -> [Text] -> Text -> Text -> ModelDetails)
-> Parser Text -> Parser ([Text] -> Text -> Text -> ModelDetails)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"family"
Parser ([Text] -> Text -> Text -> ModelDetails)
-> Parser [Text] -> Parser (Text -> Text -> ModelDetails)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe [Text])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"families" Parser (Maybe [Text]) -> [Text] -> Parser [Text]
forall a. Parser (Maybe a) -> a -> Parser a
.!= []
Parser (Text -> Text -> ModelDetails)
-> Parser Text -> Parser (Text -> ModelDetails)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"parameter_size"
Parser (Text -> ModelDetails) -> Parser Text -> Parser ModelDetails
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"quantization_level"
data Format = JsonFormat | SchemaFormat Schema
deriving (Int -> Format -> ShowS
[Format] -> ShowS
Format -> String
(Int -> Format -> ShowS)
-> (Format -> String) -> ([Format] -> ShowS) -> Show Format
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Format -> ShowS
showsPrec :: Int -> Format -> ShowS
$cshow :: Format -> String
show :: Format -> String
$cshowList :: [Format] -> ShowS
showList :: [Format] -> ShowS
Show, Format -> Format -> Bool
(Format -> Format -> Bool)
-> (Format -> Format -> Bool) -> Eq Format
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Format -> Format -> Bool
== :: Format -> Format -> Bool
$c/= :: Format -> Format -> Bool
/= :: Format -> Format -> Bool
Eq)
instance ToJSON Format where
toJSON :: Format -> Value
toJSON Format
JsonFormat = Text -> Value
String Text
"json"
toJSON (SchemaFormat Schema
schema) = Schema -> Value
forall a. ToJSON a => a -> Value
toJSON Schema
schema
data GenerateResponse = GenerateResponse
{ GenerateResponse -> Text
model :: !Text
, GenerateResponse -> UTCTime
createdAt :: !UTCTime
, GenerateResponse -> Text
genResponse :: !Text
, GenerateResponse -> Bool
done :: !Bool
, GenerateResponse -> Maybe Int64
totalDuration :: !(Maybe Int64)
, GenerateResponse -> Maybe Int64
loadDuration :: !(Maybe Int64)
, GenerateResponse -> Maybe Int64
promptEvalCount :: !(Maybe Int64)
, GenerateResponse -> Maybe Int64
promptEvalDuration :: !(Maybe Int64)
, GenerateResponse -> Maybe Int64
evalCount :: !(Maybe Int64)
, GenerateResponse -> Maybe Int64
evalDuration :: !(Maybe Int64)
, GenerateResponse -> Maybe Text
thinking :: !(Maybe Text)
}
deriving (Int -> GenerateResponse -> ShowS
[GenerateResponse] -> ShowS
GenerateResponse -> String
(Int -> GenerateResponse -> ShowS)
-> (GenerateResponse -> String)
-> ([GenerateResponse] -> ShowS)
-> Show GenerateResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GenerateResponse -> ShowS
showsPrec :: Int -> GenerateResponse -> ShowS
$cshow :: GenerateResponse -> String
show :: GenerateResponse -> String
$cshowList :: [GenerateResponse] -> ShowS
showList :: [GenerateResponse] -> ShowS
Show, GenerateResponse -> GenerateResponse -> Bool
(GenerateResponse -> GenerateResponse -> Bool)
-> (GenerateResponse -> GenerateResponse -> Bool)
-> Eq GenerateResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GenerateResponse -> GenerateResponse -> Bool
== :: GenerateResponse -> GenerateResponse -> Bool
$c/= :: GenerateResponse -> GenerateResponse -> Bool
/= :: GenerateResponse -> GenerateResponse -> Bool
Eq)
instance FromJSON GenerateResponse where
parseJSON :: Value -> Parser GenerateResponse
parseJSON = String
-> (Object -> Parser GenerateResponse)
-> Value
-> Parser GenerateResponse
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"GenerateResponse" ((Object -> Parser GenerateResponse)
-> Value -> Parser GenerateResponse)
-> (Object -> Parser GenerateResponse)
-> Value
-> Parser GenerateResponse
forall a b. (a -> b) -> a -> b
$ \Object
v ->
Text
-> UTCTime
-> Text
-> Bool
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Text
-> GenerateResponse
GenerateResponse
(Text
-> UTCTime
-> Text
-> Bool
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Text
-> GenerateResponse)
-> Parser Text
-> Parser
(UTCTime
-> Text
-> Bool
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Text
-> GenerateResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"model"
Parser
(UTCTime
-> Text
-> Bool
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Text
-> GenerateResponse)
-> Parser UTCTime
-> Parser
(Text
-> Bool
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Text
-> GenerateResponse)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser UTCTime
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"created_at"
Parser
(Text
-> Bool
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Text
-> GenerateResponse)
-> Parser Text
-> Parser
(Bool
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Text
-> GenerateResponse)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"response"
Parser
(Bool
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Text
-> GenerateResponse)
-> Parser Bool
-> Parser
(Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Text
-> GenerateResponse)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser Bool
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"done"
Parser
(Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Text
-> GenerateResponse)
-> Parser (Maybe Int64)
-> Parser
(Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Text
-> GenerateResponse)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe Int64)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"total_duration"
Parser
(Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Text
-> GenerateResponse)
-> Parser (Maybe Int64)
-> Parser
(Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Text
-> GenerateResponse)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe Int64)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"load_duration"
Parser
(Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Text
-> GenerateResponse)
-> Parser (Maybe Int64)
-> Parser
(Maybe Int64
-> Maybe Int64 -> Maybe Int64 -> Maybe Text -> GenerateResponse)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe Int64)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"prompt_eval_count"
Parser
(Maybe Int64
-> Maybe Int64 -> Maybe Int64 -> Maybe Text -> GenerateResponse)
-> Parser (Maybe Int64)
-> Parser
(Maybe Int64 -> Maybe Int64 -> Maybe Text -> GenerateResponse)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe Int64)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"prompt_eval_duration"
Parser
(Maybe Int64 -> Maybe Int64 -> Maybe Text -> GenerateResponse)
-> Parser (Maybe Int64)
-> Parser (Maybe Int64 -> Maybe Text -> GenerateResponse)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe Int64)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"eval_count"
Parser (Maybe Int64 -> Maybe Text -> GenerateResponse)
-> Parser (Maybe Int64) -> Parser (Maybe Text -> GenerateResponse)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe Int64)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"eval_duration"
Parser (Maybe Text -> GenerateResponse)
-> Parser (Maybe Text) -> Parser GenerateResponse
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"thinking"
data Role = System | User | Assistant | Tool
deriving (Int -> Role -> ShowS
[Role] -> ShowS
Role -> String
(Int -> Role -> ShowS)
-> (Role -> String) -> ([Role] -> ShowS) -> Show Role
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Role -> ShowS
showsPrec :: Int -> Role -> ShowS
$cshow :: Role -> String
show :: Role -> String
$cshowList :: [Role] -> ShowS
showList :: [Role] -> ShowS
Show, Role -> Role -> Bool
(Role -> Role -> Bool) -> (Role -> Role -> Bool) -> Eq Role
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Role -> Role -> Bool
== :: Role -> Role -> Bool
$c/= :: Role -> Role -> Bool
/= :: Role -> Role -> Bool
Eq)
instance ToJSON Role where
toJSON :: Role -> Value
toJSON Role
System = Text -> Value
String Text
"system"
toJSON Role
User = Text -> Value
String Text
"user"
toJSON Role
Assistant = Text -> Value
String Text
"assistant"
toJSON Role
Tool = Text -> Value
String Text
"tool"
instance FromJSON Role where
parseJSON :: Value -> Parser Role
parseJSON = String -> (Text -> Parser Role) -> Value -> Parser Role
forall a. String -> (Text -> Parser a) -> Value -> Parser a
withText String
"Role" ((Text -> Parser Role) -> Value -> Parser Role)
-> (Text -> Parser Role) -> Value -> Parser Role
forall a b. (a -> b) -> a -> b
$ \Text
t ->
case Text
t of
Text
"system" -> Role -> Parser Role
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Role
System
Text
"user" -> Role -> Parser Role
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Role
User
Text
"assistant" -> Role -> Parser Role
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Role
Assistant
Text
"tool" -> Role -> Parser Role
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Role
Tool
Text
_ -> String -> Parser Role
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser Role) -> String -> Parser Role
forall a b. (a -> b) -> a -> b
$ String
"Invalid Role value: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Text -> String
forall a. Show a => a -> String
show Text
t
data Message = Message
{ Message -> Role
role :: !Role
, Message -> Text
content :: !Text
, Message -> Maybe [Text]
images :: !(Maybe [Text])
, Message -> Maybe [ToolCall]
tool_calls :: !(Maybe [ToolCall])
, Message -> Maybe Text
thinking :: !(Maybe Text)
}
deriving (Int -> Message -> ShowS
[Message] -> ShowS
Message -> String
(Int -> Message -> ShowS)
-> (Message -> String) -> ([Message] -> ShowS) -> Show Message
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Message -> ShowS
showsPrec :: Int -> Message -> ShowS
$cshow :: Message -> String
show :: Message -> String
$cshowList :: [Message] -> ShowS
showList :: [Message] -> ShowS
Show, Message -> Message -> Bool
(Message -> Message -> Bool)
-> (Message -> Message -> Bool) -> Eq Message
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Message -> Message -> Bool
== :: Message -> Message -> Bool
$c/= :: Message -> Message -> Bool
/= :: Message -> Message -> Bool
Eq, (forall x. Message -> Rep Message x)
-> (forall x. Rep Message x -> Message) -> Generic Message
forall x. Rep Message x -> Message
forall x. Message -> Rep Message x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Message -> Rep Message x
from :: forall x. Message -> Rep Message x
$cto :: forall x. Rep Message x -> Message
to :: forall x. Rep Message x -> Message
Generic, [Message] -> Value
[Message] -> Encoding
Message -> Bool
Message -> Value
Message -> Encoding
(Message -> Value)
-> (Message -> Encoding)
-> ([Message] -> Value)
-> ([Message] -> Encoding)
-> (Message -> Bool)
-> ToJSON Message
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: Message -> Value
toJSON :: Message -> Value
$ctoEncoding :: Message -> Encoding
toEncoding :: Message -> Encoding
$ctoJSONList :: [Message] -> Value
toJSONList :: [Message] -> Value
$ctoEncodingList :: [Message] -> Encoding
toEncodingList :: [Message] -> Encoding
$comitField :: Message -> Bool
omitField :: Message -> Bool
ToJSON, Maybe Message
Value -> Parser [Message]
Value -> Parser Message
(Value -> Parser Message)
-> (Value -> Parser [Message]) -> Maybe Message -> FromJSON Message
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser Message
parseJSON :: Value -> Parser Message
$cparseJSONList :: Value -> Parser [Message]
parseJSONList :: Value -> Parser [Message]
$comittedField :: Maybe Message
omittedField :: Maybe Message
FromJSON)
data ChatResponse = ChatResponse
{ ChatResponse -> Text
model :: !Text
, ChatResponse -> UTCTime
createdAt :: !UTCTime
, ChatResponse -> Maybe Message
message :: !(Maybe Message)
, ChatResponse -> Bool
done :: !Bool
, ChatResponse -> Maybe Int64
totalDuration :: !(Maybe Int64)
, ChatResponse -> Maybe Int64
loadDuration :: !(Maybe Int64)
, ChatResponse -> Maybe Int64
promptEvalCount :: !(Maybe Int64)
, ChatResponse -> Maybe Int64
promptEvalDuration :: !(Maybe Int64)
, ChatResponse -> Maybe Int64
evalCount :: !(Maybe Int64)
, ChatResponse -> Maybe Int64
evalDuration :: !(Maybe Int64)
}
deriving (Int -> ChatResponse -> ShowS
[ChatResponse] -> ShowS
ChatResponse -> String
(Int -> ChatResponse -> ShowS)
-> (ChatResponse -> String)
-> ([ChatResponse] -> ShowS)
-> Show ChatResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ChatResponse -> ShowS
showsPrec :: Int -> ChatResponse -> ShowS
$cshow :: ChatResponse -> String
show :: ChatResponse -> String
$cshowList :: [ChatResponse] -> ShowS
showList :: [ChatResponse] -> ShowS
Show, ChatResponse -> ChatResponse -> Bool
(ChatResponse -> ChatResponse -> Bool)
-> (ChatResponse -> ChatResponse -> Bool) -> Eq ChatResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ChatResponse -> ChatResponse -> Bool
== :: ChatResponse -> ChatResponse -> Bool
$c/= :: ChatResponse -> ChatResponse -> Bool
/= :: ChatResponse -> ChatResponse -> Bool
Eq)
instance FromJSON ChatResponse where
parseJSON :: Value -> Parser ChatResponse
parseJSON = String
-> (Object -> Parser ChatResponse) -> Value -> Parser ChatResponse
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"ChatResponse" ((Object -> Parser ChatResponse) -> Value -> Parser ChatResponse)
-> (Object -> Parser ChatResponse) -> Value -> Parser ChatResponse
forall a b. (a -> b) -> a -> b
$ \Object
v ->
Text
-> UTCTime
-> Maybe Message
-> Bool
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> ChatResponse
ChatResponse
(Text
-> UTCTime
-> Maybe Message
-> Bool
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> ChatResponse)
-> Parser Text
-> Parser
(UTCTime
-> Maybe Message
-> Bool
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> ChatResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"model"
Parser
(UTCTime
-> Maybe Message
-> Bool
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> ChatResponse)
-> Parser UTCTime
-> Parser
(Maybe Message
-> Bool
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> ChatResponse)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser UTCTime
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"created_at"
Parser
(Maybe Message
-> Bool
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> ChatResponse)
-> Parser (Maybe Message)
-> Parser
(Bool
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> ChatResponse)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe Message)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"message"
Parser
(Bool
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> ChatResponse)
-> Parser Bool
-> Parser
(Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> ChatResponse)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser Bool
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"done"
Parser
(Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> ChatResponse)
-> Parser (Maybe Int64)
-> Parser
(Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> ChatResponse)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe Int64)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"total_duration"
Parser
(Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> Maybe Int64
-> ChatResponse)
-> Parser (Maybe Int64)
-> Parser
(Maybe Int64
-> Maybe Int64 -> Maybe Int64 -> Maybe Int64 -> ChatResponse)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe Int64)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"load_duration"
Parser
(Maybe Int64
-> Maybe Int64 -> Maybe Int64 -> Maybe Int64 -> ChatResponse)
-> Parser (Maybe Int64)
-> Parser
(Maybe Int64 -> Maybe Int64 -> Maybe Int64 -> ChatResponse)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe Int64)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"prompt_eval_count"
Parser (Maybe Int64 -> Maybe Int64 -> Maybe Int64 -> ChatResponse)
-> Parser (Maybe Int64)
-> Parser (Maybe Int64 -> Maybe Int64 -> ChatResponse)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe Int64)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"prompt_eval_duration"
Parser (Maybe Int64 -> Maybe Int64 -> ChatResponse)
-> Parser (Maybe Int64) -> Parser (Maybe Int64 -> ChatResponse)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe Int64)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"eval_count"
Parser (Maybe Int64 -> ChatResponse)
-> Parser (Maybe Int64) -> Parser ChatResponse
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe Int64)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"eval_duration"
class HasDone a where
getDone :: a -> Bool
instance HasDone GenerateResponse where
getDone :: GenerateResponse -> Bool
getDone GenerateResponse {Bool
Maybe Int64
Maybe Text
Text
UTCTime
model :: GenerateResponse -> Text
createdAt :: GenerateResponse -> UTCTime
genResponse :: GenerateResponse -> Text
done :: GenerateResponse -> Bool
totalDuration :: GenerateResponse -> Maybe Int64
loadDuration :: GenerateResponse -> Maybe Int64
promptEvalCount :: GenerateResponse -> Maybe Int64
promptEvalDuration :: GenerateResponse -> Maybe Int64
evalCount :: GenerateResponse -> Maybe Int64
evalDuration :: GenerateResponse -> Maybe Int64
thinking :: GenerateResponse -> Maybe Text
model :: Text
createdAt :: UTCTime
genResponse :: Text
done :: Bool
totalDuration :: Maybe Int64
loadDuration :: Maybe Int64
promptEvalCount :: Maybe Int64
promptEvalDuration :: Maybe Int64
evalCount :: Maybe Int64
evalDuration :: Maybe Int64
thinking :: Maybe Text
..} = Bool
done
instance HasDone ChatResponse where
getDone :: ChatResponse -> Bool
getDone ChatResponse {Bool
Maybe Int64
Maybe Message
Text
UTCTime
model :: ChatResponse -> Text
createdAt :: ChatResponse -> UTCTime
message :: ChatResponse -> Maybe Message
done :: ChatResponse -> Bool
totalDuration :: ChatResponse -> Maybe Int64
loadDuration :: ChatResponse -> Maybe Int64
promptEvalCount :: ChatResponse -> Maybe Int64
promptEvalDuration :: ChatResponse -> Maybe Int64
evalCount :: ChatResponse -> Maybe Int64
evalDuration :: ChatResponse -> Maybe Int64
model :: Text
createdAt :: UTCTime
message :: Maybe Message
done :: Bool
totalDuration :: Maybe Int64
loadDuration :: Maybe Int64
promptEvalCount :: Maybe Int64
promptEvalDuration :: Maybe Int64
evalCount :: Maybe Int64
evalDuration :: Maybe Int64
..} = Bool
done
data ModelOptions = ModelOptions
{ ModelOptions -> Maybe Int
numKeep :: Maybe Int
,
ModelOptions -> Maybe Int
seed :: Maybe Int
,
ModelOptions -> Maybe Int
numPredict :: Maybe Int
,
ModelOptions -> Maybe Int
topK :: Maybe Int
,
ModelOptions -> Maybe Double
topP :: Maybe Double
,
ModelOptions -> Maybe Double
minP :: Maybe Double
,
ModelOptions -> Maybe Double
typicalP :: Maybe Double
,
ModelOptions -> Maybe Int
repeatLastN :: Maybe Int
,
ModelOptions -> Maybe Double
temperature :: Maybe Double
,
ModelOptions -> Maybe Double
repeatPenalty :: Maybe Double
,
ModelOptions -> Maybe Double
presencePenalty :: Maybe Double
,
ModelOptions -> Maybe Double
frequencyPenalty :: Maybe Double
,
ModelOptions -> Maybe Bool
penalizeNewline :: Maybe Bool
,
ModelOptions -> Maybe [Text]
stop :: Maybe [Text]
,
ModelOptions -> Maybe Bool
numa :: Maybe Bool
,
ModelOptions -> Maybe Int
numCtx :: Maybe Int
,
ModelOptions -> Maybe Int
numBatch :: Maybe Int
,
ModelOptions -> Maybe Int
numGpu :: Maybe Int
,
ModelOptions -> Maybe Int
mainGpu :: Maybe Int
,
ModelOptions -> Maybe Bool
useMmap :: Maybe Bool
,
ModelOptions -> Maybe Int
numThread :: Maybe Int
}
deriving (Int -> ModelOptions -> ShowS
[ModelOptions] -> ShowS
ModelOptions -> String
(Int -> ModelOptions -> ShowS)
-> (ModelOptions -> String)
-> ([ModelOptions] -> ShowS)
-> Show ModelOptions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ModelOptions -> ShowS
showsPrec :: Int -> ModelOptions -> ShowS
$cshow :: ModelOptions -> String
show :: ModelOptions -> String
$cshowList :: [ModelOptions] -> ShowS
showList :: [ModelOptions] -> ShowS
Show, ModelOptions -> ModelOptions -> Bool
(ModelOptions -> ModelOptions -> Bool)
-> (ModelOptions -> ModelOptions -> Bool) -> Eq ModelOptions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ModelOptions -> ModelOptions -> Bool
== :: ModelOptions -> ModelOptions -> Bool
$c/= :: ModelOptions -> ModelOptions -> Bool
/= :: ModelOptions -> ModelOptions -> Bool
Eq)
instance ToJSON ModelOptions where
toJSON :: ModelOptions -> Value
toJSON ModelOptions
opts =
[Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$
[Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
catMaybes
[ (Key
"num_keep" Key -> Int -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.=) (Int -> Pair) -> Maybe Int -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ModelOptions -> Maybe Int
numKeep ModelOptions
opts
, (Key
"seed" Key -> Int -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.=) (Int -> Pair) -> Maybe Int -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ModelOptions -> Maybe Int
seed ModelOptions
opts
, (Key
"num_predict" Key -> Int -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.=) (Int -> Pair) -> Maybe Int -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ModelOptions -> Maybe Int
numPredict ModelOptions
opts
, (Key
"top_k" Key -> Int -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.=) (Int -> Pair) -> Maybe Int -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ModelOptions -> Maybe Int
topK ModelOptions
opts
, (Key
"top_p" Key -> Double -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.=) (Double -> Pair) -> Maybe Double -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ModelOptions -> Maybe Double
topP ModelOptions
opts
, (Key
"min_p" Key -> Double -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.=) (Double -> Pair) -> Maybe Double -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ModelOptions -> Maybe Double
minP ModelOptions
opts
, (Key
"typical_p" Key -> Double -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.=) (Double -> Pair) -> Maybe Double -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ModelOptions -> Maybe Double
typicalP ModelOptions
opts
, (Key
"repeat_last_n" Key -> Int -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.=) (Int -> Pair) -> Maybe Int -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ModelOptions -> Maybe Int
repeatLastN ModelOptions
opts
, (Key
"temperature" Key -> Double -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.=) (Double -> Pair) -> Maybe Double -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ModelOptions -> Maybe Double
temperature ModelOptions
opts
, (Key
"repeat_penalty" Key -> Double -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.=) (Double -> Pair) -> Maybe Double -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ModelOptions -> Maybe Double
repeatPenalty ModelOptions
opts
, (Key
"presence_penalty" Key -> Double -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.=) (Double -> Pair) -> Maybe Double -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ModelOptions -> Maybe Double
presencePenalty ModelOptions
opts
, (Key
"frequency_penalty" Key -> Double -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.=) (Double -> Pair) -> Maybe Double -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ModelOptions -> Maybe Double
frequencyPenalty ModelOptions
opts
, (Key
"penalize_newline" Key -> Bool -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.=) (Bool -> Pair) -> Maybe Bool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ModelOptions -> Maybe Bool
penalizeNewline ModelOptions
opts
, (Key
"stop" Key -> [Text] -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.=) ([Text] -> Pair) -> Maybe [Text] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ModelOptions -> Maybe [Text]
stop ModelOptions
opts
, (Key
"numa" Key -> Bool -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.=) (Bool -> Pair) -> Maybe Bool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ModelOptions -> Maybe Bool
numa ModelOptions
opts
, (Key
"num_ctx" Key -> Int -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.=) (Int -> Pair) -> Maybe Int -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ModelOptions -> Maybe Int
numCtx ModelOptions
opts
, (Key
"num_batch" Key -> Int -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.=) (Int -> Pair) -> Maybe Int -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ModelOptions -> Maybe Int
numBatch ModelOptions
opts
, (Key
"num_gpu" Key -> Int -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.=) (Int -> Pair) -> Maybe Int -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ModelOptions -> Maybe Int
numGpu ModelOptions
opts
, (Key
"main_gpu" Key -> Int -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.=) (Int -> Pair) -> Maybe Int -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ModelOptions -> Maybe Int
mainGpu ModelOptions
opts
, (Key
"use_mmap" Key -> Bool -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.=) (Bool -> Pair) -> Maybe Bool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ModelOptions -> Maybe Bool
useMmap ModelOptions
opts
, (Key
"num_thread" Key -> Int -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.=) (Int -> Pair) -> Maybe Int -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ModelOptions -> Maybe Int
numThread ModelOptions
opts
]
newtype Version = Version Text
deriving (Version -> Version -> Bool
(Version -> Version -> Bool)
-> (Version -> Version -> Bool) -> Eq Version
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Version -> Version -> Bool
== :: Version -> Version -> Bool
$c/= :: Version -> Version -> Bool
/= :: Version -> Version -> Bool
Eq, Int -> Version -> ShowS
[Version] -> ShowS
Version -> String
(Int -> Version -> ShowS)
-> (Version -> String) -> ([Version] -> ShowS) -> Show Version
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Version -> ShowS
showsPrec :: Int -> Version -> ShowS
$cshow :: Version -> String
show :: Version -> String
$cshowList :: [Version] -> ShowS
showList :: [Version] -> ShowS
Show)
instance FromJSON Version where
parseJSON :: Value -> Parser Version
parseJSON = String -> (Object -> Parser Version) -> Value -> Parser Version
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"version" ((Object -> Parser Version) -> Value -> Parser Version)
-> (Object -> Parser Version) -> Value -> Parser Version
forall a b. (a -> b) -> a -> b
$ \Object
v -> do
Text -> Version
Version (Text -> Version) -> Parser Text -> Parser Version
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"version"
data InputTool = InputTool
{ InputTool -> Text
toolType :: Text
, InputTool -> FunctionDef
function :: FunctionDef
}
deriving (Int -> InputTool -> ShowS
[InputTool] -> ShowS
InputTool -> String
(Int -> InputTool -> ShowS)
-> (InputTool -> String)
-> ([InputTool] -> ShowS)
-> Show InputTool
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InputTool -> ShowS
showsPrec :: Int -> InputTool -> ShowS
$cshow :: InputTool -> String
show :: InputTool -> String
$cshowList :: [InputTool] -> ShowS
showList :: [InputTool] -> ShowS
Show, InputTool -> InputTool -> Bool
(InputTool -> InputTool -> Bool)
-> (InputTool -> InputTool -> Bool) -> Eq InputTool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: InputTool -> InputTool -> Bool
== :: InputTool -> InputTool -> Bool
$c/= :: InputTool -> InputTool -> Bool
/= :: InputTool -> InputTool -> Bool
Eq, (forall x. InputTool -> Rep InputTool x)
-> (forall x. Rep InputTool x -> InputTool) -> Generic InputTool
forall x. Rep InputTool x -> InputTool
forall x. InputTool -> Rep InputTool x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. InputTool -> Rep InputTool x
from :: forall x. InputTool -> Rep InputTool x
$cto :: forall x. Rep InputTool x -> InputTool
to :: forall x. Rep InputTool x -> InputTool
Generic)
instance ToJSON InputTool where
toJSON :: InputTool -> Value
toJSON InputTool {Text
FunctionDef
toolType :: InputTool -> Text
function :: InputTool -> FunctionDef
toolType :: Text
function :: FunctionDef
..} =
[Pair] -> Value
object
[ Key
"type" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
toolType
, Key
"function" Key -> FunctionDef -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= FunctionDef
function
]
instance FromJSON InputTool where
parseJSON :: Value -> Parser InputTool
parseJSON = String -> (Object -> Parser InputTool) -> Value -> Parser InputTool
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"Tool" ((Object -> Parser InputTool) -> Value -> Parser InputTool)
-> (Object -> Parser InputTool) -> Value -> Parser InputTool
forall a b. (a -> b) -> a -> b
$ \Object
v ->
Text -> FunctionDef -> InputTool
InputTool
(Text -> FunctionDef -> InputTool)
-> Parser Text -> Parser (FunctionDef -> InputTool)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"type"
Parser (FunctionDef -> InputTool)
-> Parser FunctionDef -> Parser InputTool
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser FunctionDef
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"function"
data FunctionDef = FunctionDef
{ FunctionDef -> Text
functionName :: Text
, FunctionDef -> Maybe Text
functionDescription :: Maybe Text
, FunctionDef -> Maybe FunctionParameters
functionParameters :: Maybe FunctionParameters
, FunctionDef -> Maybe Bool
functionStrict :: Maybe Bool
}
deriving (Int -> FunctionDef -> ShowS
[FunctionDef] -> ShowS
FunctionDef -> String
(Int -> FunctionDef -> ShowS)
-> (FunctionDef -> String)
-> ([FunctionDef] -> ShowS)
-> Show FunctionDef
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FunctionDef -> ShowS
showsPrec :: Int -> FunctionDef -> ShowS
$cshow :: FunctionDef -> String
show :: FunctionDef -> String
$cshowList :: [FunctionDef] -> ShowS
showList :: [FunctionDef] -> ShowS
Show, FunctionDef -> FunctionDef -> Bool
(FunctionDef -> FunctionDef -> Bool)
-> (FunctionDef -> FunctionDef -> Bool) -> Eq FunctionDef
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FunctionDef -> FunctionDef -> Bool
== :: FunctionDef -> FunctionDef -> Bool
$c/= :: FunctionDef -> FunctionDef -> Bool
/= :: FunctionDef -> FunctionDef -> Bool
Eq, (forall x. FunctionDef -> Rep FunctionDef x)
-> (forall x. Rep FunctionDef x -> FunctionDef)
-> Generic FunctionDef
forall x. Rep FunctionDef x -> FunctionDef
forall x. FunctionDef -> Rep FunctionDef x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. FunctionDef -> Rep FunctionDef x
from :: forall x. FunctionDef -> Rep FunctionDef x
$cto :: forall x. Rep FunctionDef x -> FunctionDef
to :: forall x. Rep FunctionDef x -> FunctionDef
Generic)
instance ToJSON FunctionDef where
toJSON :: FunctionDef -> Value
toJSON FunctionDef {Maybe Bool
Maybe Text
Maybe FunctionParameters
Text
functionName :: FunctionDef -> Text
functionDescription :: FunctionDef -> Maybe Text
functionParameters :: FunctionDef -> Maybe FunctionParameters
functionStrict :: FunctionDef -> Maybe Bool
functionName :: Text
functionDescription :: Maybe Text
functionParameters :: Maybe FunctionParameters
functionStrict :: Maybe Bool
..} =
[Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$
[ Key
"name" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
functionName
]
[Pair] -> [Pair] -> [Pair]
forall a. [a] -> [a] -> [a]
++ [Pair] -> (Text -> [Pair]) -> Maybe Text -> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Text
d -> [Key
"description" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
d]) Maybe Text
functionDescription
[Pair] -> [Pair] -> [Pair]
forall a. [a] -> [a] -> [a]
++ [Pair]
-> (FunctionParameters -> [Pair])
-> Maybe FunctionParameters
-> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\FunctionParameters
p -> [Key
"parameters" Key -> FunctionParameters -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= FunctionParameters
p]) Maybe FunctionParameters
functionParameters
[Pair] -> [Pair] -> [Pair]
forall a. [a] -> [a] -> [a]
++ [Pair] -> (Bool -> [Pair]) -> Maybe Bool -> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Bool
s -> [Key
"strict" Key -> Bool -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Bool
s]) Maybe Bool
functionStrict
instance FromJSON FunctionDef where
parseJSON :: Value -> Parser FunctionDef
parseJSON = String
-> (Object -> Parser FunctionDef) -> Value -> Parser FunctionDef
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"Function" ((Object -> Parser FunctionDef) -> Value -> Parser FunctionDef)
-> (Object -> Parser FunctionDef) -> Value -> Parser FunctionDef
forall a b. (a -> b) -> a -> b
$ \Object
v ->
Text
-> Maybe Text
-> Maybe FunctionParameters
-> Maybe Bool
-> FunctionDef
FunctionDef
(Text
-> Maybe Text
-> Maybe FunctionParameters
-> Maybe Bool
-> FunctionDef)
-> Parser Text
-> Parser
(Maybe Text
-> Maybe FunctionParameters -> Maybe Bool -> FunctionDef)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"name"
Parser
(Maybe Text
-> Maybe FunctionParameters -> Maybe Bool -> FunctionDef)
-> Parser (Maybe Text)
-> Parser (Maybe FunctionParameters -> Maybe Bool -> FunctionDef)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"description"
Parser (Maybe FunctionParameters -> Maybe Bool -> FunctionDef)
-> Parser (Maybe FunctionParameters)
-> Parser (Maybe Bool -> FunctionDef)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe FunctionParameters)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"parameters"
Parser (Maybe Bool -> FunctionDef)
-> Parser (Maybe Bool) -> Parser FunctionDef
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"strict"
data FunctionParameters = FunctionParameters
{ FunctionParameters -> Text
parameterType :: Text
, FunctionParameters -> Maybe (Map Text FunctionParameters)
parameterProperties :: Maybe (HM.Map Text FunctionParameters)
, FunctionParameters -> Maybe [Text]
requiredParams :: Maybe [Text]
, FunctionParameters -> Maybe Bool
additionalProperties :: Maybe Bool
}
deriving (Int -> FunctionParameters -> ShowS
[FunctionParameters] -> ShowS
FunctionParameters -> String
(Int -> FunctionParameters -> ShowS)
-> (FunctionParameters -> String)
-> ([FunctionParameters] -> ShowS)
-> Show FunctionParameters
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FunctionParameters -> ShowS
showsPrec :: Int -> FunctionParameters -> ShowS
$cshow :: FunctionParameters -> String
show :: FunctionParameters -> String
$cshowList :: [FunctionParameters] -> ShowS
showList :: [FunctionParameters] -> ShowS
Show, FunctionParameters -> FunctionParameters -> Bool
(FunctionParameters -> FunctionParameters -> Bool)
-> (FunctionParameters -> FunctionParameters -> Bool)
-> Eq FunctionParameters
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FunctionParameters -> FunctionParameters -> Bool
== :: FunctionParameters -> FunctionParameters -> Bool
$c/= :: FunctionParameters -> FunctionParameters -> Bool
/= :: FunctionParameters -> FunctionParameters -> Bool
Eq)
instance ToJSON FunctionParameters where
toJSON :: FunctionParameters -> Value
toJSON FunctionParameters {Maybe Bool
Maybe [Text]
Maybe (Map Text FunctionParameters)
Text
parameterType :: FunctionParameters -> Text
parameterProperties :: FunctionParameters -> Maybe (Map Text FunctionParameters)
requiredParams :: FunctionParameters -> Maybe [Text]
additionalProperties :: FunctionParameters -> Maybe Bool
parameterType :: Text
parameterProperties :: Maybe (Map Text FunctionParameters)
requiredParams :: Maybe [Text]
additionalProperties :: Maybe Bool
..} =
[Pair] -> Value
object
[ Key
"type" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
parameterType
, Key
"properties" Key -> Maybe (Map Text FunctionParameters) -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Maybe (Map Text FunctionParameters)
parameterProperties
, Key
"required" Key -> Maybe [Text] -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Maybe [Text]
requiredParams
, Key
"additionalProperties" Key -> Maybe Bool -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Maybe Bool
additionalProperties
]
instance FromJSON FunctionParameters where
parseJSON :: Value -> Parser FunctionParameters
parseJSON = String
-> (Object -> Parser FunctionParameters)
-> Value
-> Parser FunctionParameters
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"parameters" ((Object -> Parser FunctionParameters)
-> Value -> Parser FunctionParameters)
-> (Object -> Parser FunctionParameters)
-> Value
-> Parser FunctionParameters
forall a b. (a -> b) -> a -> b
$ \Object
v ->
Text
-> Maybe (Map Text FunctionParameters)
-> Maybe [Text]
-> Maybe Bool
-> FunctionParameters
FunctionParameters
(Text
-> Maybe (Map Text FunctionParameters)
-> Maybe [Text]
-> Maybe Bool
-> FunctionParameters)
-> Parser Text
-> Parser
(Maybe (Map Text FunctionParameters)
-> Maybe [Text] -> Maybe Bool -> FunctionParameters)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"type"
Parser
(Maybe (Map Text FunctionParameters)
-> Maybe [Text] -> Maybe Bool -> FunctionParameters)
-> Parser (Maybe (Map Text FunctionParameters))
-> Parser (Maybe [Text] -> Maybe Bool -> FunctionParameters)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe (Map Text FunctionParameters))
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"properties"
Parser (Maybe [Text] -> Maybe Bool -> FunctionParameters)
-> Parser (Maybe [Text])
-> Parser (Maybe Bool -> FunctionParameters)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe [Text])
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"required"
Parser (Maybe Bool -> FunctionParameters)
-> Parser (Maybe Bool) -> Parser FunctionParameters
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"additionalProperties"
newtype ToolCall = ToolCall
{ ToolCall -> OutputFunction
outputFunction :: OutputFunction
}
deriving (Int -> ToolCall -> ShowS
[ToolCall] -> ShowS
ToolCall -> String
(Int -> ToolCall -> ShowS)
-> (ToolCall -> String) -> ([ToolCall] -> ShowS) -> Show ToolCall
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ToolCall -> ShowS
showsPrec :: Int -> ToolCall -> ShowS
$cshow :: ToolCall -> String
show :: ToolCall -> String
$cshowList :: [ToolCall] -> ShowS
showList :: [ToolCall] -> ShowS
Show, ToolCall -> ToolCall -> Bool
(ToolCall -> ToolCall -> Bool)
-> (ToolCall -> ToolCall -> Bool) -> Eq ToolCall
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ToolCall -> ToolCall -> Bool
== :: ToolCall -> ToolCall -> Bool
$c/= :: ToolCall -> ToolCall -> Bool
/= :: ToolCall -> ToolCall -> Bool
Eq)
data OutputFunction = OutputFunction
{ OutputFunction -> Text
outputFunctionName :: Text
, OutputFunction -> Map Text Value
arguments :: HM.Map Text Value
}
deriving (OutputFunction -> OutputFunction -> Bool
(OutputFunction -> OutputFunction -> Bool)
-> (OutputFunction -> OutputFunction -> Bool) -> Eq OutputFunction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: OutputFunction -> OutputFunction -> Bool
== :: OutputFunction -> OutputFunction -> Bool
$c/= :: OutputFunction -> OutputFunction -> Bool
/= :: OutputFunction -> OutputFunction -> Bool
Eq, Int -> OutputFunction -> ShowS
[OutputFunction] -> ShowS
OutputFunction -> String
(Int -> OutputFunction -> ShowS)
-> (OutputFunction -> String)
-> ([OutputFunction] -> ShowS)
-> Show OutputFunction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> OutputFunction -> ShowS
showsPrec :: Int -> OutputFunction -> ShowS
$cshow :: OutputFunction -> String
show :: OutputFunction -> String
$cshowList :: [OutputFunction] -> ShowS
showList :: [OutputFunction] -> ShowS
Show)
instance ToJSON OutputFunction where
toJSON :: OutputFunction -> Value
toJSON OutputFunction {Text
Map Text Value
outputFunctionName :: OutputFunction -> Text
arguments :: OutputFunction -> Map Text Value
outputFunctionName :: Text
arguments :: Map Text Value
..} =
[Pair] -> Value
object
[ Key
"name" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Text
outputFunctionName
, Key
"arguments" Key -> Map Text Value -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Map Text Value
arguments
]
instance FromJSON OutputFunction where
parseJSON :: Value -> Parser OutputFunction
parseJSON = String
-> (Object -> Parser OutputFunction)
-> Value
-> Parser OutputFunction
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"function" ((Object -> Parser OutputFunction)
-> Value -> Parser OutputFunction)
-> (Object -> Parser OutputFunction)
-> Value
-> Parser OutputFunction
forall a b. (a -> b) -> a -> b
$ \Object
v ->
Text -> Map Text Value -> OutputFunction
OutputFunction
(Text -> Map Text Value -> OutputFunction)
-> Parser Text -> Parser (Map Text Value -> OutputFunction)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"name"
Parser (Map Text Value -> OutputFunction)
-> Parser (Map Text Value) -> Parser OutputFunction
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Map Text Value)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"arguments"
instance ToJSON ToolCall where
toJSON :: ToolCall -> Value
toJSON ToolCall {OutputFunction
outputFunction :: ToolCall -> OutputFunction
outputFunction :: OutputFunction
..} = [Pair] -> Value
object [Key
"function" Key -> OutputFunction -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= OutputFunction
outputFunction]
instance FromJSON ToolCall where
parseJSON :: Value -> Parser ToolCall
parseJSON = String -> (Object -> Parser ToolCall) -> Value -> Parser ToolCall
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"tool_calls" ((Object -> Parser ToolCall) -> Value -> Parser ToolCall)
-> (Object -> Parser ToolCall) -> Value -> Parser ToolCall
forall a b. (a -> b) -> a -> b
$ \Object
v ->
OutputFunction -> ToolCall
ToolCall (OutputFunction -> ToolCall)
-> Parser OutputFunction -> Parser ToolCall
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser OutputFunction
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"function"