Skip to content

Commit da64c9a

Browse files
fix acts_as delegation to return self instead of RubyLLM (#82)
1 parent 81e8d55 commit da64c9a

6 files changed

+1022
-7
lines changed

lib/ruby_llm/active_record/acts_as.rb

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module ActsAs
99
extend ActiveSupport::Concern
1010

1111
class_methods do # rubocop:disable Metrics/BlockLength
12-
def acts_as_chat(message_class: 'Message', tool_call_class: 'ToolCall') # rubocop:disable Metrics/MethodLength
12+
def acts_as_chat(message_class: 'Message', tool_call_class: 'ToolCall')
1313
include ChatMethods
1414

1515
@message_class = message_class.to_s
@@ -21,12 +21,6 @@ def acts_as_chat(message_class: 'Message', tool_call_class: 'ToolCall') # ruboco
2121
dependent: :destroy
2222

2323
delegate :complete,
24-
:with_tool,
25-
:with_tools,
26-
:with_model,
27-
:with_temperature,
28-
:on_new_message,
29-
:on_end_message,
3024
:add_message,
3125
to: :to_llm
3226
end
@@ -85,6 +79,36 @@ def to_llm
8579
.on_end_message { |msg| persist_message_completion(msg) }
8680
end
8781

82+
def with_tool(tool)
83+
to_llm.with_tool(tool)
84+
self
85+
end
86+
87+
def with_tools(*tools)
88+
to_llm.with_tools(*tools)
89+
self
90+
end
91+
92+
def with_model(model_id, provider: nil)
93+
to_llm.with_model(model_id, provider: provider)
94+
self
95+
end
96+
97+
def with_temperature(temperature)
98+
to_llm.with_temperature(temperature)
99+
self
100+
end
101+
102+
def on_new_message(&)
103+
to_llm.on_new_message(&)
104+
self
105+
end
106+
107+
def on_end_message(&)
108+
to_llm.on_end_message(&)
109+
self
110+
end
111+
88112
def ask(message, &)
89113
message = { role: :user, content: message }
90114
messages.create!(**message)

spec/fixtures/vcr_cassettes/activerecord_actsas_chainable_methods_persists_messages_after_chaining.yml

Lines changed: 234 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)