Class: PromptBuilder::Items::Reasoning
- Defined in:
- lib/prompt_builder/items/reasoning.rb
Overview
Represents a reasoning item in a conversation. This captures the model’s chain-of-thought reasoning output.
Constant Summary
Constants inherited from Base
Instance Attribute Summary collapse
-
#content ⇒ Array<Hash>
readonly
Reasoning content blocks.
-
#encrypted_content ⇒ String?
readonly
The encrypted reasoning content.
-
#extra ⇒ Hash?
readonly
Provider-specific extra data.
-
#id ⇒ String?
readonly
The reasoning identifier.
-
#status ⇒ String?
readonly
The reasoning status.
-
#summary ⇒ Array<Hash>
readonly
Summary blocks.
Class Method Summary collapse
-
.from_h(hash) ⇒ Reasoning
Deserialize a Reasoning item from a Hash.
Instance Method Summary collapse
-
#initialize(id: nil, status: nil, encrypted_content: nil, summary: [], content: [], **extra) ⇒ Reasoning
constructor
Create a new Reasoning item.
-
#to_h ⇒ Hash
Serialize to a Hash with string keys.
Constructor Details
#initialize(id: nil, status: nil, encrypted_content: nil, summary: [], content: [], **extra) ⇒ Reasoning
Create a new Reasoning item.
34 35 36 37 38 39 40 41 |
# File 'lib/prompt_builder/items/reasoning.rb', line 34 def initialize(id: nil, status: nil, encrypted_content: nil, summary: [], content: [], **extra) @id = id&.to_s @status = status&.to_s @encrypted_content = encrypted_content&.to_s @summary = PromptBuilder.jsonify(summary) @content = PromptBuilder.jsonify(content) @extra = extra.transform_keys(&:to_s) end |
Instance Attribute Details
#content ⇒ Array<Hash> (readonly)
Returns reasoning content blocks.
21 22 23 |
# File 'lib/prompt_builder/items/reasoning.rb', line 21 def content @content end |
#encrypted_content ⇒ String? (readonly)
Returns the encrypted reasoning content.
15 16 17 |
# File 'lib/prompt_builder/items/reasoning.rb', line 15 def encrypted_content @encrypted_content end |
#extra ⇒ Hash? (readonly)
Returns provider-specific extra data.
24 25 26 |
# File 'lib/prompt_builder/items/reasoning.rb', line 24 def extra @extra end |
#id ⇒ String? (readonly)
Returns the reasoning identifier.
9 10 11 |
# File 'lib/prompt_builder/items/reasoning.rb', line 9 def id @id end |
#status ⇒ String? (readonly)
Returns the reasoning status.
12 13 14 |
# File 'lib/prompt_builder/items/reasoning.rb', line 12 def status @status end |
#summary ⇒ Array<Hash> (readonly)
Returns summary blocks.
18 19 20 |
# File 'lib/prompt_builder/items/reasoning.rb', line 18 def summary @summary end |
Class Method Details
.from_h(hash) ⇒ Reasoning
Deserialize a Reasoning item from a Hash.
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/prompt_builder/items/reasoning.rb', line 48 def from_h(hash) new( id: hash["id"], status: hash["status"], encrypted_content: hash["encrypted_content"], summary: hash["summary"] || [], content: hash["content"] || [], **hash.except("type", "id", "status", "encrypted_content", "summary", "content").transform_keys(&:to_sym) ) end |
Instance Method Details
#to_h ⇒ Hash
Serialize to a Hash with string keys. Nil and empty values are omitted.
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/prompt_builder/items/reasoning.rb', line 63 def to_h h = {"type" => "reasoning"} h["id"] = @id if @id h["status"] = @status if @status h["encrypted_content"] = @encrypted_content if @encrypted_content h["summary"] = @summary unless @summary.empty? h["content"] = @content unless @content.empty? h = PromptBuilder.jsonify(@extra).merge(h) unless @extra.empty? h end |