openai 0.65.0 → 0.66.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/README.md +1 -1
  4. data/lib/openai/models/chat/chat_completion.rb +341 -3
  5. data/lib/openai/models/chat/chat_completion_chunk.rb +341 -1
  6. data/lib/openai/models/chat/completion_create_params.rb +26 -1
  7. data/lib/openai/models/responses/response.rb +275 -1
  8. data/lib/openai/models/responses/response_create_params.rb +26 -1
  9. data/lib/openai/models/responses/responses_client_event.rb +27 -1
  10. data/lib/openai/resources/chat/completions.rb +6 -2
  11. data/lib/openai/resources/responses.rb +6 -2
  12. data/lib/openai/version.rb +1 -1
  13. data/rbi/openai/models/chat/chat_completion.rbi +620 -3
  14. data/rbi/openai/models/chat/chat_completion_chunk.rbi +621 -0
  15. data/rbi/openai/models/chat/completion_create_params.rbi +52 -0
  16. data/rbi/openai/models/responses/response.rbi +485 -0
  17. data/rbi/openai/models/responses/response_create_params.rbi +54 -0
  18. data/rbi/openai/models/responses/responses_client_event.rbi +54 -0
  19. data/rbi/openai/resources/chat/completions.rbi +12 -0
  20. data/rbi/openai/resources/responses.rbi +12 -0
  21. data/sig/openai/models/chat/chat_completion.rbs +243 -0
  22. data/sig/openai/models/chat/chat_completion_chunk.rbs +243 -0
  23. data/sig/openai/models/chat/completion_create_params.rbs +15 -0
  24. data/sig/openai/models/responses/response.rbs +189 -0
  25. data/sig/openai/models/responses/response_create_params.rbs +15 -0
  26. data/sig/openai/models/responses/responses_client_event.rbs +15 -0
  27. data/sig/openai/resources/chat/completions.rbs +2 -0
  28. data/sig/openai/resources/responses.rbs +2 -0
  29. metadata +2 -2
@@ -37,6 +37,13 @@ module OpenAI
37
37
  # @return [Symbol, :"chat.completion.chunk"]
38
38
  required :object, const: :"chat.completion.chunk"
39
39
 
40
+ # @!attribute moderation
41
+ # Moderation results for the request input and generated output. Present on the
42
+ # moderation chunk when moderated completions are requested.
43
+ #
44
+ # @return [OpenAI::Models::Chat::ChatCompletionChunk::Moderation, nil]
45
+ optional :moderation, -> { OpenAI::Chat::ChatCompletionChunk::Moderation }, nil?: true
46
+
40
47
  # @!attribute service_tier
41
48
  # Specifies the processing type used for serving the request.
42
49
  #
@@ -80,7 +87,7 @@ module OpenAI
80
87
  # @return [OpenAI::Models::CompletionUsage, nil]
81
88
  optional :usage, -> { OpenAI::CompletionUsage }, nil?: true
82
89
 
83
- # @!method initialize(id:, choices:, created:, model:, service_tier: nil, system_fingerprint: nil, usage: nil, object: :"chat.completion.chunk")
90
+ # @!method initialize(id:, choices:, created:, model:, moderation: nil, service_tier: nil, system_fingerprint: nil, usage: nil, object: :"chat.completion.chunk")
84
91
  # Some parameter documentations has been truncated, see
85
92
  # {OpenAI::Models::Chat::ChatCompletionChunk} for more details.
86
93
  #
@@ -96,6 +103,8 @@ module OpenAI
96
103
  #
97
104
  # @param model [String] The model to generate the completion.
98
105
  #
106
+ # @param moderation [OpenAI::Models::Chat::ChatCompletionChunk::Moderation, nil] Moderation results for the request input and generated output. Present
107
+ #
99
108
  # @param service_tier [Symbol, OpenAI::Models::Chat::ChatCompletionChunk::ServiceTier, nil] Specifies the processing type used for serving the request.
100
109
  #
