Class: PromptBuilder::Items::Base
- Inherits:
-
Object
- Object
- PromptBuilder::Items::Base
- Defined in:
- lib/prompt_builder/items/base.rb
Overview
Base class for conversation items. Provides polymorphic deserialization via the type field in the hash representation.
Direct Known Subclasses
Compaction, FunctionCall, FunctionCallOutput, ItemReference, Message, Reasoning
Constant Summary collapse
- TYPES =
Item type registry for polymorphic dispatch.
{ "compaction" => "Compaction", "function_call" => "FunctionCall", "function_call_output" => "FunctionCallOutput", "item_reference" => "ItemReference", "message" => "Message", "reasoning" => "Reasoning" }.freeze
Class Method Summary collapse
-
.from_h(hash) ⇒ Items::Base
Deserialize an item from a Hash by dispatching on the
typefield.
Instance Method Summary collapse
-
#to_h ⇒ Hash
Serialize the item to a Hash with string keys.
Class Method Details
.from_h(hash) ⇒ Items::Base
Deserialize an item from a Hash by dispatching on the type field.
24 25 26 27 28 29 30 |
# File 'lib/prompt_builder/items/base.rb', line 24 def from_h(hash) type = hash["type"] class_name = TYPES[type] raise InvalidItemError, "Unknown item type: #{type.inspect}" unless class_name Items.const_get(class_name).from_h(hash) end |
Instance Method Details
#to_h ⇒ Hash
Serialize the item to a Hash with string keys.
36 37 38 |
# File 'lib/prompt_builder/items/base.rb', line 36 def to_h raise NotImplementedError end |