Class: PromptBuilder::Content::InputImage
- Defined in:
- lib/prompt_builder/content/input_image.rb
Overview
Represents image input content in a message.
Constant Summary
Constants inherited from Base
Instance Attribute Summary collapse
-
#detail ⇒ String?
readonly
The detail level for the image.
-
#extra ⇒ Hash?
readonly
Provider-specific extra data.
-
#url ⇒ String?
readonly
The image URL (may be a fully qualified URL or a base64-encoded data URL such as “data:image/png;base64,…” ).
Class Method Summary collapse
-
.from_h(hash) ⇒ InputImage
Deserialize an InputImage from a Hash.
Instance Method Summary collapse
-
#initialize(url: nil, detail: nil, **extra) ⇒ InputImage
constructor
Create a new InputImage content object.
-
#to_h ⇒ Hash
Serialize to a Hash with string keys.
Constructor Details
#initialize(url: nil, detail: nil, **extra) ⇒ InputImage
Create a new InputImage content object.
36 37 38 39 40 |
# File 'lib/prompt_builder/content/input_image.rb', line 36 def initialize(url: nil, detail: nil, **extra) @detail = detail&.to_s @extra = normalize_extra_kwargs(extra) @url = url&.to_s end |
Instance Attribute Details
#detail ⇒ String? (readonly)
Returns the detail level for the image.
12 13 14 |
# File 'lib/prompt_builder/content/input_image.rb', line 12 def detail @detail end |
#extra ⇒ Hash? (readonly)
Returns provider-specific extra data.
15 16 17 |
# File 'lib/prompt_builder/content/input_image.rb', line 15 def extra @extra end |
#url ⇒ String? (readonly)
Returns the image URL (may be a fully qualified URL or a base64-encoded data URL such as “data:image/png;base64,…” ).
9 10 11 |
# File 'lib/prompt_builder/content/input_image.rb', line 9 def url @url end |
Class Method Details
.from_h(hash) ⇒ InputImage
Deserialize an InputImage from a Hash.
22 23 24 25 26 27 28 |
# File 'lib/prompt_builder/content/input_image.rb', line 22 def from_h(hash) new( url: hash["url"], detail: hash["detail"], **hash.except("type", "url", "detail").transform_keys(&:to_sym) ) end |
Instance Method Details
#to_h ⇒ Hash
Serialize to a Hash with string keys. Nil values are omitted.
45 46 47 48 49 50 51 |
# File 'lib/prompt_builder/content/input_image.rb', line 45 def to_h h = {"type" => "input_image"} h["url"] = @url if @url h["detail"] = @detail if @detail h = PromptBuilder.jsonify(@extra).merge(h) unless @extra.empty? h end |