@@ -331,6 +331,126 @@ func TestO3ModelsChatCompletionsBetaLimitations(t *testing.T) {
331
331
}
332
332
}
333
333
334
+ func TestGPT5ModelsChatCompletionsBetaLimitations (t * testing.T ) {
335
+ tests := []struct {
336
+ name string
337
+ in openai.ChatCompletionRequest
338
+ expectedError error
339
+ }{
340
+ {
341
+ name : "log_probs_unsupported" ,
342
+ in : openai.ChatCompletionRequest {
343
+ MaxCompletionTokens : 1000 ,
344
+ LogProbs : true ,
345
+ Model : openai .GPT5 ,
346
+ },
347
+ expectedError : openai .ErrReasoningModelLimitationsLogprobs ,
348
+ },
349
+ {
350
+ name : "set_temperature_unsupported" ,
351
+ in : openai.ChatCompletionRequest {
352
+ MaxCompletionTokens : 1000 ,
353
+ Model : openai .GPT5Mini ,
354
+ Messages : []openai.ChatCompletionMessage {
355
+ {
356
+ Role : openai .ChatMessageRoleUser ,
357
+ },
358
+ {
359
+ Role : openai .ChatMessageRoleAssistant ,
360
+ },
361
+ },
362
+ Temperature : float32 (2 ),
363
+ },
364
+ expectedError : openai .ErrReasoningModelLimitationsOther ,
365
+ },
366
+ {
367
+ name : "set_top_unsupported" ,
368
+ in : openai.ChatCompletionRequest {
369
+ MaxCompletionTokens : 1000 ,
370
+ Model : openai .GPT5Nano ,
371
+ Messages : []openai.ChatCompletionMessage {
372
+ {
373
+ Role : openai .ChatMessageRoleUser ,
374
+ },
375
+ {
376
+ Role : openai .ChatMessageRoleAssistant ,
377
+ },
378
+ },
379
+ Temperature : float32 (1 ),
380
+ TopP : float32 (0.1 ),
381
+ },
382
+ expectedError : openai .ErrReasoningModelLimitationsOther ,
383
+ },
384
+ {
385
+ name : "set_n_unsupported" ,
386
+ in : openai.ChatCompletionRequest {
387
+ MaxCompletionTokens : 1000 ,
388
+ Model : openai .GPT5ChatLatest ,
389
+ Messages : []openai.ChatCompletionMessage {
390
+ {
391
+ Role : openai .ChatMessageRoleUser ,
392
+ },
393
+ {
394
+ Role : openai .ChatMessageRoleAssistant ,
395
+ },
396
+ },
397
+ Temperature : float32 (1 ),
398
+ TopP : float32 (1 ),
399
+ N : 2 ,
400
+ },
401
+ expectedError : openai .ErrReasoningModelLimitationsOther ,
402
+ },
403
+ {
404
+ name : "set_presence_penalty_unsupported" ,
405
+ in : openai.ChatCompletionRequest {
406
+ MaxCompletionTokens : 1000 ,
407
+ Model : openai .GPT5 ,
408
+ Messages : []openai.ChatCompletionMessage {
409
+ {
410
+ Role : openai .ChatMessageRoleUser ,
411
+ },
412
+ {
413
+ Role : openai .ChatMessageRoleAssistant ,
414
+ },
415
+ },
416
+ PresencePenalty : float32 (0.1 ),
417
+ },
418
+ expectedError : openai .ErrReasoningModelLimitationsOther ,
419
+ },
420
+ {
421
+ name : "set_frequency_penalty_unsupported" ,
422
+ in : openai.ChatCompletionRequest {
423
+ MaxCompletionTokens : 1000 ,
424
+ Model : openai .GPT5Mini ,
425
+ Messages : []openai.ChatCompletionMessage {
426
+ {
427
+ Role : openai .ChatMessageRoleUser ,
428
+ },
429
+ {
430
+ Role : openai .ChatMessageRoleAssistant ,
431
+ },
432
+ },
433
+ FrequencyPenalty : float32 (0.1 ),
434
+ },
435
+ expectedError : openai .ErrReasoningModelLimitationsOther ,
436
+ },
437
+ }
438
+
439
+ for _ , tt := range tests {
440
+ t .Run (tt .name , func (t * testing.T ) {
441
+ config := openai .DefaultConfig ("whatever" )
442
+ config .BaseURL = "http://localhost/v1"
443
+ client := openai .NewClientWithConfig (config )
444
+ ctx := context .Background ()
445
+
446
+ _ , err := client .CreateChatCompletion (ctx , tt .in )
447
+ checks .HasError (t , err )
448
+ msg := fmt .Sprintf ("CreateChatCompletion should return wrong model error, returned: %s" , err )
449
+ checks .ErrorIs (t , err , tt .expectedError , msg )
450
+ })
451
+ }
452
+ }
453
+
334
454
func TestChatRequestOmitEmpty (t * testing.T ) {
335
455
data , err := json .Marshal (openai.ChatCompletionRequest {
336
456
// We set model b/c it's required, so omitempty doesn't make sense
@@ -946,3 +1066,142 @@ func TestFinishReason(t *testing.T) {
946
1066
}
947
1067
}
948
1068
}
1069
+
1070
+ func TestChatCompletionResponseFormatJSONSchema_UnmarshalJSON (t * testing.T ) {
1071
+ type args struct {
1072
+ data []byte
1073
+ }
1074
+ tests := []struct {
1075
+ name string
1076
+ args args
1077
+ wantErr bool
1078
+ }{
1079
+ {
1080
+ "" ,
1081
+ args {
1082
+ data : []byte (`{
1083
+ "name": "math_response",
1084
+ "strict": true,
1085
+ "schema": {
1086
+ "type": "object",
1087
+ "properties": {
1088
+ "steps": {
1089
+ "type": "array",
1090
+ "items": {
1091
+ "type": "object",
1092
+ "properties": {
1093
+ "explanation": { "type": "string" },
1094
+ "output": { "type": "string" }
1095
+ },
1096
+ "required": ["explanation","output"],
1097
+ "additionalProperties": false
1098
+ }
1099
+ },
1100
+ "final_answer": { "type": "string" }
1101
+ },
1102
+ "required": ["steps","final_answer"],
1103
+ "additionalProperties": false
1104
+ }
1105
+ }` ),
1106
+ },
1107
+ false ,
1108
+ },
1109
+ {
1110
+ "" ,
1111
+ args {
1112
+ data : []byte (`{
1113
+ "name": "math_response",
1114
+ "strict": true,
1115
+ "schema": null
1116
+ }` ),
1117
+ },
1118
+ false ,
1119
+ },
1120
+ {
1121
+ "" ,
1122
+ args {
1123
+ data : []byte (`[123,456]` ),
1124
+ },
1125
+ true ,
1126
+ },
1127
+ {
1128
+ "" ,
1129
+ args {
1130
+ data : []byte (`{
1131
+ "name": "math_response",
1132
+ "strict": true,
1133
+ "schema": 123456
1134
+ }` ),
1135
+ },
1136
+ true ,
1137
+ },
1138
+ }
1139
+ for _ , tt := range tests {
1140
+ t .Run (tt .name , func (t * testing.T ) {
1141
+ var r openai.ChatCompletionResponseFormatJSONSchema
1142
+ err := r .UnmarshalJSON (tt .args .data )
1143
+ if (err != nil ) != tt .wantErr {
1144
+ t .Errorf ("UnmarshalJSON() error = %v, wantErr %v" , err , tt .wantErr )
1145
+ }
1146
+ })
1147
+ }
1148
+ }
1149
+
1150
+ func TestChatCompletionRequest_UnmarshalJSON (t * testing.T ) {
1151
+ type args struct {
1152
+ bs []byte
1153
+ }
1154
+ tests := []struct {
1155
+ name string
1156
+ args args
1157
+ wantErr bool
1158
+ }{
1159
+ {
1160
+ "" ,
1161
+ args {bs : []byte (`{
1162
+ "model": "llama3-1b",
1163
+ "messages": [
1164
+ { "role": "system", "content": "You are a helpful math tutor." },
1165
+ { "role": "user", "content": "solve 8x + 31 = 2" }
1166
+ ],
1167
+ "response_format": {
1168
+ "type": "json_schema",
1169
+ "json_schema": {
1170
+ "name": "math_response",
1171
+ "strict": true,
1172
+ "schema": {
1173
+ "type": "object",
1174
+ "properties": {
1175
+ "steps": {
1176
+ "type": "array",
1177
+ "items": {
1178
+ "type": "object",
1179
+ "properties": {
1180
+ "explanation": { "type": "string" },
1181
+ "output": { "type": "string" }
1182
+ },
1183
+ "required": ["explanation","output"],
1184
+ "additionalProperties": false
1185
+ }
1186
+ },
1187
+ "final_answer": { "type": "string" }
1188
+ },
1189
+ "required": ["steps","final_answer"],
1190
+ "additionalProperties": false
1191
+ }
1192
+ }
1193
+ }
1194
+ }` )},
1195
+ false ,
1196
+ },
1197
+ }
1198
+ for _ , tt := range tests {
1199
+ t .Run (tt .name , func (t * testing.T ) {
1200
+ var m openai.ChatCompletionRequest
1201
+ err := json .Unmarshal (tt .args .bs , & m )
1202
+ if err != nil {
1203
+ t .Errorf ("UnmarshalJSON() error = %v, wantErr %v" , err , tt .wantErr )
1204
+ }
1205
+ })
1206
+ }
1207
+ }
0 commit comments