Class: Protege::Inference::Provider::Response
- Inherits:
-
Data
- Object
- Data
- Protege::Inference::Provider::Response
- Defined in:
- lib/protege/inference/provider/response.rb
Overview
One normalized generation result — Protege's internal representation of a model turn.
Providers never construct this: they return the wire response hash (an OpenAI assistant message + finish reason — see the providers doc), and Protege wraps it here via Response.from_wire at the Inference↔Provider seam. The harness and tracing read this object.
text: assistant text (nil when the turn is tool calls only).
tool_calls: Array<ToolCall> (empty when none were requested).
finish_reason: provider-reported reason (e.g. 'stop', 'tool_calls', 'length').
Instance Attribute Summary collapse
-
#finish_reason ⇒ Object
readonly
Returns the value of attribute finish_reason.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
-
#tool_calls ⇒ Object
readonly
Returns the value of attribute tool_calls.
Class Method Summary collapse
-
.from_wire(hash) ⇒ Response
Build a Response from a provider's wire response hash:
{ content:, tool_calls: [ {id:, function: {name:, arguments: <JSON string>}} ], finish_reason: }.
Instance Method Summary collapse
-
#to_wire ⇒ Hash
Render the model's output as a compact wire snapshot — the completion a trace trains toward: assistant text, any tool calls (in the shared function-call shape), and the finish reason.
Instance Attribute Details
#finish_reason ⇒ Object (readonly)
Returns the value of attribute finish_reason
17 18 19 |
# File 'lib/protege/inference/provider/response.rb', line 17 def finish_reason @finish_reason end |
#text ⇒ Object (readonly)
Returns the value of attribute text
17 18 19 |
# File 'lib/protege/inference/provider/response.rb', line 17 def text @text end |
#tool_calls ⇒ Object (readonly)
Returns the value of attribute tool_calls
17 18 19 |
# File 'lib/protege/inference/provider/response.rb', line 17 def tool_calls @tool_calls end |
Class Method Details
.from_wire(hash) ⇒ Response
Build a Response from a provider's wire response hash:
{ content:, tool_calls: [ {id:, function: {name:, arguments: <JSON string>}} ], finish_reason: }.
27 28 29 30 31 32 33 |
# File 'lib/protege/inference/provider/response.rb', line 27 def self.from_wire(hash) new( text: hash[:content], tool_calls: Array(hash[:tool_calls]).map { |call| ToolCall.from_wire(call) }, finish_reason: hash[:finish_reason] ) end |
Instance Method Details
#to_wire ⇒ Hash
Render the model's output as a compact wire snapshot — the completion a trace trains toward:
assistant text, any tool calls (in the shared function-call shape), and the finish reason.
Mirrors Request#to_wire; the tracing subscriber stores this verbatim. Nil/empty fields drop.
40 41 42 43 44 45 46 |
# File 'lib/protege/inference/provider/response.rb', line 40 def to_wire { text:, tool_calls: tool_calls.presence&.map(&:to_wire), finish_reason: }.compact end |