class Ollama::Handlers::Collector

# responses will contain an array of all response objects received
responses = ollama.generate(model: ‘llama3.1’, prompt: ‘Hello World’, &Collector)
@example Using the Collector handler to gather all responses
together rather than individually.
It is typically used when multiple responses are expected and need to be processed
and provide access to the complete collection of responses through its result method.
The Collector handler is designed to accumulate all responses during command execution
A handler that collects responses into an array and returns the array as the result.

def call(response)

Returns:
  • (self) - returns the handler instance itself after processing the response

Parameters:
  • response (Ollama::Response) -- the response object to be processed and stored
def call(response)
  @array << response
  self
end

def initialize(output: $stdout)

Parameters:
  • output (IO) -- the output stream to be used for handling responses,
def initialize(output: $stdout)
  super
  @array = []
end

def result

Returns:
  • (Array, nil) - the array of collected response objects,
def result
  @array
end