Class: PromptBuilder::Items::FunctionCallOutput
- Defined in:
- lib/prompt_builder/items/function_call_output.rb
Overview
Represents the output of a function call. This is added to the conversation after a tool has been invoked.
Constant Summary
Constants inherited from Base
Instance Attribute Summary collapse
-
#call_id ⇒ String
readonly
The call identifier this output corresponds to.
-
#extra ⇒ Hash?
readonly
Provider-specific extra data.
-
#id ⇒ String?
readonly
The function call output identifier.
-
#output ⇒ String, ...
readonly
The output from the function; either a plain string, an array of content objects, or nil (serialized as “”).
-
#status ⇒ String?
readonly
The function call output status.
Class Method Summary collapse
-
.from_h(hash) ⇒ FunctionCallOutput
Deserialize a FunctionCallOutput from a Hash.
Instance Method Summary collapse
-
#initialize(call_id:, output:, id: nil, status: nil, **extra) ⇒ FunctionCallOutput
constructor
Create a new FunctionCallOutput item.
-
#to_h ⇒ Hash
Serialize to a Hash with string keys.
Constructor Details
#initialize(call_id:, output:, id: nil, status: nil, **extra) ⇒ FunctionCallOutput
Create a new FunctionCallOutput item.
32 33 34 35 36 37 38 |
# File 'lib/prompt_builder/items/function_call_output.rb', line 32 def initialize(call_id:, output:, id: nil, status: nil, **extra) @id = id&.to_s @call_id = call_id&.to_s @status = status&.to_s @output = normalize_output(output) @extra = extra.transform_keys(&:to_s) end |
Instance Attribute Details
#call_id ⇒ String (readonly)
Returns the call identifier this output corresponds to.
12 13 14 |
# File 'lib/prompt_builder/items/function_call_output.rb', line 12 def call_id @call_id end |
#extra ⇒ Hash? (readonly)
Returns provider-specific extra data.
22 23 24 |
# File 'lib/prompt_builder/items/function_call_output.rb', line 22 def extra @extra end |
#id ⇒ String? (readonly)
Returns the function call output identifier.
9 10 11 |
# File 'lib/prompt_builder/items/function_call_output.rb', line 9 def id @id end |
#output ⇒ String, ... (readonly)
Returns the output from the function; either a plain string, an array of content objects, or nil (serialized as “”).
19 20 21 |
# File 'lib/prompt_builder/items/function_call_output.rb', line 19 def output @output end |
#status ⇒ String? (readonly)
Returns the function call output status.
15 16 17 |
# File 'lib/prompt_builder/items/function_call_output.rb', line 15 def status @status end |
Class Method Details
.from_h(hash) ⇒ FunctionCallOutput
Deserialize a FunctionCallOutput from a Hash.
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/prompt_builder/items/function_call_output.rb', line 45 def from_h(hash) output = hash["output"] output = output.map { |c| Content::Base.from_h(c) } if output.is_a?(Array) new( id: hash["id"], call_id: hash["call_id"], status: hash["status"], output: output, **hash.except("type", "id", "call_id", "status", "output").transform_keys(&:to_sym) ) end |
Instance Method Details
#to_h ⇒ Hash
Serialize to a Hash with string keys. A nil output is emitted as an empty string so the on-the-wire shape matches the Open Responses API.
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/prompt_builder/items/function_call_output.rb', line 62 def to_h hash = { "type" => "function_call_output", "call_id" => @call_id, "output" => serialize_output } hash["id"] = @id if @id hash["status"] = @status if @status hash = PromptBuilder.jsonify(@extra).merge(hash) unless @extra.empty? hash end |