{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}

module Data.Ollama.Common.Types where

import Data.Aeson
import Data.Text (Text)

data ModelDetails = ModelDetails
  { ModelDetails -> Maybe Text
parentModel :: Maybe Text
  , ModelDetails -> Text
format :: Text
  , ModelDetails -> Text
familiy :: 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"

newtype OllamaClient = OllamaClient
  { OllamaClient -> Text
host :: Text
  }
  deriving (OllamaClient -> OllamaClient -> Bool
(OllamaClient -> OllamaClient -> Bool)
-> (OllamaClient -> OllamaClient -> Bool) -> Eq OllamaClient
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: OllamaClient -> OllamaClient -> Bool
== :: OllamaClient -> OllamaClient -> Bool
$c/= :: OllamaClient -> OllamaClient -> Bool
/= :: OllamaClient -> OllamaClient -> Bool
Eq, Int -> OllamaClient -> ShowS
[OllamaClient] -> ShowS
OllamaClient -> String
(Int -> OllamaClient -> ShowS)
-> (OllamaClient -> String)
-> ([OllamaClient] -> ShowS)
-> Show OllamaClient
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> OllamaClient -> ShowS
showsPrec :: Int -> OllamaClient -> ShowS
$cshow :: OllamaClient -> String
show :: OllamaClient -> String
$cshowList :: [OllamaClient] -> ShowS
showList :: [OllamaClient] -> ShowS
Show)