diff --git a/lib/ruby_llm/active_record/chat_methods.rb b/lib/ruby_llm/active_record/chat_methods.rb index 173f14bf6..c1d3a3fd1 100644 --- a/lib/ruby_llm/active_record/chat_methods.rb +++ b/lib/ruby_llm/active_record/chat_methods.rb @@ -73,6 +73,13 @@ def resolve_model_from_strings # rubocop:disable Metrics/PerceivedComplexity @provider_string = nil end + def populate_messages + @chat.reset_messages! + messages_association.each do |msg| + @chat.add_message(msg.to_llm) + end + end + public def to_llm @@ -81,12 +88,7 @@ def to_llm model: model_record.model_id, provider: model_record.provider.to_sym ) - @chat.reset_messages! - - messages_association.each do |msg| - @chat.add_message(msg.to_llm) - end - + populate_messages setup_persistence_callbacks end