forked from openai/openai-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
finetuningjobcheckpoint.go
171 lines (151 loc) · 6.75 KB
/
finetuningjobcheckpoint.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
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package openai
import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
"github.com/joschahenningsen/openai-go/internal/apijson"
"github.com/joschahenningsen/openai-go/internal/apiquery"
"github.com/joschahenningsen/openai-go/internal/param"
"github.com/joschahenningsen/openai-go/internal/requestconfig"
"github.com/joschahenningsen/openai-go/option"
"github.com/joschahenningsen/openai-go/packages/pagination"
)
// FineTuningJobCheckpointService 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 [NewFineTuningJobCheckpointService] method instead.
type FineTuningJobCheckpointService struct {
Options []option.RequestOption
}
// NewFineTuningJobCheckpointService 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 NewFineTuningJobCheckpointService(opts ...option.RequestOption) (r *FineTuningJobCheckpointService) {
r = &FineTuningJobCheckpointService{}
r.Options = opts
return
}
// List checkpoints for a fine-tuning job.
func (r *FineTuningJobCheckpointService) List(ctx context.Context, fineTuningJobID string, query FineTuningJobCheckpointListParams, opts ...option.RequestOption) (res *pagination.CursorPage[FineTuningJobCheckpoint], 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/checkpoints", 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
}
// List checkpoints for a fine-tuning job.
func (r *FineTuningJobCheckpointService) ListAutoPaging(ctx context.Context, fineTuningJobID string, query FineTuningJobCheckpointListParams, opts ...option.RequestOption) *pagination.CursorPageAutoPager[FineTuningJobCheckpoint] {
return pagination.NewCursorPageAutoPager(r.List(ctx, fineTuningJobID, query, opts...))
}
// The `fine_tuning.job.checkpoint` object represents a model checkpoint for a
// fine-tuning job that is ready to use.
type FineTuningJobCheckpoint struct {
// The checkpoint identifier, which can be referenced in the API endpoints.
ID string `json:"id,required"`
// The Unix timestamp (in seconds) for when the checkpoint was created.
CreatedAt int64 `json:"created_at,required"`
// The name of the fine-tuned checkpoint model that is created.
FineTunedModelCheckpoint string `json:"fine_tuned_model_checkpoint,required"`
// The name of the fine-tuning job that this checkpoint was created from.
FineTuningJobID string `json:"fine_tuning_job_id,required"`
// Metrics at the step number during the fine-tuning job.
Metrics FineTuningJobCheckpointMetrics `json:"metrics,required"`
// The object type, which is always "fine_tuning.job.checkpoint".
Object FineTuningJobCheckpointObject `json:"object,required"`
// The step number that the checkpoint was created at.
StepNumber int64 `json:"step_number,required"`
JSON fineTuningJobCheckpointJSON `json:"-"`
}
// fineTuningJobCheckpointJSON contains the JSON metadata for the struct
// [FineTuningJobCheckpoint]
type fineTuningJobCheckpointJSON struct {
ID apijson.Field
CreatedAt apijson.Field
FineTunedModelCheckpoint apijson.Field
FineTuningJobID apijson.Field
Metrics apijson.Field
Object apijson.Field
StepNumber apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *FineTuningJobCheckpoint) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r fineTuningJobCheckpointJSON) RawJSON() string {
return r.raw
}
// Metrics at the step number during the fine-tuning job.
type FineTuningJobCheckpointMetrics struct {
FullValidLoss float64 `json:"full_valid_loss"`
FullValidMeanTokenAccuracy float64 `json:"full_valid_mean_token_accuracy"`
Step float64 `json:"step"`
TrainLoss float64 `json:"train_loss"`
TrainMeanTokenAccuracy float64 `json:"train_mean_token_accuracy"`
ValidLoss float64 `json:"valid_loss"`
ValidMeanTokenAccuracy float64 `json:"valid_mean_token_accuracy"`
JSON fineTuningJobCheckpointMetricsJSON `json:"-"`
}
// fineTuningJobCheckpointMetricsJSON contains the JSON metadata for the struct
// [FineTuningJobCheckpointMetrics]
type fineTuningJobCheckpointMetricsJSON struct {
FullValidLoss apijson.Field
FullValidMeanTokenAccuracy apijson.Field
Step apijson.Field
TrainLoss apijson.Field
TrainMeanTokenAccuracy apijson.Field
ValidLoss apijson.Field
ValidMeanTokenAccuracy apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *FineTuningJobCheckpointMetrics) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r fineTuningJobCheckpointMetricsJSON) RawJSON() string {
return r.raw
}
// The object type, which is always "fine_tuning.job.checkpoint".
type FineTuningJobCheckpointObject string
const (
FineTuningJobCheckpointObjectFineTuningJobCheckpoint FineTuningJobCheckpointObject = "fine_tuning.job.checkpoint"
)
func (r FineTuningJobCheckpointObject) IsKnown() bool {
switch r {
case FineTuningJobCheckpointObjectFineTuningJobCheckpoint:
return true
}
return false
}
type FineTuningJobCheckpointListParams struct {
// Identifier for the last checkpoint ID from the previous pagination request.
After param.Field[string] `query:"after"`
// Number of checkpoints to retrieve.
Limit param.Field[int64] `query:"limit"`
}
// URLQuery serializes [FineTuningJobCheckpointListParams]'s query parameters as
// `url.Values`.
func (r FineTuningJobCheckpointListParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatBrackets,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}