101
110
  # @param system_fingerprint [String] This fingerprint represents the backend configuration that the model runs with.
@@ -370,6 +379,337 @@ module OpenAI
370
379
  end
371
380
  end
372
381
 
382
+ # @see OpenAI::Models::Chat::ChatCompletionChunk#moderation
383
+ class Moderation < OpenAI::Internal::Type::BaseModel
384
+ # @!attribute input
385
+ # Moderation for the request input.
386
+ #
387
+ # @return [OpenAI::Models::Chat::ChatCompletionChunk::Moderation::Input::ModerationResults, OpenAI::Models::Chat::ChatCompletionChunk::Moderation::Input::Error]
388
+ required :input, union: -> { OpenAI::Chat::ChatCompletionChunk::Moderation::Input }
389
+
390
+ # @!attribute output
391
+ # Moderation for the generated output.
392
+ #
393
+ # @return [OpenAI::Models::Chat::ChatCompletionChunk::Moderation::Output::ModerationResults, OpenAI::Models::Chat::ChatCompletionChunk::Moderation::Output::Error]
394
+ required :output, union: -> { OpenAI::Chat::ChatCompletionChunk::Moderation::Output }
395
+
396
+ # @!method initialize(input:, output:)
397
+ # Moderation results for the request input and generated output. Present on the
398
+ # moderation chunk when moderated completions are requested.
399
+ #
400
+ # @param input [OpenAI::Models::Chat::ChatCompletionChunk::Moderation::Input::ModerationResults, OpenAI::Models::Chat::ChatCompletionChunk::Moderation::Input::Error] Moderation for the request input.
401
+ #
402
+ # @param output [OpenAI::Models::Chat::ChatCompletionChunk::Moderation::Output::ModerationResults, OpenAI::Models::Chat::ChatCompletionChunk::Moderation::Output::Error] Moderation for the generated output.
403
+
404
+ # Moderation for the request input.
405
+ #
406
+ # @see OpenAI::Models::Chat::ChatCompletionChunk::Moderation#input
407
+ module Input
408
+ extend OpenAI::Internal::Type::Union
409
+
410
+ discriminator :type
411
+
412
+ # Successful moderation results for the request input or generated output.
413
+ variant :moderation_results,
414
+ -> { OpenAI::Chat::ChatCompletionChunk::Moderation::Input::ModerationResults }
415
+
416
+ # An error produced while attempting moderation.
417
+ variant :error, -> { OpenAI::Chat::ChatCompletionChunk::Moderation::Input::Error }
418
+
419
+ class ModerationResults < OpenAI::Internal::Type::BaseModel
420
+ # @!attribute model
421
+ # The moderation model used to generate the results.
422
+ #
423
+ # @return [String]
424
+ required :model, String
425
+
426
+ # @!attribute results
427
+ # A list of moderation results.
428
+ #
429
+ # @return [Array<OpenAI::Models::Chat::ChatCompletionChunk::Moderation::Input::ModerationResults::Result>]
430
+ required :results,
431
+ -> { OpenAI::Internal::Type::ArrayOf[OpenAI::Chat::ChatCompletionChunk::Moderation::Input::ModerationResults::Result] }
432
+
433
+ # @!attribute type
434
+ # The object type, which is always `moderation_results`.
435
+ #
436
+ # @return [Symbol, :moderation_results]
437
+ required :type, const: :moderation_results
438
+
439
+ # @!method initialize(model:, results:, type: :moderation_results)
440
+ # Successful moderation results for the request input or generated output.
441
+ #
442
+ # @param model [String] The moderation model used to generate the results.
443
+ #
444
+ # @param results [Array<OpenAI::Models::Chat::ChatCompletionChunk::Moderation::Input::ModerationResults::Result>] A list of moderation results.
445
+ #
446
+ # @param type [Symbol, :moderation_results] The object type, which is always `moderation_results`.
447
+
448
+ class Result < OpenAI::Internal::Type::BaseModel
449
+ # @!attribute categories
450
+ # A dictionary of moderation categories to booleans, True if the input is flagged
451
+ # under this category.
452
+ #
453
+ # @return [Hash{Symbol=>Boolean}]
454
+ required :categories, OpenAI::Internal::Type::HashOf[OpenAI::Internal::Type::Boolean]
455
+
456
+ # @!attribute category_applied_input_types
457
+ # Which modalities of input are reflected by the score for each category.
458
+ #
459
+ # @return [Hash{Symbol=>Array<Symbol, OpenAI::Models::Chat::ChatCompletionChunk::Moderation::Input::ModerationResults::Result::CategoryAppliedInputType>}]
460
+ required :category_applied_input_types,
461
+ -> do
462
+ OpenAI::Internal::Type::HashOf[
463
+ OpenAI::Internal::Type::ArrayOf[
464
+ enum: OpenAI::Chat::ChatCompletionChunk::Moderation::Input::ModerationResults::Result::CategoryAppliedInputType
465
+ ]
466
+ ]
467
+ end
468
+
469
+ # @!attribute category_scores
470
+ # A dictionary of moderation categories to scores.
471
+ #
472
+ # @return [Hash{Symbol=>Float}]
473
+ required :category_scores, OpenAI::Internal::Type::HashOf[Float]
474
+
475
+ # @!attribute flagged
476
+ # A boolean indicating whether the content was flagged by any category.
477
+ #
478
+ # @return [Boolean]
479
+ required :flagged, OpenAI::Internal::Type::Boolean
480
+
481
+ # @!attribute model
482
+ # The moderation model that produced this result.
483
+ #
484
+ # @return [String]
485
+ required :model, String
486
+
487
+ # @!attribute type
488
+ # The object type, which was always `moderation_result` for successful moderation
489
+ # results.
490
+ #
491
+ # @return [Symbol, :moderation_result]
492
+ required :type, const: :moderation_result
493
+
494
+ # @!method initialize(categories:, category_applied_input_types:, category_scores:, flagged:, model:, type: :moderation_result)
495
+ # Some parameter documentations has been truncated, see
496
+ # {OpenAI::Models::Chat::ChatCompletionChunk::Moderation::Input::ModerationResults::Result}
497
+ # for more details.
498
+ #
499
+ # A moderation result produced for the response input or output.
500
+ #
501
+ # @param categories [Hash{Symbol=>Boolean}] A dictionary of moderation categories to booleans, True if the input is flagged
502
+ #
503
+ # @param category_applied_input_types [Hash{Symbol=>Array<Symbol, OpenAI::Models::Chat::ChatCompletionChunk::Moderation::Input::ModerationResults::Result::CategoryAppliedInputType>}] Which modalities of input are reflected by the score for each category.
504
+ #
505
+ # @param category_scores [Hash{Symbol=>Float}] A dictionary of moderation categories to scores.
506
+ #
507
+ # @param flagged [Boolean] A boolean indicating whether the content was flagged by any category.
508
+ #
509
+ # @param model [String] The moderation model that produced this result.
510
+ #
511
+ # @param type [Symbol, :moderation_result] The object type, which was always `moderation_result` for successful moderation
512
+
513
+ module CategoryAppliedInputType
514
+ extend OpenAI::Internal::Type::Enum
515
+
516
+ TEXT = :text
517
+ IMAGE = :image
518
+
519
+ # @!method self.values
520
+ # @return [Array<Symbol>]
521
+ end
522
+ end
523
+ end
524
+
525
+ class Error < OpenAI::Internal::Type::BaseModel
526
+ # @!attribute code
527
+ # The error code.
528
+ #
529
+ # @return [String]
530
+ required :code, String
531
+
532
+ # @!attribute message
533
+ # The error message.
534
+ #
535
+ # @return [String]
536
+ required :message, String
537
+
538
+ # @!attribute type
539
+ # The object type, which is always `error`.
540
+ #
541
+ # @return [Symbol, :error]
542
+ required :type, const: :error
543
+
544
+ # @!method initialize(code:, message:, type: :error)
545
+ # An error produced while attempting moderation.
546
+ #
547
+ # @param code [String] The error code.
548
+ #
549
+ # @param message [String] The error message.
550
+ #
551
+ # @param type [Symbol, :error] The object type, which is always `error`.
552
+ end
553
+
554
+ # @!method self.variants
555
+ # @return [Array(OpenAI::Models::Chat::ChatCompletionChunk::Moderation::Input::ModerationResults, OpenAI::Models::Chat::ChatCompletionChunk::Moderation::Input::Error)]
556
+ end
557
+
558
+ # Moderation for the generated output.
559
+ #
560
+ # @see OpenAI::Models::Chat::ChatCompletionChunk::Moderation#output
561
+ module Output
562
+ extend OpenAI::Internal::Type::Union
563
+
564
+ discriminator :type
565
+
566
+ # Successful moderation results for the request input or generated output.
567
+ variant :moderation_results,
568
+ -> { OpenAI::Chat::ChatCompletionChunk::Moderation::Output::ModerationResults }
569
+
570
+ # An error produced while attempting moderation.
571
+ variant :error, -> { OpenAI::Chat::ChatCompletionChunk::Moderation::Output::Error }
572
+
573
+ class ModerationResults < OpenAI::Internal::Type::BaseModel
574
+ # @!attribute model
575
+ # The moderation model used to generate the results.
576
+ #
577
+ # @return [String]
578
+ required :model, String
579
+
580
+ # @!attribute results
581
+ # A list of moderation results.
582
+ #
583
+ # @return [Array<OpenAI::Models::Chat::ChatCompletionChunk::Moderation::Output::ModerationResults::Result>]
584
+ required :results,
585
+ -> { OpenAI::Internal::Type::ArrayOf[OpenAI::Chat::ChatCompletionChunk::Moderation::Output::ModerationResults::Result] }
586
+
587
+ # @!attribute type
588
+ # The object type, which is always `moderation_results`.
589
+ #
590
+ # @return [Symbol, :moderation_results]
591
+ required :type, const: :moderation_results
592
+
593
+ # @!method initialize(model:, results:, type: :moderation_results)
594
+ # Successful moderation results for the request input or generated output.
595
+ #
596
+ # @param model [String] The moderation model used to generate the results.
597
+ #
598
+ # @param results [Array<OpenAI::Models::Chat::ChatCompletionChunk::Moderation::Output::ModerationResults::Result>] A list of moderation results.
599
+ #
600
+ # @param type [Symbol, :moderation_results] The object type, which is always `moderation_results`.
601
+
602
+ class Result < OpenAI::Internal::Type::BaseModel
603
+ # @!attribute categories
604
+ # A dictionary of moderation categories to booleans, True if the input is flagged
605
+ # under this category.
606
+ #
607
+ # @return [Hash{Symbol=>Boolean}]
608
+ required :categories, OpenAI::Internal::Type::HashOf[OpenAI::Internal::Type::Boolean]
609
+
610
+ # @!attribute category_applied_input_types
611
+ # Which modalities of input are reflected by the score for each category.
612
+ #
613
+ # @return [Hash{Symbol=>Array<Symbol, OpenAI::Models::Chat::ChatCompletionChunk::Moderation::Output::ModerationResults::Result::CategoryAppliedInputType>}]
614
+ required :category_applied_input_types,
615
+ -> do
616
+ OpenAI::Internal::Type::HashOf[
617
+ OpenAI::Internal::Type::ArrayOf[
618
+ enum: OpenAI::Chat::ChatCompletionChunk::Moderation::Output::ModerationResults::Result::CategoryAppliedInputType
619
+ ]
620
+ ]
621
+ end
622
+
623
+ # @!attribute category_scores
624
+ # A dictionary of moderation categories to scores.
625
+ #
626
+ # @return [Hash{Symbol=>Float}]
627
+ required :category_scores, OpenAI::Internal::Type::HashOf[Float]
628
+
629
+ # @!attribute flagged
630
+ # A boolean indicating whether the content was flagged by any category.
631
+ #
632
+ # @return [Boolean]
633
+ required :flagged, OpenAI::Internal::Type::Boolean
634
+
635
+ # @!attribute model
636
+ # The moderation model that produced this result.
637
+ #
638
+ # @return [String]
639
+ required :model, String
640
+
641
+ # @!attribute type
642
+ # The object type, which was always `moderation_result` for successful moderation
643
+ # results.
644
+ #
645
+ # @return [Symbol, :moderation_result]
646
+ required :type, const: :moderation_result
647
+
648
+ # @!method initialize(categories:, category_applied_input_types:, category_scores:, flagged:, model:, type: :moderation_result)
649
+ # Some parameter documentations has been truncated, see
650
+ # {OpenAI::Models::Chat::ChatCompletionChunk::Moderation::Output::ModerationResults::Result}
651
+ # for more details.
652
+ #
653
+ # A moderation result produced for the response input or output.
654
+ #
655
+ # @param categories [Hash{Symbol=>Boolean}] A dictionary of moderation categories to booleans, True if the input is flagged
656
+ #
657
+ # @param category_applied_input_types [Hash{Symbol=>Array<Symbol, OpenAI::Models::Chat::ChatCompletionChunk::Moderation::Output::ModerationResults::Result::CategoryAppliedInputType>}] Which modalities of input are reflected by the score for each category.
658
+ #
659
+ # @param category_scores [Hash{Symbol=>Float}] A dictionary of moderation categories to scores.
660
+ #
661
+ # @param flagged [Boolean] A boolean indicating whether the content was flagged by any category.
662
+ #
663
+ # @param model [String] The moderation model that produced this result.
664
+ #
665
+ # @param type [Symbol, :moderation_result] The object type, which was always `moderation_result` for successful moderation
666
+
667
+ module CategoryAppliedInputType
668
+ extend OpenAI::Internal::Type::Enum
669
+
670
+ TEXT = :text
671
+ IMAGE = :image
672
+
673
+ # @!method self.values
674
+ # @return [Array<Symbol>]
675
+ end
676
+ end
677
+ end
678
+
679
+ class Error < OpenAI::Internal::Type::BaseModel
680
+ # @!attribute code
681
+ # The error code.
682
+ #
683
+ # @return [String]
684
+ required :code, String
685
+
686
+ # @!attribute message
687
+ # The error message.
688
+ #
689
+ # @return [String]
690
+ required :message, String
691
+
692
+ # @!attribute type
693
+ # The object type, which is always `error`.
694
+ #
695
+ # @return [Symbol, :error]
696
+ required :type, const: :error
697
+
698
+ # @!method initialize(code:, message:, type: :error)
699
+ # An error produced while attempting moderation.
700
+ #
701
+ # @param code [String] The error code.
702
+ #
703
+ # @param message [String] The error message.
704
+ #
705
+ # @param type [Symbol, :error] The object type, which is always `error`.
706
+ end
707
+
708
+ # @!method self.variants
709
+ # @return [Array(OpenAI::Models::Chat::ChatCompletionChunk::Moderation::Output::ModerationResults, OpenAI::Models::Chat::ChatCompletionChunk::Moderation::Output::Error)]
710
+ end
711
+ end
712
+
373
713
  # Specifies the processing type used for serving the request.
