Class: Truffle::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/truffle/response.rb

Overview

A normalized response from a provider's chat call.

Every provider returns one of these regardless of its native wire format, so the agent loop never has to branch on which model it is talking to.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message:, usage: {}, raw: nil, model: nil, finish_reason: nil) ⇒ Response

Returns a new instance of Response.



11
12
13
14
15
16
17
# File 'lib/truffle/response.rb', line 11

def initialize(message:, usage: {}, raw: nil, model: nil, finish_reason: nil)
  @message = message
  @usage = usage || {}
  @raw = raw
  @model = model
  @finish_reason = finish_reason
end

Instance Attribute Details

#finish_reasonObject (readonly)

Returns the value of attribute finish_reason.



9
10
11
# File 'lib/truffle/response.rb', line 9

def finish_reason
  @finish_reason
end

#messageObject (readonly)

Returns the value of attribute message.



9
10
11
# File 'lib/truffle/response.rb', line 9

def message
  @message
end

#modelObject (readonly)

Returns the value of attribute model.



9
10
11
# File 'lib/truffle/response.rb', line 9

def model
  @model
end

#rawObject (readonly)

Returns the value of attribute raw.



9
10
11
# File 'lib/truffle/response.rb', line 9

def raw
  @raw
end

#usageObject (readonly)

Returns the value of attribute usage.



9
10
11
# File 'lib/truffle/response.rb', line 9

def usage
  @usage
end

Instance Method Details

#textObject

The text content of the assistant turn (may be nil on a pure tool call).



20
21
22
# File 'lib/truffle/response.rb', line 20

def text
  message.content
end

#tool_callsObject



24
25
26
# File 'lib/truffle/response.rb', line 24

def tool_calls
  message.tool_calls
end

#tool_calls?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/truffle/response.rb', line 28

def tool_calls?
  message.tool_calls?
end