forked from openai/openai-go
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontainer.go
More file actions
352 lines (321 loc) · 12.7 KB
/
container.go
File metadata and controls
352 lines (321 loc) · 12.7 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
// 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/respjson"
)
// ContainerService 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 [NewContainerService] method instead.
type ContainerService struct {
Options []option.RequestOption
Files ContainerFileService
}
// NewContainerService 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 NewContainerService(opts ...option.RequestOption) (r ContainerService) {
r = ContainerService{}
r.Options = opts
r.Files = NewContainerFileService(opts...)
return
}
// Create Container
func (r *ContainerService) New(ctx context.Context, body ContainerNewParams, opts ...option.RequestOption) (res *ContainerNewResponse, err error) {
opts = append(r.Options[:], opts...)
path := "containers"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// Retrieve Container
func (r *ContainerService) Get(ctx context.Context, containerID string, opts ...option.RequestOption) (res *ContainerGetResponse, err error) {
opts = append(r.Options[:], opts...)
if containerID == "" {
err = errors.New("missing required container_id parameter")
return
}
path := fmt.Sprintf("containers/%s", containerID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// List Containers
func (r *ContainerService) List(ctx context.Context, query ContainerListParams, opts ...option.RequestOption) (res *pagination.CursorPage[ContainerListResponse], err error) {
var raw *http.Response
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := "containers"
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 Containers
func (r *ContainerService) ListAutoPaging(ctx context.Context, query ContainerListParams, opts ...option.RequestOption) *pagination.CursorPageAutoPager[ContainerListResponse] {
return pagination.NewCursorPageAutoPager(r.List(ctx, query, opts...))
}
// Delete Container
func (r *ContainerService) Delete(ctx context.Context, containerID string, opts ...option.RequestOption) (err error) {
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithHeader("Accept", "")}, opts...)
if containerID == "" {
err = errors.New("missing required container_id parameter")
return
}
path := fmt.Sprintf("containers/%s", containerID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, nil, opts...)
return
}
type ContainerNewResponse struct {
// Unique identifier for the container.
ID string `json:"id,required"`
// Unix timestamp (in seconds) when the container was created.
CreatedAt int64 `json:"created_at,required"`
// Name of the container.
Name string `json:"name,required"`
// The type of this object.
Object string `json:"object,required"`
// Status of the container (e.g., active, deleted).
Status string `json:"status,required"`
// The container will expire after this time period. The anchor is the reference
// point for the expiration. The minutes is the number of minutes after the anchor
// before the container expires.
ExpiresAfter ContainerNewResponseExpiresAfter `json:"expires_after"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
CreatedAt respjson.Field
Name respjson.Field
Object respjson.Field
Status respjson.Field
ExpiresAfter respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ContainerNewResponse) RawJSON() string { return r.JSON.raw }
func (r *ContainerNewResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// The container will expire after this time period. The anchor is the reference
// point for the expiration. The minutes is the number of minutes after the anchor
// before the container expires.
type ContainerNewResponseExpiresAfter struct {
// The reference point for the expiration.
//
// Any of "last_active_at".
Anchor string `json:"anchor"`
// The number of minutes after the anchor before the container expires.
Minutes int64 `json:"minutes"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Anchor respjson.Field
Minutes respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ContainerNewResponseExpiresAfter) RawJSON() string { return r.JSON.raw }
func (r *ContainerNewResponseExpiresAfter) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type ContainerGetResponse struct {
// Unique identifier for the container.
ID string `json:"id,required"`
// Unix timestamp (in seconds) when the container was created.
CreatedAt int64 `json:"created_at,required"`
// Name of the container.
Name string `json:"name,required"`
// The type of this object.
Object string `json:"object,required"`
// Status of the container (e.g., active, deleted).
Status string `json:"status,required"`
// The container will expire after this time period. The anchor is the reference
// point for the expiration. The minutes is the number of minutes after the anchor
// before the container expires.
ExpiresAfter ContainerGetResponseExpiresAfter `json:"expires_after"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
CreatedAt respjson.Field
Name respjson.Field
Object respjson.Field
Status respjson.Field
ExpiresAfter respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ContainerGetResponse) RawJSON() string { return r.JSON.raw }
func (r *ContainerGetResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// The container will expire after this time period. The anchor is the reference
// point for the expiration. The minutes is the number of minutes after the anchor
// before the container expires.
type ContainerGetResponseExpiresAfter struct {
// The reference point for the expiration.
//
// Any of "last_active_at".
Anchor string `json:"anchor"`
// The number of minutes after the anchor before the container expires.
Minutes int64 `json:"minutes"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Anchor respjson.Field
Minutes respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ContainerGetResponseExpiresAfter) RawJSON() string { return r.JSON.raw }
func (r *ContainerGetResponseExpiresAfter) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type ContainerListResponse struct {
// Unique identifier for the container.
ID string `json:"id,required"`
// Unix timestamp (in seconds) when the container was created.
CreatedAt int64 `json:"created_at,required"`
// Name of the container.
Name string `json:"name,required"`
// The type of this object.
Object string `json:"object,required"`
// Status of the container (e.g., active, deleted).
Status string `json:"status,required"`
// The container will expire after this time period. The anchor is the reference
// point for the expiration. The minutes is the number of minutes after the anchor
// before the container expires.
ExpiresAfter ContainerListResponseExpiresAfter `json:"expires_after"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
CreatedAt respjson.Field
Name respjson.Field
Object respjson.Field
Status respjson.Field
ExpiresAfter respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ContainerListResponse) RawJSON() string { return r.JSON.raw }
func (r *ContainerListResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// The container will expire after this time period. The anchor is the reference
// point for the expiration. The minutes is the number of minutes after the anchor
// before the container expires.
type ContainerListResponseExpiresAfter struct {
// The reference point for the expiration.
//
// Any of "last_active_at".
Anchor string `json:"anchor"`
// The number of minutes after the anchor before the container expires.
Minutes int64 `json:"minutes"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Anchor respjson.Field
Minutes respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ContainerListResponseExpiresAfter) RawJSON() string { return r.JSON.raw }
func (r *ContainerListResponseExpiresAfter) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type ContainerNewParams struct {
// Name of the container to create.
Name string `json:"name,required"`
// Container expiration time in seconds relative to the 'anchor' time.
ExpiresAfter ContainerNewParamsExpiresAfter `json:"expires_after,omitzero"`
// IDs of files to copy to the container.
FileIDs []string `json:"file_ids,omitzero"`
paramObj
}
func (r ContainerNewParams) MarshalJSON() (data []byte, err error) {
type shadow ContainerNewParams
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ContainerNewParams) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Container expiration time in seconds relative to the 'anchor' time.
//
// The properties Anchor, Minutes are required.
type ContainerNewParamsExpiresAfter struct {
// Time anchor for the expiration time. Currently only 'last_active_at' is
// supported.
//
// Any of "last_active_at".
Anchor string `json:"anchor,omitzero,required"`
Minutes int64 `json:"minutes,required"`
paramObj
}
func (r ContainerNewParamsExpiresAfter) MarshalJSON() (data []byte, err error) {
type shadow ContainerNewParamsExpiresAfter
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ContainerNewParamsExpiresAfter) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
func init() {
apijson.RegisterFieldValidator[ContainerNewParamsExpiresAfter](
"anchor", "last_active_at",
)
}
type ContainerListParams struct {
// A cursor for use in pagination. `after` is an object ID that defines your place
// in the list. For instance, if you make a list request and receive 100 objects,
// ending with obj_foo, your subsequent call can include after=obj_foo in order to
// fetch the next page of the list.
After param.Opt[string] `query:"after,omitzero" json:"-"`
// A limit on the number of objects to be returned. Limit can range between 1 and
// 100, and the default is 20.
Limit param.Opt[int64] `query:"limit,omitzero" json:"-"`
// Sort order by the `created_at` timestamp of the objects. `asc` for ascending
// order and `desc` for descending order.
//
// Any of "asc", "desc".
Order ContainerListParamsOrder `query:"order,omitzero" json:"-"`
paramObj
}
// URLQuery serializes [ContainerListParams]'s query parameters as `url.Values`.
func (r ContainerListParams) URLQuery() (v url.Values, err error) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatBrackets,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
// Sort order by the `created_at` timestamp of the objects. `asc` for ascending
// order and `desc` for descending order.
type ContainerListParamsOrder string
const (
ContainerListParamsOrderAsc ContainerListParamsOrder = "asc"
ContainerListParamsOrderDesc ContainerListParamsOrder = "desc"
)