Class: LLM::Anthropic::StreamParser
- Inherits:
-
Object
- Object
- LLM::Anthropic::StreamParser
- Defined in:
- lib/llm/providers/anthropic/stream_parser.rb
Instance Attribute Summary collapse
-
#body ⇒ Hash
readonly
Returns the fully constructed response body.
Instance Method Summary collapse
-
#free ⇒ void
Frees internal parser state used during streaming.
- #initialize(stream) ⇒ LLM::Anthropic::StreamParser constructor
- #parse!(chunk) ⇒ LLM::Anthropic::StreamParser
Constructor Details
#initialize(stream) ⇒ LLM::Anthropic::StreamParser
16 17 18 19 20 21 22 |
# File 'lib/llm/providers/anthropic/stream_parser.rb', line 16 def initialize(stream) @body = {"role" => "assistant", "content" => []} @stream = stream @can_emit_content = stream.respond_to?(:on_content) @can_emit_tool_call = stream.respond_to?(:on_tool_call) @can_push_content = stream.respond_to?(:<<) end |
Instance Attribute Details
#body ⇒ Hash (readonly)
Returns the fully constructed response body
10 11 12 |
# File 'lib/llm/providers/anthropic/stream_parser.rb', line 10 def body @body end |
Instance Method Details
#free ⇒ void
This method returns an undefined value.
Frees internal parser state used during streaming.
34 35 |
# File 'lib/llm/providers/anthropic/stream_parser.rb', line 34 def free end |
#parse!(chunk) ⇒ LLM::Anthropic::StreamParser
27 28 29 |
# File 'lib/llm/providers/anthropic/stream_parser.rb', line 27 def parse!(chunk) tap { merge!(chunk) } end |