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