Class: Ollama::StreamingObserver

Inherits:
Object
  • Object
show all
Defined in:
lib/ollama/streaming_observer.rb

Overview

Presentation-only streaming observer for agent loops. This object must never control tool execution or loop termination.

Defined Under Namespace

Classes: Event

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ StreamingObserver

Returns a new instance of StreamingObserver.



9
10
11
# File 'lib/ollama/streaming_observer.rb', line 9

def initialize(&block)
  @block = block
end

Instance Method Details

#emit(type, text: nil, name: nil, state: nil, data: nil) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/ollama/streaming_observer.rb', line 13

def emit(type, text: nil, name: nil, state: nil, data: nil)
  return unless @block

  @block.call(Event.new(type: type, text: text, name: name, state: state, data: data))
rescue StandardError
  # Observers must never break control flow.
  nil
end