Class: RubyLLM::Agents::ImageUpscaleResult
- Inherits:
-
Object
- Object
- RubyLLM::Agents::ImageUpscaleResult
- Includes:
- Trackable
- Defined in:
- lib/ruby_llm/agents/results/image_upscale_result.rb
Overview
Result wrapper for image upscaling operations
Provides a consistent interface for accessing upscaled 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.
-
#face_enhance ⇒ Object
readonly
Returns the value of attribute face_enhance.
-
#image ⇒ Object
readonly
Returns the value of attribute image.
-
#model_id ⇒ Object
readonly
Returns the value of attribute model_id.
-
#output_size ⇒ Object
readonly
Returns the value of attribute output_size.
-
#scale ⇒ Object
readonly
Returns the value of attribute scale.
-
#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.
-
#upscaler_class ⇒ Object
readonly
Returns the value of attribute upscaler_class.
Class Method Summary collapse
Instance Method Summary collapse
- #base64? ⇒ Boolean
- #batch? ⇒ Boolean
- #blobs ⇒ Object
-
#count ⇒ Object
Count (always 1 for upscaling).
- #data ⇒ Object
- #datas ⇒ Object
-
#duration_ms ⇒ Object
Timing.
- #error? ⇒ Boolean
-
#execution ⇒ RubyLLM::Agents::Execution?
Loads the associated Execution record from the database.
-
#initialize(image:, source_image:, model_id:, scale:, output_size:, face_enhance:, started_at:, completed_at:, tenant_id:, upscaler_class:, error_class: nil, error_message: nil, agent_class_name: nil) ⇒ ImageUpscaleResult
constructor
Initialize a new result.
- #mime_type ⇒ Object
- #output_height ⇒ Object
- #output_width ⇒ Object
-
#save(path) ⇒ Object
File operations.
-
#single? ⇒ Boolean
Always single image for upscaling.
-
#size ⇒ Object
Size helpers.
-
#success? ⇒ Boolean
Status helpers.
- #to_blob ⇒ Object
-
#to_cache ⇒ Object
Caching.
-
#to_h ⇒ Object
Serialization.
-
#total_cost ⇒ Object
Cost estimation.
-
#url ⇒ Object
Image access.
- #urls ⇒ Object
Methods included from Trackable
Constructor Details
#initialize(image:, source_image:, model_id:, scale:, output_size:, face_enhance:, started_at:, completed_at:, tenant_id:, upscaler_class:, error_class: nil, error_message: nil, agent_class_name: nil) ⇒ ImageUpscaleResult
Initialize a new result
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/ruby_llm/agents/results/image_upscale_result.rb', line 39 def initialize(image:, source_image:, model_id:, scale:, output_size:, face_enhance:, started_at:, completed_at:, tenant_id:, upscaler_class:, error_class: nil, error_message: nil, agent_class_name: nil) @image = image @source_image = source_image @model_id = model_id @scale = scale @output_size = output_size @face_enhance = face_enhance @started_at = started_at @completed_at = completed_at @tenant_id = tenant_id @upscaler_class = upscaler_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.
20 21 22 |
# File 'lib/ruby_llm/agents/results/image_upscale_result.rb', line 20 def completed_at @completed_at end |
#error_class ⇒ Object (readonly)
Returns the value of attribute error_class.
20 21 22 |
# File 'lib/ruby_llm/agents/results/image_upscale_result.rb', line 20 def error_class @error_class end |
#error_message ⇒ Object (readonly)
Returns the value of attribute error_message.
20 21 22 |
# File 'lib/ruby_llm/agents/results/image_upscale_result.rb', line 20 def @error_message end |
#execution_id ⇒ Object
Returns the value of attribute execution_id.
23 24 25 |
# File 'lib/ruby_llm/agents/results/image_upscale_result.rb', line 23 def execution_id @execution_id end |
#face_enhance ⇒ Object (readonly)
Returns the value of attribute face_enhance.
20 21 22 |
# File 'lib/ruby_llm/agents/results/image_upscale_result.rb', line 20 def face_enhance @face_enhance end |
#image ⇒ Object (readonly)
Returns the value of attribute image.
20 21 22 |
# File 'lib/ruby_llm/agents/results/image_upscale_result.rb', line 20 def image @image end |
#model_id ⇒ Object (readonly)
Returns the value of attribute model_id.
20 21 22 |
# File 'lib/ruby_llm/agents/results/image_upscale_result.rb', line 20 def model_id @model_id end |
#output_size ⇒ Object (readonly)
Returns the value of attribute output_size.
20 21 22 |
# File 'lib/ruby_llm/agents/results/image_upscale_result.rb', line 20 def output_size @output_size end |
#scale ⇒ Object (readonly)
Returns the value of attribute scale.
20 21 22 |
# File 'lib/ruby_llm/agents/results/image_upscale_result.rb', line 20 def scale @scale end |
#source_image ⇒ Object (readonly)
Returns the value of attribute source_image.
20 21 22 |
# File 'lib/ruby_llm/agents/results/image_upscale_result.rb', line 20 def source_image @source_image end |
#started_at ⇒ Object (readonly)
Returns the value of attribute started_at.
20 21 22 |
# File 'lib/ruby_llm/agents/results/image_upscale_result.rb', line 20 def started_at @started_at end |
#tenant_id ⇒ Object (readonly)
Returns the value of attribute tenant_id.
20 21 22 |
# File 'lib/ruby_llm/agents/results/image_upscale_result.rb', line 20 def tenant_id @tenant_id end |
#upscaler_class ⇒ Object (readonly)
Returns the value of attribute upscaler_class.
20 21 22 |
# File 'lib/ruby_llm/agents/results/image_upscale_result.rb', line 20 def upscaler_class @upscaler_class end |
Class Method Details
.from_cache(data) ⇒ Object
209 210 211 |
# File 'lib/ruby_llm/agents/results/image_upscale_result.rb', line 209 def self.from_cache(data) CachedImageUpscaleResult.new(data) end |
Instance Method Details
#base64? ⇒ Boolean
105 106 107 |
# File 'lib/ruby_llm/agents/results/image_upscale_result.rb', line 105 def base64? image&.base64? || false end |
#batch? ⇒ Boolean
83 84 85 |
# File 'lib/ruby_llm/agents/results/image_upscale_result.rb', line 83 def batch? false end |
#blobs ⇒ Object
165 166 167 |
# File 'lib/ruby_llm/agents/results/image_upscale_result.rb', line 165 def blobs success? ? [to_blob].compact : [] end |
#count ⇒ Object
Count (always 1 for upscaling)
115 116 117 |
# File 'lib/ruby_llm/agents/results/image_upscale_result.rb', line 115 def count success? ? 1 : 0 end |
#data ⇒ Object
97 98 99 |
# File 'lib/ruby_llm/agents/results/image_upscale_result.rb', line 97 def data image&.data end |
#datas ⇒ Object
101 102 103 |
# File 'lib/ruby_llm/agents/results/image_upscale_result.rb', line 101 def datas success? ? [data].compact : [] end |
#duration_ms ⇒ Object
Timing
137 138 139 140 |
# File 'lib/ruby_llm/agents/results/image_upscale_result.rb', line 137 def duration_ms return 0 unless started_at && completed_at ((completed_at - started_at) * 1000).round end |
#error? ⇒ Boolean
74 75 76 |
# File 'lib/ruby_llm/agents/results/image_upscale_result.rb', line 74 def error? !success? end |
#execution ⇒ RubyLLM::Agents::Execution?
Loads the associated Execution record from the database
64 65 66 |
# File 'lib/ruby_llm/agents/results/image_upscale_result.rb', line 64 def execution @execution ||= RubyLLM::Agents::Execution.find_by(id: execution_id) if execution_id end |
#mime_type ⇒ Object
109 110 111 |
# File 'lib/ruby_llm/agents/results/image_upscale_result.rb', line 109 def mime_type image&.mime_type end |
#output_height ⇒ Object
130 131 132 133 |
# File 'lib/ruby_llm/agents/results/image_upscale_result.rb', line 130 def output_height return nil unless output_size output_size.split("x").last.to_i end |
#output_width ⇒ Object
125 126 127 128 |
# File 'lib/ruby_llm/agents/results/image_upscale_result.rb', line 125 def output_width return nil unless output_size output_size.split("x").first.to_i end |
#save(path) ⇒ Object
File operations
156 157 158 159 |
# File 'lib/ruby_llm/agents/results/image_upscale_result.rb', line 156 def save(path) raise "No image to save" unless image image.save(path) end |
#single? ⇒ Boolean
Always single image for upscaling
79 80 81 |
# File 'lib/ruby_llm/agents/results/image_upscale_result.rb', line 79 def single? true end |
#size ⇒ Object
Size helpers
121 122 123 |
# File 'lib/ruby_llm/agents/results/image_upscale_result.rb', line 121 def size output_size end |
#success? ⇒ Boolean
Status helpers
70 71 72 |
# File 'lib/ruby_llm/agents/results/image_upscale_result.rb', line 70 def success? error_class.nil? && !image.nil? end |
#to_blob ⇒ Object
161 162 163 |
# File 'lib/ruby_llm/agents/results/image_upscale_result.rb', line 161 def to_blob image&.to_blob end |
#to_cache ⇒ Object
Caching
196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/ruby_llm/agents/results/image_upscale_result.rb', line 196 def to_cache { url: url, data: data, mime_type: mime_type, model_id: model_id, scale: scale, output_size: output_size, total_cost: total_cost, cached_at: Time.current.iso8601 } end |
#to_h ⇒ Object
Serialization
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/ruby_llm/agents/results/image_upscale_result.rb', line 171 def to_h { success: success?, url: url, base64: base64?, mime_type: mime_type, source_image: source_image, model_id: model_id, scale: scale, output_size: output_size, face_enhance: face_enhance, total_cost: total_cost, duration_ms: duration_ms, started_at: started_at&.iso8601, completed_at: completed_at&.iso8601, tenant_id: tenant_id, upscaler_class: upscaler_class, error_class: error_class, error_message: , execution_id: execution_id } end |
#total_cost ⇒ Object
Cost estimation
144 145 146 147 148 149 150 151 152 |
# File 'lib/ruby_llm/agents/results/image_upscale_result.rb', line 144 def total_cost return 0 if error? # Upscaling typically has fixed per-image cost ImageGenerator::Pricing.calculate_cost( model_id: model_id, count: 1 ) end |
#url ⇒ Object
Image access
89 90 91 |
# File 'lib/ruby_llm/agents/results/image_upscale_result.rb', line 89 def url image&.url end |
#urls ⇒ Object
93 94 95 |
# File 'lib/ruby_llm/agents/results/image_upscale_result.rb', line 93 def urls success? ? [url].compact : [] end |