Class: PromptBuilder::Content::Base
- Inherits:
-
Object
- Object
- PromptBuilder::Content::Base
- Defined in:
- lib/prompt_builder/content/base.rb
Overview
Base class for content objects. Provides polymorphic deserialization via the type field in the hash representation.
Direct Known Subclasses
InputFile, InputImage, InputText, InputVideo, OutputText, ReasoningText, RefusalContent, SummaryText, Text
Constant Summary collapse
- TYPES =
Content type registry for polymorphic dispatch.
{ "input_file" => "InputFile", "input_image" => "InputImage", "input_text" => "InputText", "input_video" => "InputVideo", "output_text" => "OutputText", "reasoning_text" => "ReasoningText", "refusal" => "RefusalContent", "summary_text" => "SummaryText", "text" => "Text" }.freeze
Class Method Summary collapse
-
.from_h(hash) ⇒ Content::Base
Deserialize a content object from a Hash by dispatching on the
typefield.
Instance Method Summary collapse
-
#to_h ⇒ Hash
Serialize the content object to a Hash with string keys.
Class Method Details
.from_h(hash) ⇒ Content::Base
Deserialize a content object from a Hash by dispatching on the type field.
27 28 29 30 31 32 33 |
# File 'lib/prompt_builder/content/base.rb', line 27 def from_h(hash) type = hash["type"] class_name = TYPES[type] raise InvalidItemError, "Unknown content type: #{type.inspect}" unless class_name Content.const_get(class_name).from_h(hash) end |
Instance Method Details
#to_h ⇒ Hash
Serialize the content object to a Hash with string keys.
39 40 41 |
# File 'lib/prompt_builder/content/base.rb', line 39 def to_h raise NotImplementedError end |