| Safe Haskell | Safe-Inferred |
|---|---|
| Language | GHC2021 |
Data.Ollama.Generate
Contents
Synopsis
- generate :: GenerateOps -> IO (Either String GenerateResponse)
- defaultGenerateOps :: GenerateOps
- data GenerateOps = GenerateOps {}
- data GenerateResponse = GenerateResponse {}
Generate Texts
generate :: GenerateOps -> IO (Either String GenerateResponse) Source #
Generate function that returns either a GenerateResponse type or an error message.
It takes a GenerateOps configuration and performs a request to the Ollama generate API.
Examples:
Basic usage without streaming:
let ops = GenerateOps
{ modelName = "llama3.2"
, prompt = "Tell me a joke."
, suffix = Nothing
, images = Nothing
, format = Nothing
, system = Nothing
, template = Nothing
, stream = Nothing
, raw = Nothing
, keepAlive = Nothing
}
result <- generate ops
case result of
Left errorMsg -> putStrLn ("Error: " ++ errorMsg)
Right response -> print responseUsage with streaming to print responses to the console:
void $
generate
defaultGenerateOps
{ modelName = "llama3.2"
, prompt = "what is functional programming?"
, stream = Just (T.putStr . response_, pure ())
}In this example, the first function in the $sel:stream:GenerateOps tuple processes each chunk of response by printing it,
and the second function is a simple no-op flush.generate :: GenerateOps -> IO (Either String GenerateResponse)
defaultGenerateOps :: GenerateOps Source #
A function to create a default GenerateOps type with preset values.
Example:
let ops = defaultGenerateOps generate ops
This will generate a response using the default configuration.
data GenerateOps Source #
Input type for generate functions. This data type represents all possible configurations that you can pass to the Ollama generate API.
Example:
let ops = GenerateOps
{ modelName = "llama3.2"
, prompt = "What is the meaning of life?"
, suffix = Nothing
, images = Nothing
, format = Just "text"
, system = Nothing
, template = Nothing
, stream = Nothing
, raw = Just False
, keepAlive = Just "yes"
}Constructors
| GenerateOps | |
Fields
| |
Instances
| ToJSON GenerateOps Source # | |
Defined in Data.Ollama.Generate Methods toJSON :: GenerateOps -> Value # toEncoding :: GenerateOps -> Encoding # toJSONList :: [GenerateOps] -> Value # toEncodingList :: [GenerateOps] -> Encoding # omitField :: GenerateOps -> Bool # | |
| Show GenerateOps Source # | |
Defined in Data.Ollama.Generate Methods showsPrec :: Int -> GenerateOps -> ShowS # show :: GenerateOps -> String # showList :: [GenerateOps] -> ShowS # | |
| Eq GenerateOps Source # | |
Defined in Data.Ollama.Generate | |
data GenerateResponse Source #
Result type for generate function containing the model's response and meta-information.
Constructors
| GenerateResponse | |
Fields
| |
Instances
| FromJSON GenerateResponse Source # | |
Defined in Data.Ollama.Generate Methods parseJSON :: Value -> Parser GenerateResponse # parseJSONList :: Value -> Parser [GenerateResponse] # | |
| Show GenerateResponse Source # | |
Defined in Data.Ollama.Generate Methods showsPrec :: Int -> GenerateResponse -> ShowS # show :: GenerateResponse -> String # showList :: [GenerateResponse] -> ShowS # | |
| Eq GenerateResponse Source # | |
Defined in Data.Ollama.Generate Methods (==) :: GenerateResponse -> GenerateResponse -> Bool # (/=) :: GenerateResponse -> GenerateResponse -> Bool # | |