Class: LLM::Buffer
Overview
LLM::Buffer provides an Enumerable object that yields each message in a conversation on-demand, and only sends a request to the LLM when a response is needed.
Instance Method Summary collapse
- #<<(item) ⇒ void (also: #push)
- #each {|LLM::Message| ... } ⇒ void
-
#find ⇒ LLM::Message?
Find a message (in descending order).
- #initialize(provider) ⇒ LLM::Buffer constructor
- #inspect ⇒ String
-
#unread ⇒ Array<LLM::Message>
Returns an array of unread messages.
Constructor Details
#initialize(provider) ⇒ LLM::Buffer
15 16 17 18 19 |
# File 'lib/llm/buffer.rb', line 15 def initialize(provider) @provider = provider @pending = [] @completed = [] end |
Instance Method Details
#<<(item) ⇒ void Also known as: push
This method returns an undefined value.
55 56 57 58 |
# File 'lib/llm/buffer.rb', line 55 def <<(item) @pending << item self end |
#each {|LLM::Message| ... } ⇒ void
This method returns an undefined value.
26 27 28 29 30 31 32 33 |
# File 'lib/llm/buffer.rb', line 26 def each(...) if block_given? empty! unless @pending.empty? @completed.each { yield(_1) } else enum_for(:each, ...) end end |
#find ⇒ LLM::Message?
Find a message (in descending order)
47 48 49 |
# File 'lib/llm/buffer.rb', line 47 def find(...) reverse_each.find(...) end |
#inspect ⇒ String
63 64 65 66 |
# File 'lib/llm/buffer.rb', line 63 def inspect "#<#{self.class.name}:0x#{object_id.to_s(16)} " \ "completed_count=#{@completed.size} pending_count=#{@pending.size}>" end |
#unread ⇒ Array<LLM::Message>
Returns an array of unread messages
40 41 42 |
# File 'lib/llm/buffer.rb', line 40 def unread reject(&:read?) end |