Module: RubyLLM::Agents::ImageAnalyzer::DSL
- Includes:
- Concerns::ImageOperationDSL
- Defined in:
- lib/ruby_llm/agents/image/analyzer/dsl.rb
Overview
DSL for configuring image analyzers
Provides class-level methods to configure model, analysis type, and feature extraction options.
Constant Summary collapse
- VALID_ANALYSIS_TYPES =
%i[caption detailed tags objects colors all].freeze
Instance Method Summary collapse
-
#analysis_type(value = nil) ⇒ Symbol
Set or get the analysis type.
-
#custom_prompt(value = nil) ⇒ String?
Set or get a custom analysis prompt.
-
#detect_objects(value = nil) ⇒ Boolean
Set or get whether to detect objects.
-
#extract_colors(value = nil) ⇒ Boolean
Set or get whether to extract colors.
-
#extract_text(value = nil) ⇒ Boolean
Set or get whether to extract text (OCR).
-
#max_tags(value = nil) ⇒ Integer
Set or get maximum number of tags.
Methods included from Concerns::ImageOperationDSL
#cache_enabled?, #cache_for, #cache_ttl, #description, #model
Instance Method Details
#analysis_type(value = nil) ⇒ Symbol
Set or get the analysis type
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ruby_llm/agents/image/analyzer/dsl.rb', line 31 def analysis_type(value = nil) if value unless VALID_ANALYSIS_TYPES.include?(value) raise ArgumentError, "Analysis type must be one of: #{VALID_ANALYSIS_TYPES.join(", ")}" end @analysis_type = value else @analysis_type || inherited_or_default(:analysis_type, :detailed) end end |
#custom_prompt(value = nil) ⇒ String?
Set or get a custom analysis prompt
Allows specifying a custom prompt for the vision model to customize what information is extracted.
99 100 101 102 103 104 105 |
# File 'lib/ruby_llm/agents/image/analyzer/dsl.rb', line 99 def custom_prompt(value = nil) if value @custom_prompt = value else @custom_prompt || inherited_or_default(:custom_prompt, nil) end end |
#detect_objects(value = nil) ⇒ Boolean
Set or get whether to detect objects
When enabled, detects and identifies objects in the image with bounding boxes and confidence scores.
66 67 68 69 70 71 72 73 74 |
# File 'lib/ruby_llm/agents/image/analyzer/dsl.rb', line 66 def detect_objects(value = nil) if value.nil? result = @detect_objects result = inherited_or_default(:detect_objects, false) if result.nil? result else @detect_objects = value end end |
#extract_colors(value = nil) ⇒ Boolean
Set or get whether to extract colors
When enabled, extracts dominant colors from the image with hex values, names, and percentages.
49 50 51 52 53 54 55 56 57 |
# File 'lib/ruby_llm/agents/image/analyzer/dsl.rb', line 49 def extract_colors(value = nil) if value.nil? result = @extract_colors result = inherited_or_default(:extract_colors, false) if result.nil? result else @extract_colors = value end end |
#extract_text(value = nil) ⇒ Boolean
Set or get whether to extract text (OCR)
When enabled, extracts text visible in the image using OCR.
82 83 84 85 86 87 88 89 90 |
# File 'lib/ruby_llm/agents/image/analyzer/dsl.rb', line 82 def extract_text(value = nil) if value.nil? result = @extract_text result = inherited_or_default(:extract_text, false) if result.nil? result else @extract_text = value end end |
#max_tags(value = nil) ⇒ Integer
Set or get maximum number of tags
111 112 113 114 115 116 117 118 119 120 |
# File 'lib/ruby_llm/agents/image/analyzer/dsl.rb', line 111 def (value = nil) if value unless value.is_a?(Integer) && value > 0 raise ArgumentError, "Max tags must be a positive integer" end @max_tags = value else @max_tags || inherited_or_default(:max_tags, 10) end end |