Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 31 additions & 7 deletions lib/ruby_llm/active_record/acts_as.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module ActsAs
extend ActiveSupport::Concern

class_methods do # rubocop:disable Metrics/BlockLength
def acts_as_chat(message_class: 'Message', tool_call_class: 'ToolCall') # rubocop:disable Metrics/MethodLength
def acts_as_chat(message_class: 'Message', tool_call_class: 'ToolCall')
include ChatMethods

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

delegate :complete,
:with_tool,
:with_tools,
:with_model,
:with_temperature,
:on_new_message,
:on_end_message,
:add_message,
to: :to_llm
end
Expand Down Expand Up @@ -85,6 +79,36 @@ def to_llm
.on_end_message { |msg| persist_message_completion(msg) }
end

def with_tool(tool)
to_llm.with_tool(tool)
self
end

def with_tools(*tools)
to_llm.with_tools(*tools)
self
end

def with_model(model_id, provider: nil)
to_llm.with_model(model_id, provider: provider)
self
end

def with_temperature(temperature)
to_llm.with_temperature(temperature)
self
end

def on_new_message(&)
to_llm.on_new_message(&)
self
end

def on_end_message(&)
to_llm.on_end_message(&)
self
end

def ask(message, &)
message = { role: :user, content: message }
messages.create!(**message)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading