class RubyLLM::Generators::InstallGenerator
Generator for RubyLLM Rails models and migrations
Public Class Methods
# File lib/generators/ruby_llm/install/install_generator.rb, line 26 def self.next_migration_number(dirname) ::ActiveRecord::Generators::Base.next_migration_number(dirname) end
Public Instance Methods
# File lib/generators/ruby_llm/install/install_generator.rb, line 58 def create_convention_directories %w[agents tools schemas prompts].each do |name| empty_directory "app/#{name}" create_file "app/#{name}/.gitkeep" unless File.exist?(Rails.root.join("app/#{name}/.gitkeep")) end end
Source
# File lib/generators/ruby_llm/install/install_generator.rb, line 54 def create_initializer template 'initializer.rb.tt', 'config/initializers/ruby_llm.rb' end
Source
# File lib/generators/ruby_llm/install/install_generator.rb, line 30 def create_migration_files migration_template 'create_chats_migration.rb.tt', "db/migrate/create_#{chat_table_name}.rb" migration_template 'create_messages_migration.rb.tt', "db/migrate/create_#{message_table_name}.rb" migration_template 'create_tool_calls_migration.rb.tt', "db/migrate/create_#{tool_call_table_name}.rb" migration_template 'create_models_migration.rb.tt', "db/migrate/create_#{model_table_name}.rb" migration_template 'add_references_to_chats_tool_calls_and_messages_migration.rb.tt', 'db/migrate/add_references_to_' \ "#{chat_table_name}_#{tool_call_table_name}_and_#{message_table_name}.rb" end
Source
# File lib/generators/ruby_llm/install/install_generator.rb, line 44 def create_model_files create_namespace_modules template 'chat_model.rb.tt', "app/models/#{chat_model_name.underscore}.rb" template 'message_model.rb.tt', "app/models/#{message_model_name.underscore}.rb" template 'tool_call_model.rb.tt', "app/models/#{tool_call_model_name.underscore}.rb" template 'model_model.rb.tt', "app/models/#{model_model_name.underscore}.rb" end
Source
# File lib/generators/ruby_llm/install/install_generator.rb, line 65 def install_active_storage return if options[:skip_active_storage] say ' Installing ActiveStorage for file attachments...', :cyan rails_command 'active_storage:install' end
Source
# File lib/generators/ruby_llm/install/install_generator.rb, line 72 def show_install_info say "\n ✅ RubyLLM installed!", :green say ' ✅ ActiveStorage configured for file attachments support', :green unless options[:skip_active_storage] say "\n Next steps:", :yellow say ' 1. Run: bin/rails db:migrate' say ' 2. Run: bin/rails ruby_llm:load_models' say ' 3. Set your API keys in config/initializers/ruby_llm.rb' say " 4. Start chatting: #{chat_model_name}.create!(model: 'gpt-5-nano').ask('Hello!')" say " 5. Optional UI: #{chat_ui_generator_command}" if options[:skip_active_storage] say "\n 📎 Note: ActiveStorage was skipped", :yellow say ' File attachments won\'t work without ActiveStorage.' say ' To enable later:' say ' 1. Run: bin/rails active_storage:install && bin/rails db:migrate' say " 2. Add to your #{message_model_name} model: has_many_attached :attachments" end say "\n 📚 Documentation: https://rubyllm.com", :cyan say "\n ❤️ Love RubyLLM?", :magenta say ' • ⭐ Star on GitHub: https://github.com/crmne/ruby_llm' say ' • 🐦 Follow for updates: https://x.com/paolino' say "\n" end