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.
130 131 132 133 134 135 136 |
# File 'lib/open_router/streaming_client.rb', line 130 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
139 140 141 142 143 144 145 |
# File 'lib/open_router/streaming_client.rb', line 139 def add_chunk(chunk) @chunks << chunk @first_chunk ||= chunk @last_chunk = chunk process_chunk(chunk) end |
#build_response ⇒ Object
Build final response object
148 149 150 151 152 153 154 155 |
# File 'lib/open_router/streaming_client.rb', line 148 def build_response return nil if @chunks.empty? # Build the complete response structure response_data = build_response_structure Response.new(response_data) end |