Class: Ollama::GenerateStreamHandler

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

Overview

Consumes NDJSON lines from an Ollama /api/generate streaming HTTP body.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response, hooks, accumulator) ⇒ GenerateStreamHandler

Returns a new instance of GenerateStreamHandler.



12
13
14
15
16
# File 'lib/ollama/generate_stream_handler.rb', line 12

def initialize(response, hooks, accumulator)
  @response = response
  @hooks = hooks
  @accumulator = accumulator
end

Class Method Details

.call(response, hooks, accumulator) ⇒ Object



8
9
10
# File 'lib/ollama/generate_stream_handler.rb', line 8

def self.call(response, hooks, accumulator)
  new(response, hooks, accumulator).call
end

Instance Method Details

#callObject



18
19
20
21
# File 'lib/ollama/generate_stream_handler.rb', line 18

def call
  buffer = +""
  @response.read_body { |chunk| drain_chunk(buffer, chunk) }
end