Class: LLM::LazyConversation
- Inherits:
-
Object
- Object
- LLM::LazyConversation
- Defined in:
- lib/llm/lazy_conversation.rb
Overview
LLM::LazyConversation provides a conversation object that allows input prompts to be queued and only sent to the LLM when a response is needed.
Instance Attribute Summary collapse
- #messages ⇒ LLM::MessageQueue readonly
Instance Method Summary collapse
- #chat(prompt, role = :user, **params) ⇒ LLM::Conversation
-
#initialize(provider, params = {}) ⇒ LazyConversation
constructor
A new instance of LazyConversation.
-
#last_message(role: @provider.assistant_role) ⇒ LLM::Message
(also: #recent_message)
The last message for the given role.
Constructor Details
#initialize(provider, params = {}) ⇒ LazyConversation
Returns a new instance of LazyConversation.
27 28 29 30 31 |
# File 'lib/llm/lazy_conversation.rb', line 27 def initialize(provider, params = {}) @provider = provider @params = params @messages = LLM::MessageQueue.new(provider) end |
Instance Attribute Details
#messages ⇒ LLM::MessageQueue (readonly)
22 23 24 |
# File 'lib/llm/lazy_conversation.rb', line 22 def @messages end |
Instance Method Details
#chat(prompt, role = :user, **params) ⇒ LLM::Conversation
36 37 38 |
# File 'lib/llm/lazy_conversation.rb', line 36 def chat(prompt, role = :user, **params) tap { @messages << [prompt, role, @params.merge(params)] } end |
#last_message(role: @provider.assistant_role) ⇒ LLM::Message Also known as: recent_message
Returns The last message for the given role.
46 47 48 |
# File 'lib/llm/lazy_conversation.rb', line 46 def (role: @provider.assistant_role) .reverse_each.find { _1.role == role.to_s } end |