Class: PromptBuilder::Items::ItemReference

Inherits:
Base
  • Object
show all
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

Base::TYPES

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, **extra) ⇒ ItemReference

Create a new ItemReference item.

Parameters:

  • id (String)

    the referenced item identifier

  • extra (Hash)

    provider-specific extra keyword arguments



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

#extraHash? (readonly)

Returns provider-specific extra data.

Returns:

  • (Hash, nil)

    provider-specific extra data



11
12
13
# File 'lib/prompt_builder/items/item_reference.rb', line 11

def extra
  @extra
end

#idString (readonly)

Returns the referenced item identifier.

Returns:

  • (String)

    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.

Parameters:

  • hash (Hash)

    a Hash with string keys

Returns:



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_hHash

Serialize to a Hash with string keys.

Returns:

  • (Hash)


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