Class: LLM::Stream::IO
- Inherits:
-
LLM::Stream
- Object
- LLM::Stream
- LLM::Stream::IO
- Defined in:
- lib/llm/stream/io.rb
Overview
An LLM::Stream::IO wraps an object that responds to
#<< and forwards streamed content to it.
This enables any object that implements #<< - such as an IO, StringIO,
or a custom logger - to be used as a stream target. try
creates instances of this class automatically when given an IO-like
object.
Instance Method Summary collapse
-
#<<(content) ⇒ void
Forwards streamed content to the wrapped IO object.
-
#initialize(io) ⇒ IO
constructor
A new instance of IO.
-
#on_content(content) ⇒ void
Writes a chunk of content to the wrapped IO object.
Methods inherited from LLM::Stream
#__find__, #ctx, #enabled?, #extra, #on_compaction, #on_compaction_finish, #on_reasoning_content, #on_tool_call, #on_tool_return, #on_transform, #on_transform_finish, #queue, try, #wait
Constructor Details
#initialize(io) ⇒ IO
Returns a new instance of IO.
21 22 23 |
# File 'lib/llm/stream/io.rb', line 21 def initialize(io) @io = io end |
Instance Method Details
#<<(content) ⇒ void
This method returns an undefined value.
Forwards streamed content to the wrapped IO object.
Redefined here because alias_method in the parent class
captures the base implementation, not the overridden one.
39 40 41 |
# File 'lib/llm/stream/io.rb', line 39 def <<(content) on_content(content) end |
#on_content(content) ⇒ void
This method returns an undefined value.
Writes a chunk of content to the wrapped IO object.
29 30 31 |
# File 'lib/llm/stream/io.rb', line 29 def on_content(content) @io << content end |