Class: Ragents::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/ragents/provider.rb

Overview

Response from a provider generation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content: nil, tool_calls: nil, finish_reason: nil, usage: {}, raw_response: nil) ⇒ Response

Returns a new instance of Response.



95
96
97
98
99
100
101
# File 'lib/ragents/provider.rb', line 95

def initialize(content: nil, tool_calls: nil, finish_reason: nil, usage: {}, raw_response: nil)
  @content = content
  @tool_calls = tool_calls || []
  @finish_reason = finish_reason
  @usage = usage
  @raw_response = raw_response
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



93
94
95
# File 'lib/ragents/provider.rb', line 93

def content
  @content
end

#finish_reasonObject (readonly)

Returns the value of attribute finish_reason.



93
94
95
# File 'lib/ragents/provider.rb', line 93

def finish_reason
  @finish_reason
end

#raw_responseObject (readonly)

Returns the value of attribute raw_response.



93
94
95
# File 'lib/ragents/provider.rb', line 93

def raw_response
  @raw_response
end

#tool_callsObject (readonly)

Returns the value of attribute tool_calls.



93
94
95
# File 'lib/ragents/provider.rb', line 93

def tool_calls
  @tool_calls
end

#usageObject (readonly)

Returns the value of attribute usage.



93
94
95
# File 'lib/ragents/provider.rb', line 93

def usage
  @usage
end

Instance Method Details

#has_tool_calls?Boolean

Returns:

  • (Boolean)


103
104
105
# File 'lib/ragents/provider.rb', line 103

def has_tool_calls?
  !@tool_calls.empty?
end

#to_hObject



114
115
116
117
118
119
120
121
# File 'lib/ragents/provider.rb', line 114

def to_h
  {
    content: @content,
    tool_calls: @tool_calls,
    finish_reason: @finish_reason,
    usage: @usage
  }
end

#to_messageObject



107
108
109
110
111
112
# File 'lib/ragents/provider.rb', line 107

def to_message
  Message.assistant(
    @content,
    tool_calls: @tool_calls.empty? ? nil : @tool_calls.map(&:to_h)
  )
end