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