{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}

{- |
Module      : Data.Ollama.Show
Copyright   : (c) 2025 Tushar Adhatrao
License     : MIT
Maintainer  : Tushar Adhatrao <tusharadhatrao@gmail.com>
Stability   : experimental
Description : Functionality for retrieving detailed information about models in the Ollama client.

This module provides functions to fetch detailed information about a specific model on the Ollama server.
It includes both high-level ('showModel', 'showModelM') and low-level ('showModelOps', 'showModelOpsM') APIs
for retrieving model details, with support for verbose output. The operation is performed via a POST request
to the "/api//show" endpoint, returning a 'ShowModelResponse' containing comprehensive model metadata.

The 'ShowModelOps' type configures the request, and 'ShowModelResponse' and 'ShowModelInfo' represent the
response structure. The module also re-exports 'CT.ModelDetails' for completeness.

Note: Verbose mode parsing is currently not fully supported.

Example:

>>> showModel "gemma3"
Right (ShowModelResponse {modelFile = "...", ...})

@since 1.0.0.0
-}
module Data.Ollama.Show
  ( -- * Show Model Info API
    showModel
  , showModelM
  , showModelOps
  , showModelOpsM

    -- * Response Types
  , ShowModelResponse (..)
  , ShowModelInfo (..)
  , CT.ModelDetails (..)
  ) where

import Control.Monad.IO.Class (MonadIO (liftIO))
import Data.Aeson
import Data.Ollama.Common.Config (OllamaConfig)
import Data.Ollama.Common.Error (OllamaError)
import Data.Ollama.Common.Types qualified as CT
import Data.Ollama.Common.Utils (commonNonStreamingHandler, withOllamaRequest)
import Data.Text (Text)
import GHC.Generics
import GHC.Int (Int64)

-- | Configuration options for requesting model information.
data ShowModelOps = ShowModelOps
  { ShowModelOps -> Text
name :: !Text
  -- ^ The name of the model to query (e.g., "gemma3").
  , ShowModelOps -> Maybe Bool
verbose :: !(Maybe Bool)
  -- ^ Optional flag to request verbose output. Note: Verbose mode parsing is currently incomplete.
  }
  deriving (Int -> ShowModelOps -> ShowS
[ShowModelOps] -> ShowS
ShowModelOps -> String
(Int -> ShowModelOps -> ShowS)
-> (ShowModelOps -> String)
-> ([ShowModelOps] -> ShowS)
-> Show ShowModelOps
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ShowModelOps -> ShowS
showsPrec :: Int -> ShowModelOps -> ShowS
$cshow :: ShowModelOps -> String
show :: ShowModelOps -> String
$cshowList :: [ShowModelOps] -> ShowS
showList :: [ShowModelOps] -> ShowS
Show, ShowModelOps -> ShowModelOps -> Bool
(ShowModelOps -> ShowModelOps -> Bool)
-> (ShowModelOps -> ShowModelOps -> Bool) -> Eq ShowModelOps
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ShowModelOps -> ShowModelOps -> Bool
== :: ShowModelOps -> ShowModelOps -> Bool
$c/= :: ShowModelOps -> ShowModelOps -> Bool
/= :: ShowModelOps -> ShowModelOps -> Bool
Eq, (forall x. ShowModelOps -> Rep ShowModelOps x)
-> (forall x. Rep ShowModelOps x -> ShowModelOps)
-> Generic ShowModelOps
forall x. Rep ShowModelOps x -> ShowModelOps
forall x. ShowModelOps -> Rep ShowModelOps x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ShowModelOps -> Rep ShowModelOps x
from :: forall x. ShowModelOps -> Rep ShowModelOps x
$cto :: forall x. Rep ShowModelOps x -> ShowModelOps
to :: forall x. Rep ShowModelOps x -> ShowModelOps
Generic, [ShowModelOps] -> Value
[ShowModelOps] -> Encoding
ShowModelOps -> Bool
ShowModelOps -> Value
ShowModelOps -> Encoding
(ShowModelOps -> Value)
-> (ShowModelOps -> Encoding)
-> ([ShowModelOps] -> Value)
-> ([ShowModelOps] -> Encoding)
-> (ShowModelOps -> Bool)
-> ToJSON ShowModelOps
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: ShowModelOps -> Value
toJSON :: ShowModelOps -> Value
$ctoEncoding :: ShowModelOps -> Encoding
toEncoding :: ShowModelOps -> Encoding
$ctoJSONList :: [ShowModelOps] -> Value
toJSONList :: [ShowModelOps] -> Value
$ctoEncodingList :: [ShowModelOps] -> Encoding
toEncodingList :: [ShowModelOps] -> Encoding
$comitField :: ShowModelOps -> Bool
omitField :: ShowModelOps -> Bool
ToJSON)

