-
Notifications
You must be signed in to change notification settings - Fork 121
/
Copy pathfinetuningjob.go
1527 lines (1379 loc) · 61.7 KB
/
finetuningjob.go
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 (
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
"net/url"
"github.com/openai/openai-go/internal/apijson"
"github.com/openai/openai-go/internal/apiquery"
"github.com/openai/openai-go/internal/requestconfig"
"github.com/openai/openai-go/option"
"github.com/openai/openai-go/packages/pagination"
"github.com/openai/openai-go/packages/param"
"github.com/openai/openai-go/packages/resp"
"github.com/openai/openai-go/shared"
"github.com/openai/openai-go/shared/constant"
)
// FineTuningJobService 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 [NewFineTuningJobService] method instead.
type FineTuningJobService struct {
Options []option.RequestOption
Checkpoints FineTuningJobCheckpointService
}
// NewFineTuningJobService 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 NewFineTuningJobService(opts ...option.RequestOption) (r FineTuningJobService) {
r = FineTuningJobService{}
r.Options = opts
r.Checkpoints = NewFineTuningJobCheckpointService(opts...)
return
}
// Creates a fine-tuning job which begins the process of creating a new model from
// a given dataset.
//
// Response includes details of the enqueued job including job status and the name
// of the fine-tuned models once complete.
//
// [Learn more about fine-tuning](https://platform.openai.com/docs/guides/fine-tuning)
func (r *FineTuningJobService) New(ctx context.Context, body FineTuningJobNewParams, opts ...option.RequestOption) (res *FineTuningJob, err error) {
opts = append(r.Options[:], opts...)
path := "fine_tuning/jobs"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// Get info about a fine-tuning job.
//
// [Learn more about fine-tuning](https://platform.openai.com/docs/guides/fine-tuning)
func (r *FineTuningJobService) Get(ctx context.Context, fineTuningJobID string, opts ...option.RequestOption) (res *FineTuningJob, err error) {
opts = append(r.Options[:], opts...)
if fineTuningJobID == "" {
err = errors.New("missing required fine_tuning_job_id parameter")
return
}
path := fmt.Sprintf("fine_tuning/jobs/%s", fineTuningJobID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// List your organization's fine-tuning jobs
func (r *FineTuningJobService) List(ctx context.Context, query FineTuningJobListParams, opts ...option.RequestOption) (res *pagination.CursorPage[FineTuningJob], err error) {
var raw *http.Response
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := "fine_tuning/jobs"
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...)
if err != nil {
return nil, err
}
err = cfg.Execute()
if err != nil {
return nil, err
}
res.SetPageConfig(cfg, raw)
return res, nil
}
// List your organization's fine-tuning jobs
func (r *FineTuningJobService) ListAutoPaging(ctx context.Context, query FineTuningJobListParams, opts ...option.RequestOption) *pagination.CursorPageAutoPager[FineTuningJob] {
return pagination.NewCursorPageAutoPager(r.List(ctx, query, opts...))
}
// Immediately cancel a fine-tune job.
func (r *FineTuningJobService) Cancel(ctx context.Context, fineTuningJobID string, opts ...option.RequestOption) (res *FineTuningJob, err error) {
opts = append(r.Options[:], opts...)
if fineTuningJobID == "" {
err = errors.New("missing required fine_tuning_job_id parameter")
return
}
path := fmt.Sprintf("fine_tuning/jobs/%s/cancel", fineTuningJobID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...)
return
}
// Get status updates for a fine-tuning job.
func (r *FineTuningJobService) ListEvents(ctx context.Context, fineTuningJobID string, query FineTuningJobListEventsParams, opts ...option.RequestOption) (res *pagination.CursorPage[FineTuningJobEvent], err error) {
var raw *http.Response
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
if fineTuningJobID == "" {
err = errors.New("missing required fine_tuning_job_id parameter")
return
}
path := fmt.Sprintf("fine_tuning/jobs/%s/events", fineTuningJobID)
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...)
if err != nil {
return nil, err
}
err = cfg.Execute()
if err != nil {
return nil, err
}
res.SetPageConfig(cfg, raw)
return res, nil
}
// Get status updates for a fine-tuning job.
func (r *FineTuningJobService) ListEventsAutoPaging(ctx context.Context, fineTuningJobID string, query FineTuningJobListEventsParams, opts ...option.RequestOption) *pagination.CursorPageAutoPager[FineTuningJobEvent] {
return pagination.NewCursorPageAutoPager(r.ListEvents(ctx, fineTuningJobID, query, opts...))
}
// The `fine_tuning.job` object represents a fine-tuning job that has been created
// through the API.
type FineTuningJob struct {
// The object identifier, which can be referenced in the API endpoints.
ID string `json:"id,required"`
// The Unix timestamp (in seconds) for when the fine-tuning job was created.
CreatedAt int64 `json:"created_at,required"`
// For fine-tuning jobs that have `failed`, this will contain more information on
// the cause of the failure.
Error FineTuningJobError `json:"error,required"`
// The name of the fine-tuned model that is being created. The value will be null
// if the fine-tuning job is still running.
FineTunedModel string `json:"fine_tuned_model,required"`
// The Unix timestamp (in seconds) for when the fine-tuning job was finished. The
// value will be null if the fine-tuning job is still running.
FinishedAt int64 `json:"finished_at,required"`
// The hyperparameters used for the fine-tuning job. This value will only be
// returned when running `supervised` jobs.
Hyperparameters FineTuningJobHyperparameters `json:"hyperparameters,required"`
// The base model that is being fine-tuned.
Model string `json:"model,required"`
// The object type, which is always "fine_tuning.job".
Object constant.FineTuningJob `json:"object,required"`
// The organization that owns the fine-tuning job.
OrganizationID string `json:"organization_id,required"`
// The compiled results file ID(s) for the fine-tuning job. You can retrieve the
// results with the
// [Files API](https://platform.openai.com/docs/api-reference/files/retrieve-contents).
ResultFiles []string `json:"result_files,required"`
// The seed used for the fine-tuning job.
Seed int64 `json:"seed,required"`
// The current status of the fine-tuning job, which can be either
// `validating_files`, `queued`, `running`, `succeeded`, `failed`, or `cancelled`.
//
// Any of "validating_files", "queued", "running", "succeeded", "failed",
// "cancelled".
Status FineTuningJobStatus `json:"status,required"`
// The total number of billable tokens processed by this fine-tuning job. The value
// will be null if the fine-tuning job is still running.
TrainedTokens int64 `json:"trained_tokens,required"`
// The file ID used for training. You can retrieve the training data with the
// [Files API](https://platform.openai.com/docs/api-reference/files/retrieve-contents).
TrainingFile string `json:"training_file,required"`
// The file ID used for validation. You can retrieve the validation results with
// the
// [Files API](https://platform.openai.com/docs/api-reference/files/retrieve-contents).
ValidationFile string `json:"validation_file,required"`
// The Unix timestamp (in seconds) for when the fine-tuning job is estimated to
// finish. The value will be null if the fine-tuning job is not running.
EstimatedFinish int64 `json:"estimated_finish,nullable"`
// A list of integrations to enable for this fine-tuning job.
Integrations []FineTuningJobWandbIntegrationObject `json:"integrations,nullable"`
// Set of 16 key-value pairs that can be attached to an object. This can be useful
// for storing additional information about the object in a structured format, and
// querying for objects via API or the dashboard.
//
// Keys are strings with a maximum length of 64 characters. Values are strings with
// a maximum length of 512 characters.
Metadata shared.Metadata `json:"metadata,nullable"`
// The method used for fine-tuning.
Method FineTuningJobMethod `json:"method"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
ID resp.Field
CreatedAt resp.Field
Error resp.Field
FineTunedModel resp.Field
FinishedAt resp.Field
Hyperparameters resp.Field
Model resp.Field
Object resp.Field
OrganizationID resp.Field
ResultFiles resp.Field
Seed resp.Field
Status resp.Field
TrainedTokens resp.Field
TrainingFile resp.Field
ValidationFile resp.Field
EstimatedFinish resp.Field
Integrations resp.Field
Metadata resp.Field
Method resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r FineTuningJob) RawJSON() string { return r.JSON.raw }
func (r *FineTuningJob) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// For fine-tuning jobs that have `failed`, this will contain more information on
// the cause of the failure.
type FineTuningJobError struct {
// A machine-readable error code.
Code string `json:"code,required"`
// A human-readable error message.
Message string `json:"message,required"`
// The parameter that was invalid, usually `training_file` or `validation_file`.
// This field will be null if the failure was not parameter-specific.
Param string `json:"param,required"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
Code resp.Field
Message resp.Field
Param resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r FineTuningJobError) RawJSON() string { return r.JSON.raw }
func (r *FineTuningJobError) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// The hyperparameters used for the fine-tuning job. This value will only be
// returned when running `supervised` jobs.
type FineTuningJobHyperparameters struct {
// Number of examples in each batch. A larger batch size means that model
// parameters are updated less frequently, but with lower variance.
BatchSize FineTuningJobHyperparametersBatchSizeUnion `json:"batch_size"`
// Scaling factor for the learning rate. A smaller learning rate may be useful to
// avoid overfitting.
LearningRateMultiplier FineTuningJobHyperparametersLearningRateMultiplierUnion `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 FineTuningJobHyperparametersNEpochsUnion `json:"n_epochs"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
BatchSize resp.Field
LearningRateMultiplier resp.Field
NEpochs resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r FineTuningJobHyperparameters) RawJSON() string { return r.JSON.raw }
func (r *FineTuningJobHyperparameters) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// FineTuningJobHyperparametersBatchSizeUnion 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 FineTuningJobHyperparametersBatchSizeUnion 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 resp.Field
OfInt resp.Field
raw string
} `json:"-"`
}
func (u FineTuningJobHyperparametersBatchSizeUnion) AsAuto() (v constant.Auto) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u FineTuningJobHyperparametersBatchSizeUnion) AsInt() (v int64) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u FineTuningJobHyperparametersBatchSizeUnion) RawJSON() string { return u.JSON.raw }
func (r *FineTuningJobHyperparametersBatchSizeUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// FineTuningJobHyperparametersLearningRateMultiplierUnion 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 FineTuningJobHyperparametersLearningRateMultiplierUnion 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 resp.Field
OfFloat resp.Field
raw string
} `json:"-"`
}
func (u FineTuningJobHyperparametersLearningRateMultiplierUnion) AsAuto() (v constant.Auto) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u FineTuningJobHyperparametersLearningRateMultiplierUnion) AsFloat() (v float64) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u FineTuningJobHyperparametersLearningRateMultiplierUnion) RawJSON() string { return u.JSON.raw }
func (r *FineTuningJobHyperparametersLearningRateMultiplierUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// FineTuningJobHyperparametersNEpochsUnion 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 FineTuningJobHyperparametersNEpochsUnion 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 resp.Field
OfInt resp.Field
raw string
} `json:"-"`
}
func (u FineTuningJobHyperparametersNEpochsUnion) AsAuto() (v constant.Auto) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u FineTuningJobHyperparametersNEpochsUnion) AsInt() (v int64) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u FineTuningJobHyperparametersNEpochsUnion) RawJSON() string { return u.JSON.raw }
func (r *FineTuningJobHyperparametersNEpochsUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// The current status of the fine-tuning job, which can be either
// `validating_files`, `queued`, `running`, `succeeded`, `failed`, or `cancelled`.
type FineTuningJobStatus string
const (
FineTuningJobStatusValidatingFiles FineTuningJobStatus = "validating_files"
FineTuningJobStatusQueued FineTuningJobStatus = "queued"
FineTuningJobStatusRunning FineTuningJobStatus = "running"
FineTuningJobStatusSucceeded FineTuningJobStatus = "succeeded"
FineTuningJobStatusFailed FineTuningJobStatus = "failed"
FineTuningJobStatusCancelled FineTuningJobStatus = "cancelled"
)
// The method used for fine-tuning.
type FineTuningJobMethod struct {
// Configuration for the DPO fine-tuning method.
Dpo FineTuningJobMethodDpo `json:"dpo"`
// Configuration for the supervised fine-tuning method.
Supervised FineTuningJobMethodSupervised `json:"supervised"`
// The type of method. Is either `supervised` or `dpo`.
//
// Any of "supervised", "dpo".
Type string `json:"type"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
Dpo resp.Field
Supervised resp.Field
Type resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r FineTuningJobMethod) RawJSON() string { return r.JSON.raw }
func (r *FineTuningJobMethod) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Configuration for the DPO fine-tuning method.
type FineTuningJobMethodDpo struct {
// The hyperparameters used for the fine-tuning job.
Hyperparameters FineTuningJobMethodDpoHyperparameters `json:"hyperparameters"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
Hyperparameters resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r FineTuningJobMethodDpo) RawJSON() string { return r.JSON.raw }
func (r *FineTuningJobMethodDpo) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// The hyperparameters used for the fine-tuning job.
type FineTuningJobMethodDpoHyperparameters struct {
// Number of examples in each batch. A larger batch size means that model
// parameters are updated less frequently, but with lower variance.
BatchSize FineTuningJobMethodDpoHyperparametersBatchSizeUnion `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 FineTuningJobMethodDpoHyperparametersBetaUnion `json:"beta"`
// Scaling factor for the learning rate. A smaller learning rate may be useful to
// avoid overfitting.
LearningRateMultiplier FineTuningJobMethodDpoHyperparametersLearningRateMultiplierUnion `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 FineTuningJobMethodDpoHyperparametersNEpochsUnion `json:"n_epochs"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
BatchSize resp.Field
Beta resp.Field
LearningRateMultiplier resp.Field
NEpochs resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r FineTuningJobMethodDpoHyperparameters) RawJSON() string { return r.JSON.raw }
func (r *FineTuningJobMethodDpoHyperparameters) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// FineTuningJobMethodDpoHyperparametersBatchSizeUnion 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 FineTuningJobMethodDpoHyperparametersBatchSizeUnion 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 resp.Field
OfInt resp.Field
raw string
} `json:"-"`
}
func (u FineTuningJobMethodDpoHyperparametersBatchSizeUnion) AsAuto() (v constant.Auto) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u FineTuningJobMethodDpoHyperparametersBatchSizeUnion) AsInt() (v int64) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u FineTuningJobMethodDpoHyperparametersBatchSizeUnion) RawJSON() string { return u.JSON.raw }
func (r *FineTuningJobMethodDpoHyperparametersBatchSizeUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// FineTuningJobMethodDpoHyperparametersBetaUnion 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 FineTuningJobMethodDpoHyperparametersBetaUnion 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 resp.Field
OfFloat resp.Field
raw string
} `json:"-"`
}
func (u FineTuningJobMethodDpoHyperparametersBetaUnion) AsAuto() (v constant.Auto) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u FineTuningJobMethodDpoHyperparametersBetaUnion) AsFloat() (v float64) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u FineTuningJobMethodDpoHyperparametersBetaUnion) RawJSON() string { return u.JSON.raw }
func (r *FineTuningJobMethodDpoHyperparametersBetaUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// FineTuningJobMethodDpoHyperparametersLearningRateMultiplierUnion 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 FineTuningJobMethodDpoHyperparametersLearningRateMultiplierUnion 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 resp.Field
OfFloat resp.Field
raw string
} `json:"-"`
}
func (u FineTuningJobMethodDpoHyperparametersLearningRateMultiplierUnion) AsAuto() (v constant.Auto) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u FineTuningJobMethodDpoHyperparametersLearningRateMultiplierUnion) AsFloat() (v float64) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u FineTuningJobMethodDpoHyperparametersLearningRateMultiplierUnion) RawJSON() string {
return u.JSON.raw
}
func (r *FineTuningJobMethodDpoHyperparametersLearningRateMultiplierUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// FineTuningJobMethodDpoHyperparametersNEpochsUnion 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 FineTuningJobMethodDpoHyperparametersNEpochsUnion 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 resp.Field
OfInt resp.Field
raw string
} `json:"-"`
}
func (u FineTuningJobMethodDpoHyperparametersNEpochsUnion) AsAuto() (v constant.Auto) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u FineTuningJobMethodDpoHyperparametersNEpochsUnion) AsInt() (v int64) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u FineTuningJobMethodDpoHyperparametersNEpochsUnion) RawJSON() string { return u.JSON.raw }
func (r *FineTuningJobMethodDpoHyperparametersNEpochsUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Configuration for the supervised fine-tuning method.
type FineTuningJobMethodSupervised struct {
// The hyperparameters used for the fine-tuning job.
Hyperparameters FineTuningJobMethodSupervisedHyperparameters `json:"hyperparameters"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
Hyperparameters resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r FineTuningJobMethodSupervised) RawJSON() string { return r.JSON.raw }
func (r *FineTuningJobMethodSupervised) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// The hyperparameters used for the fine-tuning job.
type FineTuningJobMethodSupervisedHyperparameters struct {
// Number of examples in each batch. A larger batch size means that model
// parameters are updated less frequently, but with lower variance.
BatchSize FineTuningJobMethodSupervisedHyperparametersBatchSizeUnion `json:"batch_size"`
// Scaling factor for the learning rate. A smaller learning rate may be useful to
// avoid overfitting.
LearningRateMultiplier FineTuningJobMethodSupervisedHyperparametersLearningRateMultiplierUnion `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 FineTuningJobMethodSupervisedHyperparametersNEpochsUnion `json:"n_epochs"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
BatchSize resp.Field
LearningRateMultiplier resp.Field
NEpochs resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r FineTuningJobMethodSupervisedHyperparameters) RawJSON() string { return r.JSON.raw }
func (r *FineTuningJobMethodSupervisedHyperparameters) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// FineTuningJobMethodSupervisedHyperparametersBatchSizeUnion 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 FineTuningJobMethodSupervisedHyperparametersBatchSizeUnion 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 resp.Field
OfInt resp.Field
raw string
} `json:"-"`
}
func (u FineTuningJobMethodSupervisedHyperparametersBatchSizeUnion) AsAuto() (v constant.Auto) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u FineTuningJobMethodSupervisedHyperparametersBatchSizeUnion) AsInt() (v int64) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u FineTuningJobMethodSupervisedHyperparametersBatchSizeUnion) RawJSON() string {
return u.JSON.raw
}
func (r *FineTuningJobMethodSupervisedHyperparametersBatchSizeUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// FineTuningJobMethodSupervisedHyperparametersLearningRateMultiplierUnion 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 FineTuningJobMethodSupervisedHyperparametersLearningRateMultiplierUnion 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 resp.Field
OfFloat resp.Field
raw string
} `json:"-"`
}
func (u FineTuningJobMethodSupervisedHyperparametersLearningRateMultiplierUnion) AsAuto() (v constant.Auto) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u FineTuningJobMethodSupervisedHyperparametersLearningRateMultiplierUnion) AsFloat() (v float64) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u FineTuningJobMethodSupervisedHyperparametersLearningRateMultiplierUnion) RawJSON() string {
return u.JSON.raw
}
func (r *FineTuningJobMethodSupervisedHyperparametersLearningRateMultiplierUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// FineTuningJobMethodSupervisedHyperparametersNEpochsUnion 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 FineTuningJobMethodSupervisedHyperparametersNEpochsUnion 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 resp.Field
OfInt resp.Field
raw string
} `json:"-"`
}
func (u FineTuningJobMethodSupervisedHyperparametersNEpochsUnion) AsAuto() (v constant.Auto) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u FineTuningJobMethodSupervisedHyperparametersNEpochsUnion) AsInt() (v int64) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u FineTuningJobMethodSupervisedHyperparametersNEpochsUnion) RawJSON() string { return u.JSON.raw }
func (r *FineTuningJobMethodSupervisedHyperparametersNEpochsUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Fine-tuning job event object
type FineTuningJobEvent struct {
// The object identifier.
ID string `json:"id,required"`
// The Unix timestamp (in seconds) for when the fine-tuning job was created.
CreatedAt int64 `json:"created_at,required"`
// The log level of the event.
//
// Any of "info", "warn", "error".
Level FineTuningJobEventLevel `json:"level,required"`
// The message of the event.
Message string `json:"message,required"`
// The object type, which is always "fine_tuning.job.event".
Object constant.FineTuningJobEvent `json:"object,required"`
// The data associated with the event.
Data interface{} `json:"data"`
// The type of event.
//
// Any of "message", "metrics".
Type FineTuningJobEventType `json:"type"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
ID resp.Field
CreatedAt resp.Field
Level resp.Field
Message resp.Field
Object resp.Field
Data resp.Field
Type resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r FineTuningJobEvent) RawJSON() string { return r.JSON.raw }
func (r *FineTuningJobEvent) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// The log level of the event.
type FineTuningJobEventLevel string
const (
FineTuningJobEventLevelInfo FineTuningJobEventLevel = "info"
FineTuningJobEventLevelWarn FineTuningJobEventLevel = "warn"
FineTuningJobEventLevelError FineTuningJobEventLevel = "error"
)
// The type of event.
type FineTuningJobEventType string
const (
FineTuningJobEventTypeMessage FineTuningJobEventType = "message"
FineTuningJobEventTypeMetrics FineTuningJobEventType = "metrics"
)
// The settings for your integration with Weights and Biases. This payload
// specifies the project that metrics will be sent to. Optionally, you can set an
// explicit display name for your run, add tags to your run, and set a default
// entity (team, username, etc) to be associated with your run.
type FineTuningJobWandbIntegration struct {
// The name of the project that the new run will be created under.
Project string `json:"project,required"`
// The entity to use for the run. This allows you to set the team or username of
// the WandB user that you would like associated with the run. If not set, the
// default entity for the registered WandB API key is used.
Entity string `json:"entity,nullable"`
// A display name to set for the run. If not set, we will use the Job ID as the
// name.
Name string `json:"name,nullable"`
// A list of tags to be attached to the newly created run. These tags are passed
// through directly to WandB. Some default tags are generated by OpenAI:
// "openai/finetune", "openai/{base-model}", "openai/{ftjob-abcdef}".
Tags []string `json:"tags"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
Project resp.Field
Entity resp.Field
Name resp.Field
Tags resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r FineTuningJobWandbIntegration) RawJSON() string { return r.JSON.raw }
func (r *FineTuningJobWandbIntegration) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type FineTuningJobWandbIntegrationObject struct {
// The type of the integration being enabled for the fine-tuning job
Type constant.Wandb `json:"type,required"`
// The settings for your integration with Weights and Biases. This payload
// specifies the project that metrics will be sent to. Optionally, you can set an
// explicit display name for your run, add tags to your run, and set a default
// entity (team, username, etc) to be associated with your run.
Wandb FineTuningJobWandbIntegration `json:"wandb,required"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
Type resp.Field
Wandb resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r FineTuningJobWandbIntegrationObject) RawJSON() string { return r.JSON.raw }
func (r *FineTuningJobWandbIntegrationObject) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type FineTuningJobNewParams struct {
// The name of the model to fine-tune. You can select one of the
// [supported models](https://platform.openai.com/docs/guides/fine-tuning#which-models-can-be-fine-tuned).
Model FineTuningJobNewParamsModel `json:"model,omitzero,required"`
// The ID of an uploaded file that contains training data.
//
// See [upload file](https://platform.openai.com/docs/api-reference/files/create)
// for how to upload a file.
//
// Your dataset must be formatted as a JSONL file. Additionally, you must upload
// your file with the purpose `fine-tune`.
//
// The contents of the file should differ depending on if the model uses the
// [chat](https://platform.openai.com/docs/api-reference/fine-tuning/chat-input),
// [completions](https://platform.openai.com/docs/api-reference/fine-tuning/completions-input)
// format, or if the fine-tuning method uses the
// [preference](https://platform.openai.com/docs/api-reference/fine-tuning/preference-input)
// format.
//
// See the [fine-tuning guide](https://platform.openai.com/docs/guides/fine-tuning)
// for more details.
TrainingFile string `json:"training_file,required"`
// The seed controls the reproducibility of the job. Passing in the same seed and
// job parameters should produce the same results, but may differ in rare cases. If
// a seed is not specified, one will be generated for you.
Seed param.Opt[int64] `json:"seed,omitzero"`
// A string of up to 64 characters that will be added to your fine-tuned model
// name.
//
// For example, a `suffix` of "custom-model-name" would produce a model name like
// `ft:gpt-4o-mini:openai:custom-model-name:7p4lURel`.
Suffix param.Opt[string] `json:"suffix,omitzero"`
// The ID of an uploaded file that contains validation data.
//
// If you provide this file, the data is used to generate validation metrics
// periodically during fine-tuning. These metrics can be viewed in the fine-tuning
// results file. The same data should not be present in both train and validation
// files.
//
// Your dataset must be formatted as a JSONL file. You must upload your file with
// the purpose `fine-tune`.
//
// See the [fine-tuning guide](https://platform.openai.com/docs/guides/fine-tuning)
// for more details.
ValidationFile param.Opt[string] `json:"validation_file,omitzero"`
// A list of integrations to enable for your fine-tuning job.
Integrations []FineTuningJobNewParamsIntegration `json:"integrations,omitzero"`
// Set of 16 key-value pairs that can be attached to an object. This can be useful
// for storing additional information about the object in a structured format, and
// querying for objects via API or the dashboard.
//
// Keys are strings with a maximum length of 64 characters. Values are strings with
// a maximum length of 512 characters.
Metadata shared.MetadataParam `json:"metadata,omitzero"`
// The hyperparameters used for the fine-tuning job. This value is now deprecated
// in favor of `method`, and should be passed in under the `method` parameter.
Hyperparameters FineTuningJobNewParamsHyperparameters `json:"hyperparameters,omitzero"`
// The method used for fine-tuning.
Method FineTuningJobNewParamsMethod `json:"method,omitzero"`
paramObj
}
// IsPresent returns true if the field's value is not omitted and not the JSON
// "null". To check if this field is omitted, use [param.IsOmitted].
func (f FineTuningJobNewParams) IsPresent() bool { return !param.IsOmitted(f) && !f.IsNull() }
func (r FineTuningJobNewParams) MarshalJSON() (data []byte, err error) {
type shadow FineTuningJobNewParams
return param.MarshalObject(r, (*shadow)(&r))
}
// The name of the model to fine-tune. You can select one of the
// [supported models](https://platform.openai.com/docs/guides/fine-tuning#which-models-can-be-fine-tuned).
type FineTuningJobNewParamsModel string
const (
FineTuningJobNewParamsModelBabbage002 FineTuningJobNewParamsModel = "babbage-002"
FineTuningJobNewParamsModelDavinci002 FineTuningJobNewParamsModel = "davinci-002"
FineTuningJobNewParamsModelGPT3_5Turbo FineTuningJobNewParamsModel = "gpt-3.5-turbo"
FineTuningJobNewParamsModelGPT4oMini FineTuningJobNewParamsModel = "gpt-4o-mini"
)
// The hyperparameters used for the fine-tuning job. This value is now deprecated
// in favor of `method`, and should be passed in under the `method` parameter.