Class: RubyLlmAgents::ImageAnalyzerGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/ruby_llm_agents/image_analyzer_generator.rb

Overview

ImageAnalyzer generator for creating new image analyzers

Usage:

rails generate ruby_llm_agents:image_analyzer Product
rails generate ruby_llm_agents:image_analyzer Content --model gpt-4o --analysis_type detailed
rails generate ruby_llm_agents:image_analyzer Photo --extract_colors --detect_objects

This will create:

- app/agents/images/product_analyzer.rb

Instance Method Summary collapse

Instance Method Details

#create_image_analyzer_fileObject



53
54
55
56
# File 'lib/generators/ruby_llm_agents/image_analyzer_generator.rb', line 53

def create_image_analyzer_file
  analyzer_path = name.underscore
  template "image_analyzer.rb.tt", "app/agents/images/#{analyzer_path}_analyzer.rb"
end

#ensure_base_class_and_skill_fileObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/generators/ruby_llm_agents/image_analyzer_generator.rb', line 34

def ensure_base_class_and_skill_file
  images_dir = "app/agents/images"

  # Create directory if needed
  empty_directory images_dir

  # Create base class if it doesn't exist
  base_class_path = "#{images_dir}/application_image_analyzer.rb"
  unless File.exist?(File.join(destination_root, base_class_path))
    template "application_image_analyzer.rb.tt", base_class_path
  end

  # Create skill file if it doesn't exist
  skill_file_path = "#{images_dir}/IMAGE_ANALYZERS.md"
  unless File.exist?(File.join(destination_root, skill_file_path))
    template "skills/IMAGE_ANALYZERS.md.tt", skill_file_path
  end
end

#show_usageObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/generators/ruby_llm_agents/image_analyzer_generator.rb', line 58

def show_usage
  analyzer_class_name = name.split("/").map(&:camelize).join("::")
  full_class_name = "Images::#{analyzer_class_name}Analyzer"
  say ""
  say "Image analyzer #{full_class_name} created!", :green
  say ""
  say "Usage:"
  say "  # Analyze an image"
  say "  result = #{full_class_name}.call(image: 'photo.jpg')"
  say "  result.caption      # => 'A sunset over mountains'"
  say "  result.tags         # => ['sunset', 'mountains', 'nature']"
  say "  result.description  # => 'Detailed description...'"
  say ""
  say "  # Override settings at runtime"
  say "  result = #{full_class_name}.call("
  say "    image: 'product.jpg',"
  say "    analysis_type: :all,"
  say "    extract_colors: true,"
  say "    detect_objects: true"
  say "  )"
  say ""
  say "  # Access detected objects and colors"
  say "  result.objects  # => [{name: 'laptop', location: 'center', confidence: 'high'}]"
  say "  result.colors   # => [{hex: '#C0C0C0', name: 'silver', percentage: 45}]"
  say ""
end