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.
Instance Method Summary collapse
- #call(res) ⇒ Object
-
#initialize(hooks) ⇒ ChatStreamProcessor
constructor
A new instance of ChatStreamProcessor.
Constructor Details
#initialize(hooks) ⇒ ChatStreamProcessor
Returns a new instance of ChatStreamProcessor.
8 9 10 |
# File 'lib/ollama/client/chat_stream_processor.rb', line 8 def initialize(hooks) @hooks = hooks end |
Instance Method Details
#call(res) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/ollama/client/chat_stream_processor.rb', line 12 def call(res) reset_accumulators! buffer = +"" res.read_body { |chunk| drain_chunk(buffer, chunk) } build_result end |