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
@@ -154,6 +154,24 @@ module OpenAI
154
154
  end
155
155
  attr_writer :model
156
156
 
157
+ # Configuration for running moderation on the input and output of this response.
158
+ sig do
159
+ returns(
160
+ T.nilable(OpenAI::Responses::ResponsesClientEvent::Moderation)
161
+ )
162
+ end
163
+ attr_reader :moderation
164
+
165
+ sig do
166
+ params(
167
+ moderation:
168
+ T.nilable(
169
+ OpenAI::Responses::ResponsesClientEvent::Moderation::OrHash
170
+ )
171
+ ).void
172
+ end
173
+ attr_writer :moderation
174
+
157
175
  # Whether to allow the model to run tool calls in parallel.
158
176
  sig { returns(T.nilable(T::Boolean)) }
159
177
  attr_accessor :parallel_tool_calls
@@ -485,6 +503,10 @@ module OpenAI
485
503
  OpenAI::ChatModel::OrSymbol,
486
504
  OpenAI::ResponsesModel::ResponsesOnlyModel::OrSymbol
487
505
  ),
506
+ moderation:
507
+ T.nilable(
508
+ OpenAI::Responses::ResponsesClientEvent::Moderation::OrHash
509
+ ),
488
510
  parallel_tool_calls: T.nilable(T::Boolean),
489
511
  previous_response_id: T.nilable(String),
490
512
  prompt: T.nilable(OpenAI::Responses::ResponsePrompt::OrHash),
@@ -616,6 +638,8 @@ module OpenAI
616
638
  # [model guide](https://platform.openai.com/docs/models) to browse and compare
617
639
  # available models.
618
640
  model: nil,
641
+ # Configuration for running moderation on the input and output of this response.
642
+ moderation: nil,
619
643
  # Whether to allow the model to run tool calls in parallel.
620
644
  parallel_tool_calls: nil,
621
645
  # The unique ID of the previous response to the model. Use this to create
@@ -777,6 +801,8 @@ module OpenAI
777
801
  OpenAI::ChatModel::OrSymbol,
778
802
  OpenAI::ResponsesModel::ResponsesOnlyModel::OrSymbol
779
803
  ),
804
+ moderation:
805
+ T.nilable(OpenAI::Responses::ResponsesClientEvent::Moderation),
780
806
  parallel_tool_calls: T.nilable(T::Boolean),
781
807
  previous_response_id: T.nilable(String),
782
808
  prompt: T.nilable(OpenAI::Responses::ResponsePrompt),
@@ -934,6 +960,34 @@ module OpenAI
934
960
  end
935
961
  end
936
962
 
963
+ class Moderation < OpenAI::Internal::Type::BaseModel
964
+ OrHash =
965
+ T.type_alias do
966
+ T.any(
967
+ OpenAI::Responses::ResponsesClientEvent::Moderation,
968
+ OpenAI::Internal::AnyHash
969
+ )
970
+ end
971
+
972
+ # The moderation model to use for moderated completions, e.g.
973
+ # 'omni-moderation-latest'.
974
+ sig { returns(String) }
975
+ attr_accessor :model
976
+
977
+ # Configuration for running moderation on the input and output of this response.
978
+ sig { params(model: String).returns(T.attached_class) }
979
+ def self.new(
980
+ # The moderation model to use for moderated completions, e.g.
981
+ # 'omni-moderation-latest'.
982
+ model:
983
+ )
984
+ end
985
+
986
+ sig { override.returns({ model: String }) }
987
+ def to_hash
988
+ end
989
+ end
990
+
937
991
  # The retention policy for the prompt cache. Set to `24h` to enable extended
938
992
  # prompt caching, which keeps cached prefixes active for longer, up to a maximum
939
993
  # of 24 hours.
@@ -67,6 +67,10 @@ module OpenAI
67
67
  OpenAI::Chat::CompletionCreateParams::Modality::OrSymbol
68
68
  ]
69
69
  ),
