Class: RubyLLM::Agents::ImageVariationResult
- Inherits:
-
Object
- Object
- RubyLLM::Agents::ImageVariationResult
- Includes:
- Trackable
- Defined in:
- lib/ruby_llm/agents/results/image_variation_result.rb
Overview
Result wrapper for image variation operations
Provides a consistent interface for accessing variation images, metadata, timing, and cost information.
Instance Attribute Summary collapse
-
#completed_at ⇒ Object
readonly
Returns the value of attribute completed_at.
-
#error_class ⇒ Object
readonly
Returns the value of attribute error_class.
-
#error_message ⇒ Object
readonly
Returns the value of attribute error_message.
-
#execution_id ⇒ Object
Returns the value of attribute execution_id.
-
#images ⇒ Object
readonly
Returns the value of attribute images.
-
#model_id ⇒ Object
readonly
Returns the value of attribute model_id.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#source_image ⇒ Object
readonly
Returns the value of attribute source_image.
-
#started_at ⇒ Object
readonly
Returns the value of attribute started_at.
-
#tenant_id ⇒ Object
readonly
Returns the value of attribute tenant_id.
-
#variation_strength ⇒ Object
readonly
Returns the value of attribute variation_strength.
-
#variator_class ⇒ Object
readonly
Returns the value of attribute variator_class.
Class Method Summary collapse
Instance Method Summary collapse
- #base64? ⇒ Boolean
- #batch? ⇒ Boolean
- #blobs ⇒ Object
-
#count ⇒ Object
Count.
- #data ⇒ Object
- #datas ⇒ Object
-
#duration_ms ⇒ Object
Timing.
- #error? ⇒ Boolean
-
#execution ⇒ RubyLLM::Agents::Execution?
Loads the associated Execution record from the database.
-
#image ⇒ Object
Image access.
-
#initialize(images:, source_image:, model_id:, size:, variation_strength:, started_at:, completed_at:, tenant_id:, variator_class:, error_class: nil, error_message: nil, agent_class_name: nil) ⇒ ImageVariationResult
constructor
Initialize a new result.
- #mime_type ⇒ Object
-
#save(path) ⇒ Object
File operations.
- #save_all(directory, prefix: "variation") ⇒ Object
- #single? ⇒ Boolean
-
#success? ⇒ Boolean
Status helpers.
- #to_blob ⇒ Object
-
#to_cache ⇒ Object
Caching.
-
#to_h ⇒ Object
Serialization.
-
#total_cost ⇒ Object
Cost estimation.
- #url ⇒ Object
- #urls ⇒ Object
Methods included from Trackable
Constructor Details
#initialize(images:, source_image:, model_id:, size:, variation_strength:, started_at:, completed_at:, tenant_id:, variator_class:, error_class: nil, error_message: nil, agent_class_name: nil) ⇒ ImageVariationResult
Initialize a new result
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ruby_llm/agents/results/image_variation_result.rb', line 37 def initialize(images:, source_image:, model_id:, size:, variation_strength:, started_at:, completed_at:, tenant_id:, variator_class:, error_class: nil, error_message: nil, agent_class_name: nil) @images = images @source_image = source_image @model_id = model_id @size = size @variation_strength = variation_strength @started_at = started_at @completed_at = completed_at @tenant_id = tenant_id @variator_class = variator_class @error_class = error_class @error_message = @execution_id = nil # Tracking @agent_class_name = agent_class_name register_with_tracker end |
Instance Attribute Details
#completed_at ⇒ Object (readonly)
Returns the value of attribute completed_at.
19 20 21 |
# File 'lib/ruby_llm/agents/results/image_variation_result.rb', line 19 def completed_at @completed_at end |
#error_class ⇒ Object (readonly)
Returns the value of attribute error_class.
19 20 21 |
# File 'lib/ruby_llm/agents/results/image_variation_result.rb', line 19 def error_class @error_class end |
#error_message ⇒ Object (readonly)
Returns the value of attribute error_message.
19 20 21 |
# File 'lib/ruby_llm/agents/results/image_variation_result.rb', line 19 def @error_message end |
#execution_id ⇒ Object
Returns the value of attribute execution_id.
22 23 24 |
# File 'lib/ruby_llm/agents/results/image_variation_result.rb', line 22 def execution_id @execution_id end |
#images ⇒ Object (readonly)
Returns the value of attribute images.
19 20 21 |
# File 'lib/ruby_llm/agents/results/image_variation_result.rb', line 19 def images @images end |
#model_id ⇒ Object (readonly)
Returns the value of attribute model_id.
19 20 21 |
# File 'lib/ruby_llm/agents/results/image_variation_result.rb', line 19 def model_id @model_id end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
19 20 21 |
# File 'lib/ruby_llm/agents/results/image_variation_result.rb', line 19 def size @size end |
#source_image ⇒ Object (readonly)
Returns the value of attribute source_image.
19 20 21 |
# File 'lib/ruby_llm/agents/results/image_variation_result.rb', line 19 def source_image @source_image end |
#started_at ⇒ Object (readonly)
Returns the value of attribute started_at.
19 20 21 |
# File 'lib/ruby_llm/agents/results/image_variation_result.rb', line 19 def started_at @started_at end |
#tenant_id ⇒ Object (readonly)
Returns the value of attribute tenant_id.
19 20 21 |
# File 'lib/ruby_llm/agents/results/image_variation_result.rb', line 19 def tenant_id @tenant_id end |
#variation_strength ⇒ Object (readonly)
Returns the value of attribute variation_strength.
19 20 21 |
# File 'lib/ruby_llm/agents/results/image_variation_result.rb', line 19 def variation_strength @variation_strength end |
#variator_class ⇒ Object (readonly)
Returns the value of attribute variator_class.
19 20 21 |
# File 'lib/ruby_llm/agents/results/image_variation_result.rb', line 19 def variator_class @variator_class end |
Class Method Details
.from_cache(data) ⇒ Object
198 199 200 |
# File 'lib/ruby_llm/agents/results/image_variation_result.rb', line 198 def self.from_cache(data) CachedImageVariationResult.new(data) end |
Instance Method Details
#base64? ⇒ Boolean
105 106 107 |
# File 'lib/ruby_llm/agents/results/image_variation_result.rb', line 105 def base64? image&.base64? || false end |
#batch? ⇒ Boolean
79 80 81 |
# File 'lib/ruby_llm/agents/results/image_variation_result.rb', line 79 def batch? count > 1 end |
#blobs ⇒ Object
156 157 158 |
# File 'lib/ruby_llm/agents/results/image_variation_result.rb', line 156 def blobs images.map(&:to_blob) end |
#count ⇒ Object
Count
115 116 117 |
# File 'lib/ruby_llm/agents/results/image_variation_result.rb', line 115 def count images.size end |
#data ⇒ Object
97 98 99 |
# File 'lib/ruby_llm/agents/results/image_variation_result.rb', line 97 def data image&.data end |
#datas ⇒ Object
101 102 103 |
# File 'lib/ruby_llm/agents/results/image_variation_result.rb', line 101 def datas images.map(&:data).compact end |
#duration_ms ⇒ Object
Timing
121 122 123 124 |
# File 'lib/ruby_llm/agents/results/image_variation_result.rb', line 121 def duration_ms return 0 unless started_at && completed_at ((completed_at - started_at) * 1000).round end |
#error? ⇒ Boolean
71 72 73 |
# File 'lib/ruby_llm/agents/results/image_variation_result.rb', line 71 def error? !success? end |
#execution ⇒ RubyLLM::Agents::Execution?
Loads the associated Execution record from the database
61 62 63 |
# File 'lib/ruby_llm/agents/results/image_variation_result.rb', line 61 def execution @execution ||= RubyLLM::Agents::Execution.find_by(id: execution_id) if execution_id end |
#image ⇒ Object
Image access
85 86 87 |
# File 'lib/ruby_llm/agents/results/image_variation_result.rb', line 85 def image images.first end |
#mime_type ⇒ Object
109 110 111 |
# File 'lib/ruby_llm/agents/results/image_variation_result.rb', line 109 def mime_type image&.mime_type end |
#save(path) ⇒ Object
File operations
140 141 142 143 |
# File 'lib/ruby_llm/agents/results/image_variation_result.rb', line 140 def save(path) raise "No image to save" unless image image.save(path) end |
#save_all(directory, prefix: "variation") ⇒ Object
145 146 147 148 149 150 |
# File 'lib/ruby_llm/agents/results/image_variation_result.rb', line 145 def save_all(directory, prefix: "variation") images.each_with_index do |img, idx| filename = "#{prefix}_#{idx + 1}.png" img.save(File.join(directory, filename)) end end |
#single? ⇒ Boolean
75 76 77 |
# File 'lib/ruby_llm/agents/results/image_variation_result.rb', line 75 def single? count == 1 end |
#success? ⇒ Boolean
Status helpers
67 68 69 |
# File 'lib/ruby_llm/agents/results/image_variation_result.rb', line 67 def success? error_class.nil? && images.any? end |
#to_blob ⇒ Object
152 153 154 |
# File 'lib/ruby_llm/agents/results/image_variation_result.rb', line 152 def to_blob image&.to_blob end |
#to_cache ⇒ Object
Caching
187 188 189 190 191 192 193 194 195 196 |
# File 'lib/ruby_llm/agents/results/image_variation_result.rb', line 187 def to_cache { urls: urls, datas: datas, mime_type: mime_type, model_id: model_id, total_cost: total_cost, cached_at: Time.current.iso8601 } end |
#to_h ⇒ Object
Serialization
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/ruby_llm/agents/results/image_variation_result.rb', line 162 def to_h { success: success?, count: count, urls: urls, base64: base64?, mime_type: mime_type, source_image: source_image, model_id: model_id, size: size, variation_strength: variation_strength, total_cost: total_cost, duration_ms: duration_ms, started_at: started_at&.iso8601, completed_at: completed_at&.iso8601, tenant_id: tenant_id, variator_class: variator_class, error_class: error_class, error_message: , execution_id: execution_id } end |
#total_cost ⇒ Object
Cost estimation
128 129 130 131 132 133 134 135 136 |
# File 'lib/ruby_llm/agents/results/image_variation_result.rb', line 128 def total_cost return 0 if error? ImageGenerator::Pricing.calculate_cost( model_id: model_id, size: size, count: count ) end |
#url ⇒ Object
89 90 91 |
# File 'lib/ruby_llm/agents/results/image_variation_result.rb', line 89 def url image&.url end |
#urls ⇒ Object
93 94 95 |
# File 'lib/ruby_llm/agents/results/image_variation_result.rb', line 93 def urls images.map(&:url).compact end |