374
714
  #
375
715
  # - If set to 'auto', then the request will be processed with the service tier
@@ -151,6 +151,12 @@ module OpenAI
151
151
  -> { OpenAI::Internal::Type::ArrayOf[enum: OpenAI::Chat::CompletionCreateParams::Modality] },
152
152
  nil?: true
153
153
 
154
+ # @!attribute moderation
155
+ # Configuration for running moderation on the request input and generated output.
156
+ #
157
+ # @return [OpenAI::Models::Chat::CompletionCreateParams::Moderation, nil]
158
+ optional :moderation, -> { OpenAI::Chat::CompletionCreateParams::Moderation }, nil?: true
159
+
154
160
  # @!attribute n
155
161
  # How many chat completion choices to generate for each input message. Note that
156
162
  # you will be charged based on the number of generated tokens across all of the
@@ -394,7 +400,7 @@ module OpenAI
394
400
  # @return [OpenAI::Models::Chat::CompletionCreateParams::WebSearchOptions, nil]
395
401
  optional :web_search_options, -> { OpenAI::Chat::CompletionCreateParams::WebSearchOptions }
396
402
 
397
- # @!method initialize(messages:, model:, audio: nil, frequency_penalty: nil, function_call: nil, functions: nil, logit_bias: nil, logprobs: nil, max_completion_tokens: nil, max_tokens: nil, metadata: nil, modalities: nil, n: nil, parallel_tool_calls: nil, prediction: nil, presence_penalty: nil, prompt_cache_key: nil, prompt_cache_retention: nil, reasoning_effort: nil, response_format: nil, safety_identifier: nil, seed: nil, service_tier: nil, stop: nil, store: nil, stream_options: nil, temperature: nil, tool_choice: nil, tools: nil, top_logprobs: nil, top_p: nil, user: nil, verbosity: nil, web_search_options: nil, request_options: {})
403
+ # @!method initialize(messages:, model:, audio: nil, frequency_penalty: nil, function_call: nil, functions: nil, logit_bias: nil, logprobs: nil, max_completion_tokens: nil, max_tokens: nil, metadata: nil, modalities: nil, moderation: nil, n: nil, parallel_tool_calls: nil, prediction: nil, presence_penalty: nil, prompt_cache_key: nil, prompt_cache_retention: nil, reasoning_effort: nil, response_format: nil, safety_identifier: nil, seed: nil, service_tier: nil, stop: nil, store: nil, stream_options: nil, temperature: nil, tool_choice: nil, tools: nil, top_logprobs: nil, top_p: nil, user: nil, verbosity: nil, web_search_options: nil, request_options: {})
398
404
  # Some parameter documentations has been truncated, see