70
+ moderation:
71
+ T.nilable(
72
+ OpenAI::Chat::CompletionCreateParams::Moderation::OrHash
73
+ ),
70
74
  n: T.nilable(Integer),
71
75
  parallel_tool_calls: T::Boolean,
72
76
  prediction:
@@ -209,6 +213,8 @@ module OpenAI
209
213
  #
210
214
  # `["text", "audio"]`
211
215
  modalities: nil,
216
+ # Configuration for running moderation on the request input and generated output.
217
+ moderation: nil,
212
218
  # How many chat completion choices to generate for each input message. Note that
213
219
  # you will be charged based on the number of generated tokens across all of the
214
220
  # choices. Keep `n` as `1` to minimize costs.
@@ -416,6 +422,10 @@ module OpenAI
416
422
  OpenAI::Chat::CompletionCreateParams::Modality::OrSymbol
417
423
  ]
418
424
  ),
425
+ moderation:
426
+ T.nilable(
427
+ OpenAI::Chat::CompletionCreateParams::Moderation::OrHash
428
+ ),
419
429
  n: T.nilable(Integer),
420
430
  parallel_tool_calls: T::Boolean,
421
431
  prediction:
@@ -556,6 +566,8 @@ module OpenAI
556
566
  #
557
567
  # `["text", "audio"]`
558
568
  modalities: nil,
569
+ # Configuration for running moderation on the request input and generated output.
570
+ moderation: nil,
559
571
  # How many chat completion choices to generate for each input message. Note that
560
572
  # you will be charged based on the number of generated tokens across all of the
561
573
  # choices. Keep `n` as `1` to minimize costs.
@@ -53,6 +53,10 @@ module OpenAI
53
53
  OpenAI::ChatModel::OrSymbol,
54
54
  OpenAI::ResponsesModel::ResponsesOnlyModel::OrSymbol
55
55
  ),
56
+ moderation:
57
+ T.nilable(
58
+ OpenAI::Responses::ResponseCreateParams::Moderation::OrHash
59
+ ),
56
60
  parallel_tool_calls: T.nilable(T::Boolean),
57
61
  previous_response_id: T.nilable(String),
58
62
  prompt: T.nilable(OpenAI::Responses::ResponsePrompt::OrHash),
@@ -188,6 +192,8 @@ module OpenAI
188
192
  # [model guide](https://platform.openai.com/docs/models) to browse and compare
189
193
  # available models.
190
194
  model: nil,
195
+ # Configuration for running moderation on the input and output of this response.
196
+ moderation: nil,
191
197
  # Whether to allow the model to run tool calls in parallel.
192
198
  parallel_tool_calls: nil,
193
199
  # The unique ID of the previous response to the model. Use this to create
@@ -358,6 +364,10 @@ module OpenAI
358
364
  OpenAI::ChatModel::OrSymbol,
359
365
  OpenAI::ResponsesModel::ResponsesOnlyModel::OrSymbol
360
366
  ),
367
+ moderation:
368
+ T.nilable(
369
+ OpenAI::Responses::ResponseCreateParams::Moderation::OrHash
370
+ ),
361
371
  parallel_tool_calls: T.nilable(T::Boolean),
362
372
  previous_response_id: T.nilable(String),
363
373
  prompt: T.nilable(OpenAI::Responses::ResponsePrompt::OrHash),
@@ -499,6 +509,8 @@ module OpenAI
499
509
  # [model guide](https://platform.openai.com/docs/models) to browse and compare
500
510
  # available models.
501
511
  model: nil,
512
+ # Configuration for running moderation on the input and output of this response.
513
+ moderation: nil,
502
514
  # Whether to allow the model to run tool calls in parallel.
503
515
  parallel_tool_calls: nil,
504
516
  # The unique ID of the previous response to the model. Use this to create
@@ -10,6 +10,7 @@ module OpenAI
10
10
  created: Integer,
11
11
  model: String,
12
12
  object: :"chat.completion",
