Class: PromptBuilder::Items::Reasoning

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

Base::TYPES

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id: nil, status: nil, encrypted_content: nil, summary: [], content: [], **extra) ⇒ Reasoning

Create a new Reasoning item.

Parameters:

  • id (String, nil) (defaults to: nil)

    the reasoning identifier

  • status (String, nil) (defaults to: nil)

    the reasoning status

  • encrypted_content (String, nil) (defaults to: nil)

    the encrypted reasoning content

  • summary (Array<Hash>) (defaults to: [])

    summary blocks

  • content (Array<Hash>) (defaults to: [])

    reasoning content blocks

  • extra (Hash)

    provider-specific extra keyword arguments



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

#contentArray<Hash> (readonly)

Returns reasoning content blocks.

Returns:

  • (Array<Hash>)

    reasoning content blocks



21
22
23
# File 'lib/prompt_builder/items/reasoning.rb', line 21

def content
  @content
end

#encrypted_contentString? (readonly)

Returns the encrypted reasoning content.

Returns:

  • (String, nil)

    the encrypted reasoning content



15
16
17
# File 'lib/prompt_builder/items/reasoning.rb', line 15

def encrypted_content
  @encrypted_content
end

#extraHash? (readonly)

Returns provider-specific extra data.

Returns:

  • (Hash, nil)

    provider-specific extra data



24
25
26
# File 'lib/prompt_builder/items/reasoning.rb', line 24

def extra
  @extra
end

#idString? (readonly)

Returns the reasoning identifier.

Returns:

  • (String, nil)

    the reasoning identifier



9
10
11
# File 'lib/prompt_builder/items/reasoning.rb', line 9

def id
  @id
end

#statusString? (readonly)

Returns the reasoning status.

Returns:

  • (String, nil)

    the reasoning status



12
13
14
# File 'lib/prompt_builder/items/reasoning.rb', line 12

def status
  @status
end

#summaryArray<Hash> (readonly)

Returns summary blocks.

Returns:

  • (Array<Hash>)

    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.

Parameters:

  • hash (Hash)

    a Hash with string keys

Returns:



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_hHash

Serialize to a Hash with string keys. Nil and empty values are omitted.

Returns:

  • (Hash)


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