Class: OpenAI::Models::Chat::ChatCompletionChunk::Choice

Inherits:
Internal::Type::BaseModel show all
Defined in:
lib/openai/models/chat/chat_completion_chunk.rb,
sig/openai/models/chat/chat_completion_chunk.rbs

Defined Under Namespace

Modules: FinishReason Classes: Delta, Logprobs

Instance Attribute Summary collapse

Attributes inherited from Internal::Type::BaseModel

#last_response

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Internal::Type::BaseModel

==, #==, #[], #_request_id, #_set_last_response, coerce, #deconstruct_keys, #deep_to_h, dump, #encode_with, fields, hash, #hash, inherited, #inspect, inspect, known_fields, optional, recursively_to_h, required, #to_h, #to_json, #to_s, to_sorbet_type, #to_yaml

Methods included from Internal::Type::Converter

#coerce, coerce, coerce_cached, coerce_with_error, #dump, dump, #inspect, inspect, meta_info, new_coerce_state, resolve_type, type_info

Methods included from Internal::Util::SorbetRuntimeSupport

#const_missing, #define_sorbet_constant!, #sorbet_constant_defined?, #to_sorbet_type, to_sorbet_type

Constructor Details

#initialize(delta:, index:, finish_reason: nil, logprobs: nil) ⇒ Choice

Returns a new instance of Choice.

Parameters:

  • delta —

    A chat completion delta generated by streamed model responses. Streamed audio can arrive in partial updates with an ID, base64 data, or transcript text. The final audio update contains only its expiry timestamp.

  • index —

    The index of the choice in the list of choices.

  • finish_reason (defaults to: nil) —

    The reason the model stopped generating tokens. This will be stop if the model hit a natural stop point or a provided stop sequence, length if the maximum number of tokens specified in the request was reached, content_filter if content was omitted due to a flag from our content filters, tool_calls if the model called a tool, or function_call (deprecated) if the model called a function. Omitted from the final audio update containing only delta.audio.expires_at.

  • logprobs (defaults to: nil) —

    Log probability information for the choice.

  • delta: (OpenAI::Chat::ChatCompletionChunk::Choice::Delta)
  • index: (Integer)
  • finish_reason: (OpenAI::Models::Chat::ChatCompletionChunk::Choice::finish_reason, nil) (defaults to: nil)
  • logprobs: (OpenAI::Chat::ChatCompletionChunk::Choice::Logprobs, nil) (defaults to: nil)


173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
# File 'lib/openai/models/chat/chat_completion_chunk.rb', line 173

