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
@@ -34,6 +34,21 @@ module OpenAI
34
34
  sig { returns(Symbol) }
35
35
  attr_accessor :object
36
36
 
37
+ # Moderation results for the request input and generated output. Present on the
38
+ # moderation chunk when moderated completions are requested.
39
+ sig do
40
+ returns(T.nilable(OpenAI::Chat::ChatCompletionChunk::Moderation))
41
+ end
42
+ attr_reader :moderation
43
+
44
+ sig do
45
+ params(
46
+ moderation:
47
+ T.nilable(OpenAI::Chat::ChatCompletionChunk::Moderation::OrHash)
48
+ ).void
49
+ end
50
+ attr_writer :moderation
51
+
37
52
  # Specifies the processing type used for serving the request.
38
53
  #
39
54
  # - If set to 'auto', then the request will be processed with the service tier
@@ -91,6 +106,8 @@ module OpenAI
91
106
  T::Array[OpenAI::Chat::ChatCompletionChunk::Choice::OrHash],
92
107
  created: Integer,
93
108
  model: String,
109
+ moderation:
110
+ T.nilable(OpenAI::Chat::ChatCompletionChunk::Moderation::OrHash),
94
111
  service_tier:
95
112
  T.nilable(
96
113
  OpenAI::Chat::ChatCompletionChunk::ServiceTier::OrSymbol
@@ -112,6 +129,9 @@ module OpenAI
112
129
  created:,
113
130
  # The model to generate the completion.
114
131
  model:,
132
+ # Moderation results for the request input and generated output. Present on the
133
+ # moderation chunk when moderated completions are requested.
134
+ moderation: nil,
115
135
  # Specifies the processing type used for serving the request.
116
136
  #
117
137
  # - If set to 'auto', then the request will be processed with the service tier
@@ -154,6 +174,8 @@ module OpenAI
154
174
  created: Integer,
155
175
  model: String,
156
176
  object: Symbol,
177
+ moderation:
178
+ T.nilable(OpenAI::Chat::ChatCompletionChunk::Moderation),
157
179
  service_tier:
158
180
  T.nilable(
159
181
  OpenAI::Chat::ChatCompletionChunk::ServiceTier::TaggedSymbol
@@ -781,6 +803,605 @@ module OpenAI
781
803
  end
782
804
  end
783
805
 
806
+ class Moderation < OpenAI::Internal::Type::BaseModel
807
+ OrHash =
808
+ T.type_alias do
809
+ T.any(
810
+ OpenAI::Chat::ChatCompletionChunk::Moderation,
811
+ OpenAI::Internal::AnyHash
812
+ )
813
+ end
814
+
815
+ # Moderation for the request input.
816
+ sig do
817
+ returns(
818
+ OpenAI::Chat::ChatCompletionChunk::Moderation::Input::Variants
819
+ )
820
+ end
821
+ attr_accessor :input
822
+
823
+ # Moderation for the generated output.
824
+ sig do
825
+ returns(
826
+ OpenAI::Chat::ChatCompletionChunk::Moderation::Output::Variants
827
+ )
828
+ end
829
+ attr_accessor :output
830
+
831
+ # Moderation results for the request input and generated output. Present on the
832
+ # moderation chunk when moderated completions are requested.
833
+ sig do
834
+ params(
835
+ input:
836
+ T.any(
837
+ OpenAI::Chat::ChatCompletionChunk::Moderation::Input::ModerationResults::OrHash,
838
+ OpenAI::Chat::ChatCompletionChunk::Moderation::Input::Error::OrHash
839
+ ),
840
+ output:
841
+ T.any(
842
+ OpenAI::Chat::ChatCompletionChunk::Moderation::Output::ModerationResults::OrHash,
843
+ OpenAI::Chat::ChatCompletionChunk::Moderation::Output::Error::OrHash
844
+ )
845
+ ).returns(T.attached_class)
846
+ end
847
+ def self.new(
848
+ # Moderation for the request input.
849
+ input:,
850
+ # Moderation for the generated output.
851
+ output:
852
+ )
853
+ end
854
+
855
+ sig do
856
+ override.returns(
857
+ {
858
+ input:
859
+ OpenAI::Chat::ChatCompletionChunk::Moderation::Input::Variants,
860
+ output:
861
+ OpenAI::Chat::ChatCompletionChunk::Moderation::Output::Variants
862
+ }
863
+ )
864
+ end
865
+ def to_hash
866
+ end
867
+
868
+ # Moderation for the request input.
869
+ module Input
870
+ extend OpenAI::Internal::Type::Union
871
+
872
+ Variants =
873
+ T.type_alias do
874
+ T.any(
875
+ OpenAI::Chat::ChatCompletionChunk::Moderation::Input::ModerationResults,
876
+ OpenAI::Chat::ChatCompletionChunk::Moderation::Input::Error
877
+ )
878
+ end
879
+
880
+ class ModerationResults < OpenAI::Internal::Type::BaseModel
881
+ OrHash =
882
+ T.type_alias do
883
+ T.any(
884
+ OpenAI::Chat::ChatCompletionChunk::Moderation::Input::ModerationResults,
885
+ OpenAI::Internal::AnyHash
886
+ )
887
+ end
888
+
889
+ # The moderation model used to generate the results.
890
+ sig { returns(String) }
891
+ attr_accessor :model
892
+
893
+ # A list of moderation results.
894
+ sig do
895
+ returns(
896
+ T::Array[
897
+ OpenAI::Chat::ChatCompletionChunk::Moderation::Input::ModerationResults::Result
898
+ ]
899
+ )
900
+ end
901
+ attr_accessor :results
902
+
903
+ # The object type, which is always `moderation_results`.
904
+ sig { returns(Symbol) }
905
+ attr_accessor :type
906
+
907
+ # Successful moderation results for the request input or generated output.
908
+ sig do
909
+ params(
910
+ model: String,
911
+ results:
912
+ T::Array[
913
+ OpenAI::Chat::ChatCompletionChunk::Moderation::Input::ModerationResults::Result::OrHash
914
+ ],
915
+ type: Symbol
916
+ ).returns(T.attached_class)
917
+ end
918
+ def self.new(
919
+ # The moderation model used to generate the results.
920
+ model:,
921
+ # A list of moderation results.
922
+ results:,
923
+ # The object type, which is always `moderation_results`.
924
+ type: :moderation_results
925
+ )
926
+ end
927
+
928
+ sig do
929
+ override.returns(
930
+ {
931
+ model: String,
932
+ results:
933
+ T::Array[
934
+ OpenAI::Chat::ChatCompletionChunk::Moderation::Input::ModerationResults::Result
935
+ ],
936
+ type: Symbol
937
+ }
938
+ )
939
+ end
940
+ def to_hash
941
+ end
942
+
943
+ class Result < OpenAI::Internal::Type::BaseModel
944
+ OrHash =
945
+ T.type_alias do
946
+ T.any(
947
+ OpenAI::Chat::ChatCompletionChunk::Moderation::Input::ModerationResults::Result,
948
+ OpenAI::Internal::AnyHash
949
+ )
950
+ end
951
+
952
+ # A dictionary of moderation categories to booleans, True if the input is flagged
953
+ # under this category.
954
+ sig { returns(T::Hash[Symbol, T::Boolean]) }
955
+ attr_accessor :categories
956
+
957
+ # Which modalities of input are reflected by the score for each category.
958
+ sig do
959
+ returns(
960
+ T::Hash[
961
+ Symbol,
962
+ T::Array[
963
+ OpenAI::Chat::ChatCompletionChunk::Moderation::Input::ModerationResults::Result::CategoryAppliedInputType::TaggedSymbol
964
+ ]
965
+ ]
966
+ )
967
+ end
968
+ attr_accessor :category_applied_input_types
969
+
970
+ # A dictionary of moderation categories to scores.
971
+ sig { returns(T::Hash[Symbol, Float]) }
972
+ attr_accessor :category_scores
973
+
974
+ # A boolean indicating whether the content was flagged by any category.
975
+ sig { returns(T::Boolean) }
976
+ attr_accessor :flagged
977
+
978
+ # The moderation model that produced this result.
979
+ sig { returns(String) }
980
+ attr_accessor :model
981
+
982
+ # The object type, which was always `moderation_result` for successful moderation
983
+ # results.
984
+ sig { returns(Symbol) }
985
+ attr_accessor :type
986
+
987
+ # A moderation result produced for the response input or output.
988
+ sig do
989
+ params(
990
+ categories: T::Hash[Symbol, T::Boolean],
991
+ category_applied_input_types:
992
+ T::Hash[
993
+ Symbol,
994
+ T::Array[
995
+ OpenAI::Chat::ChatCompletionChunk::Moderation::Input::ModerationResults::Result::CategoryAppliedInputType::OrSymbol
996
+ ]
997
+ ],
998
+ category_scores: T::Hash[Symbol, Float],
999
+ flagged: T::Boolean,
1000
+ model: String,
1001
+ type: Symbol
1002
+ ).returns(T.attached_class)
1003
+ end
1004
+ def self.new(
1005
+ # A dictionary of moderation categories to booleans, True if the input is flagged
1006
+ # under this category.
1007
+ categories:,
1008
+ # Which modalities of input are reflected by the score for each category.
1009
+ category_applied_input_types:,
1010
+ # A dictionary of moderation categories to scores.
1011
+ category_scores:,
1012
+ # A boolean indicating whether the content was flagged by any category.
1013
+ flagged:,
1014
+ # The moderation model that produced this result.
1015
+ model:,
1016
+ # The object type, which was always `moderation_result` for successful moderation
1017
+ # results.
1018
+ type: :moderation_result
1019
+ )
1020
+ end
1021
+
1022
+ sig do
1023
+ override.returns(
1024
+ {
1025
+ categories: T::Hash[Symbol, T::Boolean],
1026
+ category_applied_input_types:
1027
+ T::Hash[
1028
+ Symbol,
1029
+ T::Array[
1030
+ OpenAI::Chat::ChatCompletionChunk::Moderation::Input::ModerationResults::Result::CategoryAppliedInputType::TaggedSymbol
1031
+ ]
1032
+ ],
1033
+ category_scores: T::Hash[Symbol, Float],
1034
+ flagged: T::Boolean,
1035
+ model: String,
1036
+ type: Symbol
1037
+ }
1038
+ )
1039
+ end
1040
+ def to_hash
1041
+ end
1042
+
1043
+ module CategoryAppliedInputType
1044
+ extend OpenAI::Internal::Type::Enum
1045
+
1046
+ TaggedSymbol =
1047
+ T.type_alias do
1048
+ T.all(
1049
+ Symbol,
1050
+ OpenAI::Chat::ChatCompletionChunk::Moderation::Input::ModerationResults::Result::CategoryAppliedInputType
1051
+ )
1052
+ end
1053
+ OrSymbol = T.type_alias { T.any(Symbol, String) }
1054
+
1055
+ TEXT =
1056
+ T.let(
1057
+ :text,
1058
+ OpenAI::Chat::ChatCompletionChunk::Moderation::Input::ModerationResults::Result::CategoryAppliedInputType::TaggedSymbol
1059
+ )
1060
+ IMAGE =
1061
+ T.let(
1062
+ :image,
1063
+ OpenAI::Chat::ChatCompletionChunk::Moderation::Input::ModerationResults::Result::CategoryAppliedInputType::TaggedSymbol
1064
+ )
1065
+
1066
+ sig do
1067
+ override.returns(
1068
+ T::Array[
1069
+ OpenAI::Chat::ChatCompletionChunk::Moderation::Input::ModerationResults::Result::CategoryAppliedInputType::TaggedSymbol
1070
+ ]
1071
+ )
1072
+ end
1073
+ def self.values
1074
+ end
1075
+ end
1076
+ end
1077
+ end
1078
+
1079
+ class Error < OpenAI::Internal::Type::BaseModel
1080
+ OrHash =
1081
+ T.type_alias do
1082
+ T.any(
1083
+ OpenAI::Chat::ChatCompletionChunk::Moderation::Input::Error,
1084
+ OpenAI::Internal::AnyHash
1085
+ )
1086
+ end
1087
+
1088
+ # The error code.
1089
+ sig { returns(String) }
1090
+ attr_accessor :code
1091
+
1092
+ # The error message.
1093
+ sig { returns(String) }
1094
+ attr_accessor :message
1095
+
1096
+ # The object type, which is always `error`.
1097
+ sig { returns(Symbol) }
1098
+ attr_accessor :type
1099
+
1100
+ # An error produced while attempting moderation.
1101
+ sig do
1102
+ params(code: String, message: String, type: Symbol).returns(
1103
+ T.attached_class
1104
+ )
1105
+ end
1106
+ def self.new(
1107
+ # The error code.
1108
+ code:,
1109
+ # The error message.
1110
+ message:,
1111
+ # The object type, which is always `error`.
1112
+ type: :error
1113
+ )
1114
+ end
1115
+
1116
+ sig do
1117
+ override.returns(
1118
+ { code: String, message: String, type: Symbol }
1119
+ )
1120
+ end
1121
+ def to_hash
1122
+ end
1123
+ end
1124
+
1125
+ sig do
1126
+ override.returns(
1127
+ T::Array[
1128
+ OpenAI::Chat::ChatCompletionChunk::Moderation::Input::Variants
1129
+ ]
1130
+ )
1131
+ end
1132
+ def self.variants
1133
+ end
1134
+ end
1135
+
1136
+ # Moderation for the generated output.
1137
+ module Output
1138
+ extend OpenAI::Internal::Type::Union
1139
+
1140
+ Variants =
1141
+ T.type_alias do
1142
+ T.any(
1143
+ OpenAI::Chat::ChatCompletionChunk::Moderation::Output::ModerationResults,
1144
+ OpenAI::Chat::ChatCompletionChunk::Moderation::Output::Error
1145
+ )
1146
+ end
1147
+
1148
+ class ModerationResults < OpenAI::Internal::Type::BaseModel
1149
+ OrHash =
1150
+ T.type_alias do
1151
+ T.any(
1152
+ OpenAI::Chat::ChatCompletionChunk::Moderation::Output::ModerationResults,
1153
+ OpenAI::Internal::AnyHash
1154
+ )
1155
+ end
1156
+
1157
+ # The moderation model used to generate the results.
1158
+ sig { returns(String) }
1159
+ attr_accessor :model
1160
+
1161
+ # A list of moderation results.
1162
+ sig do
1163
+ returns(
1164
+ T::Array[
1165
+ OpenAI::Chat::ChatCompletionChunk::Moderation::Output::ModerationResults::Result
1166
+ ]
1167
+ )
1168
+ end
1169
+ attr_accessor :results
1170
+
1171
+ # The object type, which is always `moderation_results`.
1172
+ sig { returns(Symbol) }
1173
+ attr_accessor :type
1174
+
1175
+ # Successful moderation results for the request input or generated output.
1176
+ sig do
1177
+ params(
1178
+ model: String,
1179
+ results:
1180
+ T::Array[
1181
+ OpenAI::Chat::ChatCompletionChunk::Moderation::Output::ModerationResults::Result::OrHash
1182
+ ],
1183
+ type: Symbol
1184
+ ).returns(T.attached_class)
1185
+ end
1186
+ def self.new(
1187
+ # The moderation model used to generate the results.
1188
+ model:,
1189
+ # A list of moderation results.
1190
+ results:,
1191
+ # The object type, which is always `moderation_results`.
1192
+ type: :moderation_results
1193
+ )
1194
+ end
1195
+
1196
+ sig do
1197
+ override.returns(
1198
+ {
1199
+ model: String,
1200
+ results:
1201
+ T::Array[
1202
+ OpenAI::Chat::ChatCompletionChunk::Moderation::Output::ModerationResults::Result
1203
+ ],
1204
+ type: Symbol
1205
+ }
1206
+ )
1207
+ end
1208
+ def to_hash
1209
+ end
1210
+
1211
+ class Result < OpenAI::Internal::Type::BaseModel
1212
+ OrHash =
1213
+ T.type_alias do
1214
+ T.any(
1215
+ OpenAI::Chat::ChatCompletionChunk::Moderation::Output::ModerationResults::Result,
1216
+ OpenAI::Internal::AnyHash
1217
+ )
1218
+ end
1219
+
1220
+ # A dictionary of moderation categories to booleans, True if the input is flagged
1221
+ # under this category.
1222
+ sig { returns(T::Hash[Symbol, T::Boolean]) }
1223
+ attr_accessor :categories
1224
+
1225
+ # Which modalities of input are reflected by the score for each category.
1226
+ sig do
1227
+ returns(
1228
+ T::Hash[
1229
+ Symbol,
1230
+ T::Array[
1231
+ OpenAI::Chat::ChatCompletionChunk::Moderation::Output::ModerationResults::Result::CategoryAppliedInputType::TaggedSymbol
1232
+ ]
1233
+ ]
1234
+ )
1235
+ end
1236
+ attr_accessor :category_applied_input_types
1237
+
1238
+ # A dictionary of moderation categories to scores.
1239
+ sig { returns(T::Hash[Symbol, Float]) }
1240
+ attr_accessor :category_scores
1241
+
1242
+ # A boolean indicating whether the content was flagged by any category.
1243
+ sig { returns(T::Boolean) }
1244
+ attr_accessor :flagged
1245
+
1246
+ # The moderation model that produced this result.
1247
+ sig { returns(String) }
1248
+ attr_accessor :model
1249
+
1250
+ # The object type, which was always `moderation_result` for successful moderation
1251
+ # results.
1252
+ sig { returns(Symbol) }
1253
+ attr_accessor :type
1254
+
1255
+ # A moderation result produced for the response input or output.
1256
+ sig do
1257
+ params(
1258
+ categories: T::Hash[Symbol, T::Boolean],
1259
+ category_applied_input_types:
1260
+ T::Hash[
1261
+ Symbol,
1262
+ T::Array[
1263
+ OpenAI::Chat::ChatCompletionChunk::Moderation::Output::ModerationResults::Result::CategoryAppliedInputType::OrSymbol
1264
+ ]
1265
+ ],
1266
+ category_scores: T::Hash[Symbol, Float],
1267
+ flagged: T::Boolean,
1268
+ model: String,
1269
+ type: Symbol
1270
+ ).returns(T.attached_class)
1271
+ end
1272
+ def self.new(
1273
+ # A dictionary of moderation categories to booleans, True if the input is flagged
1274
+ # under this category.
1275
+ categories:,
1276
+ # Which modalities of input are reflected by the score for each category.
1277
+ category_applied_input_types:,
1278
+ # A dictionary of moderation categories to scores.
1279
+ category_scores:,
1280
+ # A boolean indicating whether the content was flagged by any category.
1281
+ flagged:,
1282
+ # The moderation model that produced this result.
1283
+ model:,
1284
+ # The object type, which was always `moderation_result` for successful moderation
1285
+ # results.
1286
+ type: :moderation_result
1287
+ )
1288
+ end
1289
+
1290
+ sig do
1291
+ override.returns(
1292
+ {
1293
+ categories: T::Hash[Symbol, T::Boolean],
1294
+ category_applied_input_types:
1295
+ T::Hash[
1296
+ Symbol,
1297
+ T::Array[
1298
+ OpenAI::Chat::ChatCompletionChunk::Moderation::Output::ModerationResults::Result::CategoryAppliedInputType::TaggedSymbol
1299
+ ]
1300
+ ],
1301
+ category_scores: T::Hash[Symbol, Float],
1302
+ flagged: T::Boolean,
1303
+ model: String,
1304
+ type: Symbol
1305
+ }
1306
+ )
1307
+ end
1308
+ def to_hash
1309
+ end
1310
+
1311
+ module CategoryAppliedInputType
1312
+ extend OpenAI::Internal::Type::Enum
1313
+
1314
+ TaggedSymbol =
1315
+ T.type_alias do
1316
+ T.all(
1317
+ Symbol,
1318
+ OpenAI::Chat::ChatCompletionChunk::Moderation::Output::ModerationResults::Result::CategoryAppliedInputType
1319
+ )
1320
+ end
1321
+ OrSymbol = T.type_alias { T.any(Symbol, String) }
1322
+
1323
+ TEXT =
1324
+ T.let(
1325
+ :text,
1326
+ OpenAI::Chat::ChatCompletionChunk::Moderation::Output::ModerationResults::Result::CategoryAppliedInputType::TaggedSymbol
1327
+ )
1328
+ IMAGE =
1329
+ T.let(
1330
+ :image,
1331
+ OpenAI::Chat::ChatCompletionChunk::Moderation::Output::ModerationResults::Result::CategoryAppliedInputType::TaggedSymbol
1332
+ )
1333
+
1334
+ sig do
1335
+ override.returns(
1336
+ T::Array[
1337
+ OpenAI::Chat::ChatCompletionChunk::Moderation::Output::ModerationResults::Result::CategoryAppliedInputType::TaggedSymbol
1338
+ ]
1339
+ )
1340
+ end
1341
+ def self.values
1342
+ end
1343
+ end
1344
+ end
1345
+ end
1346
+
1347
+ class Error < OpenAI::Internal::Type::BaseModel
1348
+ OrHash =
1349
+ T.type_alias do
1350
+ T.any(
1351
+ OpenAI::Chat::ChatCompletionChunk::Moderation::Output::Error,
1352
+ OpenAI::Internal::AnyHash
1353
+ )
1354
+ end
1355
+
1356
+ # The error code.
1357
+ sig { returns(String) }
1358
+ attr_accessor :code
1359
+
1360
+ # The error message.
1361
+ sig { returns(String) }
1362
+ attr_accessor :message
1363
+
1364
+ # The object type, which is always `error`.
1365
+ sig { returns(Symbol) }
1366
+ attr_accessor :type
1367
+
1368
+ # An error produced while attempting moderation.
1369
+ sig do
1370
+ params(code: String, message: String, type: Symbol).returns(
1371
+ T.attached_class
1372
+ )
1373
+ end
1374
+ def self.new(
1375
+ # The error code.
1376
+ code:,
1377
+ # The error message.
1378
+ message:,
1379
+ # The object type, which is always `error`.
1380
+ type: :error
1381
+ )
1382
+ end
1383
+
1384
+ sig do
1385
+ override.returns(
1386
+ { code: String, message: String, type: Symbol }
1387
+ )
1388
+ end
1389
+ def to_hash
1390
+ end
1391
+ end
1392
+
1393
+ sig do
1394
+ override.returns(
1395
+ T::Array[
1396
+ OpenAI::Chat::ChatCompletionChunk::Moderation::Output::Variants
1397
+ ]
1398
+ )
1399
+ end
1400
+ def self.variants
1401
+ end
1402
+ end
1403
+ end
1404
+
784
1405
  # Specifies the processing type used for serving the request.
785
1406
  #
786
1407
  # - If set to 'auto', then the request will be processed with the service tier