Class: RubyLLM::Agents::ImageEditor

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

Overview

Image editor for inpainting and image editing

Allows editing specific regions of an image using a mask. The mask indicates which parts of the image should be modified. White areas in the mask are edited, black areas are preserved.

Examples:

Basic usage

result = RubyLLM::Agents::ImageEditor.call(
  image: "path/to/image.png",
  mask: "path/to/mask.png",
  prompt: "Replace with a red car"
)
result.url # => "https://..."

Custom editor class

class ProductEditor < RubyLLM::Agents::ImageEditor
  model "gpt-image-1"
  size "1024x1024"

  description "Edits product images"
end

result = ProductEditor.call(
  image: product_photo,
  mask: background_mask,
  prompt: "Professional studio background"
)

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

Initialize a new image editor instance

Parameters:

  • image (String, IO)

    Source image (path, URL, or IO object)

  • mask (String, IO)

    Mask image (path, URL, or IO object)

  • prompt (String)

    Description of the desired edit

  • options (Hash)

    Additional options

Options Hash (**options):

  • :model (String)

    Model to use

  • :size (String)

    Output image size

  • :count (Integer)

    Number of edits to generate

  • :tenant (Object)

    Tenant for multi-tenancy



75
76
77
78
79
80
81
# File 'lib/ruby_llm/agents/image/editor.rb', line 75

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

Instance Attribute Details

#imageObject (readonly)

Returns the value of attribute image.



63
64
65
# File 'lib/ruby_llm/agents/image/editor.rb', line 63

def image
  @image
end

#maskObject (readonly)

Returns the value of attribute mask.



63
64
65
# File 'lib/ruby_llm/agents/image/editor.rb', line 63

def mask
  @mask
end

#optionsObject (readonly)

Returns the value of attribute options.



63
64
65
# File 'lib/ruby_llm/agents/image/editor.rb', line 63

def options
  @options
end

#promptObject (readonly)

Returns the value of attribute prompt.



63
64
65
# File 'lib/ruby_llm/agents/image/editor.rb', line 63

def prompt
  @prompt
end

#tenant_idObject (readonly)

Returns the value of attribute tenant_id.



63
64
65
# File 'lib/ruby_llm/agents/image/editor.rb', line 63

def tenant_id
  @tenant_id
end

Class Method Details

.call(image:, mask:, prompt:, **options) ⇒ ImageEditResult

Execute image editing with the given source image, mask, and prompt

Parameters:

  • image (String, IO)

    Path, URL, or IO object of the source image

  • mask (String, IO)

    Path, URL, or IO object of the mask image

  • prompt (String)

    Description of the desired edit

  • options (Hash)

    Additional options (model, size, etc.)

Returns:



48
49
50
# File 'lib/ruby_llm/agents/image/editor.rb', line 48

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

.inherited(subclass) ⇒ Object

Ensure subclasses inherit DSL settings



53
54
55
56
57
58
59
60
# File 'lib/ruby_llm/agents/image/editor.rb', line 53

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

Instance Method Details

#callImageEditResult

Execute the image edit

Returns:



86
87
88
# File 'lib/ruby_llm/agents/image/editor.rb', line 86

def call
  execute
end