Class: PromptBuilder::Items::Compaction
- Defined in:
- lib/prompt_builder/items/compaction.rb
Overview
Represents a compaction item that summarizes earlier conversation history.
Constant Summary
Constants inherited from Base
Instance Attribute Summary collapse
-
#created_by ⇒ String?
readonly
Who created the compaction (e.g. “user” or “assistant”).
-
#encrypted_content ⇒ String?
readonly
Encrypted compacted content.
-
#extra ⇒ Hash?
readonly
Provider-specific extra data.
-
#id ⇒ String?
readonly
The compaction item identifier.
Class Method Summary collapse
-
.from_h(hash) ⇒ Compaction
Deserialize a Compaction item from a Hash.
Instance Method Summary collapse
-
#initialize(id: nil, encrypted_content: nil, created_by: nil, **extra) ⇒ Compaction
constructor
Create a new Compaction item.
-
#to_h ⇒ Hash
Serialize to a Hash with string keys.
Constructor Details
#initialize(id: nil, encrypted_content: nil, created_by: nil, **extra) ⇒ Compaction
Create a new Compaction item.
25 26 27 28 29 30 |
# File 'lib/prompt_builder/items/compaction.rb', line 25 def initialize(id: nil, encrypted_content: nil, created_by: nil, **extra) @id = id&.to_s @encrypted_content = encrypted_content&.to_s @created_by = created_by&.to_s @extra = extra.transform_keys(&:to_s) end |
Instance Attribute Details
#created_by ⇒ String? (readonly)
Returns who created the compaction (e.g. “user” or “assistant”).
14 15 16 |
# File 'lib/prompt_builder/items/compaction.rb', line 14 def created_by @created_by end |
#encrypted_content ⇒ String? (readonly)
Returns encrypted compacted content.
11 12 13 |
# File 'lib/prompt_builder/items/compaction.rb', line 11 def encrypted_content @encrypted_content end |
#extra ⇒ Hash? (readonly)
Returns provider-specific extra data.
17 18 19 |
# File 'lib/prompt_builder/items/compaction.rb', line 17 def extra @extra end |
#id ⇒ String? (readonly)
Returns the compaction item identifier.
8 9 10 |
# File 'lib/prompt_builder/items/compaction.rb', line 8 def id @id end |
Class Method Details
.from_h(hash) ⇒ Compaction
Deserialize a Compaction item from a Hash.
37 38 39 40 41 42 43 44 |
# File 'lib/prompt_builder/items/compaction.rb', line 37 def from_h(hash) new( id: hash["id"], encrypted_content: hash["encrypted_content"], created_by: hash["created_by"], **hash.except("type", "id", "encrypted_content", "created_by").transform_keys(&:to_sym) ) end |
Instance Method Details
#to_h ⇒ Hash
Serialize to a Hash with string keys. Nil values are omitted.
50 51 52 53 54 55 56 57 |
# File 'lib/prompt_builder/items/compaction.rb', line 50 def to_h h = {"type" => "compaction"} h["id"] = @id if @id h["encrypted_content"] = @encrypted_content if @encrypted_content h["created_by"] = @created_by if @created_by h = PromptBuilder.jsonify(@extra).merge(h) unless @extra.empty? h end |