Class: PromptBuilder::Content::InputText
- Defined in:
- lib/prompt_builder/content/input_text.rb
Overview
Represents text input content in a message.
Constant Summary
Constants inherited from Base
Instance Attribute Summary collapse
-
#extra ⇒ Hash?
readonly
Provider-specific extra data.
-
#text ⇒ String
readonly
The text content.
Class Method Summary collapse
-
.from_h(hash) ⇒ InputText
Deserialize an InputText from a Hash.
Instance Method Summary collapse
-
#initialize(text:, **extra) ⇒ InputText
constructor
Create a new InputText content object.
-
#to_h ⇒ Hash
Serialize to a Hash with string keys.
Constructor Details
#initialize(text:, **extra) ⇒ InputText
Create a new InputText content object.
17 18 19 20 |
# File 'lib/prompt_builder/content/input_text.rb', line 17 def initialize(text:, **extra) @text = text&.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/content/input_text.rb', line 11 def extra @extra end |
#text ⇒ String (readonly)
Returns the text content.
8 9 10 |
# File 'lib/prompt_builder/content/input_text.rb', line 8 def text @text end |
Class Method Details
.from_h(hash) ⇒ InputText
Deserialize an InputText from a Hash.
27 28 29 |
# File 'lib/prompt_builder/content/input_text.rb', line 27 def from_h(hash) new(text: hash["text"], **hash.except("type", "text").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/content/input_text.rb', line 35 def to_h h = {"type" => "input_text", "text" => @text} h = PromptBuilder.jsonify(@extra).merge(h) unless @extra.empty? h end |