Repository navigation
Expand file tree
/
Copy pathadminorganizationprojectratelimit.go
More file actions
175 lines (161 loc) · 8.24 KB
/
Copy pathadminorganizationprojectratelimit.go
File metadata and controls
175 lines (161 loc) · 8.24 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
// File generated from our OpenAPI spec by Castiron. See CONTRIBUTING.md for details.
package openai
import (
"context"
"errors"
"net/http"
"net/url"
"slices"
"github.com/openai/openai-go/v3/internal/apijson"
"github.com/openai/openai-go/v3/internal/apiquery"
"github.com/openai/openai-go/v3/internal/requestconfig"
"github.com/openai/openai-go/v3/option"
"github.com/openai/openai-go/v3/packages/pagination"
"github.com/openai/openai-go/v3/packages/param"
"github.com/openai/openai-go/v3/packages/respjson"
"github.com/openai/openai-go/v3/shared/constant"
)
// AdminOrganizationProjectRateLimitService 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 [NewAdminOrganizationProjectRateLimitService] method instead.
type AdminOrganizationProjectRateLimitService struct {
Options []option.RequestOption
}
// NewAdminOrganizationProjectRateLimitService 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 NewAdminOrganizationProjectRateLimitService(opts ...option.RequestOption) (r AdminOrganizationProjectRateLimitService) {
r = AdminOrganizationProjectRateLimitService{}
r.Options = requestconfig.InheritedOptions(opts...)
return
}
// Returns the rate limits per model for a project.
func (r *AdminOrganizationProjectRateLimitService) ListRateLimits(ctx context.Context, projectID string, query AdminOrganizationProjectRateLimitListRateLimitsParams, opts ...option.RequestOption) (res *pagination.ConversationCursorPage[ProjectRateLimit], err error) {
var raw *http.Response
var preClientOpts = []option.RequestOption{requestconfig.WithAdminAPIKeyAuthSecurity()}
opts = slices.Concat(preClientOpts, r.Options, opts)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
if projectID == "" {
err = errors.New("missing required project_id parameter")
return nil, err
}
path := requestconfig.FormatPath("organization/projects/%s/rate_limits", projectID)
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
}
// Returns the rate limits per model for a project.
func (r *AdminOrganizationProjectRateLimitService) ListRateLimitsAutoPaging(ctx context.Context, projectID string, query AdminOrganizationProjectRateLimitListRateLimitsParams, opts ...option.RequestOption) *pagination.ConversationCursorPageAutoPager[ProjectRateLimit] {
return pagination.NewConversationCursorPageAutoPager(r.ListRateLimits(ctx, projectID, query, opts...))
}
// Updates a project rate limit.
func (r *AdminOrganizationProjectRateLimitService) UpdateRateLimit(ctx context.Context, projectID string, rateLimitID string, body AdminOrganizationProjectRateLimitUpdateRateLimitParams, opts ...option.RequestOption) (res *ProjectRateLimit, err error) {
var preClientOpts = []option.RequestOption{requestconfig.WithAdminAPIKeyAuthSecurity()}
opts = slices.Concat(preClientOpts, r.Options, opts)
if projectID == "" {
err = errors.New("missing required project_id parameter")
return nil, err
}
if rateLimitID == "" {
err = errors.New("missing required rate_limit_id parameter")
return nil, err
}
path := requestconfig.FormatPath("organization/projects/%s/rate_limits/%s", projectID, rateLimitID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return res, err
}
// Represents a project rate limit config.
type ProjectRateLimit struct {
// The identifier, which can be referenced in API endpoints.
ID string `json:"id" api:"required"`
// The maximum requests per minute.
MaxRequestsPer1Minute int64 `json:"max_requests_per_1_minute" api:"required"`
// The maximum tokens per minute.
MaxTokensPer1Minute int64 `json:"max_tokens_per_1_minute" api:"required"`
// The model this rate limit applies to.
Model string `json:"model" api:"required"`
// The object type, which is always `project.rate_limit`
Object constant.ProjectRateLimit `json:"object" default:"project.rate_limit"`
// The maximum batch input tokens per day. Only present for relevant models.
Batch1DayMaxInputTokens int64 `json:"batch_1_day_max_input_tokens"`
// The maximum audio megabytes per minute. Only present for relevant models.
MaxAudioMegabytesPer1Minute int64 `json:"max_audio_megabytes_per_1_minute"`
// The maximum images per minute. Only present for relevant models.
MaxImagesPer1Minute int64 `json:"max_images_per_1_minute"`
// The maximum requests per day. Only present for relevant models.
MaxRequestsPer1Day int64 `json:"max_requests_per_1_day"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
MaxRequestsPer1Minute respjson.Field
MaxTokensPer1Minute respjson.Field
Model respjson.Field
Object respjson.Field
Batch1DayMaxInputTokens respjson.Field
MaxAudioMegabytesPer1Minute respjson.Field
MaxImagesPer1Minute respjson.Field
MaxRequestsPer1Day respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ProjectRateLimit) RawJSON() string { return r.JSON.raw }
func (r *ProjectRateLimit) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type AdminOrganizationProjectRateLimitListRateLimitsParams 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 cursor for use in pagination. `before` is an object ID that defines your place
// in the list. For instance, if you make a list request and receive 100 objects,
// beginning with obj_foo, your subsequent call can include before=obj_foo in order
// to fetch the previous page of the list.
Before param.Opt[string] `query:"before,omitzero" json:"-"`
// A limit on the number of objects to be returned. The default is 100.
Limit param.Opt[int64] `query:"limit,omitzero" json:"-"`
paramObj
}
// URLQuery serializes [AdminOrganizationProjectRateLimitListRateLimitsParams]'s
// query parameters as `url.Values`.
func (r AdminOrganizationProjectRateLimitListRateLimitsParams) URLQuery() (v url.Values, err error) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatBrackets,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
type AdminOrganizationProjectRateLimitUpdateRateLimitParams struct {
// The maximum batch input tokens per day. Only relevant for certain models.
Batch1DayMaxInputTokens param.Opt[int64] `json:"batch_1_day_max_input_tokens,omitzero"`
// The maximum audio megabytes per minute. Only relevant for certain models.
MaxAudioMegabytesPer1Minute param.Opt[int64] `json:"max_audio_megabytes_per_1_minute,omitzero"`
// The maximum images per minute. Only relevant for certain models.
MaxImagesPer1Minute param.Opt[int64] `json:"max_images_per_1_minute,omitzero"`
// The maximum requests per day. Only relevant for certain models.
MaxRequestsPer1Day param.Opt[int64] `json:"max_requests_per_1_day,omitzero"`
// The maximum requests per minute.
MaxRequestsPer1Minute param.Opt[int64] `json:"max_requests_per_1_minute,omitzero"`
// The maximum tokens per minute.
MaxTokensPer1Minute param.Opt[int64] `json:"max_tokens_per_1_minute,omitzero"`
paramObj
}
func (r AdminOrganizationProjectRateLimitUpdateRateLimitParams) MarshalJSON() (data []byte, err error) {
type shadow AdminOrganizationProjectRateLimitUpdateRateLimitParams
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *AdminOrganizationProjectRateLimitUpdateRateLimitParams) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}