Class: TurnKit::ImageResult
- Inherits:
-
Object
- Object
- TurnKit::ImageResult
- Defined in:
- lib/turnkit/image_result.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#mime_type ⇒ Object
readonly
Returns the value of attribute mime_type.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#provider ⇒ Object
readonly
Returns the value of attribute provider.
-
#revised_prompt ⇒ Object
readonly
Returns the value of attribute revised_prompt.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#usage ⇒ Object
readonly
Returns the value of attribute usage.
Class Method Summary collapse
Instance Method Summary collapse
- #cost ⇒ Object
-
#initialize(url: nil, data: nil, mime_type: nil, revised_prompt: nil, model: nil, provider: nil, usage: Usage.new, params: {}, metadata: {}) ⇒ ImageResult
constructor
A new instance of ImageResult.
- #to_blob ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(url: nil, data: nil, mime_type: nil, revised_prompt: nil, model: nil, provider: nil, usage: Usage.new, params: {}, metadata: {}) ⇒ ImageResult
Returns a new instance of ImageResult.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/turnkit/image_result.rb', line 14 def initialize(url: nil, data: nil, mime_type: nil, revised_prompt: nil, model: nil, provider: nil, usage: Usage.new, params: {}, metadata: {}, **) @url = url @data = data @mime_type = mime_type @revised_prompt = revised_prompt @model = model @provider = provider @usage = usage.is_a?(Usage) ? usage : Usage.from_h(usage || {}) @params = params || {} @metadata = || {} end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
8 9 10 |
# File 'lib/turnkit/image_result.rb', line 8 def data @data end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
8 9 10 |
# File 'lib/turnkit/image_result.rb', line 8 def @metadata end |
#mime_type ⇒ Object (readonly)
Returns the value of attribute mime_type.
8 9 10 |
# File 'lib/turnkit/image_result.rb', line 8 def mime_type @mime_type end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
8 9 10 |
# File 'lib/turnkit/image_result.rb', line 8 def model @model end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
8 9 10 |
# File 'lib/turnkit/image_result.rb', line 8 def params @params end |
#provider ⇒ Object (readonly)
Returns the value of attribute provider.
8 9 10 |
# File 'lib/turnkit/image_result.rb', line 8 def provider @provider end |
#revised_prompt ⇒ Object (readonly)
Returns the value of attribute revised_prompt.
8 9 10 |
# File 'lib/turnkit/image_result.rb', line 8 def revised_prompt @revised_prompt end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
8 9 10 |
# File 'lib/turnkit/image_result.rb', line 8 def url @url end |
#usage ⇒ Object (readonly)
Returns the value of attribute usage.
8 9 10 |
# File 'lib/turnkit/image_result.rb', line 8 def usage @usage end |
Class Method Details
.from_h(value) ⇒ Object
10 11 12 |
# File 'lib/turnkit/image_result.rb', line 10 def self.from_h(value) new(**value.transform_keys(&:to_sym)) end |
Instance Method Details
#cost ⇒ Object
32 33 34 |
# File 'lib/turnkit/image_result.rb', line 32 def cost Cost.from_usage(usage, model: model) end |
#to_blob ⇒ Object
26 27 28 29 30 |
# File 'lib/turnkit/image_result.rb', line 26 def to_blob raise Error, "image has no url or data" if url.to_s.empty? && data.to_s.empty? data ? Base64.decode64(data) : URI.open(url, &:read) end |
#to_h ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/turnkit/image_result.rb', line 36 def to_h { "url" => url, "data" => data, "mime_type" => mime_type, "revised_prompt" => revised_prompt, "model" => model, "provider" => provider, "usage" => usage.to_h, "cost" => cost.to_h, "params" => params, "metadata" => }.compact end |