13
+ moderation: OpenAI::Chat::ChatCompletion::Moderation?,
13
14
  service_tier: OpenAI::Models::Chat::ChatCompletion::service_tier?,
14
15
  system_fingerprint: String,
15
16
  usage: OpenAI::CompletionUsage
@@ -26,6 +27,8 @@ module OpenAI
26
27
 
27
28
  attr_accessor object: :"chat.completion"
28
29
 
30
+ attr_accessor moderation: OpenAI::Chat::ChatCompletion::Moderation?
31
+
29
32
  attr_accessor service_tier: OpenAI::Models::Chat::ChatCompletion::service_tier?
30
33
 
31
34
  attr_reader system_fingerprint: String?
@@ -41,6 +44,7 @@ module OpenAI
41
44
  choices: ::Array[OpenAI::Chat::ChatCompletion::Choice],
42
45
  created: Integer,
43
46
  model: String,
47
+ ?moderation: OpenAI::Chat::ChatCompletion::Moderation?,
44
48
  ?service_tier: OpenAI::Models::Chat::ChatCompletion::service_tier?,
45
49
  ?system_fingerprint: String,
46
50
  ?usage: OpenAI::CompletionUsage,
@@ -53,6 +57,7 @@ module OpenAI
53
57
  created: Integer,
54
58
  model: String,
55
59
  object: :"chat.completion",
60
+ moderation: OpenAI::Chat::ChatCompletion::Moderation?,
56
61
  service_tier: OpenAI::Models::Chat::ChatCompletion::service_tier?,
57
62
  system_fingerprint: String,
58
63
  usage: OpenAI::CompletionUsage
@@ -127,6 +132,244 @@ module OpenAI
127
132
  end
128
133
  end
129
134
 
