github crmne/ruby_llm 1.7.1

19 hours ago

RubyLLM 1.7.1: Generator Fixes & Enhanced Upgrades 🔧

Bug fixes and improvements for Rails generators, with special focus on namespaced models and automatic migration of existing apps.

🐛 Critical Fixes

Namespaced Model Support

The generators now properly handle namespaced models throughout:

# Now works correctly with namespaced models
rails g ruby_llm:install chat:LLM::Chat message:LLM::Message model:LLM::Model
rails g ruby_llm:upgrade_to_v1_7 chat:Assistant::Chat message:Assistant::Message

Fixed issues:

  • Invalid table names like :assistant/chats:assistant_chats
  • Model migration failures with namespaced models ✅
  • Foreign key migrations now handle custom table names correctly ✅
  • Namespace modules automatically created with table_name_prefix

✨ Automatic acts_as API Migration

The upgrade generator now automatically converts from the old acts_as API to the new one:

# BEFORE running upgrade generator (OLD API)
class Conversation < ApplicationRecord
  acts_as_chat message_class: 'ChatMessage', tool_call_class: 'AIToolCall'
end

class ChatMessage < ApplicationRecord
  acts_as_message chat_class: 'Conversation', chat_foreign_key: 'conversation_id'
end

# AFTER running upgrade generator (NEW API)
class Conversation < ApplicationRecord
  acts_as_chat messages: :chat_messages, message_class: 'ChatMessage', model: :model
end

class ChatMessage < ApplicationRecord
  acts_as_message chat: :conversation, chat_class: 'Conversation', tool_calls: :ai_tool_calls, tool_call_class: 'AIToolCall', model: :model
end

The generator:

  • Converts from old *_class parameters to new association-based parameters
  • Adds the new model association to all models
  • Preserves custom class names and associations
  • Handles both simple and complex/namespaced models

No manual changes needed - the generator handles the complete API migration automatically! 🎉

🏗️ Generator Architecture Improvements

DRY Generator Code

Created a shared GeneratorHelpers module to eliminate duplication between generators:

  • Shared acts_as_* declaration logic
  • Common database detection methods
  • Unified namespace handling
  • Consistent table name generation

Better Rails Conventions

  • Generators reorganized into proper subdirectories
  • Private methods moved to conventional location
  • Follows Rails generator best practices
  • Cleaner, more maintainable code

🚨 Troubleshooting Helper

Added clear troubleshooting for the most common upgrade issue:

# If you see: "undefined local variable or method 'acts_as_model'"
# Add this to config/application.rb BEFORE your Application class:

RubyLLM.configure do |config|
  config.use_new_acts_as = true
end

module YourApp
  class Application < Rails::Application
    # ...
  end
end

The upgrade generator now shows this warning proactively and documentation includes a dedicated troubleshooting section.

🔄 Migration Improvements

  • Fixed instance variable usage in migration templates
  • Better handling of existing Model tables during upgrade
  • Initializer creation if missing during upgrade
  • Simplified upgrade instructions pointing to migration guide

Installation

gem 'ruby_llm', '1.7.1'

Upgrading from 1.7.0

Just update your gem - all fixes are backward compatible:

bundle update ruby_llm

Upgrading from 1.6.x

Use the improved upgrade generator:

rails generate ruby_llm:upgrade_to_v1_7
rails db:migrate

The generator now handles everything automatically, including updating your model files!

Merged PRs

  • Fix namespaced model table names in upgrade generator by @willcosgrove in #398
  • Fix namespaced models in Model migration and foreign key migrations by @willcosgrove in #399

New Contributors

Full Changelog: 1.7.0...1.7.1

Don't miss a new ruby_llm release

NewReleases is sending notifications on new releases.