Class: RubyLLM::Template::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/ruby_llm/template/install_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_root ⇒ Object



12
13
14
# File 'lib/generators/ruby_llm/template/install_generator.rb', line 12

def self.source_root
  @source_root ||= File.expand_path("templates", __dir__)
end

Instance Method Details

#create_initializer ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/generators/ruby_llm/template/install_generator.rb', line 16

def create_initializer
  create_file "config/initializers/ruby_llm_template.rb", "    # frozen_string_literal: true\n\n    RubyLLM::Template.configure do |config|\n      # Set the directory where your prompts are stored\n      # Default: Rails.root.join(\"app\", \"prompts\")\n      # config.template_directory = Rails.root.join(\"app\", \"prompts\")\n    end\n  RUBY\nend\n"

#create_template_directory ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/generators/ruby_llm/template/install_generator.rb', line 28

def create_template_directory
  empty_directory "app/prompts"

  create_file "app/prompts/.keep", ""

  # Create an example template
  create_example_template
end

#show_readme ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/generators/ruby_llm/template/install_generator.rb', line 37

def show_readme
  say "\n    RubyLLM Template has been installed!\n\n    Prompts directory: app/prompts/\n    Configuration: config/initializers/ruby_llm_template.rb\n\n    Example usage:\n      RubyLLM.chat.with_template(:extract_metadata, document: @document).complete\n\n    Template structure:\n      app/prompts/extract_metadata/\n        \u251C\u2500\u2500 system.txt.erb    # System message\n        \u251C\u2500\u2500 user.txt.erb      # User prompt\n        \u251C\u2500\u2500 assistant.txt.erb # Assistant message (optional)\n        \u2514\u2500\u2500 schema.rb         # RubyLLM::Schema definition (optional)\n\n    Get started by creating your first template!\n  MESSAGE\nend\n"