135
+ type moderation =
136
+ {
137
+ input: OpenAI::Models::Chat::ChatCompletion::Moderation::input,
138
+ output: OpenAI::Models::Chat::ChatCompletion::Moderation::output
139
+ }
140
+
141
+ class Moderation < OpenAI::Internal::Type::BaseModel
142
+ attr_accessor input: OpenAI::Models::Chat::ChatCompletion::Moderation::input
143
+
144
+ attr_accessor output: OpenAI::Models::Chat::ChatCompletion::Moderation::output
145
+
146
+ def initialize: (
147
+ input: OpenAI::Models::Chat::ChatCompletion::Moderation::input,
148
+ output: OpenAI::Models::Chat::ChatCompletion::Moderation::output
149
+ ) -> void
150
+
151
+ def to_hash: -> {
152
+ input: OpenAI::Models::Chat::ChatCompletion::Moderation::input,
153
+ output: OpenAI::Models::Chat::ChatCompletion::Moderation::output
154
+ }
155
+
156
+ type input =
157
+ OpenAI::Chat::ChatCompletion::Moderation::Input::ModerationResults
158
+ | OpenAI::Chat::ChatCompletion::Moderation::Input::Error
159
+
160
+ module Input
161
+ extend OpenAI::Internal::Type::Union
162
+
163
+ type moderation_results =
164
+ {
165
+ model: String,
166
+ results: ::Array[OpenAI::Chat::ChatCompletion::Moderation::Input::ModerationResults::Result],
167
+ type: :moderation_results
168
+ }
169
+
170
+ class ModerationResults < OpenAI::Internal::Type::BaseModel
171
+ attr_accessor model: String
172
+
173
+ attr_accessor results: ::Array[OpenAI::Chat::ChatCompletion::Moderation::Input::ModerationResults::Result]
174
+
175
+ attr_accessor type: :moderation_results
176
+
177
+ def initialize: (
178
+ model: String,
179
+ results: ::Array[OpenAI::Chat::ChatCompletion::Moderation::Input::ModerationResults::Result],
180
+ ?type: :moderation_results
181
+ ) -> void
182
+
183
+ def to_hash: -> {
184
+ model: String,
185
+ results: ::Array[OpenAI::Chat::ChatCompletion::Moderation::Input::ModerationResults::Result],
186
+ type: :moderation_results
187
+ }
188
+
189
+ type result =
190
+ {
191
+ categories: ::Hash[Symbol, bool],
192
+ category_applied_input_types: ::Hash[Symbol, ::Array[OpenAI::Models::Chat::ChatCompletion::Moderation::Input::ModerationResults::Result::category_applied_input_type]],
193
+ category_scores: ::Hash[Symbol, Float],
194
+ flagged: bool,
195
+ model: String,
196
+ type: :moderation_result
197
+ }
198
+
199
+ class Result < OpenAI::Internal::Type::BaseModel
200
+ attr_accessor categories: ::Hash[Symbol, bool]
201
+
202
+ attr_accessor category_applied_input_types: ::Hash[Symbol, ::Array[OpenAI::Models::Chat::ChatCompletion::Moderation::Input::ModerationResults::Result::category_applied_input_type]]
203
+
204
+ attr_accessor category_scores: ::Hash[Symbol, Float]
205
+
206
+ attr_accessor flagged: bool
207
+
208
+ attr_accessor model: String
209
+
210
+ attr_accessor type: :moderation_result
211
+
212
+ def initialize: (
213
+ categories: ::Hash[Symbol, bool],
214
+ category_applied_input_types: ::Hash[Symbol, ::Array[OpenAI::Models::Chat::ChatCompletion::Moderation::Input::ModerationResults::Result::category_applied_input_type]],
215
+ category_scores: ::Hash[Symbol, Float],
216
+ flagged: bool,
217
+ model: String,
218
+ ?type: :moderation_result
219
+ ) -> void
220
+
221
+ def to_hash: -> {
222
+ categories: ::Hash[Symbol, bool],
223
+ category_applied_input_types: ::Hash[Symbol, ::Array[OpenAI::Models::Chat::ChatCompletion::Moderation::Input::ModerationResults::Result::category_applied_input_type]],
224
+ category_scores: ::Hash[Symbol, Float],
225
+ flagged: bool,
226
+ model: String,
227
+ type: :moderation_result
228
+ }
229
+
230
+ type category_applied_input_type = :text | :image
231
+
232
+ module CategoryAppliedInputType
233
+ extend OpenAI::Internal::Type::Enum
234
+
235
+ TEXT: :text
236
+ IMAGE: :image
237
+
238
+ def self?.values: -> ::Array[OpenAI::Models::Chat::ChatCompletion::Moderation::Input::ModerationResults::Result::category_applied_input_type]
239
+ end
240
+ end
241
+ end
242
+
243
+ type error = { code: String, message: String, type: :error }
244
+
245
+ class Error < OpenAI::Internal::Type::BaseModel
246
+ attr_accessor code: String
247
+
248
+ attr_accessor message: String
249
+
250
+ attr_accessor type: :error
251
+
252
+ def initialize: (
253
+ code: String,
254
+ message: String,
255
+ ?type: :error
256
+ ) -> void
257
+
258
+ def to_hash: -> { code: String, message: String, type: :error }
259
+ end
260
+
261
+ def self?.variants: -> ::Array[OpenAI::Models::Chat::ChatCompletion::Moderation::input]
262
+ end
263
+
264
+ type output =
265
+ OpenAI::Chat::ChatCompletion::Moderation::Output::ModerationResults
266
+ | OpenAI::Chat::ChatCompletion::Moderation::Output::Error
267
+
268
+ module Output
269
+ extend OpenAI::Internal::Type::Union
270
+
271
+ type moderation_results =
272
+ {
273
+ model: String,
274
+ results: ::Array[OpenAI::Chat::ChatCompletion::Moderation::Output::ModerationResults::Result],
275
+ type: :moderation_results
276
+ }
277
+
278
+ class ModerationResults < OpenAI::Internal::Type::BaseModel
279
+ attr_accessor model: String
280
+
281
+ attr_accessor results: ::Array[OpenAI::Chat::ChatCompletion::Moderation::Output::ModerationResults::Result]
282
+
283
+ attr_accessor type: :moderation_results
284
+
285
+ def initialize: (
286
+ model: String,
287
+ results: ::Array[OpenAI::Chat::ChatCompletion::Moderation::Output::ModerationResults::Result],
288
+ ?type: :moderation_results
289
+ ) -> void
290
+
291
+ def to_hash: -> {
292
+ model: String,
293
+ results: ::Array[OpenAI::Chat::ChatCompletion::Moderation::Output::ModerationResults::Result],
294
+ type: :moderation_results
295
+ }
296
+
297
+ type result =
298
+ {
299
+ categories: ::Hash[Symbol, bool],
300
+ category_applied_input_types: ::Hash[Symbol, ::Array[OpenAI::Models::Chat::ChatCompletion::Moderation::Output::ModerationResults::Result::category_applied_input_type]],
301
+ category_scores: ::Hash[Symbol, Float],
302
+ flagged: bool,
303
+ model: String,
304
+ type: :moderation_result
305
+ }
306
+
307
+ class Result < OpenAI::Internal::Type::BaseModel
308
+ attr_accessor categories: ::Hash[Symbol, bool]
309
+
310
+ attr_accessor category_applied_input_types: ::Hash[Symbol, ::Array[OpenAI::Models::Chat::ChatCompletion::Moderation::Output::ModerationResults::Result::category_applied_input_type]]
311
+
312
+ attr_accessor category_scores: ::Hash[Symbol, Float]
313
+
314
+ attr_accessor flagged: bool
315
+
316
+ attr_accessor model: String
317
+
318
+ attr_accessor type: :moderation_result
319
+
320
+ def initialize: (
321
+ categories: ::Hash[Symbol, bool],
322
+ category_applied_input_types: ::Hash[Symbol, ::Array[OpenAI::Models::Chat::ChatCompletion::Moderation::Output::ModerationResults::Result::category_applied_input_type]],
323
+ category_scores: ::Hash[Symbol, Float],
324
+ flagged: bool,
325
+ model: String,
326
+ ?type: :moderation_result
327
+ ) -> void
328
+
329
+ def to_hash: -> {
330
+ categories: ::Hash[Symbol, bool],
331
+ category_applied_input_types: ::Hash[Symbol, ::Array[OpenAI::Models::Chat::ChatCompletion::Moderation::Output::ModerationResults::Result::category_applied_input_type]],
332
+ category_scores: ::Hash[Symbol, Float],
333
+ flagged: bool,
334
+ model: String,
335
+ type: :moderation_result
336
+ }
337
+
338
+ type category_applied_input_type = :text | :image
339
+
340
+ module CategoryAppliedInputType
341
+ extend OpenAI::Internal::Type::Enum
342
+
343
+ TEXT: :text
344
+ IMAGE: :image
345
+
346
+ def self?.values: -> ::Array[OpenAI::Models::Chat::ChatCompletion::Moderation::Output::ModerationResults::Result::category_applied_input_type]
347
+ end
348
+ end
349
+ end
350
+
351
+ type error = { code: String, message: String, type: :error }
352
+
353
+ class Error < OpenAI::Internal::Type::BaseModel
354
+ attr_accessor code: String
355
+
356
+ attr_accessor message: String
357
+
358
+ attr_accessor type: :error
359
+
360
+ def initialize: (
361
+ code: String,
362
+ message: String,
363
+ ?type: :error
364
+ ) -> void
365
+
366
+ def to_hash: -> { code: String, message: String, type: :error }
367
+ end
368
+
369
+ def self?.variants: -> ::Array[OpenAI::Models::Chat::ChatCompletion::Moderation::output]
370
+ end
371
+ end
372
+
130
373
  type service_tier = :auto | :default | :flex | :scale | :priority
131
374
 
132
375
  module ServiceTier