Class: PromptBuilder::Items::ItemReference
- Defined in:
- lib/prompt_builder/items/item_reference.rb
Overview
Represents a reference to an existing conversation item by ID.
Constant Summary
Constants inherited from Base
Instance Attribute Summary collapse
-
#extra ⇒ Hash?
readonly
Provider-specific extra data.
-
#id ⇒ String
readonly
The referenced item identifier.
Class Method Summary collapse
-
.from_h(hash) ⇒ ItemReference
Deserialize an ItemReference from a Hash.
Instance Method Summary collapse
-
#initialize(id:, **extra) ⇒ ItemReference
constructor
Create a new ItemReference item.
-
#to_h ⇒ Hash
Serialize to a Hash with string keys.
Constructor Details
#initialize(id:, **extra) ⇒ ItemReference
Create a new ItemReference item.
17 18 19 20 |
# File 'lib/prompt_builder/items/item_reference.rb', line 17 def initialize(id:, **extra) @id = id&.to_s @extra = extra.transform_keys(&:to_s) end |
Instance Attribute Details
#extra ⇒ Hash? (readonly)
Returns provider-specific extra data.
11 12 13 |
# File 'lib/prompt_builder/items/item_reference.rb', line 11 def extra @extra end |
#id ⇒ String (readonly)
Returns the referenced item identifier.
8 9 10 |
# File 'lib/prompt_builder/items/item_reference.rb', line 8 def id @id end |
Class Method Details
.from_h(hash) ⇒ ItemReference
Deserialize an ItemReference from a Hash.
27 28 29 |
# File 'lib/prompt_builder/items/item_reference.rb', line 27 def from_h(hash) new(id: hash["id"], **hash.except("type", "id").transform_keys(&:to_sym)) end |
Instance Method Details
#to_h ⇒ Hash
Serialize to a Hash with string keys.
35 36 37 38 39 |
# File 'lib/prompt_builder/items/item_reference.rb', line 35 def to_h h = {"type" => "item_reference", "id" => @id} h = PromptBuilder.jsonify(@extra).merge(h) unless @extra.empty? h end |