Class: RubyLLM::Agents::CachedImagePipelineResult
- Inherits:
-
Object
- Object
- RubyLLM::Agents::CachedImagePipelineResult
- Defined in:
- lib/ruby_llm/agents/results/image_pipeline_result.rb
Overview
Lightweight result for cached pipelines
Instance Attribute Summary collapse
-
#cached_at ⇒ Object
readonly
Returns the value of attribute cached_at.
-
#step_results ⇒ Object
readonly
Returns the value of attribute step_results.
-
#total_cost ⇒ Object
readonly
Returns the value of attribute total_cost.
Instance Method Summary collapse
- #cached? ⇒ Boolean
- #error? ⇒ Boolean
- #final_image ⇒ Object
-
#initialize(data) ⇒ CachedImagePipelineResult
constructor
A new instance of CachedImagePipelineResult.
- #step(name) ⇒ Object (also: #[])
- #step_count ⇒ Object
- #success? ⇒ Boolean
- #url ⇒ Object
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_at ⇒ Object (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_results ⇒ Object (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_cost ⇒ Object (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
384 385 386 |
# File 'lib/ruby_llm/agents/results/image_pipeline_result.rb', line 384 def cached? true end |
#error? ⇒ Boolean
380 381 382 |
# File 'lib/ruby_llm/agents/results/image_pipeline_result.rb', line 380 def error? !success? end |
#final_image ⇒ Object
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_count ⇒ Object
388 389 390 |
# File 'lib/ruby_llm/agents/results/image_pipeline_result.rb', line 388 def step_count step_results.size end |
#success? ⇒ Boolean
376 377 378 |
# File 'lib/ruby_llm/agents/results/image_pipeline_result.rb', line 376 def success? step_results.any? end |
#url ⇒ Object
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 |