Class: OpenRouter::ResponseAccumulator
- Inherits:
-
Object
- Object
- OpenRouter::ResponseAccumulator
- Defined in:
- lib/open_router/streaming_client.rb
Overview
Accumulates streaming chunks to reconstruct a complete response
Instance Method Summary collapse
-
#add_chunk(chunk) ⇒ Object
Add a streaming chunk.
-
#build_response ⇒ Object
Build final response object.
-
#initialize ⇒ ResponseAccumulator
constructor
A new instance of ResponseAccumulator.
Constructor Details
#initialize ⇒ ResponseAccumulator
Returns a new instance of ResponseAccumulator.
149 150 151 152 153 154 155 |
# File 'lib/open_router/streaming_client.rb', line 149 def initialize @chunks = [] @content_parts = [] @tool_calls = {} @first_chunk = nil @last_chunk = nil end |
Instance Method Details
#add_chunk(chunk) ⇒ Object
Add a streaming chunk
158 159 160 161 162 163 164 |
# File 'lib/open_router/streaming_client.rb', line 158 def add_chunk(chunk) @chunks << chunk @first_chunk ||= chunk @last_chunk = chunk process_chunk(chunk) end |
#build_response ⇒ Object
Build final response object
167 168 169 170 171 172 173 174 |
# File 'lib/open_router/streaming_client.rb', line 167 def build_response return nil if @chunks.empty? # Build the complete response structure response_data = build_response_structure Response.new(response_data) end |