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
# File 'lib/llm/message_queue.rb', line 14

def initialize(provider)
  @provider = provider
  @messages = []
end

Instance Method Details

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

This method returns an undefined value.

Parameters:

  • message (Object)

    A message to add to the conversation thread



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

def <<(message)
  @messages << message
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



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

def each
  @messages = complete! unless @messages.grep(LLM::Message).size == @messages.size
  @messages.each { yield(_1) }
end