-- | Response structure for model information.
data ShowModelResponse = ShowModelResponse
  { ShowModelResponse -> Text
modelFile :: !Text
  -- ^ The content of the model's Modelfile.
  , ShowModelResponse -> Maybe Text
parameters :: !(Maybe Text)
  -- ^ Optional model parameters (e.g., temperature settings).
  , ShowModelResponse -> Maybe Text
template :: !(Maybe Text)
  -- ^ Optional template used for the model.
  , ShowModelResponse -> ModelDetails
details :: !CT.ModelDetails
  -- ^ General details about the model (e.g., format, family).
  , ShowModelResponse -> ShowModelInfo
modelInfo :: !ShowModelInfo
  -- ^ Detailed technical information about the model.
  , ShowModelResponse -> Maybe Text
license :: !(Maybe Text)
  -- ^ Optional license information for the model.
  --
  -- @since 0.2.0.0
  , ShowModelResponse -> Maybe [Text]
capabilities :: Maybe [Text]
  -- ^ Optional list of model capabilities.
  --
  -- @since 0.2.0.0
  }
  deriving (Int -> ShowModelResponse -> ShowS
[ShowModelResponse] -> ShowS
ShowModelResponse -> String
(Int -> ShowModelResponse -> ShowS)
-> (ShowModelResponse -> String)
-> ([ShowModelResponse] -> ShowS)
-> Show ShowModelResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ShowModelResponse -> ShowS
showsPrec :: Int -> ShowModelResponse -> ShowS
$cshow :: ShowModelResponse -> String
show :: ShowModelResponse -> String
$cshowList :: [ShowModelResponse] -> ShowS
showList :: [ShowModelResponse] -> ShowS
Show, ShowModelResponse -> ShowModelResponse -> Bool
(ShowModelResponse -> ShowModelResponse -> Bool)
-> (ShowModelResponse -> ShowModelResponse -> Bool)
-> Eq ShowModelResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ShowModelResponse -> ShowModelResponse -> Bool
== :: ShowModelResponse -> ShowModelResponse -> Bool
$c/= :: ShowModelResponse -> ShowModelResponse -> Bool
/= :: ShowModelResponse -> ShowModelResponse -> Bool
Eq)