class Choice < OpenAI::Internal::Type::BaseModel
  # @!attribute delta
  #   A chat completion delta generated by streamed model responses. Streamed audio
  #   can arrive in partial updates with an ID, base64 data, or transcript text. The
  #   final audio update contains only its expiry timestamp.
  #
  #   @return [OpenAI::Models::Chat::ChatCompletionChunk::Choice::Delta]
  required :delta, -> { OpenAI::Chat::ChatCompletionChunk::Choice::Delta }

  # @!attribute index
  #   The index of the choice in the list of choices.
  #
  #   @return [Integer]
  required :index, Integer

  # @!attribute finish_reason
  #   The reason the model stopped generating tokens. This will be `stop` if the model
  #   hit a natural stop point or a provided stop sequence, `length` if the maximum
  #   number of tokens specified in the request was reached, `content_filter` if
  #   content was omitted due to a flag from our content filters, `tool_calls` if the
  #   model called a tool, or `function_call` (deprecated) if the model called a
  #   function. Omitted from the final audio update containing only
  #   `delta.audio.expires_at`.
  #
  #   @return [Symbol, OpenAI::Models::Chat::ChatCompletionChunk::Choice::FinishReason, nil]
  optional(
    :finish_reason,
    enum: -> {
      OpenAI::Chat::ChatCompletionChunk::Choice::FinishReason
    },
    nil?: true
  )

  # @!attribute logprobs
  #   Log probability information for the choice.
  #
  #   @return [OpenAI::Models::Chat::ChatCompletionChunk::Choice::Logprobs, nil]
  optional :logprobs, -> { OpenAI::Chat::ChatCompletionChunk::Choice::Logprobs }, nil?: true

  # @!method initialize(delta:, index:, finish_reason: nil, logprobs: nil)
  #   @param delta [OpenAI::Models::Chat::ChatCompletionChunk::Choice::Delta]
  #     A chat completion delta generated by streamed model responses. Streamed audio
  #     can arrive in partial updates with an ID, base64 data, or transcript text. The
  #     final audio update contains only its expiry timestamp.
  #
  #   @param index [Integer]
  #     The index of the choice in the list of choices.
  #
  #   @param finish_reason [Symbol, OpenAI::Models::Chat::ChatCompletionChunk::Choice::FinishReason, nil]
  #     The reason the model stopped generating tokens. This will be `stop` if the model
  #     hit a natural stop point or a provided stop sequence, `length` if the maximum
  #     number of tokens specified in the request was reached, `content_filter` if
  #     content was omitted due to a flag from our content filters, `tool_calls` if the
  #     model called a tool, or `function_call` (deprecated) if the model called a
  #     function. Omitted from the final audio update containing only
  #     `delta.audio.expires_at`.
  #
  #   @param logprobs [OpenAI::Models::Chat::ChatCompletionChunk::Choice::Logprobs, nil]
  #     Log probability information for the choice.

  # @see OpenAI::Models::Chat::ChatCompletionChunk::Choice#delta
  class Delta < OpenAI::Internal::Type::BaseModel
    # @!attribute audio
    #   A partial audio response. Audio chunks may carry an ID, base64 data, or
    #   transcript text; the final audio update contains only its expiry timestamp.
    #
    #   @return [OpenAI::Models::Chat::ChatCompletionChunk::Choice::Delta::Audio, nil]
    optional :audio, -> { OpenAI::Chat::ChatCompletionChunk::Choice::Delta::Audio }

    # @!attribute content
    #   The contents of the chunk message.
    #
    #   @return [String, nil]
    optional :content, String, nil?: true

    # @!attribute function_call
    #   @deprecated
    #
    #   Deprecated and replaced by `tool_calls`. The name and arguments of a function
    #   that should be called, as generated by the model.
    #
    #   @return [OpenAI::Models::Chat::ChatCompletionChunk::Choice::Delta::FunctionCall, nil]
    optional :function_call, -> { OpenAI::Chat::ChatCompletionChunk::Choice::Delta::FunctionCall }

    # @!attribute refusal
    #   The refusal message generated by the model.
    #
    #   @return [String, nil]
    optional :refusal, String, nil?: true

    # @!attribute role
    #   The role of the author of this message.
    #
    #   @return [Symbol, OpenAI::Models::Chat::ChatCompletionChunk::Choice::Delta::Role, nil]
    optional :role, enum: -> { OpenAI::Chat::ChatCompletionChunk::Choice::Delta::Role }

    # @!attribute tool_calls
    #
    #   @return [Array<OpenAI::Models::Chat::ChatCompletionChunk::Choice::Delta::ToolCall>, nil]
    optional(
      :tool_calls,
      -> { OpenAI::Internal::Type::ArrayOf[OpenAI::Chat::ChatCompletionChunk::Choice::Delta::ToolCall] }
    )

    # @!method initialize(audio: nil, content: nil, function_call: nil, refusal: nil, role: nil, tool_calls: nil)
    #   A chat completion delta generated by streamed model responses. Streamed audio
    #   can arrive in partial updates with an ID, base64 data, or transcript text. The
    #   final audio update contains only its expiry timestamp.
    #
    #   @param audio [OpenAI::Models::Chat::ChatCompletionChunk::Choice::Delta::Audio]
    #     A partial audio response. Audio chunks may carry an ID, base64 data, or
    #     transcript text; the final audio update contains only its expiry timestamp.
    #
    #   @param content [String, nil]
    #     The contents of the chunk message.
    #
    #   @param function_call [OpenAI::Models::Chat::ChatCompletionChunk::Choice::Delta::FunctionCall]
    #     Deprecated and replaced by `tool_calls`. The name and arguments of a function
    #     that should be called, as generated by the model.
    #
    #   @param refusal [String, nil]
    #     The refusal message generated by the model.
    #
    #   @param role [Symbol, OpenAI::Models::Chat::ChatCompletionChunk::Choice::Delta::Role]
    #     The role of the author of this message.
    #
    #   @param tool_calls [Array<OpenAI::Models::Chat::ChatCompletionChunk::Choice::Delta::ToolCall>]

    # @see OpenAI::Models::Chat::ChatCompletionChunk::Choice::Delta#audio
    class Audio < OpenAI::Internal::Type::BaseModel
      # @!attribute id
      #   Unique identifier for this audio response.
      #
      #   @return [String, nil]
      optional :id, String

      # @!attribute data
      #   Base64 encoded audio bytes generated by the model, in the format specified in
      #   the request.
      #
      #   @return [String, nil]
      optional :data, String

      # @!attribute expires_at
      #   The Unix timestamp (in seconds) for when this audio response will no longer be
      #   accessible on the server for use in multi-turn conversations.
      #
      #   @return [Integer, nil]
      optional :expires_at, Integer

      # @!attribute transcript
      #   Transcript text from this audio chunk.
      #
      #   @return [String, nil]
      optional :transcript, String

      # @!method initialize(id: nil, data: nil, expires_at: nil, transcript: nil)
      #   A partial audio response. Audio chunks may carry an ID, base64 data, or
      #   transcript text; the final audio update contains only its expiry timestamp.
      #
      #   @param id [String]
      #     Unique identifier for this audio response.
      #
      #   @param data [String]
      #     Base64 encoded audio bytes generated by the model, in the format specified in
      #     the request.
      #
      #   @param expires_at [Integer]
      #     The Unix timestamp (in seconds) for when this audio response will no longer be
      #     accessible on the server for use in multi-turn conversations.
      #
      #   @param transcript [String]
      #     Transcript text from this audio chunk.
    end

    # @deprecated
    #
    # @see OpenAI::Models::Chat::ChatCompletionChunk::Choice::Delta#function_call
    class FunctionCall < OpenAI::Internal::Type::BaseModel
      # @!attribute arguments
      #   The arguments to call the function with, as generated by the model in JSON
      #   format. Note that the model does not always generate valid JSON, and may
      #   hallucinate parameters not defined by your function schema. Validate the
      #   arguments in your code before calling your function.
      #
      #   @return [String, nil]
      optional :arguments, String

      # @!attribute name
      #   The name of the function to call.
      #
      #   @return [String, nil]
      optional :name, String

      # @!method initialize(arguments: nil, name: nil)
      #   Deprecated and replaced by `tool_calls`. The name and arguments of a function
      #   that should be called, as generated by the model.
      #
      #   @param arguments [String]
      #     The arguments to call the function with, as generated by the model in JSON
      #     format. Note that the model does not always generate valid JSON, and may
      #     hallucinate parameters not defined by your function schema. Validate the
      #     arguments in your code before calling your function.
      #
      #   @param name [String]
      #     The name of the function to call.
    end

    # The role of the author of this message.
    #
    # @see OpenAI::Models::Chat::ChatCompletionChunk::Choice::Delta#role
    module Role
      extend OpenAI::Internal::Type::Enum

      DEVELOPER = :developer
      SYSTEM = :system
      USER = :user
      ASSISTANT = :assistant
      TOOL = :tool

      # @!method self.values
      #   @return [Array<Symbol>]
    end

    class ToolCall < OpenAI::Internal::Type::BaseModel
      # @!attribute index
      #
      #   @return [Integer]
      required :index, Integer

      # @!attribute id
      #   The ID of the tool call.
      #
      #   @return [String, nil]
      optional :id, String

      # @!attribute function
      #
      #   @return [OpenAI::Models::Chat::ChatCompletionChunk::Choice::Delta::ToolCall::Function, nil]
      optional :function, -> { OpenAI::Chat::ChatCompletionChunk::Choice::Delta::ToolCall::Function }

      # @!attribute type
      #   The type of the tool. Currently, only `function` is supported.
      #
      #   @return [Symbol, OpenAI::Models::Chat::ChatCompletionChunk::Choice::Delta::ToolCall::Type, nil]
      optional :type, enum: -> { OpenAI::Chat::ChatCompletionChunk::Choice::Delta::ToolCall::Type }

      # @!method initialize(index:, id: nil, function: nil, type: nil)
      #   @param index [Integer]
      #
      #   @param id [String]
      #     The ID of the tool call.
      #
      #   @param function [OpenAI::Models::Chat::ChatCompletionChunk::Choice::Delta::ToolCall::Function]
      #
      #   @param type [Symbol, OpenAI::Models::Chat::ChatCompletionChunk::Choice::Delta::ToolCall::Type]
      #     The type of the tool. Currently, only `function` is supported.

      # @see OpenAI::Models::Chat::ChatCompletionChunk::Choice::Delta::ToolCall#function
      class Function < OpenAI::Internal::Type::BaseModel
        # @!attribute arguments
        #   The arguments to call the function with, as generated by the model in JSON
        #   format. Note that the model does not always generate valid JSON, and may
        #   hallucinate parameters not defined by your function schema. Validate the
        #   arguments in your code before calling your function.
        #
        #   @return [String, nil]
        optional :arguments, String

        # @!attribute name
        #   The name of the function to call.
        #
        #   @return [String, nil]
        optional :name, String

        # @!method initialize(arguments: nil, name: nil)
        #   @param arguments [String]
        #     The arguments to call the function with, as generated by the model in JSON
        #     format. Note that the model does not always generate valid JSON, and may
        #     hallucinate parameters not defined by your function schema. Validate the
        #     arguments in your code before calling your function.
        #
        #   @param name [String]
        #     The name of the function to call.
      end

      # The type of the tool. Currently, only `function` is supported.
      #
      # @see OpenAI::Models::Chat::ChatCompletionChunk::Choice::Delta::ToolCall#type
      module Type
        extend OpenAI::Internal::Type::Enum

        FUNCTION = :function

        # @!method self.values
        #   @return [Array<Symbol>]
      end
    end
  end

  # The reason the model stopped generating tokens. This will be `stop` if the model
  # hit a natural stop point or a provided stop sequence, `length` if the maximum
  # number of tokens specified in the request was reached, `content_filter` if
  # content was omitted due to a flag from our content filters, `tool_calls` if the
  # model called a tool, or `function_call` (deprecated) if the model called a
  # function. Omitted from the final audio update containing only
  # `delta.audio.expires_at`.
  #
  # @see OpenAI::Models::Chat::ChatCompletionChunk::Choice#finish_reason
  module FinishReason
    extend OpenAI::Internal::Type::Enum

    STOP = :stop
    LENGTH = :length
    TOOL_CALLS = :tool_calls
    CONTENT_FILTER = :content_filter
    FUNCTION_CALL = :function_call

    # @!method self.values
    #   @return [Array<Symbol>]
  end

  # @see OpenAI::Models::Chat::ChatCompletionChunk::Choice#logprobs
  class Logprobs < OpenAI::Internal::Type::BaseModel
    # @!attribute content
    #   A list of message content tokens with log probability information.
    #
    #   @return [Array<OpenAI::Models::Chat::ChatCompletionTokenLogprob>, nil]
    required(
      :content,
      -> { OpenAI::Internal::Type::ArrayOf[OpenAI::Chat::ChatCompletionTokenLogprob] },
      nil?: true
    )

    # @!attribute refusal
    #   A list of message refusal tokens with log probability information.
    #
    #   @return [Array<OpenAI::Models::Chat::ChatCompletionTokenLogprob>, nil]
    required(
      :refusal,
      -> { OpenAI::Internal::Type::ArrayOf[OpenAI::Chat::ChatCompletionTokenLogprob] },
      nil?: true
    )

    # @!method initialize(content:, refusal:)
    #   Log probability information for the choice.
    #
    #   @param content [Array<OpenAI::Models::Chat::ChatCompletionTokenLogprob>, nil]
    #     A list of message content tokens with log probability information.
    #
    #   @param refusal [Array<OpenAI::Models::Chat::ChatCompletionTokenLogprob>, nil]
    #     A list of message refusal tokens with log probability information.
  end
