Class: Durable::Llm::Providers::Cohere::CohereResponse

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

Overview

Response object for Cohere chat API responses.

Wraps the raw response and provides a consistent interface for accessing message content and metadata.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ CohereResponse

Returns a new instance of CohereResponse.



154
155
156
# File 'lib/durable/llm/providers/cohere.rb', line 154

def initialize(response)
  @raw_response = response
end

Instance Attribute Details

#raw_responseObject (readonly)

Returns the value of attribute raw_response.



152
153
154
# File 'lib/durable/llm/providers/cohere.rb', line 152

def raw_response
  @raw_response
end

Instance Method Details

#choicesObject



158
159
160
# File 'lib/durable/llm/providers/cohere.rb', line 158

def choices
  @raw_response.dig('message', 'content')&.map { |generation| CohereChoice.new(generation) } || []
end

#to_sObject



162
163
164
# File 'lib/durable/llm/providers/cohere.rb', line 162

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