forked from openai/openai-go
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfinetuningmethod.go
More file actions
1487 lines (1318 loc) · 52.8 KB
/
finetuningmethod.go
File metadata and controls
1487 lines (1318 loc) · 52.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
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
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package openai
import (
"encoding/json"
"github.com/openai/openai-go/internal/apijson"
"github.com/openai/openai-go/option"
"github.com/openai/openai-go/packages/param"
"github.com/openai/openai-go/packages/respjson"
"github.com/openai/openai-go/shared/constant"
)
// FineTuningMethodService contains methods and other services that help with
// interacting with the openai API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewFineTuningMethodService] method instead.
type FineTuningMethodService struct {
Options []option.RequestOption
}
// NewFineTuningMethodService generates a new service that applies the given
// options to each request. These options are applied after the parent client's
// options (if there is one), and before any request-specific options.
func NewFineTuningMethodService(opts ...option.RequestOption) (r FineTuningMethodService) {
r = FineTuningMethodService{}
r.Options = opts
return
}
// The hyperparameters used for the DPO fine-tuning job.
type DpoHyperparametersResp struct {
// Number of examples in each batch. A larger batch size means that model
// parameters are updated less frequently, but with lower variance.
BatchSize DpoHyperparametersBatchSizeUnionResp `json:"batch_size"`
// The beta value for the DPO method. A higher beta value will increase the weight
// of the penalty between the policy and reference model.
Beta DpoHyperparametersBetaUnionResp `json:"beta"`
// Scaling factor for the learning rate. A smaller learning rate may be useful to
// avoid overfitting.
LearningRateMultiplier DpoHyperparametersLearningRateMultiplierUnionResp `json:"learning_rate_multiplier"`
// The number of epochs to train the model for. An epoch refers to one full cycle
// through the training dataset.
NEpochs DpoHyperparametersNEpochsUnionResp `json:"n_epochs"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
BatchSize respjson.Field
Beta respjson.Field
LearningRateMultiplier respjson.Field
NEpochs respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r DpoHyperparametersResp) RawJSON() string { return r.JSON.raw }
func (r *DpoHyperparametersResp) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// ToParam converts this DpoHyperparametersResp to a DpoHyperparameters.
//
// Warning: the fields of the param type will not be present. ToParam should only
// be used at the last possible moment before sending a request. Test for this with
// DpoHyperparameters.Overrides()
func (r DpoHyperparametersResp) ToParam() DpoHyperparameters {
return param.Override[DpoHyperparameters](json.RawMessage(r.RawJSON()))
}
// DpoHyperparametersBatchSizeUnionResp contains all possible properties and values
// from [constant.Auto], [int64].
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
//
// If the underlying value is not a json object, one of the following properties
// will be valid: OfAuto OfInt]
type DpoHyperparametersBatchSizeUnionResp struct {
// This field will be present if the value is a [constant.Auto] instead of an
// object.
OfAuto constant.Auto `json:",inline"`
// This field will be present if the value is a [int64] instead of an object.
OfInt int64 `json:",inline"`
JSON struct {
OfAuto respjson.Field
OfInt respjson.Field
raw string
} `json:"-"`
}
func (u DpoHyperparametersBatchSizeUnionResp) AsAuto() (v constant.Auto) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u DpoHyperparametersBatchSizeUnionResp) AsInt() (v int64) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u DpoHyperparametersBatchSizeUnionResp) RawJSON() string { return u.JSON.raw }
func (r *DpoHyperparametersBatchSizeUnionResp) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// DpoHyperparametersBetaUnionResp contains all possible properties and values from
// [constant.Auto], [float64].
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
//
// If the underlying value is not a json object, one of the following properties
// will be valid: OfAuto OfFloat]
type DpoHyperparametersBetaUnionResp struct {
// This field will be present if the value is a [constant.Auto] instead of an
// object.
OfAuto constant.Auto `json:",inline"`
// This field will be present if the value is a [float64] instead of an object.
OfFloat float64 `json:",inline"`
JSON struct {
OfAuto respjson.Field
OfFloat respjson.Field
raw string
} `json:"-"`
}
func (u DpoHyperparametersBetaUnionResp) AsAuto() (v constant.Auto) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u DpoHyperparametersBetaUnionResp) AsFloat() (v float64) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u DpoHyperparametersBetaUnionResp) RawJSON() string { return u.JSON.raw }
func (r *DpoHyperparametersBetaUnionResp) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// DpoHyperparametersLearningRateMultiplierUnionResp contains all possible
// properties and values from [constant.Auto], [float64].
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
//
// If the underlying value is not a json object, one of the following properties
// will be valid: OfAuto OfFloat]
type DpoHyperparametersLearningRateMultiplierUnionResp struct {
// This field will be present if the value is a [constant.Auto] instead of an
// object.
OfAuto constant.Auto `json:",inline"`
// This field will be present if the value is a [float64] instead of an object.
OfFloat float64 `json:",inline"`
JSON struct {
OfAuto respjson.Field
OfFloat respjson.Field
raw string
} `json:"-"`
}
func (u DpoHyperparametersLearningRateMultiplierUnionResp) AsAuto() (v constant.Auto) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u DpoHyperparametersLearningRateMultiplierUnionResp) AsFloat() (v float64) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u DpoHyperparametersLearningRateMultiplierUnionResp) RawJSON() string { return u.JSON.raw }
func (r *DpoHyperparametersLearningRateMultiplierUnionResp) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// DpoHyperparametersNEpochsUnionResp contains all possible properties and values
// from [constant.Auto], [int64].
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
//
// If the underlying value is not a json object, one of the following properties
// will be valid: OfAuto OfInt]
type DpoHyperparametersNEpochsUnionResp struct {
// This field will be present if the value is a [constant.Auto] instead of an
// object.
OfAuto constant.Auto `json:",inline"`
// This field will be present if the value is a [int64] instead of an object.
OfInt int64 `json:",inline"`
JSON struct {
OfAuto respjson.Field
OfInt respjson.Field
raw string
} `json:"-"`
}
func (u DpoHyperparametersNEpochsUnionResp) AsAuto() (v constant.Auto) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u DpoHyperparametersNEpochsUnionResp) AsInt() (v int64) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u DpoHyperparametersNEpochsUnionResp) RawJSON() string { return u.JSON.raw }
func (r *DpoHyperparametersNEpochsUnionResp) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// The hyperparameters used for the DPO fine-tuning job.
type DpoHyperparameters struct {
// Number of examples in each batch. A larger batch size means that model
// parameters are updated less frequently, but with lower variance.
BatchSize DpoHyperparametersBatchSizeUnion `json:"batch_size,omitzero"`
// The beta value for the DPO method. A higher beta value will increase the weight
// of the penalty between the policy and reference model.
Beta DpoHyperparametersBetaUnion `json:"beta,omitzero"`
// Scaling factor for the learning rate. A smaller learning rate may be useful to
// avoid overfitting.
LearningRateMultiplier DpoHyperparametersLearningRateMultiplierUnion `json:"learning_rate_multiplier,omitzero"`
// The number of epochs to train the model for. An epoch refers to one full cycle
// through the training dataset.
NEpochs DpoHyperparametersNEpochsUnion `json:"n_epochs,omitzero"`
paramObj
}
func (r DpoHyperparameters) MarshalJSON() (data []byte, err error) {
type shadow DpoHyperparameters
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *DpoHyperparameters) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
type DpoHyperparametersBatchSizeUnion struct {
// Construct this variant with constant.ValueOf[constant.Auto]()
OfAuto constant.Auto `json:",omitzero,inline"`
OfInt param.Opt[int64] `json:",omitzero,inline"`
paramUnion
}
func (u DpoHyperparametersBatchSizeUnion) MarshalJSON() ([]byte, error) {
return param.MarshalUnion(u, u.OfAuto, u.OfInt)
}
func (u *DpoHyperparametersBatchSizeUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, u)
}
func (u *DpoHyperparametersBatchSizeUnion) asAny() any {
if !param.IsOmitted(u.OfAuto) {
return &u.OfAuto
} else if !param.IsOmitted(u.OfInt) {
return &u.OfInt.Value
}
return nil
}
// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
type DpoHyperparametersBetaUnion struct {
// Construct this variant with constant.ValueOf[constant.Auto]()
OfAuto constant.Auto `json:",omitzero,inline"`
OfFloat param.Opt[float64] `json:",omitzero,inline"`
paramUnion
}
func (u DpoHyperparametersBetaUnion) MarshalJSON() ([]byte, error) {
return param.MarshalUnion(u, u.OfAuto, u.OfFloat)
}
func (u *DpoHyperparametersBetaUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, u)
}
func (u *DpoHyperparametersBetaUnion) asAny() any {
if !param.IsOmitted(u.OfAuto) {
return &u.OfAuto
} else if !param.IsOmitted(u.OfFloat) {
return &u.OfFloat.Value
}
return nil
}
// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
type DpoHyperparametersLearningRateMultiplierUnion struct {
// Construct this variant with constant.ValueOf[constant.Auto]()
OfAuto constant.Auto `json:",omitzero,inline"`
OfFloat param.Opt[float64] `json:",omitzero,inline"`
paramUnion
}
func (u DpoHyperparametersLearningRateMultiplierUnion) MarshalJSON() ([]byte, error) {
return param.MarshalUnion(u, u.OfAuto, u.OfFloat)
}
func (u *DpoHyperparametersLearningRateMultiplierUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, u)
}
func (u *DpoHyperparametersLearningRateMultiplierUnion) asAny() any {
if !param.IsOmitted(u.OfAuto) {
return &u.OfAuto
} else if !param.IsOmitted(u.OfFloat) {
return &u.OfFloat.Value
}
return nil
}
// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
type DpoHyperparametersNEpochsUnion struct {
// Construct this variant with constant.ValueOf[constant.Auto]()
OfAuto constant.Auto `json:",omitzero,inline"`
OfInt param.Opt[int64] `json:",omitzero,inline"`
paramUnion
}
func (u DpoHyperparametersNEpochsUnion) MarshalJSON() ([]byte, error) {
return param.MarshalUnion(u, u.OfAuto, u.OfInt)
}
func (u *DpoHyperparametersNEpochsUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, u)
}
func (u *DpoHyperparametersNEpochsUnion) asAny() any {
if !param.IsOmitted(u.OfAuto) {
return &u.OfAuto
} else if !param.IsOmitted(u.OfInt) {
return &u.OfInt.Value
}
return nil
}
// Configuration for the DPO fine-tuning method.
type DpoMethod struct {
// The hyperparameters used for the DPO fine-tuning job.
Hyperparameters DpoHyperparametersResp `json:"hyperparameters"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Hyperparameters respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r DpoMethod) RawJSON() string { return r.JSON.raw }
func (r *DpoMethod) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// ToParam converts this DpoMethod to a DpoMethodParam.
//
// Warning: the fields of the param type will not be present. ToParam should only
// be used at the last possible moment before sending a request. Test for this with
// DpoMethodParam.Overrides()
func (r DpoMethod) ToParam() DpoMethodParam {
return param.Override[DpoMethodParam](json.RawMessage(r.RawJSON()))
}
// Configuration for the DPO fine-tuning method.
type DpoMethodParam struct {
// The hyperparameters used for the DPO fine-tuning job.
Hyperparameters DpoHyperparameters `json:"hyperparameters,omitzero"`
paramObj
}
func (r DpoMethodParam) MarshalJSON() (data []byte, err error) {
type shadow DpoMethodParam
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *DpoMethodParam) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// The hyperparameters used for the reinforcement fine-tuning job.
type ReinforcementHyperparametersResp struct {
// Number of examples in each batch. A larger batch size means that model
// parameters are updated less frequently, but with lower variance.
BatchSize ReinforcementHyperparametersBatchSizeUnionResp `json:"batch_size"`
// Multiplier on amount of compute used for exploring search space during training.
ComputeMultiplier ReinforcementHyperparametersComputeMultiplierUnionResp `json:"compute_multiplier"`
// The number of training steps between evaluation runs.
EvalInterval ReinforcementHyperparametersEvalIntervalUnionResp `json:"eval_interval"`
// Number of evaluation samples to generate per training step.
EvalSamples ReinforcementHyperparametersEvalSamplesUnionResp `json:"eval_samples"`
// Scaling factor for the learning rate. A smaller learning rate may be useful to
// avoid overfitting.
LearningRateMultiplier ReinforcementHyperparametersLearningRateMultiplierUnionResp `json:"learning_rate_multiplier"`
// The number of epochs to train the model for. An epoch refers to one full cycle
// through the training dataset.
NEpochs ReinforcementHyperparametersNEpochsUnionResp `json:"n_epochs"`
// Level of reasoning effort.
//
// Any of "default", "low", "medium", "high".
ReasoningEffort ReinforcementHyperparametersReasoningEffort `json:"reasoning_effort"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
BatchSize respjson.Field
ComputeMultiplier respjson.Field
EvalInterval respjson.Field
EvalSamples respjson.Field
LearningRateMultiplier respjson.Field
NEpochs respjson.Field
ReasoningEffort respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ReinforcementHyperparametersResp) RawJSON() string { return r.JSON.raw }
func (r *ReinforcementHyperparametersResp) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// ToParam converts this ReinforcementHyperparametersResp to a
// ReinforcementHyperparameters.
//
// Warning: the fields of the param type will not be present. ToParam should only
// be used at the last possible moment before sending a request. Test for this with
// ReinforcementHyperparameters.Overrides()
func (r ReinforcementHyperparametersResp) ToParam() ReinforcementHyperparameters {
return param.Override[ReinforcementHyperparameters](json.RawMessage(r.RawJSON()))
}
// ReinforcementHyperparametersBatchSizeUnionResp contains all possible properties
// and values from [constant.Auto], [int64].
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
//
// If the underlying value is not a json object, one of the following properties
// will be valid: OfAuto OfInt]
type ReinforcementHyperparametersBatchSizeUnionResp struct {
// This field will be present if the value is a [constant.Auto] instead of an
// object.
OfAuto constant.Auto `json:",inline"`
// This field will be present if the value is a [int64] instead of an object.
OfInt int64 `json:",inline"`
JSON struct {
OfAuto respjson.Field
OfInt respjson.Field
raw string
} `json:"-"`
}
func (u ReinforcementHyperparametersBatchSizeUnionResp) AsAuto() (v constant.Auto) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u ReinforcementHyperparametersBatchSizeUnionResp) AsInt() (v int64) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u ReinforcementHyperparametersBatchSizeUnionResp) RawJSON() string { return u.JSON.raw }
func (r *ReinforcementHyperparametersBatchSizeUnionResp) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// ReinforcementHyperparametersComputeMultiplierUnionResp contains all possible
// properties and values from [constant.Auto], [float64].
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
//
// If the underlying value is not a json object, one of the following properties
// will be valid: OfAuto OfFloat]
type ReinforcementHyperparametersComputeMultiplierUnionResp struct {
// This field will be present if the value is a [constant.Auto] instead of an
// object.
OfAuto constant.Auto `json:",inline"`
// This field will be present if the value is a [float64] instead of an object.
OfFloat float64 `json:",inline"`
JSON struct {
OfAuto respjson.Field
OfFloat respjson.Field
raw string
} `json:"-"`
}
func (u ReinforcementHyperparametersComputeMultiplierUnionResp) AsAuto() (v constant.Auto) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u ReinforcementHyperparametersComputeMultiplierUnionResp) AsFloat() (v float64) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u ReinforcementHyperparametersComputeMultiplierUnionResp) RawJSON() string { return u.JSON.raw }
func (r *ReinforcementHyperparametersComputeMultiplierUnionResp) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// ReinforcementHyperparametersEvalIntervalUnionResp contains all possible
// properties and values from [constant.Auto], [int64].
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
//
// If the underlying value is not a json object, one of the following properties
// will be valid: OfAuto OfInt]
type ReinforcementHyperparametersEvalIntervalUnionResp struct {
// This field will be present if the value is a [constant.Auto] instead of an
// object.
OfAuto constant.Auto `json:",inline"`
// This field will be present if the value is a [int64] instead of an object.
OfInt int64 `json:",inline"`
JSON struct {
OfAuto respjson.Field
OfInt respjson.Field
raw string
} `json:"-"`
}
func (u ReinforcementHyperparametersEvalIntervalUnionResp) AsAuto() (v constant.Auto) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u ReinforcementHyperparametersEvalIntervalUnionResp) AsInt() (v int64) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u ReinforcementHyperparametersEvalIntervalUnionResp) RawJSON() string { return u.JSON.raw }
func (r *ReinforcementHyperparametersEvalIntervalUnionResp) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// ReinforcementHyperparametersEvalSamplesUnionResp contains all possible
// properties and values from [constant.Auto], [int64].
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
//
// If the underlying value is not a json object, one of the following properties
// will be valid: OfAuto OfInt]
type ReinforcementHyperparametersEvalSamplesUnionResp struct {
// This field will be present if the value is a [constant.Auto] instead of an
// object.
OfAuto constant.Auto `json:",inline"`
// This field will be present if the value is a [int64] instead of an object.
OfInt int64 `json:",inline"`
JSON struct {
OfAuto respjson.Field
OfInt respjson.Field
raw string
} `json:"-"`
}
func (u ReinforcementHyperparametersEvalSamplesUnionResp) AsAuto() (v constant.Auto) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u ReinforcementHyperparametersEvalSamplesUnionResp) AsInt() (v int64) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u ReinforcementHyperparametersEvalSamplesUnionResp) RawJSON() string { return u.JSON.raw }
func (r *ReinforcementHyperparametersEvalSamplesUnionResp) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// ReinforcementHyperparametersLearningRateMultiplierUnionResp contains all
// possible properties and values from [constant.Auto], [float64].
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
//
// If the underlying value is not a json object, one of the following properties
// will be valid: OfAuto OfFloat]
type ReinforcementHyperparametersLearningRateMultiplierUnionResp struct {
// This field will be present if the value is a [constant.Auto] instead of an
// object.
OfAuto constant.Auto `json:",inline"`
// This field will be present if the value is a [float64] instead of an object.
OfFloat float64 `json:",inline"`
JSON struct {
OfAuto respjson.Field
OfFloat respjson.Field
raw string
} `json:"-"`
}
func (u ReinforcementHyperparametersLearningRateMultiplierUnionResp) AsAuto() (v constant.Auto) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u ReinforcementHyperparametersLearningRateMultiplierUnionResp) AsFloat() (v float64) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u ReinforcementHyperparametersLearningRateMultiplierUnionResp) RawJSON() string {
return u.JSON.raw
}
func (r *ReinforcementHyperparametersLearningRateMultiplierUnionResp) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// ReinforcementHyperparametersNEpochsUnionResp contains all possible properties
// and values from [constant.Auto], [int64].
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
//
// If the underlying value is not a json object, one of the following properties
// will be valid: OfAuto OfInt]
type ReinforcementHyperparametersNEpochsUnionResp struct {
// This field will be present if the value is a [constant.Auto] instead of an
// object.
OfAuto constant.Auto `json:",inline"`
// This field will be present if the value is a [int64] instead of an object.
OfInt int64 `json:",inline"`
JSON struct {
OfAuto respjson.Field
OfInt respjson.Field
raw string
} `json:"-"`
}
func (u ReinforcementHyperparametersNEpochsUnionResp) AsAuto() (v constant.Auto) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u ReinforcementHyperparametersNEpochsUnionResp) AsInt() (v int64) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u ReinforcementHyperparametersNEpochsUnionResp) RawJSON() string { return u.JSON.raw }
func (r *ReinforcementHyperparametersNEpochsUnionResp) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Level of reasoning effort.
type ReinforcementHyperparametersReasoningEffort string
const (
ReinforcementHyperparametersReasoningEffortDefault ReinforcementHyperparametersReasoningEffort = "default"
ReinforcementHyperparametersReasoningEffortLow ReinforcementHyperparametersReasoningEffort = "low"
ReinforcementHyperparametersReasoningEffortMedium ReinforcementHyperparametersReasoningEffort = "medium"
ReinforcementHyperparametersReasoningEffortHigh ReinforcementHyperparametersReasoningEffort = "high"
)
// The hyperparameters used for the reinforcement fine-tuning job.
type ReinforcementHyperparameters struct {
// Number of examples in each batch. A larger batch size means that model
// parameters are updated less frequently, but with lower variance.
BatchSize ReinforcementHyperparametersBatchSizeUnion `json:"batch_size,omitzero"`
// Multiplier on amount of compute used for exploring search space during training.
ComputeMultiplier ReinforcementHyperparametersComputeMultiplierUnion `json:"compute_multiplier,omitzero"`
// The number of training steps between evaluation runs.
EvalInterval ReinforcementHyperparametersEvalIntervalUnion `json:"eval_interval,omitzero"`
// Number of evaluation samples to generate per training step.
EvalSamples ReinforcementHyperparametersEvalSamplesUnion `json:"eval_samples,omitzero"`
// Scaling factor for the learning rate. A smaller learning rate may be useful to
// avoid overfitting.
LearningRateMultiplier ReinforcementHyperparametersLearningRateMultiplierUnion `json:"learning_rate_multiplier,omitzero"`
// The number of epochs to train the model for. An epoch refers to one full cycle
// through the training dataset.
NEpochs ReinforcementHyperparametersNEpochsUnion `json:"n_epochs,omitzero"`
// Level of reasoning effort.
//
// Any of "default", "low", "medium", "high".
ReasoningEffort ReinforcementHyperparametersReasoningEffort `json:"reasoning_effort,omitzero"`
paramObj
}
func (r ReinforcementHyperparameters) MarshalJSON() (data []byte, err error) {
type shadow ReinforcementHyperparameters
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ReinforcementHyperparameters) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
type ReinforcementHyperparametersBatchSizeUnion struct {
// Construct this variant with constant.ValueOf[constant.Auto]()
OfAuto constant.Auto `json:",omitzero,inline"`
OfInt param.Opt[int64] `json:",omitzero,inline"`
paramUnion
}
func (u ReinforcementHyperparametersBatchSizeUnion) MarshalJSON() ([]byte, error) {
return param.MarshalUnion(u, u.OfAuto, u.OfInt)
}
func (u *ReinforcementHyperparametersBatchSizeUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, u)
}
func (u *ReinforcementHyperparametersBatchSizeUnion) asAny() any {
if !param.IsOmitted(u.OfAuto) {
return &u.OfAuto
} else if !param.IsOmitted(u.OfInt) {
return &u.OfInt.Value
}
return nil
}
// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
type ReinforcementHyperparametersComputeMultiplierUnion struct {
// Construct this variant with constant.ValueOf[constant.Auto]()
OfAuto constant.Auto `json:",omitzero,inline"`
OfFloat param.Opt[float64] `json:",omitzero,inline"`
paramUnion
}
func (u ReinforcementHyperparametersComputeMultiplierUnion) MarshalJSON() ([]byte, error) {
return param.MarshalUnion(u, u.OfAuto, u.OfFloat)
}
func (u *ReinforcementHyperparametersComputeMultiplierUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, u)
}
func (u *ReinforcementHyperparametersComputeMultiplierUnion) asAny() any {
if !param.IsOmitted(u.OfAuto) {
return &u.OfAuto
} else if !param.IsOmitted(u.OfFloat) {
return &u.OfFloat.Value
}
return nil
}
// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
type ReinforcementHyperparametersEvalIntervalUnion struct {
// Construct this variant with constant.ValueOf[constant.Auto]()
OfAuto constant.Auto `json:",omitzero,inline"`
OfInt param.Opt[int64] `json:",omitzero,inline"`
paramUnion
}
func (u ReinforcementHyperparametersEvalIntervalUnion) MarshalJSON() ([]byte, error) {
return param.MarshalUnion(u, u.OfAuto, u.OfInt)
}
func (u *ReinforcementHyperparametersEvalIntervalUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, u)
}
func (u *ReinforcementHyperparametersEvalIntervalUnion) asAny() any {
if !param.IsOmitted(u.OfAuto) {
return &u.OfAuto
} else if !param.IsOmitted(u.OfInt) {
return &u.OfInt.Value
}
return nil
}
// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
type ReinforcementHyperparametersEvalSamplesUnion struct {
// Construct this variant with constant.ValueOf[constant.Auto]()
OfAuto constant.Auto `json:",omitzero,inline"`
OfInt param.Opt[int64] `json:",omitzero,inline"`
paramUnion
}
func (u ReinforcementHyperparametersEvalSamplesUnion) MarshalJSON() ([]byte, error) {
return param.MarshalUnion(u, u.OfAuto, u.OfInt)
}
func (u *ReinforcementHyperparametersEvalSamplesUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, u)
}
func (u *ReinforcementHyperparametersEvalSamplesUnion) asAny() any {
if !param.IsOmitted(u.OfAuto) {
return &u.OfAuto
} else if !param.IsOmitted(u.OfInt) {
return &u.OfInt.Value
}
return nil
}
// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
type ReinforcementHyperparametersLearningRateMultiplierUnion struct {
// Construct this variant with constant.ValueOf[constant.Auto]()
OfAuto constant.Auto `json:",omitzero,inline"`
OfFloat param.Opt[float64] `json:",omitzero,inline"`
paramUnion
}
func (u ReinforcementHyperparametersLearningRateMultiplierUnion) MarshalJSON() ([]byte, error) {
return param.MarshalUnion(u, u.OfAuto, u.OfFloat)
}
func (u *ReinforcementHyperparametersLearningRateMultiplierUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, u)
}
func (u *ReinforcementHyperparametersLearningRateMultiplierUnion) asAny() any {
if !param.IsOmitted(u.OfAuto) {
return &u.OfAuto
} else if !param.IsOmitted(u.OfFloat) {
return &u.OfFloat.Value
}
return nil
}
// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
type ReinforcementHyperparametersNEpochsUnion struct {
// Construct this variant with constant.ValueOf[constant.Auto]()
OfAuto constant.Auto `json:",omitzero,inline"`
OfInt param.Opt[int64] `json:",omitzero,inline"`
paramUnion
}
func (u ReinforcementHyperparametersNEpochsUnion) MarshalJSON() ([]byte, error) {
return param.MarshalUnion(u, u.OfAuto, u.OfInt)
}
func (u *ReinforcementHyperparametersNEpochsUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, u)
}
func (u *ReinforcementHyperparametersNEpochsUnion) asAny() any {
if !param.IsOmitted(u.OfAuto) {
return &u.OfAuto
} else if !param.IsOmitted(u.OfInt) {
return &u.OfInt.Value
}
return nil
}
// Configuration for the reinforcement fine-tuning method.
type ReinforcementMethod struct {
// The grader used for the fine-tuning job.
Grader ReinforcementMethodGraderUnion `json:"grader,required"`
// The hyperparameters used for the reinforcement fine-tuning job.
Hyperparameters ReinforcementHyperparametersResp `json:"hyperparameters"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Grader respjson.Field
Hyperparameters respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ReinforcementMethod) RawJSON() string { return r.JSON.raw }
func (r *ReinforcementMethod) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// ToParam converts this ReinforcementMethod to a ReinforcementMethodParam.
//
// Warning: the fields of the param type will not be present. ToParam should only
// be used at the last possible moment before sending a request. Test for this with
// ReinforcementMethodParam.Overrides()
func (r ReinforcementMethod) ToParam() ReinforcementMethodParam {
return param.Override[ReinforcementMethodParam](json.RawMessage(r.RawJSON()))
}
// ReinforcementMethodGraderUnion contains all possible properties and values from
// [StringCheckGrader], [TextSimilarityGrader], [PythonGrader], [ScoreModelGrader],
// [MultiGrader].
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
type ReinforcementMethodGraderUnion struct {
// This field is a union of [string], [string], [[]ScoreModelGraderInput]
Input ReinforcementMethodGraderUnionInput `json:"input"`
Name string `json:"name"`
// This field is from variant [StringCheckGrader].
Operation StringCheckGraderOperation `json:"operation"`
Reference string `json:"reference"`
Type string `json:"type"`
// This field is from variant [TextSimilarityGrader].
EvaluationMetric TextSimilarityGraderEvaluationMetric `json:"evaluation_metric"`
// This field is from variant [PythonGrader].
Source string `json:"source"`
// This field is from variant [PythonGrader].
ImageTag string `json:"image_tag"`
// This field is from variant [ScoreModelGrader].
Model string `json:"model"`
// This field is from variant [ScoreModelGrader].
Range []float64 `json:"range"`
// This field is from variant [ScoreModelGrader].
SamplingParams any `json:"sampling_params"`
// This field is from variant [MultiGrader].
CalculateOutput string `json:"calculate_output"`
// This field is from variant [MultiGrader].
Graders MultiGraderGradersUnion `json:"graders"`
JSON struct {
Input respjson.Field
Name respjson.Field
Operation respjson.Field
Reference respjson.Field
Type respjson.Field
EvaluationMetric respjson.Field
Source respjson.Field
ImageTag respjson.Field
Model respjson.Field
Range respjson.Field
SamplingParams respjson.Field
CalculateOutput respjson.Field
Graders respjson.Field
raw string
} `json:"-"`
}
func (u ReinforcementMethodGraderUnion) AsStringCheckGrader() (v StringCheckGrader) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u ReinforcementMethodGraderUnion) AsTextSimilarityGrader() (v TextSimilarityGrader) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u ReinforcementMethodGraderUnion) AsPythonGrader() (v PythonGrader) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u ReinforcementMethodGraderUnion) AsScoreModelGrader() (v ScoreModelGrader) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u ReinforcementMethodGraderUnion) AsMultiGrader() (v MultiGrader) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u ReinforcementMethodGraderUnion) RawJSON() string { return u.JSON.raw }
func (r *ReinforcementMethodGraderUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// ReinforcementMethodGraderUnionInput is an implicit subunion of
// [ReinforcementMethodGraderUnion]. ReinforcementMethodGraderUnionInput provides
// convenient access to the sub-properties of the union.
//
// For type safety it is recommended to directly use a variant of the
// [ReinforcementMethodGraderUnion].
//
// If the underlying value is not a json object, one of the following properties
// will be valid: OfString OfScoreModelGraderInputArray]
type ReinforcementMethodGraderUnionInput struct {
// This field will be present if the value is a [string] instead of an object.
OfString string `json:",inline"`
// This field will be present if the value is a [[]ScoreModelGraderInput] instead
// of an object.
OfScoreModelGraderInputArray []ScoreModelGraderInput `json:",inline"`
JSON struct {
OfString respjson.Field
OfScoreModelGraderInputArray respjson.Field
raw string
} `json:"-"`
}
func (r *ReinforcementMethodGraderUnionInput) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}