-
Notifications
You must be signed in to change notification settings - Fork 124
/
Copy pathfinetuningcheckpointpermission.go
263 lines (238 loc) · 10.9 KB
/
finetuningcheckpointpermission.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
// 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/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/constant"
)
// FineTuningCheckpointPermissionService 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 [NewFineTuningCheckpointPermissionService] method instead.
type FineTuningCheckpointPermissionService struct {
Options []option.RequestOption
}
// NewFineTuningCheckpointPermissionService 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 NewFineTuningCheckpointPermissionService(opts ...option.RequestOption) (r FineTuningCheckpointPermissionService) {
r = FineTuningCheckpointPermissionService{}
r.Options = opts
return
}
// **NOTE:** Calling this endpoint requires an [admin API key](../admin-api-keys).
//
// This enables organization owners to share fine-tuned models with other projects
// in their organization.
func (r *FineTuningCheckpointPermissionService) New(ctx context.Context, fineTunedModelCheckpoint string, body FineTuningCheckpointPermissionNewParams, opts ...option.RequestOption) (res *pagination.Page[FineTuningCheckpointPermissionNewResponse], err error) {
var raw *http.Response
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
if fineTunedModelCheckpoint == "" {
err = errors.New("missing required fine_tuned_model_checkpoint parameter")
return
}
path := fmt.Sprintf("fine_tuning/checkpoints/%s/permissions", fineTunedModelCheckpoint)
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodPost, path, body, &res, opts...)
if err != nil {
return nil, err
}
err = cfg.Execute()
if err != nil {
return nil, err
}
res.SetPageConfig(cfg, raw)
return res, nil
}
// **NOTE:** Calling this endpoint requires an [admin API key](../admin-api-keys).
//
// This enables organization owners to share fine-tuned models with other projects
// in their organization.
func (r *FineTuningCheckpointPermissionService) NewAutoPaging(ctx context.Context, fineTunedModelCheckpoint string, body FineTuningCheckpointPermissionNewParams, opts ...option.RequestOption) *pagination.PageAutoPager[FineTuningCheckpointPermissionNewResponse] {
return pagination.NewPageAutoPager(r.New(ctx, fineTunedModelCheckpoint, body, opts...))
}
// **NOTE:** This endpoint requires an [admin API key](../admin-api-keys).
//
// Organization owners can use this endpoint to view all permissions for a
// fine-tuned model checkpoint.
func (r *FineTuningCheckpointPermissionService) Get(ctx context.Context, fineTunedModelCheckpoint string, query FineTuningCheckpointPermissionGetParams, opts ...option.RequestOption) (res *FineTuningCheckpointPermissionGetResponse, err error) {
opts = append(r.Options[:], opts...)
if fineTunedModelCheckpoint == "" {
err = errors.New("missing required fine_tuned_model_checkpoint parameter")
return
}
path := fmt.Sprintf("fine_tuning/checkpoints/%s/permissions", fineTunedModelCheckpoint)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
return
}
// **NOTE:** This endpoint requires an [admin API key](../admin-api-keys).
//
// Organization owners can use this endpoint to delete a permission for a
// fine-tuned model checkpoint.
func (r *FineTuningCheckpointPermissionService) Delete(ctx context.Context, fineTunedModelCheckpoint string, opts ...option.RequestOption) (res *FineTuningCheckpointPermissionDeleteResponse, err error) {
opts = append(r.Options[:], opts...)
if fineTunedModelCheckpoint == "" {
err = errors.New("missing required fine_tuned_model_checkpoint parameter")
return
}
path := fmt.Sprintf("fine_tuning/checkpoints/%s/permissions", fineTunedModelCheckpoint)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...)
return
}
// The `checkpoint.permission` object represents a permission for a fine-tuned
// model checkpoint.
type FineTuningCheckpointPermissionNewResponse struct {
// The permission identifier, which can be referenced in the API endpoints.
ID string `json:"id,required"`
// The Unix timestamp (in seconds) for when the permission was created.
CreatedAt int64 `json:"created_at,required"`
// The object type, which is always "checkpoint.permission".
Object constant.CheckpointPermission `json:"object,required"`
// The project identifier that the permission is for.
ProjectID string `json:"project_id,required"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
ID resp.Field
CreatedAt resp.Field
Object resp.Field
ProjectID resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r FineTuningCheckpointPermissionNewResponse) RawJSON() string { return r.JSON.raw }
func (r *FineTuningCheckpointPermissionNewResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type FineTuningCheckpointPermissionGetResponse struct {
Data []FineTuningCheckpointPermissionGetResponseData `json:"data,required"`
HasMore bool `json:"has_more,required"`
Object constant.List `json:"object,required"`
FirstID string `json:"first_id,nullable"`
LastID string `json:"last_id,nullable"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
Data resp.Field
HasMore resp.Field
Object resp.Field
FirstID resp.Field
LastID resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r FineTuningCheckpointPermissionGetResponse) RawJSON() string { return r.JSON.raw }
func (r *FineTuningCheckpointPermissionGetResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// The `checkpoint.permission` object represents a permission for a fine-tuned
// model checkpoint.
type FineTuningCheckpointPermissionGetResponseData struct {
// The permission identifier, which can be referenced in the API endpoints.
ID string `json:"id,required"`
// The Unix timestamp (in seconds) for when the permission was created.
CreatedAt int64 `json:"created_at,required"`
// The object type, which is always "checkpoint.permission".
Object constant.CheckpointPermission `json:"object,required"`
// The project identifier that the permission is for.
ProjectID string `json:"project_id,required"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
ID resp.Field
CreatedAt resp.Field
Object resp.Field
ProjectID resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r FineTuningCheckpointPermissionGetResponseData) RawJSON() string { return r.JSON.raw }
func (r *FineTuningCheckpointPermissionGetResponseData) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type FineTuningCheckpointPermissionDeleteResponse struct {
// The ID of the fine-tuned model checkpoint permission that was deleted.
ID string `json:"id,required"`
// Whether the fine-tuned model checkpoint permission was successfully deleted.
Deleted bool `json:"deleted,required"`
// The object type, which is always "checkpoint.permission".
Object constant.CheckpointPermission `json:"object,required"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
ID resp.Field
Deleted resp.Field
Object resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r FineTuningCheckpointPermissionDeleteResponse) RawJSON() string { return r.JSON.raw }
func (r *FineTuningCheckpointPermissionDeleteResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type FineTuningCheckpointPermissionNewParams struct {
// The project identifiers to grant access to.
ProjectIDs []string `json:"project_ids,omitzero,required"`
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 FineTuningCheckpointPermissionNewParams) IsPresent() bool {
return !param.IsOmitted(f) && !f.IsNull()
}
func (r FineTuningCheckpointPermissionNewParams) MarshalJSON() (data []byte, err error) {
type shadow FineTuningCheckpointPermissionNewParams
return param.MarshalObject(r, (*shadow)(&r))
}
type FineTuningCheckpointPermissionGetParams struct {
// Identifier for the last permission ID from the previous pagination request.
After param.Opt[string] `query:"after,omitzero" json:"-"`
// Number of permissions to retrieve.
Limit param.Opt[int64] `query:"limit,omitzero" json:"-"`
// The ID of the project to get permissions for.
ProjectID param.Opt[string] `query:"project_id,omitzero" json:"-"`
// The order in which to retrieve permissions.
//
// Any of "ascending", "descending".
Order FineTuningCheckpointPermissionGetParamsOrder `query:"order,omitzero" json:"-"`
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 FineTuningCheckpointPermissionGetParams) IsPresent() bool {
return !param.IsOmitted(f) && !f.IsNull()
}
// URLQuery serializes [FineTuningCheckpointPermissionGetParams]'s query parameters
// as `url.Values`.
func (r FineTuningCheckpointPermissionGetParams) URLQuery() (v url.Values, err error) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatBrackets,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
// The order in which to retrieve permissions.
type FineTuningCheckpointPermissionGetParamsOrder string
const (
FineTuningCheckpointPermissionGetParamsOrderAscending FineTuningCheckpointPermissionGetParamsOrder = "ascending"
FineTuningCheckpointPermissionGetParamsOrderDescending FineTuningCheckpointPermissionGetParamsOrder = "descending"
)