Class: Protege::Inference::Provider::Response

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

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#finish_reasonObject (readonly)

Returns the value of attribute finish_reason

Returns:

  • (Object)

    the current value of finish_reason



17
18
19
# File 'lib/protege/inference/provider/response.rb', line 17

def finish_reason
  @finish_reason
end

#textObject (readonly)

Returns the value of attribute text

Returns:

  • (Object)

    the current value of text



17
18
19
# File 'lib/protege/inference/provider/response.rb', line 17

def text
  @text
end

#tool_callsObject (readonly)

Returns the value of attribute tool_calls

Returns:

  • (Object)

    the current value of 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: }.

Parameters:

  • hash (Hash)

    the provider's response hash (symbol keys)

Returns:



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_wireHash

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.

Returns:

  • (Hash)

    the response snapshot



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