Class: RubyConversations::ConversationManager

Overview

Manages a conversation, including message storage, relationships, and LLM integration.

Instance Attribute Summary collapse

Attributes included from RubyConversations::Concerns::ConversationChat

#tools_optional

Instance Method Summary collapse

Methods included from RubyConversations::Concerns::MessageProcessing

#process_message_prompts

Methods included from RubyConversations::Concerns::LlmCredentials

#configure_llm_credentials

Methods included from RubyConversations::Concerns::ConversationTemplates

#all_templates, #template_for

Methods included from RubyConversations::Concerns::ConversationMessages

#initialize_messages, #with_prompt, #with_prompts, #with_user_message

Methods included from RubyConversations::Concerns::ConversationChat

#call_llm, #enable_image_generation, #llm, #tool_calls?, #tool_names, #tools_configured?, #tools_required?, #validate_tool_calls

Constructor Details

#initialize(attributes = {}) ⇒ ConversationManager

Returns a new instance of ConversationManager.



18
19
20
21
# File 'lib/ruby_conversations/conversation_manager.rb', line 18

def initialize(attributes = {})
  setup_attributes(attributes)
  configure_llm_credentials
end

Instance Attribute Details

#conversationableObject

Returns the value of attribute conversationable.



15
16
17
# File 'lib/ruby_conversations/conversation_manager.rb', line 15

def conversationable
  @conversationable
end

#conversationable_idObject

Returns the value of attribute conversationable_id.



15
16
17
# File 'lib/ruby_conversations/conversation_manager.rb', line 15

def conversationable_id
  @conversationable_id
end

#conversationable_typeObject

Returns the value of attribute conversationable_type.



15
16
17
# File 'lib/ruby_conversations/conversation_manager.rb', line 15

def conversationable_type
  @conversationable_type
end

#created_atObject

Returns the value of attribute created_at.



15
16
17
# File 'lib/ruby_conversations/conversation_manager.rb', line 15

def created_at
  @created_at
end

#idObject

Returns the value of attribute id.



15
16
17
# File 'lib/ruby_conversations/conversation_manager.rb', line 15

def id
  @id
end

#messagesObject

Returns the value of attribute messages.



15
16
17
# File 'lib/ruby_conversations/conversation_manager.rb', line 15

def messages
  @messages
end

#toolObject

Returns the value of attribute tool.



15
16
17
# File 'lib/ruby_conversations/conversation_manager.rb', line 15

def tool
  @tool
end

#toolsObject

Returns the value of attribute tools.



15
16
17
# File 'lib/ruby_conversations/conversation_manager.rb', line 15

def tools
  @tools
end

#updated_atObject

Returns the value of attribute updated_at.



15
16
17
# File 'lib/ruby_conversations/conversation_manager.rb', line 15

def updated_at
  @updated_at
end

Instance Method Details

#chatObject



23
24
25
26
27
28
# File 'lib/ruby_conversations/conversation_manager.rb', line 23

def chat
  @chat ||= build_chat_with_caching
rescue RubyLLM::ModelNotFoundError
  RubyLLM.models.refresh!
  @chat ||= build_chat_with_caching
end

#conversation_attributes_for_storageObject



38
39
40
# File 'lib/ruby_conversations/conversation_manager.rb', line 38

def conversation_attributes_for_storage
  { ai_conversation: base_attributes.merge(relationship_attributes).merge(messages_attributes).compact }
end

#model_identifierObject



30
31
32
# File 'lib/ruby_conversations/conversation_manager.rb', line 30

def model_identifier
  @model_identifier ||= RubyConversations.configuration.default_llm_model
end

#providerObject



34
35
36
# File 'lib/ruby_conversations/conversation_manager.rb', line 34

def provider
  @provider ||= RubyConversations.configuration.default_llm_provider
end