Class: RubyLLM::Agents::CachedImagePipelineResult

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_llm/agents/results/image_pipeline_result.rb

Overview

Lightweight result for cached pipelines

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ CachedImagePipelineResult

Returns a new instance of CachedImagePipelineResult.



370
371
372
373
374
# File 'lib/ruby_llm/agents/results/image_pipeline_result.rb', line 370

def initialize(data)
  @step_results = data[:step_results] || []
  @total_cost = data[:total_cost]
  @cached_at = data[:cached_at]
end

Instance Attribute Details

#cached_atObject (readonly)

Returns the value of attribute cached_at.



368
369
370
# File 'lib/ruby_llm/agents/results/image_pipeline_result.rb', line 368

def cached_at
  @cached_at
end

#step_resultsObject (readonly)

Returns the value of attribute step_results.



368
369
370
# File 'lib/ruby_llm/agents/results/image_pipeline_result.rb', line 368

def step_results
  @step_results
end

#total_costObject (readonly)

Returns the value of attribute total_cost.



368
369
370
# File 'lib/ruby_llm/agents/results/image_pipeline_result.rb', line 368

def total_cost
  @total_cost
end

Instance Method Details

#cached?Boolean

Returns:

  • (Boolean)


384
385
386
# File 'lib/ruby_llm/agents/results/image_pipeline_result.rb', line 384

def cached?
  true
end

#error?Boolean

Returns:

  • (Boolean)


380
381
382
# File 'lib/ruby_llm/agents/results/image_pipeline_result.rb', line 380

def error?
  !success?
end

#final_imageObject



399
400
401
402
403
404
405
406
407
408
# File 'lib/ruby_llm/agents/results/image_pipeline_result.rb', line 399

def final_image
  # Find last non-analyzer step
  image_step = step_results.reverse.find { |s| s[:type] != :analyzer }
  return nil unless image_step

  cached = image_step[:cached_result]
  return nil unless cached

  cached[:urls]&.first || cached[:url] || cached[:datas]&.first || cached[:data]
end

#step(name) ⇒ Object Also known as: []



392
393
394
395
# File 'lib/ruby_llm/agents/results/image_pipeline_result.rb', line 392

def step(name)
  step_data = step_results.find { |s| s[:name] == name }
  step_data&.dig(:cached_result)
end

#step_countObject



388
389
390
# File 'lib/ruby_llm/agents/results/image_pipeline_result.rb', line 388

def step_count
  step_results.size
end

#success?Boolean

Returns:

  • (Boolean)


376
377
378
# File 'lib/ruby_llm/agents/results/image_pipeline_result.rb', line 376

def success?
  step_results.any?
end

#urlObject



410
411
412
# File 'lib/ruby_llm/agents/results/image_pipeline_result.rb', line 410

def url
  final_image if final_image.is_a?(String) && final_image.start_with?("http")
end