-- | Detailed technical information about a model.
data ShowModelInfo = ShowModelInfo
  { ShowModelInfo -> Maybe Text
generalArchitecture :: !(Maybe Text)
  -- ^ The architecture of the model (e.g., "llama").
  , ShowModelInfo -> Maybe Int
generalFileType :: !(Maybe Int)
  -- ^ The file type identifier for the model.
  , ShowModelInfo -> Maybe Int64
generalParameterCount :: !(Maybe Int64)
  -- ^ The number of parameters in the model.
  , ShowModelInfo -> Maybe Int
generalQuantizationVersion :: !(Maybe Int)
  -- ^ The quantization version used by the model.
  , ShowModelInfo -> Maybe Int
llamaAttentionHeadCount :: !(Maybe Int)
  -- ^ Number of attention heads in the LLaMA model.
  , ShowModelInfo -> Maybe Int
llamaAttentionHeadCountKV :: !(Maybe Int)
  -- ^ Number of key-value attention heads in the LLaMA model.
  , ShowModelInfo -> Maybe Float
llamaAttentionLayerNormRMSEpsilon :: !(Maybe Float)
  -- ^ RMS epsilon for layer normalization in the LLaMA model.
  , ShowModelInfo -> Maybe Int
llamaBlockCount :: !(Maybe Int)
  -- ^ Number of blocks in the LLaMA model.
  , ShowModelInfo -> Maybe Int
llamaContextLength :: !(Maybe Int)
  -- ^ Context length supported by the LLaMA model.
  , ShowModelInfo -> Maybe Int
llamaEmbeddingLength :: !(Maybe Int)
  -- ^ Embedding length used by the LLaMA model.
  , ShowModelInfo -> Maybe Int
llamaFeedForwardLength :: !(Maybe Int)
  -- ^ Feed-forward layer length in the LLaMA model.
  , ShowModelInfo -> Maybe Int
llamaRopeDimensionCount :: !(Maybe Int)
  -- ^ RoPE dimension count in the LLaMA model.
  , ShowModelInfo -> Maybe Int64
llamaRopeFreqBase :: !(Maybe Int64)
  -- ^ Base frequency for RoPE in the LLaMA model.
  , ShowModelInfo -> Maybe Int64
llamaVocabSize :: !(Maybe Int64)
  -- ^ Vocabulary size of the LLaMA model.
  , ShowModelInfo -> Maybe Int
tokenizerGgmlBosToken_id :: !(Maybe Int)
  -- ^ BOS (beginning of sequence) token ID for the GGML tokenizer.
  , ShowModelInfo -> Maybe Int
tokenizerGgmlEosToken_id :: !(Maybe Int)
  -- ^ EOS (end of sequence) token ID for the GGML tokenizer.
  , ShowModelInfo -> Maybe [Text]
tokenizerGgmlMerges :: !(Maybe [Text])
  -- ^ List of merges for the GGML tokenizer.
  , ShowModelInfo -> Maybe Text
tokenizerGgmlMode :: !(Maybe Text)
  -- ^ Mode of the GGML tokenizer.
  , ShowModelInfo -> Maybe Text
tokenizerGgmlPre :: !(Maybe Text)
  -- ^ Pre-tokenization configuration for the GGML tokenizer.
  , ShowModelInfo -> Maybe [Text]
tokenizerGgmlTokenType :: !(Maybe [Text])
  -- ^ Token type information for the GGML tokenizer.
  , ShowModelInfo -> Maybe [Text]
tokenizerGgmlTokens :: !(Maybe [Text])
  -- ^ List of tokens for the GGML tokenizer.
  }
  deriving (Int -> ShowModelInfo -> ShowS
[ShowModelInfo] -> ShowS
ShowModelInfo -> String
(Int -> ShowModelInfo -> ShowS)
-> (ShowModelInfo -> String)
-> ([ShowModelInfo] -> ShowS)
-> Show ShowModelInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ShowModelInfo -> ShowS
showsPrec :: Int -> ShowModelInfo -> ShowS
$cshow :: ShowModelInfo -> String
show :: ShowModelInfo -> String
$cshowList :: [ShowModelInfo] -> ShowS
showList :: [ShowModelInfo] -> ShowS
Show, ShowModelInfo -> ShowModelInfo -> Bool
(ShowModelInfo -> ShowModelInfo -> Bool)
-> (ShowModelInfo -> ShowModelInfo -> Bool) -> Eq ShowModelInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ShowModelInfo -> ShowModelInfo -> Bool
== :: ShowModelInfo -> ShowModelInfo -> Bool
$c/= :: ShowModelInfo -> ShowModelInfo -> Bool
/= :: ShowModelInfo -> ShowModelInfo -> Bool
Eq)

-- | JSON parsing instance for 'ShowModelResponse'.
instance FromJSON ShowModelResponse where
  parseJSON :: Value -> Parser ShowModelResponse
parseJSON = String
-> (Object -> Parser ShowModelResponse)
-> Value
-> Parser ShowModelResponse
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"ShowModelResponse" ((Object -> Parser ShowModelResponse)
 -> Value -> Parser ShowModelResponse)
-> (Object -> Parser ShowModelResponse)
-> Value
-> Parser ShowModelResponse
forall a b. (a -> b) -> a -> b
$ \Object
v ->
    Text
-> Maybe Text
-> Maybe Text
-> ModelDetails
-> ShowModelInfo
-> Maybe Text
-> Maybe [Text]
-> ShowModelResponse
ShowModelResponse
      (Text
 -> Maybe Text
 -> Maybe Text
 -> ModelDetails
 -> ShowModelInfo
 -> Maybe Text
 -> Maybe [Text]
 -> ShowModelResponse)
-> Parser Text
-> Parser
     (Maybe Text
      -> Maybe Text
      -> ModelDetails
      -> ShowModelInfo
      -> Maybe Text
      -> Maybe [Text]
      -> ShowModelResponse)
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
"modelfile"
      Parser
  (Maybe Text
   -> Maybe Text
   -> ModelDetails
   -> ShowModelInfo
   -> Maybe Text
   -> Maybe [Text]
   -> ShowModelResponse)
-> Parser (Maybe Text)
-> Parser
     (Maybe Text
      -> ModelDetails
      -> ShowModelInfo
      -> Maybe Text
      -> Maybe [Text]
      -> ShowModelResponse)
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
"parameters"
      Parser
  (Maybe Text
   -> ModelDetails
   -> ShowModelInfo
   -> Maybe Text
   -> Maybe [Text]
   -> ShowModelResponse)
