class Ollama::Handlers::Print

ollama.generate(model: ‘llama3.1’, prompt: ‘Hello World’, &Print)
@example Using the Print handler with a generate command
ollama.chat(model: ‘llama3.1’, messages:, &Print)
@example Using the Print handler with a chat command
where immediate feedback is desired.
displays it directly, making it useful for interactive terminal applications
commands to a specified output stream. It extracts content from responses and
The Print handler is designed to output text responses from Ollama API
A handler that prints response content to the output stream.

def call(response)

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

Parameters:
  • response (Ollama::Response) -- the response object to be processed
def call(response)
  if content = response.response || response.message&.content
    @output.print content
  end
  response.done and @output.puts
  self
end

def initialize(output: $stdout)

Parameters:
  • output (IO) -- the output stream to be used for handling responses, defaults to $stdout
def initialize(output: $stdout)
  super
  @output.sync = true
end