end

Instance Attribute Details

#delta ⇒ OpenAI::Chat::ChatCompletionChunk::Choice::Delta

A chat completion delta generated by streamed model responses. Streamed audio can arrive in partial updates with an ID, base64 data, or transcript text. The final audio update contains only its expiry timestamp.

Returns:

  • (OpenAI::Chat::ChatCompletionChunk::Choice::Delta)


180
# File 'lib/openai/models/chat/chat_completion_chunk.rb', line 180

required :delta, -> { OpenAI::Chat::ChatCompletionChunk::Choice::Delta }

#finish_reason ⇒ OpenAI::Models::Chat::ChatCompletionChunk::Choice::finish_reason?

The reason the model stopped generating tokens. This will be stop if the model hit a natural stop point or a provided stop sequence, length if the maximum number of tokens specified in the request was reached, content_filter if content was omitted due to a flag from our content filters, tool_calls if the model called a tool, or function_call (deprecated) if the model called a function. Omitted from the final audio update containing only delta.audio.expires_at.

Returns:

  • (OpenAI::Models::Chat::ChatCompletionChunk::Choice::finish_reason, nil)


198
199
200
201
202
203
204
# File 'lib/openai/models/chat/chat_completion_chunk.rb', line 198

optional(
  :finish_reason,
  enum: -> {
    OpenAI::Chat::ChatCompletionChunk::Choice::FinishReason
  },
  nil?: true
)