-> Parser (Maybe Text)
-> Parser
     (ModelDetails
      -> ShowModelInfo
      -> Maybe Text
      -> Maybe [Text]
      -> ShowModelResponse)
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
"template"
      Parser
  (ModelDetails
   -> ShowModelInfo
   -> Maybe Text
   -> Maybe [Text]
   -> ShowModelResponse)
-> Parser ModelDetails
-> Parser
     (ShowModelInfo -> Maybe Text -> Maybe [Text] -> ShowModelResponse)
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 ModelDetails
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"details"
      Parser
  (ShowModelInfo -> Maybe Text -> Maybe [Text] -> ShowModelResponse)
-> Parser ShowModelInfo
-> Parser (Maybe Text -> Maybe [Text] -> ShowModelResponse)
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 ShowModelInfo
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"model_info"
      Parser (Maybe Text -> Maybe [Text] -> ShowModelResponse)
-> Parser (Maybe Text)
-> Parser (Maybe [Text] -> ShowModelResponse)
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
"license"
      Parser (Maybe [Text] -> ShowModelResponse)
-> Parser (Maybe [Text]) -> Parser ShowModelResponse
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
"capabilities"

-- | JSON parsing instance for 'ShowModelInfo'.
instance FromJSON ShowModelInfo where
  parseJSON :: Value -> Parser ShowModelInfo
parseJSON = String
-> (Object -> Parser ShowModelInfo)
-> Value
-> Parser ShowModelInfo
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"ModelInfo" ((Object -> Parser ShowModelInfo) -> Value -> Parser ShowModelInfo)
-> (Object -> Parser ShowModelInfo)
-> Value
-> Parser ShowModelInfo
forall a b. (a -> b) -> a -> b
$ \Object
v ->
    Maybe Text
-> Maybe Int
-> Maybe Int64
-> Maybe Int
-> Maybe Int
-> Maybe Int
-> Maybe Float
-> Maybe Int
-> Maybe Int
-> Maybe Int
-> Maybe Int
-> Maybe Int
-> Maybe Int64
-> Maybe Int64
-> Maybe Int
-> Maybe Int
-> Maybe [Text]
-> Maybe Text
-> Maybe Text
-> Maybe [Text]
-> Maybe [Text]
-> ShowModelInfo
ShowModelInfo
      (Maybe Text
 -> Maybe Int
 -> Maybe Int64
 -> Maybe Int
 -> Maybe Int
 -> Maybe Int
 -> Maybe Float
 -> Maybe Int
 -> Maybe Int
 -> Maybe Int
 -> Maybe Int
 -> Maybe Int
 -> Maybe Int64
 -> Maybe Int64
 -> Maybe Int
 -> Maybe Int
 -> Maybe [Text]
 -> Maybe Text
 -> Maybe Text
 -> Maybe [Text]
 -> Maybe [Text]
 -> ShowModelInfo)
-> Parser (Maybe Text)
-> Parser
     (Maybe Int
      -> Maybe Int64
      -> Maybe Int
      -> Maybe Int
      -> Maybe Int
      -> Maybe Float
      -> Maybe Int
      -> Maybe Int
      -> Maybe Int
      -> Maybe Int
      -> Maybe Int
      -> Maybe Int64
      -> Maybe Int64
      -> Maybe Int
      -> Maybe Int
      -> Maybe [Text]
      -> Maybe Text
      -> Maybe Text
      -> Maybe [Text]
      -> Maybe [Text]
      -> ShowModelInfo)
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 (Maybe a)
.:? Key
"general.architecture"
      Parser
  (Maybe Int
   -> Maybe Int64
   -> Maybe Int
   -> Maybe Int
   -> Maybe Int
   -> Maybe Float
   -> Maybe Int
   -> Maybe Int
   -> Maybe Int
   -> Maybe Int
   -> Maybe Int
   -> Maybe Int64
   -> Maybe Int64
   -> Maybe Int
   -> Maybe Int
   -> Maybe [Text]
   -> Maybe Text
   -> Maybe Text
   -> Maybe [Text]
   -> Maybe [Text]
   -> ShowModelInfo)
