Class: RubyLLM::Agents::ImageTransformer

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

Overview

Image transformer for style transfer and image-to-image generation

Transforms an existing image based on a text prompt while maintaining the overall structure. The strength parameter controls how much the image is transformed.

Examples:

Basic usage

result = RubyLLM::Agents::ImageTransformer.call(
  image: "path/to/photo.jpg",
  prompt: "Convert to watercolor painting style"
)
result.url # => "https://..."

Custom transformer class

class AnimeTransformer < RubyLLM::Agents::ImageTransformer
  model "sdxl"
  strength 0.8
  template "anime style, studio ghibli, {prompt}"

  description "Transforms photos into anime style"
end

result = AnimeTransformer.call(
  image: user_photo,
  prompt: "portrait of a person"
)

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:, prompt:, **options) ⇒ ImageTransformer

Initialize a new image transformer instance

Parameters:

  • image (String, IO)

    Source image (path, URL, or IO object)

  • prompt (String)

    Description of the desired transformation

  • options (Hash)

    Additional options

Options Hash (**options):

  • :model (String)

    Model to use

  • :size (String)

    Output image size

  • :strength (Float)

    Transformation strength (0.0-1.0)

  • :count (Integer)

    Number of transformations to generate

  • :tenant (Object)

    Tenant for multi-tenancy



79
80
81
82
83
84
# File 'lib/ruby_llm/agents/image/transformer.rb', line 79

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

Instance Attribute Details

#imageObject (readonly)

Returns the value of attribute image.



67
68
69
# File 'lib/ruby_llm/agents/image/transformer.rb', line 67

def image
  @image
end

#optionsObject (readonly)

Returns the value of attribute options.



67
68
69
# File 'lib/ruby_llm/agents/image/transformer.rb', line 67

def options
  @options
end

#promptObject (readonly)

Returns the value of attribute prompt.



67
68
69
# File 'lib/ruby_llm/agents/image/transformer.rb', line 67

def prompt
  @prompt
end

#tenant_idObject (readonly)

Returns the value of attribute tenant_id.



67
68
69
# File 'lib/ruby_llm/agents/image/transformer.rb', line 67

def tenant_id
  @tenant_id
end

Class Method Details

.call(image:, prompt:, **options) ⇒ ImageTransformResult

Execute image transformation

Parameters:

  • image (String, IO)

    Path, URL, or IO object of the source image

  • prompt (String)

    Description of the desired transformation

  • options (Hash)

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

Returns:



46
47
48
# File 'lib/ruby_llm/agents/image/transformer.rb', line 46

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

.inherited(subclass) ⇒ Object

Ensure subclasses inherit DSL settings



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/ruby_llm/agents/image/transformer.rb', line 51

def inherited(subclass)
  super
  subclass.instance_variable_set(:@model, @model)
  subclass.instance_variable_set(:@size, @size)
  subclass.instance_variable_set(:@strength, @strength)
  subclass.instance_variable_set(:@preserve_composition, @preserve_composition)
  subclass.instance_variable_set(:@version, @version)
  subclass.instance_variable_set(:@description, @description)
  subclass.instance_variable_set(:@cache_ttl, @cache_ttl)
  subclass.instance_variable_set(:@template_string, @template_string)
  subclass.instance_variable_set(:@negative_prompt, @negative_prompt)
  subclass.instance_variable_set(:@guidance_scale, @guidance_scale)
  subclass.instance_variable_set(:@steps, @steps)
end

Instance Method Details

#callImageTransformResult

Execute the image transformation

Returns:



89
90
91
# File 'lib/ruby_llm/agents/image/transformer.rb', line 89

def call
  execute
end