Class: Engram::Integrations::RubyLLM::MemoryChat

Inherits:
Object
  • Object
show all
Defined in:
lib/engram/integrations/ruby_llm.rb

Overview

Wraps a RubyLLM chat so every ‘ask` is preceded by recall + inject. Experimental in v0.1 — surface may change as the RubyLLM integration matures.

chat = Engram.with_memory(RubyLLM.chat, memory: current_user.memory)
chat.ask("why am I rate limited?")  # recall + inject happen automatically

Instance Method Summary collapse

Constructor Details

#initialize(chat, memory:, limit: Engram.config.default_limit) ⇒ MemoryChat

Returns a new instance of MemoryChat.



12
13
14
15
16
# File 'lib/engram/integrations/ruby_llm.rb', line 12

def initialize(chat, memory:, limit: Engram.config.default_limit)
  @chat = chat
  @memory = memory
  @limit = limit
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, **kwargs, &block) ⇒ Object



23
24
25
26
27
# File 'lib/engram/integrations/ruby_llm.rb', line 23

def method_missing(name, *args, **kwargs, &block)
  return super unless @chat.respond_to?(name)

  @chat.public_send(name, *args, **kwargs, &block)
end

Instance Method Details

#ask(message, **opts) ⇒ Object



18
19
20
21
# File 'lib/engram/integrations/ruby_llm.rb', line 18

def ask(message, **opts)
  augmented = @memory.inject_into(message.to_s, query: message.to_s, limit: @limit)
  @chat.ask(augmented, **opts)
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/engram/integrations/ruby_llm.rb', line 29

def respond_to_missing?(name, include_private = false)
  @chat.respond_to?(name, include_private) || super
end