-> Parser (Maybe Int)
-> Parser
     (Maybe Int64
      -> Maybe Int
      -> Maybe Int
      -> Maybe Int
      -> Maybe Float
      -> Maybe Int
      -> Maybe Int
      -> Maybe Int
      -> Maybe Int
      -> Maybe Int
      -> Maybe Int64
      -> Maybe Int64
      -> Maybe Int
      -> Maybe Int
      -> Maybe [Text]
      -> Maybe Text
      -> Maybe Text
      -> Maybe [Text]
      -> Maybe [Text]
      -> ShowModelInfo)
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 Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"general.file_type"
      Parser
  (Maybe Int64
   -> Maybe Int
   -> Maybe Int
   -> Maybe Int
   -> Maybe Float
   -> Maybe Int
   -> Maybe Int
   -> Maybe Int
   -> Maybe Int
   -> Maybe Int
   -> Maybe Int64
   -> Maybe Int64
   -> Maybe Int
   -> Maybe Int
   -> Maybe [Text]
   -> Maybe Text
   -> Maybe Text
   -> Maybe [Text]
   -> Maybe [Text]
   -> ShowModelInfo)
-> Parser (Maybe Int64)
-> Parser
     (Maybe Int
      -> Maybe Int
      -> Maybe Int
      -> Maybe Float
      -> Maybe Int
      -> Maybe Int
      -> Maybe Int
      -> Maybe Int
      -> Maybe Int
      -> Maybe Int64
      -> Maybe Int64
      -> Maybe Int
      -> Maybe Int
      -> Maybe [Text]
      -> Maybe Text
      -> Maybe Text
      -> Maybe [Text]
      -> Maybe [Text]
      -> ShowModelInfo)
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
"general.parameter_count"
      Parser
  (Maybe Int
   -> Maybe Int
   -> Maybe Int
   -> Maybe Float
   -> Maybe Int
   -> Maybe Int
   -> Maybe Int
   -> Maybe Int
   -> Maybe Int
   -> Maybe Int64
   -> Maybe Int64
   -> Maybe Int
   -> Maybe Int
   -> Maybe [Text]
   -> Maybe Text
   -> Maybe Text
   -> Maybe [Text]
   -> Maybe [Text]
   -> ShowModelInfo)
-> Parser (Maybe Int)
-> Parser
     (Maybe Int
      -> Maybe Int
      -> Maybe Float
      -> Maybe Int
      -> Maybe Int
      -> Maybe Int
      -> Maybe Int
      -> Maybe Int
      -> Maybe Int64
      -> Maybe Int64
      -> Maybe Int
      -> Maybe Int
      -> Maybe [Text]
      -> Maybe Text
      -> Maybe Text
      -> Maybe [Text]
      -> Maybe [Text]
      -> ShowModelInfo)
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 Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"general.quantization_version"
      Parser
  (Maybe Int
   -> Maybe Int
   -> Maybe Float
   -> Maybe Int
   -> Maybe Int
   -> Maybe Int
   -> Maybe Int
   -> Maybe Int
   -> Maybe Int64
   -> Maybe Int64
   -> Maybe Int
   -> Maybe Int
   -> Maybe [Text]
   -> Maybe Text
   -> Maybe Text
   -> Maybe [Text]
   -> Maybe [Text]
   -> ShowModelInfo)
-> Parser (Maybe Int)
-> Parser
     (Maybe Int
      -> Maybe Float
      -> Maybe Int
      -> Maybe Int
      -> Maybe Int
      -> Maybe Int
      -> Maybe Int
      -> Maybe Int64
      -> Maybe Int64
      -> Maybe Int
      -> Maybe Int
      -> Maybe [Text]
      -> Maybe Text
      -> Maybe Text
      -> Maybe [Text]
      -> Maybe [Text]
      -> ShowModelInfo)
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 Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"llama.attention.head_count"
      Parser
  (Maybe Int
   -> Maybe Float
   -> Maybe Int
   -> Maybe Int
   -> Maybe Int
   -> Maybe Int
   -> Maybe Int
   -> Maybe Int64
   -> Maybe Int64
   -> Maybe Int
   -> Maybe Int
   -> Maybe [Text]
   -> Maybe Text
   -> Maybe Text
   -> Maybe [Text]
   -> Maybe [Text]
   -> ShowModelInfo)
