Class: RubyLLM::Agents::ImageEditResult
- Inherits:
-
Object
- Object
- RubyLLM::Agents::ImageEditResult
- Includes:
- Trackable
- Defined in:
- lib/ruby_llm/agents/results/image_edit_result.rb
Overview
Result wrapper for image editing operations
Provides a consistent interface for accessing edited images, metadata, timing, and cost information.
Instance Attribute Summary collapse
-
#completed_at ⇒ Object
readonly
Returns the value of attribute completed_at.
-
#editor_class ⇒ Object
readonly
Returns the value of attribute editor_class.
-
#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.
-
#mask ⇒ Object
readonly
Returns the value of attribute mask.
-
#model_id ⇒ Object
readonly
Returns the value of attribute model_id.
-
#prompt ⇒ Object
readonly
Returns the value of attribute prompt.
-
#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.
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:, mask:, prompt:, model_id:, size:, started_at:, completed_at:, tenant_id:, editor_class:, error_class: nil, error_message: nil, agent_class_name: nil) ⇒ ImageEditResult
constructor
Initialize a new result.
- #input_tokens ⇒ Object
- #mime_type ⇒ Object
- #revised_prompt ⇒ Object
-
#save(path) ⇒ Object
File operations.
- #save_all(directory, prefix: "edited") ⇒ 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:, mask:, prompt:, model_id:, size:, started_at:, completed_at:, tenant_id:, editor_class:, error_class: nil, error_message: nil, agent_class_name: nil) ⇒ ImageEditResult
Initialize a new result
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ruby_llm/agents/results/image_edit_result.rb', line 41 def initialize(images:, source_image:, mask:, prompt:, model_id:, size:, started_at:, completed_at:, tenant_id:, editor_class:, error_class: nil, error_message: nil, agent_class_name: nil) @images = images @source_image = source_image @mask = mask @prompt = prompt @model_id = model_id @size = size @started_at = started_at @completed_at = completed_at @tenant_id = tenant_id @editor_class = editor_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.
22 23 24 |
# File 'lib/ruby_llm/agents/results/image_edit_result.rb', line 22 def completed_at @completed_at end |
#editor_class ⇒ Object (readonly)
Returns the value of attribute editor_class.
22 23 24 |
# File 'lib/ruby_llm/agents/results/image_edit_result.rb', line 22 def editor_class @editor_class end |
#error_class ⇒ Object (readonly)
Returns the value of attribute error_class.
22 23 24 |
# File 'lib/ruby_llm/agents/results/image_edit_result.rb', line 22 def error_class @error_class end |
#error_message ⇒ Object (readonly)
Returns the value of attribute error_message.
22 23 24 |
# File 'lib/ruby_llm/agents/results/image_edit_result.rb', line 22 def @error_message end |
#execution_id ⇒ Object
Returns the value of attribute execution_id.
25 26 27 |
# File 'lib/ruby_llm/agents/results/image_edit_result.rb', line 25 def execution_id @execution_id end |
#images ⇒ Object (readonly)
Returns the value of attribute images.
22 23 24 |
# File 'lib/ruby_llm/agents/results/image_edit_result.rb', line 22 def images @images end |
#mask ⇒ Object (readonly)
Returns the value of attribute mask.
22 23 24 |
# File 'lib/ruby_llm/agents/results/image_edit_result.rb', line 22 def mask @mask end |
#model_id ⇒ Object (readonly)
Returns the value of attribute model_id.
22 23 24 |
# File 'lib/ruby_llm/agents/results/image_edit_result.rb', line 22 def model_id @model_id end |
#prompt ⇒ Object (readonly)
Returns the value of attribute prompt.
22 23 24 |
# File 'lib/ruby_llm/agents/results/image_edit_result.rb', line 22 def prompt @prompt end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
22 23 24 |
# File 'lib/ruby_llm/agents/results/image_edit_result.rb', line 22 def size @size end |
#source_image ⇒ Object (readonly)
Returns the value of attribute source_image.
22 23 24 |
# File 'lib/ruby_llm/agents/results/image_edit_result.rb', line 22 def source_image @source_image end |
#started_at ⇒ Object (readonly)
Returns the value of attribute started_at.
22 23 24 |
# File 'lib/ruby_llm/agents/results/image_edit_result.rb', line 22 def started_at @started_at end |
#tenant_id ⇒ Object (readonly)
Returns the value of attribute tenant_id.
22 23 24 |
# File 'lib/ruby_llm/agents/results/image_edit_result.rb', line 22 def tenant_id @tenant_id end |
Class Method Details
.from_cache(data) ⇒ Object
211 212 213 |
# File 'lib/ruby_llm/agents/results/image_edit_result.rb', line 211 def self.from_cache(data) CachedImageEditResult.new(data) end |
Instance Method Details
#base64? ⇒ Boolean
110 111 112 |
# File 'lib/ruby_llm/agents/results/image_edit_result.rb', line 110 def base64? image&.base64? || false end |
#batch? ⇒ Boolean
84 85 86 |
# File 'lib/ruby_llm/agents/results/image_edit_result.rb', line 84 def batch? count > 1 end |
#blobs ⇒ Object
169 170 171 |
# File 'lib/ruby_llm/agents/results/image_edit_result.rb', line 169 def blobs images.map(&:to_blob) end |
#count ⇒ Object
Count
124 125 126 |
# File 'lib/ruby_llm/agents/results/image_edit_result.rb', line 124 def count images.size end |
#data ⇒ Object
102 103 104 |
# File 'lib/ruby_llm/agents/results/image_edit_result.rb', line 102 def data image&.data end |
#datas ⇒ Object
106 107 108 |
# File 'lib/ruby_llm/agents/results/image_edit_result.rb', line 106 def datas images.map(&:data).compact end |
#duration_ms ⇒ Object
Timing
130 131 132 133 |
# File 'lib/ruby_llm/agents/results/image_edit_result.rb', line 130 def duration_ms return 0 unless started_at && completed_at ((completed_at - started_at) * 1000).round end |
#error? ⇒ Boolean
76 77 78 |
# File 'lib/ruby_llm/agents/results/image_edit_result.rb', line 76 def error? !success? end |
#execution ⇒ RubyLLM::Agents::Execution?
Loads the associated Execution record from the database
66 67 68 |
# File 'lib/ruby_llm/agents/results/image_edit_result.rb', line 66 def execution @execution ||= RubyLLM::Agents::Execution.find_by(id: execution_id) if execution_id end |
#image ⇒ Object
Image access
90 91 92 |
# File 'lib/ruby_llm/agents/results/image_edit_result.rb', line 90 def image images.first end |
#input_tokens ⇒ Object
147 148 149 |
# File 'lib/ruby_llm/agents/results/image_edit_result.rb', line 147 def input_tokens (prompt.length / 4.0).ceil end |
#mime_type ⇒ Object
114 115 116 |
# File 'lib/ruby_llm/agents/results/image_edit_result.rb', line 114 def mime_type image&.mime_type end |
#revised_prompt ⇒ Object
118 119 120 |
# File 'lib/ruby_llm/agents/results/image_edit_result.rb', line 118 def revised_prompt image&.revised_prompt end |
#save(path) ⇒ Object
File operations
153 154 155 156 |
# File 'lib/ruby_llm/agents/results/image_edit_result.rb', line 153 def save(path) raise "No image to save" unless image image.save(path) end |
#save_all(directory, prefix: "edited") ⇒ Object
158 159 160 161 162 163 |
# File 'lib/ruby_llm/agents/results/image_edit_result.rb', line 158 def save_all(directory, prefix: "edited") images.each_with_index do |img, idx| filename = "#{prefix}_#{idx + 1}.png" img.save(File.join(directory, filename)) end end |
#single? ⇒ Boolean
80 81 82 |
# File 'lib/ruby_llm/agents/results/image_edit_result.rb', line 80 def single? count == 1 end |
#success? ⇒ Boolean
Status helpers
72 73 74 |
# File 'lib/ruby_llm/agents/results/image_edit_result.rb', line 72 def success? error_class.nil? && images.any? end |
#to_blob ⇒ Object
165 166 167 |
# File 'lib/ruby_llm/agents/results/image_edit_result.rb', line 165 def to_blob image&.to_blob end |
#to_cache ⇒ Object
Caching
200 201 202 203 204 205 206 207 208 209 |
# File 'lib/ruby_llm/agents/results/image_edit_result.rb', line 200 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
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/ruby_llm/agents/results/image_edit_result.rb', line 175 def to_h { success: success?, count: count, urls: urls, base64: base64?, mime_type: mime_type, source_image: source_image, prompt: prompt, model_id: model_id, size: size, total_cost: total_cost, duration_ms: duration_ms, started_at: started_at&.iso8601, completed_at: completed_at&.iso8601, tenant_id: tenant_id, editor_class: editor_class, error_class: error_class, error_message: , execution_id: execution_id } end |
#total_cost ⇒ Object
Cost estimation
137 138 139 140 141 142 143 144 145 |
# File 'lib/ruby_llm/agents/results/image_edit_result.rb', line 137 def total_cost return 0 if error? ImageGenerator::Pricing.calculate_cost( model_id: model_id, size: size, count: count ) end |
#url ⇒ Object
94 95 96 |
# File 'lib/ruby_llm/agents/results/image_edit_result.rb', line 94 def url image&.url end |
#urls ⇒ Object
98 99 100 |
# File 'lib/ruby_llm/agents/results/image_edit_result.rb', line 98 def urls images.map(&:url).compact end |