Class: RubynCode::LLM::Adapters::AnthropicStreaming
- Inherits:
-
Object
- Object
- RubynCode::LLM::Adapters::AnthropicStreaming
- Includes:
- JsonParsing
- Defined in:
- lib/rubyn_code/llm/adapters/anthropic_streaming.rb
Overview
SSE streaming parser for the Anthropic Messages API.
Handles Anthropic-specific event types: message_start, content_block_start, content_block_delta, content_block_stop, message_delta, message_stop, error. Accumulates content blocks and produces a normalized LLM::Response via #finalize.
Defined Under Namespace
Classes: Event, OverloadError, ParseError
Constant Summary collapse
- HANDLERS =
{ 'message_start' => :handle_message_start, 'content_block_start' => :handle_content_block_start, 'content_block_delta' => :handle_content_block_delta, 'content_block_stop' => :handle_content_block_stop, 'message_delta' => :handle_message_delta, 'message_stop' => :handle_message_stop, 'error' => :handle_error }.freeze
Instance Method Summary collapse
- #feed(chunk) ⇒ Object
- #finalize ⇒ Object
-
#initialize(&block) ⇒ AnthropicStreaming
constructor
A new instance of AnthropicStreaming.
Constructor Details
#initialize(&block) ⇒ AnthropicStreaming
Returns a new instance of AnthropicStreaming.
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rubyn_code/llm/adapters/anthropic_streaming.rb', line 31 def initialize(&block) @callback = block @buffer = +'' @response_id = nil @content_blocks = [] @current_block_index = nil @current_text = +'' @current_thinking_text = +'' @current_tool_input_json = +'' @stop_reason = nil @stop_details = nil @usage = nil end |
Instance Method Details
#feed(chunk) ⇒ Object
45 46 47 48 |
# File 'lib/rubyn_code/llm/adapters/anthropic_streaming.rb', line 45 def feed(chunk) @buffer << chunk consume_events end |