-> Parser (Maybe Int)
-> Parser
     (Maybe Float
      -> Maybe Int
      -> Maybe Int
      -> Maybe Int
      -> Maybe Int
      -> Maybe Int
      -> Maybe Int64
      -> Maybe Int64
      -> Maybe Int
      -> Maybe Int
      -> Maybe [Text]
      -> Maybe Text
      -> Maybe Text
      -> Maybe [Text]
      -> Maybe [Text]
      -> ShowModelInfo)
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 Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"llama.attention.head_count_kv"
      Parser
  (Maybe Float
   -> Maybe Int
   -> Maybe Int
   -> Maybe Int
   -> Maybe Int
   -> Maybe Int
   -> Maybe Int64
   -> Maybe Int64
   -> Maybe Int
   -> Maybe Int
   -> Maybe [Text]
   -> Maybe Text
   -> Maybe Text
   -> Maybe [Text]
   -> Maybe [Text]
   -> ShowModelInfo)
-> Parser (Maybe Float)
-> Parser
     (Maybe Int
      -> Maybe Int
      -> Maybe Int
      -> Maybe Int
      -> Maybe Int
      -> Maybe Int64
      -> Maybe Int64
      -> Maybe Int
      -> Maybe Int
      -> Maybe [Text]
      -> Maybe Text
      -> Maybe Text
      -> Maybe [Text]
      -> Maybe [Text]
      -> ShowModelInfo)
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 Float)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"llama.attention.layer_norm_rms_epsilon"
      Parser
  (Maybe Int
   -> Maybe Int
   -> Maybe Int
   -> Maybe Int
   -> Maybe Int
   -> Maybe Int64
   -> Maybe Int64
   -> Maybe Int
   -> Maybe Int
   -> Maybe [Text]
   -> Maybe Text
   -> Maybe Text
   -> Maybe [Text]
   -> Maybe [Text]
   -> ShowModelInfo)
-> Parser (Maybe Int)
-> Parser
     (Maybe Int
      -> Maybe Int
      -> Maybe Int
      -> Maybe Int
      -> Maybe Int64
      -> Maybe Int64
      -> Maybe Int
      -> Maybe Int
      -> Maybe [Text]
      -> Maybe Text
      -> Maybe Text
      -> Maybe [Text]
      -> Maybe [Text]
      -> ShowModelInfo)
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 Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"llama.block_count"
      Parser
  (Maybe Int
   -> Maybe Int
   -> Maybe Int
   -> Maybe Int
   -> Maybe Int64
   -> Maybe Int64
   -> Maybe Int
   -> Maybe Int
   -> Maybe [Text]
   -> Maybe Text
   -> Maybe Text
   -> Maybe [Text]
   -> Maybe [Text]
   -> ShowModelInfo)
-> Parser (Maybe Int)
-> Parser
     (Maybe Int
      -> Maybe Int
      -> Maybe Int
      -> Maybe Int64
      -> Maybe Int64
      -> Maybe Int
      -> Maybe Int
      -> Maybe [Text]
      -> Maybe Text
      -> Maybe Text
      -> Maybe [Text]
      -> Maybe [Text]
      -> ShowModelInfo)
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 Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"llama.context_length"
      Parser
  (Maybe Int
   -> Maybe Int
   -> Maybe Int
   -> Maybe Int64
   -> Maybe Int64
   -> Maybe Int
   -> Maybe Int
   -> Maybe [Text]
   -> Maybe Text
   -> Maybe Text
   -> Maybe [Text]
   -> Maybe [Text]
   -> ShowModelInfo)
-> Parser (Maybe Int)
-> Parser
     (Maybe Int
      -> Maybe Int
      -> Maybe Int64
      -> Maybe Int64
      -> Maybe Int
      -> Maybe Int
      -> Maybe [Text]
      -> Maybe Text
      -> Maybe Text
      -> Maybe [Text]
      -> Maybe [Text]
      -> ShowModelInfo)
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 Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"llama.embedding_length"
      Parser
  (Maybe Int
   -> Maybe Int
   -> Maybe Int64
   -> Maybe Int64
   -> Maybe Int
   -> Maybe Int
   -> Maybe [Text]
   -> Maybe Text
   -> Maybe Text
   -> Maybe [Text]
   -> Maybe [Text]
   -> ShowModelInfo)
-> Parser (Maybe Int)
-> Parser
     (Maybe Int
      -> Maybe Int64
      -> Maybe Int64
      -> Maybe Int
      -> Maybe Int
      -> Maybe [Text]
      -> Maybe Text
      -> Maybe Text
      -> Maybe [Text]
      -> Maybe [Text]
      -> ShowModelInfo)
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 Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"llama.feed_forward_length"
      Parser
  (Maybe Int
   -> Maybe Int64
   -> Maybe Int64
   -> Maybe Int
   -> Maybe Int
   -> Maybe [Text]
   -> Maybe Text
   -> Maybe Text
   -> Maybe [Text]
   -> Maybe [Text]
   -> ShowModelInfo)
