Class: RubyLLM::Agents::ImageVariator

Inherits:
Object
  • Object
show all
Extended by:
DSL
Includes:
Execution
Defined in:
lib/ruby_llm/agents/image/variator.rb,
lib/ruby_llm/agents/image/variator/dsl.rb,
lib/ruby_llm/agents/image/variator/execution.rb

Overview

Image variator for generating variations of existing images

Creates variations of an input image while maintaining the overall composition and style. Useful for exploring design alternatives or generating A/B test variants.

Examples:

Basic usage

result = RubyLLM::Agents::ImageVariator.call(image: "path/to/image.png")
result.urls # => ["https://...", ...]

Custom variator class

class LogoVariator < RubyLLM::Agents::ImageVariator
  model "gpt-image-1"
  variation_strength 0.3
  size "1024x1024"

  description "Creates variations of logos"
end

result = LogoVariator.call(image: , count: 4)

Defined Under Namespace

Modules: DSL, Execution

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Execution

#execute

Constructor Details

#initialize(image:, **options) ⇒ ImageVariator

Initialize a new image variator instance

Parameters:

  • image (String, IO)

    Source image (path, URL, or IO object)

  • options (Hash)

    Additional options

Options Hash (**options):

  • :model (String)

    Model to use

  • :count (Integer)

    Number of variations to generate

  • :size (String)

    Output image size

  • :variation_strength (Float)

    How different variations should be (0.0-1.0)

  • :tenant (Object)

    Tenant for multi-tenancy



66
67
68
69
70
# File 'lib/ruby_llm/agents/image/variator.rb', line 66

def initialize(image:, **options)
  @image = image
  @options = options
  @tenant_id = nil
end

Instance Attribute Details

#imageObject (readonly)

Returns the value of attribute image.



55
56
57
# File 'lib/ruby_llm/agents/image/variator.rb', line 55

def image
  @image
end

#optionsObject (readonly)

Returns the value of attribute options.



55
56
57
# File 'lib/ruby_llm/agents/image/variator.rb', line 55

def options
  @options
end

#tenant_idObject (readonly)

Returns the value of attribute tenant_id.



55
56
57
# File 'lib/ruby_llm/agents/image/variator.rb', line 55

def tenant_id
  @tenant_id
end

Class Method Details

.call(image:, **options) ⇒ ImageVariationResult

Execute image variation with the given source image

Parameters:

  • image (String, IO)

    Path, URL, or IO object of the source image

  • options (Hash)

    Additional options (model, count, size, etc.)

Returns:



39
40
41
# File 'lib/ruby_llm/agents/image/variator.rb', line 39

def call(image:, **options)
  new(image: image, **options).call
end

.inherited(subclass) ⇒ Object

Ensure subclasses inherit DSL settings



44
45
46
47
48
49
50
51
52
# File 'lib/ruby_llm/agents/image/variator.rb', line 44

def inherited(subclass)
  super
  subclass.instance_variable_set(:@model, @model)
  subclass.instance_variable_set(:@size, @size)
  subclass.instance_variable_set(:@variation_strength, @variation_strength)
  subclass.instance_variable_set(:@version, @version)
  subclass.instance_variable_set(:@description, @description)
  subclass.instance_variable_set(:@cache_ttl, @cache_ttl)
end

Instance Method Details

#callImageVariationResult

Execute the image variation

Returns:



75
76
77
# File 'lib/ruby_llm/agents/image/variator.rb', line 75

def call
  execute
end