Class: Ollama::Handlers::Print
- Inherits:
-
Object
- Object
- Ollama::Handlers::Print
- Includes:
- Concern
- Defined in:
- lib/ollama/handlers/print.rb
Overview
A handler that prints response content to the output stream.
The Print handler is designed to output text responses from Ollama API commands to a specified output stream. It extracts content from responses and displays it directly, making it useful for interactive terminal applications where immediate feedback is desired.
Instance Attribute Summary
Attributes included from Concern
Instance Method Summary collapse
-
#call(response) ⇒ self
The call method processes a response by printing its content to the output stream.
-
#initialize(output: $stdout) ⇒ Print
constructor
The initialize method sets up a new handler instance with the specified output destination and enables synchronous writing to the output stream.
Methods included from Concern
Constructor Details
#initialize(output: $stdout) ⇒ Print
The initialize method sets up a new handler instance with the specified output destination and enables synchronous writing to the output stream.
20 21 22 23 |
# File 'lib/ollama/handlers/print.rb', line 20 def initialize(output: $stdout) super @output.sync = true end |
Instance Method Details
#call(response) ⇒ self
The call method processes a response by printing its content to the output stream.
This method extracts content from the response object and prints it to the configured output stream. If the response indicates completion, it adds a newline character after printing. The method returns the handler instance itself to allow for method chaining.
36 37 38 39 40 41 42 |
# File 'lib/ollama/handlers/print.rb', line 36 def call(response) if content = response.response || response.&.content @output.print content end response.done and @output.puts self end |