Slim::Client
HTTP client for Ollama API.
Supports both blocking and streaming requests.
Example
client = Slim::Client.new
# Blocking
response = client.generate("llama3.2:3b", "Hello!")
# Streaming
client.generate("llama3.2:3b", "Hello!") do |chunk|
print chunk
end
Constructors
Instance methods
Chat completion (blocking).
Uses the chat format with message history.
chat(model : String, messages : Array(Message), *, options : Options | Nil = nil, &block : String -> ) : Response
Chat completion with streaming.
Yields each text chunk as it's generated.
generate(model : String, prompt : String, *, system : String | Nil = nil, options : Options | Nil = nil, context : Array(Int32) | Nil = nil) : Response
Generate a completion (blocking).
Returns the full response after generation completes.
Parameters
model- Model name (e.g., "llama3.2:3b")prompt- The prompt textsystem- Optional system promptoptions- Sampling options (temperature, top_p, etc.)context- Context from previous generation (for conversation continuity)
generate(model : String, prompt : String, *, system : String | Nil = nil, options : Options | Nil = nil, context : Array(Int32) | Nil = nil, &block : String -> ) : Response
Generate a completion with streaming.
Yields each text chunk as it's generated. Returns the final response with stats.
host
Sourcetimeout
Sourcetimeout=(timeout : Time::Span)
Source