Class: Durable::Llm::Providers::Xai::XaiResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/durable/llm/providers/xai.rb

Overview

Represents a response from xAI's chat completion API.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ XaiResponse

Initializes the response with raw API data.

Parameters:

  • response (Hash)

    The parsed JSON response from xAI



206
207
208
# File 'lib/durable/llm/providers/xai.rb', line 206

def initialize(response)
  @raw_response = response
end

Instance Attribute Details

#raw_responseObject (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

#choicesArray<XaiChoice>

Returns the choices from the response.

Returns:

  • (Array<XaiChoice>)

    Array of choice objects



213
214
215
# File 'lib/durable/llm/providers/xai.rb', line 213

def choices
  @raw_response['choices'].map { |choice| XaiChoice.new(choice) }
end

#dataArray?

Returns the data field from the response.

Returns:

  • (Array, nil)

    The data array or nil



220
221
222
# File 'lib/durable/llm/providers/xai.rb', line 220

def data
  @raw_response['data']
end

#to_sString

Converts the response to a string by joining all choice messages.

Returns:

  • (String)

    The concatenated response text



227
228
229
# File 'lib/durable/llm/providers/xai.rb', line 227

def to_s
  choices.map(&:to_s).join(' ')
end