Class: LLM::MessageQueue

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/llm/message_queue.rb

Overview

LLM::MessageQueue 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

Constructor Details

#initialize(provider) ⇒ LLM::MessageQueue

Parameters:



14
15
16
17
18
# File 'lib/llm/message_queue.rb', line 14

def initialize(provider)
  @provider = provider
  @pending = []
  @completed = []
end

Instance Method Details

#<<(item) ⇒ void Also known as: push

This method returns an undefined value.

Parameters:

  • item ([LLM::Message, Hash])

    A message and its parameters



34
35
36
37
# File 'lib/llm/message_queue.rb', line 34

def <<(item)
  @pending << item
  self
end

#each {|LLM::Message| ... } ⇒ void

This method returns an undefined value.

Yields:

  • (LLM::Message)

    Yields each message in the conversation thread

Raises:

  • (NotImplementedError)

    When the method is not implemented by a subclass



25
26
27
28
# File 'lib/llm/message_queue.rb', line 25

def each
  complete! unless @pending.empty?
  @completed.each { yield(_1) }
end