Class: Durable::Llm::Providers::Xai::XaiStreamChoice

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

Overview

Represents a choice in a streaming response from xAI.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(choice) ⇒ XaiStreamChoice

Initializes the stream choice with delta and finish reason.

Parameters:

  • choice (Array, Hash)

    The choice data from the stream chunk



317
318
319
320
321
# File 'lib/durable/llm/providers/xai.rb', line 317

def initialize(choice)
  @choice = [choice].flatten.first
  @delta = XaiStreamDelta.new(@choice['delta'])
  @finish_reason = @choice['finish_reason']
end

Instance Attribute Details

#deltaObject (readonly)

Returns the value of attribute delta.



312
313
314
# File 'lib/durable/llm/providers/xai.rb', line 312

def delta
  @delta
end

#finish_reasonObject (readonly)

Returns the value of attribute finish_reason.



312
313
314
# File 'lib/durable/llm/providers/xai.rb', line 312

def finish_reason
  @finish_reason
end

Instance Method Details

#to_sString

Converts the choice to a string by returning the delta content.

Returns:

  • (String)

    The delta content



326
327
328
# File 'lib/durable/llm/providers/xai.rb', line 326

def to_s
  @delta.to_s
end