Class: Durable::Llm::Providers::Xai::XaiResponse
- Inherits:
-
Object
- Object
- Durable::Llm::Providers::Xai::XaiResponse
- Defined in:
- lib/durable/llm/providers/xai.rb
Overview
Represents a response from xAI's chat completion API.
Instance Attribute Summary collapse
-
#raw_response ⇒ Object
readonly
Returns the value of attribute raw_response.
Instance Method Summary collapse
-
#choices ⇒ Array<XaiChoice>
Returns the choices from the response.
-
#data ⇒ Array?
Returns the data field from the response.
-
#initialize(response) ⇒ XaiResponse
constructor
Initializes the response with raw API data.
-
#to_s ⇒ String
Converts the response to a string by joining all choice messages.
Constructor Details
#initialize(response) ⇒ XaiResponse
Initializes the response with raw API data.
206 207 208 |
# File 'lib/durable/llm/providers/xai.rb', line 206 def initialize(response) @raw_response = response end |
Instance Attribute Details
#raw_response ⇒ Object (readonly)
Returns the value of attribute raw_response.
201 202 203 |
# File 'lib/durable/llm/providers/xai.rb', line 201 def raw_response @raw_response end |
Instance Method Details
#choices ⇒ Array<XaiChoice>
Returns the choices from the response.
213 214 215 |
# File 'lib/durable/llm/providers/xai.rb', line 213 def choices @raw_response['choices'].map { |choice| XaiChoice.new(choice) } end |
#data ⇒ Array?
Returns the data field from the response.
220 221 222 |
# File 'lib/durable/llm/providers/xai.rb', line 220 def data @raw_response['data'] end |
#to_s ⇒ String
Converts the response to a string by joining all choice messages.
227 228 229 |
# File 'lib/durable/llm/providers/xai.rb', line 227 def to_s choices.map(&:to_s).join(' ') end |