1// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
  2
  3package openai
  4
  5import (
  6	"context"
  7	"errors"
  8	"fmt"
  9	"net/http"
 10	"net/url"
 11
 12	"github.com/openai/openai-go/internal/apijson"
 13	"github.com/openai/openai-go/internal/apiquery"
 14	"github.com/openai/openai-go/internal/requestconfig"
 15	"github.com/openai/openai-go/option"
 16	"github.com/openai/openai-go/packages/pagination"
 17	"github.com/openai/openai-go/packages/param"
 18	"github.com/openai/openai-go/packages/respjson"
 19	"github.com/openai/openai-go/shared/constant"
 20)
 21
 22// FineTuningCheckpointPermissionService contains methods and other services that
 23// help with interacting with the openai API.
 24//
 25// Note, unlike clients, this service does not read variables from the environment
 26// automatically. You should not instantiate this service directly, and instead use
 27// the [NewFineTuningCheckpointPermissionService] method instead.
 28type FineTuningCheckpointPermissionService struct {
 29	Options []option.RequestOption
 30}
 31
 32// NewFineTuningCheckpointPermissionService generates a new service that applies
 33// the given options to each request. These options are applied after the parent
 34// client's options (if there is one), and before any request-specific options.
 35func NewFineTuningCheckpointPermissionService(opts ...option.RequestOption) (r FineTuningCheckpointPermissionService) {
 36	r = FineTuningCheckpointPermissionService{}
 37	r.Options = opts
 38	return
 39}
 40
 41// **NOTE:** Calling this endpoint requires an [admin API key](../admin-api-keys).
 42//
 43// This enables organization owners to share fine-tuned models with other projects
 44// in their organization.
 45func (r *FineTuningCheckpointPermissionService) New(ctx context.Context, fineTunedModelCheckpoint string, body FineTuningCheckpointPermissionNewParams, opts ...option.RequestOption) (res *pagination.Page[FineTuningCheckpointPermissionNewResponse], err error) {
 46	var raw *http.Response
 47	opts = append(r.Options[:], opts...)
 48	opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
 49	if fineTunedModelCheckpoint == "" {
 50		err = errors.New("missing required fine_tuned_model_checkpoint parameter")
 51		return
 52	}
 53	path := fmt.Sprintf("fine_tuning/checkpoints/%s/permissions", fineTunedModelCheckpoint)
 54	cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodPost, path, body, &res, opts...)
 55	if err != nil {
 56		return nil, err
 57	}
 58	err = cfg.Execute()
 59	if err != nil {
 60		return nil, err
 61	}
 62	res.SetPageConfig(cfg, raw)
 63	return res, nil
 64}
 65
 66// **NOTE:** Calling this endpoint requires an [admin API key](../admin-api-keys).
 67//
 68// This enables organization owners to share fine-tuned models with other projects
 69// in their organization.
 70func (r *FineTuningCheckpointPermissionService) NewAutoPaging(ctx context.Context, fineTunedModelCheckpoint string, body FineTuningCheckpointPermissionNewParams, opts ...option.RequestOption) *pagination.PageAutoPager[FineTuningCheckpointPermissionNewResponse] {
 71	return pagination.NewPageAutoPager(r.New(ctx, fineTunedModelCheckpoint, body, opts...))
 72}
 73
 74// **NOTE:** This endpoint requires an [admin API key](../admin-api-keys).
 75//
 76// Organization owners can use this endpoint to view all permissions for a
 77// fine-tuned model checkpoint.
 78func (r *FineTuningCheckpointPermissionService) Get(ctx context.Context, fineTunedModelCheckpoint string, query FineTuningCheckpointPermissionGetParams, opts ...option.RequestOption) (res *FineTuningCheckpointPermissionGetResponse, err error) {
 79	opts = append(r.Options[:], opts...)
 80	if fineTunedModelCheckpoint == "" {
 81		err = errors.New("missing required fine_tuned_model_checkpoint parameter")
 82		return
 83	}
 84	path := fmt.Sprintf("fine_tuning/checkpoints/%s/permissions", fineTunedModelCheckpoint)
 85	err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
 86	return
 87}
 88
 89// **NOTE:** This endpoint requires an [admin API key](../admin-api-keys).
 90//
 91// Organization owners can use this endpoint to delete a permission for a
 92// fine-tuned model checkpoint.
 93func (r *FineTuningCheckpointPermissionService) Delete(ctx context.Context, fineTunedModelCheckpoint string, permissionID string, opts ...option.RequestOption) (res *FineTuningCheckpointPermissionDeleteResponse, err error) {
 94	opts = append(r.Options[:], opts...)
 95	if fineTunedModelCheckpoint == "" {
 96		err = errors.New("missing required fine_tuned_model_checkpoint parameter")
 97		return
 98	}
 99	if permissionID == "" {
100		err = errors.New("missing required permission_id parameter")
101		return
102	}
103	path := fmt.Sprintf("fine_tuning/checkpoints/%s/permissions/%s", fineTunedModelCheckpoint, permissionID)
104	err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...)
105	return
106}
107
108// The `checkpoint.permission` object represents a permission for a fine-tuned
109// model checkpoint.
110type FineTuningCheckpointPermissionNewResponse struct {
111	// The permission identifier, which can be referenced in the API endpoints.
112	ID string `json:"id,required"`
113	// The Unix timestamp (in seconds) for when the permission was created.
114	CreatedAt int64 `json:"created_at,required"`
115	// The object type, which is always "checkpoint.permission".
116	Object constant.CheckpointPermission `json:"object,required"`
117	// The project identifier that the permission is for.
118	ProjectID string `json:"project_id,required"`
119	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
120	JSON struct {
121		ID          respjson.Field
122		CreatedAt   respjson.Field
123		Object      respjson.Field
124		ProjectID   respjson.Field
125		ExtraFields map[string]respjson.Field
126		raw         string
127	} `json:"-"`
128}
129
130// Returns the unmodified JSON received from the API
131func (r FineTuningCheckpointPermissionNewResponse) RawJSON() string { return r.JSON.raw }
132func (r *FineTuningCheckpointPermissionNewResponse) UnmarshalJSON(data []byte) error {
133	return apijson.UnmarshalRoot(data, r)
134}
135
136type FineTuningCheckpointPermissionGetResponse struct {
137	Data    []FineTuningCheckpointPermissionGetResponseData `json:"data,required"`
138	HasMore bool                                            `json:"has_more,required"`
139	Object  constant.List                                   `json:"object,required"`
140	FirstID string                                          `json:"first_id,nullable"`
141	LastID  string                                          `json:"last_id,nullable"`
142	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
143	JSON struct {
144		Data        respjson.Field
145		HasMore     respjson.Field
146		Object      respjson.Field
147		FirstID     respjson.Field
148		LastID      respjson.Field
149		ExtraFields map[string]respjson.Field
150		raw         string
151	} `json:"-"`
152}
153
154// Returns the unmodified JSON received from the API
155func (r FineTuningCheckpointPermissionGetResponse) RawJSON() string { return r.JSON.raw }
156func (r *FineTuningCheckpointPermissionGetResponse) UnmarshalJSON(data []byte) error {
157	return apijson.UnmarshalRoot(data, r)
158}
159
160// The `checkpoint.permission` object represents a permission for a fine-tuned
161// model checkpoint.
162type FineTuningCheckpointPermissionGetResponseData struct {
163	// The permission identifier, which can be referenced in the API endpoints.
164	ID string `json:"id,required"`
165	// The Unix timestamp (in seconds) for when the permission was created.
166	CreatedAt int64 `json:"created_at,required"`
167	// The object type, which is always "checkpoint.permission".
168	Object constant.CheckpointPermission `json:"object,required"`
169	// The project identifier that the permission is for.
170	ProjectID string `json:"project_id,required"`
171	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
172	JSON struct {
173		ID          respjson.Field
174		CreatedAt   respjson.Field
175		Object      respjson.Field
176		ProjectID   respjson.Field
177		ExtraFields map[string]respjson.Field
178		raw         string
179	} `json:"-"`
180}
181
182// Returns the unmodified JSON received from the API
183func (r FineTuningCheckpointPermissionGetResponseData) RawJSON() string { return r.JSON.raw }
184func (r *FineTuningCheckpointPermissionGetResponseData) UnmarshalJSON(data []byte) error {
185	return apijson.UnmarshalRoot(data, r)
186}
187
188type FineTuningCheckpointPermissionDeleteResponse struct {
189	// The ID of the fine-tuned model checkpoint permission that was deleted.
190	ID string `json:"id,required"`
191	// Whether the fine-tuned model checkpoint permission was successfully deleted.
192	Deleted bool `json:"deleted,required"`
193	// The object type, which is always "checkpoint.permission".
194	Object constant.CheckpointPermission `json:"object,required"`
195	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
196	JSON struct {
197		ID          respjson.Field
198		Deleted     respjson.Field
199		Object      respjson.Field
200		ExtraFields map[string]respjson.Field
201		raw         string
202	} `json:"-"`
203}
204
205// Returns the unmodified JSON received from the API
206func (r FineTuningCheckpointPermissionDeleteResponse) RawJSON() string { return r.JSON.raw }
207func (r *FineTuningCheckpointPermissionDeleteResponse) UnmarshalJSON(data []byte) error {
208	return apijson.UnmarshalRoot(data, r)
209}
210
211type FineTuningCheckpointPermissionNewParams struct {
212	// The project identifiers to grant access to.
213	ProjectIDs []string `json:"project_ids,omitzero,required"`
214	paramObj
215}
216
217func (r FineTuningCheckpointPermissionNewParams) MarshalJSON() (data []byte, err error) {
218	type shadow FineTuningCheckpointPermissionNewParams
219	return param.MarshalObject(r, (*shadow)(&r))
220}
221func (r *FineTuningCheckpointPermissionNewParams) UnmarshalJSON(data []byte) error {
222	return apijson.UnmarshalRoot(data, r)
223}
224
225type FineTuningCheckpointPermissionGetParams struct {
226	// Identifier for the last permission ID from the previous pagination request.
227	After param.Opt[string] `query:"after,omitzero" json:"-"`
228	// Number of permissions to retrieve.
229	Limit param.Opt[int64] `query:"limit,omitzero" json:"-"`
230	// The ID of the project to get permissions for.
231	ProjectID param.Opt[string] `query:"project_id,omitzero" json:"-"`
232	// The order in which to retrieve permissions.
233	//
234	// Any of "ascending", "descending".
235	Order FineTuningCheckpointPermissionGetParamsOrder `query:"order,omitzero" json:"-"`
236	paramObj
237}
238
239// URLQuery serializes [FineTuningCheckpointPermissionGetParams]'s query parameters
240// as `url.Values`.
241func (r FineTuningCheckpointPermissionGetParams) URLQuery() (v url.Values, err error) {
242	return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
243		ArrayFormat:  apiquery.ArrayQueryFormatBrackets,
244		NestedFormat: apiquery.NestedQueryFormatBrackets,
245	})
246}
247
248// The order in which to retrieve permissions.
249type FineTuningCheckpointPermissionGetParamsOrder string
250
251const (
252	FineTuningCheckpointPermissionGetParamsOrderAscending  FineTuningCheckpointPermissionGetParamsOrder = "ascending"
253	FineTuningCheckpointPermissionGetParamsOrderDescending FineTuningCheckpointPermissionGetParamsOrder = "descending"
254)