-> Parser (Maybe Int)
-> Parser
     (Maybe Int64
      -> Maybe Int64
      -> Maybe Int
      -> Maybe Int
      -> Maybe [Text]
      -> Maybe Text
      -> Maybe Text
      -> Maybe [Text]
      -> Maybe [Text]
      -> ShowModelInfo)
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 Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"llama.rope.dimension_count"
      Parser
  (Maybe Int64
   -> Maybe Int64
   -> Maybe Int
   -> Maybe Int
   -> Maybe [Text]
   -> Maybe Text
   -> Maybe Text
   -> Maybe [Text]
   -> Maybe [Text]
   -> ShowModelInfo)
-> Parser (Maybe Int64)
-> Parser
     (Maybe Int64
      -> Maybe Int
      -> Maybe Int
      -> Maybe [Text]
      -> Maybe Text
      -> Maybe Text
      -> Maybe [Text]
      -> Maybe [Text]
      -> ShowModelInfo)
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
"llama.rope.freq_base"
      Parser
  (Maybe Int64
   -> Maybe Int
   -> Maybe Int
   -> Maybe [Text]
   -> Maybe Text
   -> Maybe Text
   -> Maybe [Text]
   -> Maybe [Text]
   -> ShowModelInfo)
-> Parser (Maybe Int64)
-> Parser
     (Maybe Int
      -> Maybe Int
      -> Maybe [Text]
      -> Maybe Text
      -> Maybe Text
      -> Maybe [Text]
      -> Maybe [Text]
      -> ShowModelInfo)
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
"llama.vocab_size"
      Parser
  (Maybe Int
   -> Maybe Int
   -> Maybe [Text]
   -> Maybe Text
   -> Maybe Text
   -> Maybe [Text]
   -> Maybe [Text]
   -> ShowModelInfo)
-> Parser (Maybe Int)
-> Parser
     (Maybe Int
      -> Maybe [Text]
      -> Maybe Text
      -> Maybe Text
      -> Maybe [Text]
      -> Maybe [Text]
      -> ShowModelInfo)
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 Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"tokenizer.ggml.bos_token_id"
      Parser
  (Maybe Int
   -> Maybe [Text]
   -> Maybe Text
   -> Maybe Text
   -> Maybe [Text]
   -> Maybe [Text]
   -> ShowModelInfo)
-> Parser (Maybe Int)
-> Parser
     (Maybe [Text]
      -> Maybe Text
      -> Maybe Text
      -> Maybe [Text]
      -> Maybe [Text]
      -> ShowModelInfo)
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 Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"tokenizer.ggml.eos_token_id"
      Parser
  (Maybe [Text]
   -> Maybe Text
   -> Maybe Text
   -> Maybe [Text]
   -> Maybe [Text]
   -> ShowModelInfo)
-> Parser (Maybe [Text])
-> Parser
     (Maybe Text
      -> Maybe Text -> Maybe [Text] -> Maybe [Text] -> ShowModelInfo)
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
"tokenizer.ggml.merges"
      Parser
  (Maybe Text
   -> Maybe Text -> Maybe [Text] -> Maybe [Text] -> ShowModelInfo)
-> Parser (Maybe Text)
-> Parser
     (Maybe Text -> Maybe [Text] -> Maybe [Text] -> ShowModelInfo)
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
"tokenizer.ggml.model"
      Parser
  (Maybe Text -> Maybe [Text] -> Maybe [Text] -> ShowModelInfo)
-> Parser (Maybe Text)
-> Parser (Maybe [Text] -> Maybe [Text] -> ShowModelInfo)
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
"tokenizer.ggml.pre"
      Parser (Maybe [Text] -> Maybe [Text] -> ShowModelInfo)
-> Parser (Maybe [Text]) -> Parser (Maybe [Text] -> ShowModelInfo)
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
"tokenizer.ggml.token_type"
      Parser (Maybe [Text] -> ShowModelInfo)
-> Parser (Maybe [Text]) -> Parser ShowModelInfo
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
"tokenizer.ggml.tokens"

{- | Retrieves model information with configuration options.

Sends a POST request to the "/api//show" endpoint to fetch detailed information about
the specified model. Supports verbose output if 'verbose' is 'Just True' (though verbose
mode parsing is currently incomplete). Returns 'Right' with a 'ShowModelResponse' on
success or 'Left' with an 'OllamaError' on failure.
-}
showModelOps ::
  -- | Model name
  Text ->
  -- | Optional verbose flag
  Maybe Bool ->
  -- | Optional 'OllamaConfig' (defaults to 'defaultOllamaConfig' if 'Nothing')
  Maybe OllamaConfig ->
  IO (Either OllamaError ShowModelResponse)