#index ⇒ Integer

The index of the choice in the list of choices.

Returns:

  • (Integer)


186
# File 'lib/openai/models/chat/chat_completion_chunk.rb', line 186

required :index, Integer

#logprobs ⇒ OpenAI::Chat::ChatCompletionChunk::Choice::Logprobs?

Log probability information for the choice.

Returns:

  • (OpenAI::Chat::ChatCompletionChunk::Choice::Logprobs, nil)


210
# File 'lib/openai/models/chat/chat_completion_chunk.rb', line 210

optional :logprobs, -> { OpenAI::Chat::ChatCompletionChunk::Choice::Logprobs }, nil?: true

Class Method Details

.values ⇒ Array<Symbol>

Returns:

  • (Array<Symbol>)


# File 'lib/openai/models/chat/chat_completion_chunk.rb', line 467

Instance Method Details

#to_hash ⇒ { delta: OpenAI::Chat::ChatCompletionChunk::Choice::Delta, index: Integer, ?finish_reason: OpenAI::Models::Chat::ChatCompletionChunk::Choice::finish_reason?, ?logprobs: OpenAI::Chat::ChatCompletionChunk::Choice::Logprobs? }

Returns:

  • ({ delta: OpenAI::Chat::ChatCompletionChunk::Choice::Delta, index: Integer, ?finish_reason: OpenAI::Models::Chat::ChatCompletionChunk::Choice::finish_reason?, ?logprobs: OpenAI::Chat::ChatCompletionChunk::Choice::Logprobs? })


229
230
231
232
233
234
# File 'sig/openai/models/chat/chat_completion_chunk.rbs', line 229

def to_hash: -> {
  delta: OpenAI::Chat::ChatCompletionChunk::Choice::Delta,
  index: Integer,
  ?finish_reason: OpenAI::Models::Chat::ChatCompletionChunk::Choice::finish_reason?,
  ?logprobs: OpenAI::Chat::ChatCompletionChunk::Choice::Logprobs?
}