Class: Ollama::Client::ChatStreamProcessor
- Inherits:
-
Object
- Object
- Ollama::Client::ChatStreamProcessor
- Defined in:
- lib/ollama/client/chat_stream_processor.rb
Overview
Consumes an NDJSON /api/chat stream, aggregates message fields, and dispatches hooks. Line buffering matches Ollama::GenerateStreamHandler so both NDJSON parsers stay parallel.
Class Method Summary collapse
-
.call(res, hooks, provider: nil) ⇒ Hash
Convenience class method to process a stream.
Instance Method Summary collapse
-
#call(res) ⇒ Hash
The aggregated result.
-
#initialize(hooks, provider: nil) ⇒ ChatStreamProcessor
constructor
A new instance of ChatStreamProcessor.
Constructor Details
#initialize(hooks, provider: nil) ⇒ ChatStreamProcessor
Returns a new instance of ChatStreamProcessor.
19 20 21 22 |
# File 'lib/ollama/client/chat_stream_processor.rb', line 19 def initialize(hooks, provider: nil) @hooks = hooks @provider = provider end |
Class Method Details
.call(res, hooks, provider: nil) ⇒ Hash
Convenience class method to process a stream.
13 14 15 |
# File 'lib/ollama/client/chat_stream_processor.rb', line 13 def self.call(res, hooks, provider: nil) new(hooks, provider: provider).call(res) end |
Instance Method Details
#call(res) ⇒ Hash
Returns the aggregated result.
26 27 28 29 30 31 32 33 |
# File 'lib/ollama/client/chat_stream_processor.rb', line 26 def call(res) reset_accumulators! buffer = +"" res.read_body { |chunk| drain_chunk(buffer, chunk) } build_result end |