showModelOps :: Text
-> Maybe Bool
-> Maybe OllamaConfig
-> IO (Either OllamaError ShowModelResponse)
showModelOps Text
modelName Maybe Bool
verbose_ Maybe OllamaConfig
mbConfig = do
  Text
-> ByteString
-> Maybe ShowModelOps
-> Maybe OllamaConfig
-> (Response BodyReader
    -> IO (Either OllamaError ShowModelResponse))
-> IO (Either OllamaError ShowModelResponse)
forall payload response.
ToJSON payload =>
Text
-> ByteString
-> Maybe payload
-> Maybe OllamaConfig
-> (Response BodyReader -> IO (Either OllamaError response))
-> IO (Either OllamaError response)
withOllamaRequest
    Text
"/api//show"
    ByteString
"POST"
    ( ShowModelOps -> Maybe ShowModelOps
forall a. a -> Maybe a
Just (ShowModelOps -> Maybe ShowModelOps)
-> ShowModelOps -> Maybe ShowModelOps
forall a b. (a -> b) -> a -> b
$
        ShowModelOps
          { name :: Text
name = Text
modelName
          , verbose :: Maybe Bool
verbose = Maybe Bool
verbose_
          }
    )
    Maybe OllamaConfig
mbConfig
    Response BodyReader -> IO (Either OllamaError ShowModelResponse)
forall a.
FromJSON a =>
Response BodyReader -> IO (Either OllamaError a)
commonNonStreamingHandler

{- | Simplified API for retrieving model information.

A higher-level function that fetches model information using default settings for
verbose output and Ollama configuration. Suitable for basic use cases.
-}
showModel ::
  -- | Model name
  Text ->
  IO (Either OllamaError ShowModelResponse)
showModel :: Text -> IO (Either OllamaError ShowModelResponse)
showModel Text
modelName =
  Text
-> Maybe Bool
-> Maybe OllamaConfig
-> IO (Either OllamaError ShowModelResponse)
showModelOps Text
modelName Maybe Bool
forall a. Maybe a
Nothing Maybe OllamaConfig
forall a. Maybe a
Nothing

{- | MonadIO version of 'showModel' for use in monadic contexts.

Lifts the 'showModel' function into a 'MonadIO' context, allowing it to be used in
monadic computations.
-}
showModelM :: MonadIO m => Text -> m (Either OllamaError ShowModelResponse)
showModelM :: forall (m :: * -> *).
MonadIO m =>
Text -> m (Either OllamaError ShowModelResponse)
showModelM Text
t = IO (Either OllamaError ShowModelResponse)
-> m (Either OllamaError ShowModelResponse)
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Either OllamaError ShowModelResponse)
 -> m (Either OllamaError ShowModelResponse))
-> IO (Either OllamaError ShowModelResponse)
-> m (Either OllamaError ShowModelResponse)
forall a b. (a -> b) -> a -> b
$ Text -> IO (Either OllamaError ShowModelResponse)
showModel Text
t

{- | MonadIO version of 'showModelOps' for use in monadic contexts.

Lifts the 'showModelOps' function into a 'MonadIO' context, allowing it to be used in
monadic computations with full configuration options.
-}
showModelOpsM ::
  MonadIO m =>
  Text ->
  Maybe Bool ->
  Maybe OllamaConfig ->
  m (Either OllamaError ShowModelResponse)
showModelOpsM :: forall (m :: * -> *).
MonadIO m =>
Text
-> Maybe Bool
-> Maybe OllamaConfig
-> m (Either OllamaError ShowModelResponse)
showModelOpsM Text
t Maybe Bool
v Maybe OllamaConfig
mbCfg = IO (Either OllamaError ShowModelResponse)
-> m (Either OllamaError ShowModelResponse)
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Either OllamaError ShowModelResponse)
 -> m (Either OllamaError ShowModelResponse))
-> IO (Either OllamaError ShowModelResponse)
-> m (Either OllamaError ShowModelResponse)
forall a b. (a -> b) -> a -> b
$ Text
-> Maybe Bool
-> Maybe OllamaConfig
-> IO (Either OllamaError ShowModelResponse)
showModelOps Text
t Maybe Bool
v Maybe OllamaConfig
mbCfg