class

Slim::Client

Inherits Reference < Object

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

new(host : String = DEFAULT_HOST, timeout : Time::Span = 5.minutes)
Source

Instance methods

chat(model : String, messages : Array(Message), *, options : Options | Nil = nil) : Response

Chat completion (blocking).

Uses the chat format with message history.

Source
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.

Source
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 text
  • system - Optional system prompt
  • options - Sampling options (temperature, top_p, etc.)
  • context - Context from previous generation (for conversation continuity)
Source
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.

Source
has_model?(name : String) : Bool

Check if a model is available locally.

Source
host
Source
host=(host : String)
Source
list_models

List available models.

Source
ping

Check if Ollama is reachable.

Source
pull(model : String) : Bool

Pull a model (blocking).

Downloads the model if not present.

Source
timeout
Source
timeout=(timeout : Time::Span)
Source