-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Labels
enhancementNew feature or requestNew feature or request
Description
First off, love the library, thanks so much- SO clean!
I'm building a rails engine and use RubyLLM's activerecord integration so I create accompanying records. In order to get it to work, I had to set this in an initializer:
# Ensure AR chat models (acts_as_chat) can call `with_template`
if defined?(RubyLLM::ActiveRecord::ActsAs::ChatMethods)
mod = RubyLLM::ActiveRecord::ActsAs::ChatMethods
unless mod.instance_methods(false).include?(:with_template)
mod.module_eval do
# Return the underlying RubyLLM::Chat so chaining goes to it
def with_template(template_name, context = {})
to_llm.with_template(template_name, context)
end
end
end
end
and this on my Chat model thats using acts_as_chat:
def with_template(template_name, context = {})
to_llm.with_template(template_name, context)
end
FWIW, gpt5 says:
Clean, upstream fix in the gem:
- Add an AR integration module and include it when acts_as_chat is present:
- lib/ruby_llm/template/active_record.rb
module RubyLLM
module Template
module ActiveRecordChatExtension
def with_template(template_name, context = {})
to_llm.with_template(template_name, context)
self
end
end
end
end
- In the gem’s Railtie or main init:
initializer "ruby_llm_template.active_record" do
if defined?(RubyLLM::ActiveRecord::ActsAs::ChatMethods)
RubyLLM::ActiveRecord::ActsAs::ChatMethods.include(
RubyLLM::Template::ActiveRecordChatExtension
)
end
end
#This makes .with_template available on any AR chat model automatically, matching the Rails integration style of ruby_llm.
danielfriis
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request