Class: PromptBuilder::Content::RefusalContent

Inherits:
Base
  • Object
show all
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

Base::TYPES

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(refusal:, **extra) ⇒ RefusalContent

Create a new RefusalContent object.

Parameters:

  • refusal (String)

    the refusal message

  • extra (Hash)

    provider-specific extra keyword arguments



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

#extraHash? (readonly)

Returns provider-specific extra data.

Returns:

  • (Hash, nil)

    provider-specific extra data



11
12
13
# File 'lib/prompt_builder/content/refusal_content.rb', line 11

def extra
  @extra
end

#refusalString (readonly)

Returns the refusal message.

Returns:

  • (String)

    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.

Parameters:

  • hash (Hash)

    a Hash with string keys

Returns:



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_hHash

Serialize to a Hash with string keys.

Returns:

  • (Hash)


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