Class: RubyLLM::Agents::ImagePipeline

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

Overview

Image pipeline for chaining multiple image operations

Orchestrates complex image workflows by chaining generators, transformers, upscalers, analyzers, and other image operations into a single pipeline with aggregated results and costs.

Examples:

Basic pipeline

class ProductPipeline < RubyLLM::Agents::ImagePipeline
  step :generate, generator: ProductGenerator
  step :upscale, upscaler: PhotoUpscaler
  step :remove_background, remover: BackgroundRemover
end

result = ProductPipeline.call(prompt: "Professional laptop photo")
result.final_image   # => The processed image
result.total_cost    # => Combined cost of all steps

Pipeline with analysis

class AnalysisPipeline < RubyLLM::Agents::ImagePipeline
  step :generate, generator: ProductGenerator
  step :analyze, analyzer: ProductAnalyzer

  description "Generates and analyzes product images"
end

result = AnalysisPipeline.call(prompt: "Wireless earbuds")
result.analysis   # => ImageAnalysisResult from analyzer step

Conditional pipeline

class SmartPipeline < RubyLLM::Agents::ImagePipeline
  step :generate, generator: ProductGenerator
  step :upscale, upscaler: PhotoUpscaler, if: ->(ctx) { ctx[:upscale] }
  step :remove_background, remover: BackgroundRemover, if: ->(ctx) { ctx[:transparent] }
end

result = SmartPipeline.call(prompt: "...", upscale: true, transparent: false)

Defined Under Namespace

Modules: DSL, Execution

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ ImagePipeline

Initialize a new pipeline instance

Parameters:

  • options (Hash)

    Pipeline options

Options Hash (**options):

  • :prompt (String)

    Prompt for generation steps

  • :image (String, IO)

    Input image

  • :tenant (Object)

    Tenant for multi-tenancy



82
83
84
85
86
87
# File 'lib/ruby_llm/agents/image/pipeline.rb', line 82

def initialize(**options)
  @options = options
  @tenant_id = nil
  @step_results = []
  @context = options.dup
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



74
75
76
# File 'lib/ruby_llm/agents/image/pipeline.rb', line 74

def context
  @context
end

#optionsObject (readonly)

Returns the value of attribute options.



74
75
76
# File 'lib/ruby_llm/agents/image/pipeline.rb', line 74

def options
  @options
end

#step_resultsObject (readonly)

Returns the value of attribute step_results.



74
75
76
# File 'lib/ruby_llm/agents/image/pipeline.rb', line 74

def step_results
  @step_results
end

#tenant_idObject (readonly)

Returns the value of attribute tenant_id.



74
75
76
# File 'lib/ruby_llm/agents/image/pipeline.rb', line 74

def tenant_id
  @tenant_id
end

Class Method Details

.call(**options) ⇒ ImagePipelineResult

Execute pipeline with the given options

Parameters:

  • options (Hash)

    Pipeline options

Options Hash (**options):

  • :prompt (String)

    Prompt for generation steps

  • :image (String, IO)

    Input image for non-generation pipelines

  • :tenant (Object)

    Tenant for multi-tenancy

Returns:



57
58
59
# File 'lib/ruby_llm/agents/image/pipeline.rb', line 57

def call(**options)
  new(**options).call
end

.inherited(subclass) ⇒ Object

Ensure subclasses inherit DSL settings and steps



62
63
64
65
66
67
68
69
70
71
# File 'lib/ruby_llm/agents/image/pipeline.rb', line 62

def inherited(subclass)
  super
  # Copy steps to subclass
  subclass.instance_variable_set(:@steps, @steps&.dup || [])
  subclass.instance_variable_set(:@callbacks, @callbacks&.dup || {before: [], after: []})
  subclass.instance_variable_set(:@version, @version)
  subclass.instance_variable_set(:@description, @description)
  subclass.instance_variable_set(:@cache_ttl, @cache_ttl)
  subclass.instance_variable_set(:@stop_on_error, @stop_on_error)
end

Instance Method Details

#callImagePipelineResult

Execute the pipeline

Returns:



92
93
94
# File 'lib/ruby_llm/agents/image/pipeline.rb', line 92

def call
  execute
end