Class: Durable::Llm::Providers::OpenAI::OpenAIResponse

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

Overview

Response object for OpenAI chat completion API responses.

This class wraps the raw response from OpenAI’s chat completions endpoint and provides a consistent interface for accessing choices, usage data, and other response components.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ OpenAIResponse

Returns a new instance of OpenAIResponse.



271
272
273
# File 'lib/durable/llm/providers/openai.rb', line 271

def initialize(response)
  @raw_response = response
end

Instance Attribute Details

#raw_responseObject (readonly)

Returns the value of attribute raw_response.



269
270
271
# File 'lib/durable/llm/providers/openai.rb', line 269

def raw_response
  @raw_response
end

Instance Method Details

#choicesObject



275
276
277
# File 'lib/durable/llm/providers/openai.rb', line 275

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

#dataObject



279
280
281
# File 'lib/durable/llm/providers/openai.rb', line 279

def data
  @raw_response['data']
end

#embeddingObject



283
284
285
# File 'lib/durable/llm/providers/openai.rb', line 283

def embedding
  @raw_response['embedding']
end

#to_sObject



287
288
289
# File 'lib/durable/llm/providers/openai.rb', line 287

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