399
405
  # {OpenAI::Models::Chat::CompletionCreateParams} for more details.
400
406
  #
@@ -422,6 +428,8 @@ module OpenAI
422
428
  #
423
429
  # @param modalities [Array<Symbol, OpenAI::Models::Chat::CompletionCreateParams::Modality>, nil] Output types that you would like the model to generate.
424
430
  #
431
+ # @param moderation [OpenAI::Models::Chat::CompletionCreateParams::Moderation, nil] Configuration for running moderation on the request input and generated output.
432
+ #
425
433
  # @param n [Integer, nil] How many chat completion choices to generate for each input message. Note that y
426
434
  #
427
435
  # @param parallel_tool_calls [Boolean] Whether to enable [parallel function calling](https://platform.openai.com/docs/g
@@ -579,6 +587,23 @@ module OpenAI
579
587
  # @return [Array<Symbol>]
580
588
  end
581
589
 
590
+ class Moderation < OpenAI::Internal::Type::BaseModel
591
+ # @!attribute model
592
+ # The moderation model to use for moderated completions, e.g.
593
+ # 'omni-moderation-latest'.
594
+ #
595
+ # @return [String]
596
+ required :model, String
597
+
598
+ # @!method initialize(model:)
599
+ # Some parameter documentations has been truncated, see
600
+ # {OpenAI::Models::Chat::CompletionCreateParams::Moderation} for more details.
601
+ #
602
+ # Configuration for running moderation on the request input and generated output.
603
+ #
604
+ # @param model [String] The moderation model to use for moderated completions, e.g. 'omni-moderation-lat
605
+ end
606
+
582
607
  # The retention policy for the prompt cache. Set to `24h` to enable extended
583
608
  # prompt caching, which keeps cached prefixes active for longer, up to a maximum
584
609
  # of 24 hours.