feat(api): add container endpoint

This commit is contained in:
stainless-app[bot]
2025-05-21 18:37:05 +00:00
parent e7e2123de7
commit 2bd777d681
12 changed files with 1428 additions and 238 deletions

View File

@@ -1,4 +1,4 @@
configured_endpoints: 87
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-a5651cb97f86d1e2531af6aef8c5230f1ea350560fbae790ca2e481b30a6c217.yml
openapi_spec_hash: 66a5104fd3bb43383cf919225df7a6fd
config_hash: bb657c3fed232a56930035de3aaed936
configured_endpoints: 97
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-6af14840a810139bf407013167ce1c8fb21b6ef8eb0cc3db58b51af7d52c4b5a.yml
openapi_spec_hash: 3241bde6b273cfec0035e522bd07985d
config_hash: 7367b68a4e7db36885c1a886f57b17f6

37
api.md
View File

@@ -702,6 +702,7 @@ Methods:
- <code title="post /responses">client.Responses.<a href="https://pkg.go.dev/github.com/openai/openai-go/responses#ResponseService.New">New</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, body <a href="https://pkg.go.dev/github.com/openai/openai-go/responses">responses</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go/responses#ResponseNewParams">ResponseNewParams</a>) (<a href="https://pkg.go.dev/github.com/openai/openai-go/responses">responses</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go/responses#Response">Response</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
- <code title="get /responses/{response_id}">client.Responses.<a href="https://pkg.go.dev/github.com/openai/openai-go/responses#ResponseService.Get">Get</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, responseID <a href="https://pkg.go.dev/builtin#string">string</a>, query <a href="https://pkg.go.dev/github.com/openai/openai-go/responses">responses</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go/responses#ResponseGetParams">ResponseGetParams</a>) (<a href="https://pkg.go.dev/github.com/openai/openai-go/responses">responses</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go/responses#Response">Response</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
- <code title="delete /responses/{response_id}">client.Responses.<a href="https://pkg.go.dev/github.com/openai/openai-go/responses#ResponseService.Delete">Delete</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, responseID <a href="https://pkg.go.dev/builtin#string">string</a>) <a href="https://pkg.go.dev/builtin#error">error</a></code>
- <code title="post /responses/{response_id}/cancel">client.Responses.<a href="https://pkg.go.dev/github.com/openai/openai-go/responses#ResponseService.Cancel">Cancel</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, responseID <a href="https://pkg.go.dev/builtin#string">string</a>) <a href="https://pkg.go.dev/builtin#error">error</a></code>
## InputItems
@@ -712,3 +713,39 @@ Response Types:
Methods:
- <code title="get /responses/{response_id}/input_items">client.Responses.InputItems.<a href="https://pkg.go.dev/github.com/openai/openai-go/responses#InputItemService.List">List</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, responseID <a href="https://pkg.go.dev/builtin#string">string</a>, query <a href="https://pkg.go.dev/github.com/openai/openai-go/responses">responses</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go/responses#InputItemListParams">InputItemListParams</a>) (<a href="https://pkg.go.dev/github.com/openai/openai-go/packages/pagination">pagination</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go/packages/pagination#CursorPage">CursorPage</a>[<a href="https://pkg.go.dev/github.com/openai/openai-go/responses">responses</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go/responses#ResponseItemUnion">ResponseItemUnion</a>], <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
# Containers
Response Types:
- <a href="https://pkg.go.dev/github.com/openai/openai-go">openai</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go#ContainerNewResponse">ContainerNewResponse</a>
- <a href="https://pkg.go.dev/github.com/openai/openai-go">openai</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go#ContainerGetResponse">ContainerGetResponse</a>
- <a href="https://pkg.go.dev/github.com/openai/openai-go">openai</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go#ContainerListResponse">ContainerListResponse</a>
Methods:
- <code title="post /containers">client.Containers.<a href="https://pkg.go.dev/github.com/openai/openai-go#ContainerService.New">New</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, body <a href="https://pkg.go.dev/github.com/openai/openai-go">openai</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go#ContainerNewParams">ContainerNewParams</a>) (<a href="https://pkg.go.dev/github.com/openai/openai-go">openai</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go#ContainerNewResponse">ContainerNewResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
- <code title="get /containers/{container_id}">client.Containers.<a href="https://pkg.go.dev/github.com/openai/openai-go#ContainerService.Get">Get</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, containerID <a href="https://pkg.go.dev/builtin#string">string</a>) (<a href="https://pkg.go.dev/github.com/openai/openai-go">openai</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go#ContainerGetResponse">ContainerGetResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
- <code title="get /containers">client.Containers.<a href="https://pkg.go.dev/github.com/openai/openai-go#ContainerService.List">List</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, query <a href="https://pkg.go.dev/github.com/openai/openai-go">openai</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go#ContainerListParams">ContainerListParams</a>) (<a href="https://pkg.go.dev/github.com/openai/openai-go/packages/pagination">pagination</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go/packages/pagination#CursorPage">CursorPage</a>[<a href="https://pkg.go.dev/github.com/openai/openai-go">openai</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go#ContainerListResponse">ContainerListResponse</a>], <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
- <code title="delete /containers/{container_id}">client.Containers.<a href="https://pkg.go.dev/github.com/openai/openai-go#ContainerService.Delete">Delete</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, containerID <a href="https://pkg.go.dev/builtin#string">string</a>) <a href="https://pkg.go.dev/builtin#error">error</a></code>
## Files
Response Types:
- <a href="https://pkg.go.dev/github.com/openai/openai-go">openai</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go#ContainerFileNewResponse">ContainerFileNewResponse</a>
- <a href="https://pkg.go.dev/github.com/openai/openai-go">openai</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go#ContainerFileGetResponse">ContainerFileGetResponse</a>
- <a href="https://pkg.go.dev/github.com/openai/openai-go">openai</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go#ContainerFileListResponse">ContainerFileListResponse</a>
Methods:
- <code title="post /containers/{container_id}/files">client.Containers.Files.<a href="https://pkg.go.dev/github.com/openai/openai-go#ContainerFileService.New">New</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, containerID <a href="https://pkg.go.dev/builtin#string">string</a>, body <a href="https://pkg.go.dev/github.com/openai/openai-go">openai</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go#ContainerFileNewParams">ContainerFileNewParams</a>) (<a href="https://pkg.go.dev/github.com/openai/openai-go">openai</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go#ContainerFileNewResponse">ContainerFileNewResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
- <code title="get /containers/{container_id}/files/{file_id}">client.Containers.Files.<a href="https://pkg.go.dev/github.com/openai/openai-go#ContainerFileService.Get">Get</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, containerID <a href="https://pkg.go.dev/builtin#string">string</a>, fileID <a href="https://pkg.go.dev/builtin#string">string</a>) (<a href="https://pkg.go.dev/github.com/openai/openai-go">openai</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go#ContainerFileGetResponse">ContainerFileGetResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
- <code title="get /containers/{container_id}/files">client.Containers.Files.<a href="https://pkg.go.dev/github.com/openai/openai-go#ContainerFileService.List">List</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, containerID <a href="https://pkg.go.dev/builtin#string">string</a>, query <a href="https://pkg.go.dev/github.com/openai/openai-go">openai</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go#ContainerFileListParams">ContainerFileListParams</a>) (<a href="https://pkg.go.dev/github.com/openai/openai-go/packages/pagination">pagination</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go/packages/pagination#CursorPage">CursorPage</a>[<a href="https://pkg.go.dev/github.com/openai/openai-go">openai</a>.<a href="https://pkg.go.dev/github.com/openai/openai-go#ContainerFileListResponse">ContainerFileListResponse</a>], <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
- <code title="delete /containers/{container_id}/files/{file_id}">client.Containers.Files.<a href="https://pkg.go.dev/github.com/openai/openai-go#ContainerFileService.Delete">Delete</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, containerID <a href="https://pkg.go.dev/builtin#string">string</a>, fileID <a href="https://pkg.go.dev/builtin#string">string</a>) <a href="https://pkg.go.dev/builtin#error">error</a></code>
### Content
Methods:
- <code title="get /containers/{container_id}/files/{file_id}/content">client.Containers.Files.Content.<a href="https://pkg.go.dev/github.com/openai/openai-go#ContainerFileContentService.Get">Get</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, containerID <a href="https://pkg.go.dev/builtin#string">string</a>, fileID <a href="https://pkg.go.dev/builtin#string">string</a>) <a href="https://pkg.go.dev/builtin#error">error</a></code>

View File

@@ -32,6 +32,7 @@ type Client struct {
Batches BatchService
Uploads UploadService
Responses responses.ResponseService
Containers ContainerService
}
// DefaultClientOptions read from the environment (OPENAI_API_KEY, OPENAI_ORG_ID,
@@ -79,6 +80,7 @@ func NewClient(opts ...option.RequestOption) (r Client) {
r.Batches = NewBatchService(opts...)
r.Uploads = NewUploadService(opts...)
r.Responses = responses.NewResponseService(opts...)
r.Containers = NewContainerService(opts...)
return
}

352
container.go Normal file
View File

@@ -0,0 +1,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"
)

113
container_test.go Normal file
View File

@@ -0,0 +1,113 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package openai_test
import (
"context"
"errors"
"os"
"testing"
"github.com/openai/openai-go"
"github.com/openai/openai-go/internal/testutil"
"github.com/openai/openai-go/option"
)
func TestContainerNewWithOptionalParams(t *testing.T) {
baseURL := "http://localhost:4010"
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
baseURL = envURL
}
if !testutil.CheckTestServer(t, baseURL) {
return
}
client := openai.NewClient(
option.WithBaseURL(baseURL),
option.WithAPIKey("My API Key"),
)
_, err := client.Containers.New(context.TODO(), openai.ContainerNewParams{
Name: "name",
ExpiresAfter: openai.ContainerNewParamsExpiresAfter{
Anchor: "last_active_at",
Minutes: 0,
},
FileIDs: []string{"string"},
})
if err != nil {
var apierr *openai.Error
if errors.As(err, &apierr) {
t.Log(string(apierr.DumpRequest(true)))
}
t.Fatalf("err should be nil: %s", err.Error())
}
}
func TestContainerGet(t *testing.T) {
baseURL := "http://localhost:4010"
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
baseURL = envURL
}
if !testutil.CheckTestServer(t, baseURL) {
return
}
client := openai.NewClient(
option.WithBaseURL(baseURL),
option.WithAPIKey("My API Key"),
)
_, err := client.Containers.Get(context.TODO(), "container_id")
if err != nil {
var apierr *openai.Error
if errors.As(err, &apierr) {
t.Log(string(apierr.DumpRequest(true)))
}
t.Fatalf("err should be nil: %s", err.Error())
}
}
func TestContainerListWithOptionalParams(t *testing.T) {
baseURL := "http://localhost:4010"
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
baseURL = envURL
}
if !testutil.CheckTestServer(t, baseURL) {
return
}
client := openai.NewClient(
option.WithBaseURL(baseURL),
option.WithAPIKey("My API Key"),
)
_, err := client.Containers.List(context.TODO(), openai.ContainerListParams{
After: openai.String("after"),
Limit: openai.Int(0),
Order: openai.ContainerListParamsOrderAsc,
})
if err != nil {
var apierr *openai.Error
if errors.As(err, &apierr) {
t.Log(string(apierr.DumpRequest(true)))
}
t.Fatalf("err should be nil: %s", err.Error())
}
}
func TestContainerDelete(t *testing.T) {
baseURL := "http://localhost:4010"
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
baseURL = envURL
}
if !testutil.CheckTestServer(t, baseURL) {
return
}
client := openai.NewClient(
option.WithBaseURL(baseURL),
option.WithAPIKey("My API Key"),
)
err := client.Containers.Delete(context.TODO(), "container_id")
if err != nil {
var apierr *openai.Error
if errors.As(err, &apierr) {
t.Log(string(apierr.DumpRequest(true)))
}
t.Fatalf("err should be nil: %s", err.Error())
}
}

286
containerfile.go Normal file
View File

@@ -0,0 +1,286 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package openai
import (
"bytes"
"context"
"errors"
"fmt"
"io"
"mime/multipart"
"net/http"
"net/url"
"github.com/openai/openai-go/internal/apiform"
"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"
"github.com/openai/openai-go/shared/constant"
)
// ContainerFileService 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 [NewContainerFileService] method instead.
type ContainerFileService struct {
Options []option.RequestOption
Content ContainerFileContentService
}
// NewContainerFileService 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 NewContainerFileService(opts ...option.RequestOption) (r ContainerFileService) {
r = ContainerFileService{}
r.Options = opts
r.Content = NewContainerFileContentService(opts...)
return
}
// Create a Container File
//
// You can send either a multipart/form-data request with the raw file content, or
// a JSON request with a file ID.
func (r *ContainerFileService) New(ctx context.Context, containerID string, body ContainerFileNewParams, opts ...option.RequestOption) (res *ContainerFileNewResponse, err error) {
opts = append(r.Options[:], opts...)
if containerID == "" {
err = errors.New("missing required container_id parameter")
return
}
path := fmt.Sprintf("containers/%s/files", containerID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// Retrieve Container File
func (r *ContainerFileService) Get(ctx context.Context, containerID string, fileID string, opts ...option.RequestOption) (res *ContainerFileGetResponse, err error) {
opts = append(r.Options[:], opts...)
if containerID == "" {
err = errors.New("missing required container_id parameter")
return
}
if fileID == "" {
err = errors.New("missing required file_id parameter")
return
}
path := fmt.Sprintf("containers/%s/files/%s", containerID, fileID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// List Container files
func (r *ContainerFileService) List(ctx context.Context, containerID string, query ContainerFileListParams, opts ...option.RequestOption) (res *pagination.CursorPage[ContainerFileListResponse], err error) {
var raw *http.Response
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
if containerID == "" {
err = errors.New("missing required container_id parameter")
return
}
path := fmt.Sprintf("containers/%s/files", containerID)
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 Container files
func (r *ContainerFileService) ListAutoPaging(ctx context.Context, containerID string, query ContainerFileListParams, opts ...option.RequestOption) *pagination.CursorPageAutoPager[ContainerFileListResponse] {
return pagination.NewCursorPageAutoPager(r.List(ctx, containerID, query, opts...))
}
// Delete Container File
func (r *ContainerFileService) Delete(ctx context.Context, containerID string, fileID 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
}
if fileID == "" {
err = errors.New("missing required file_id parameter")
return
}
path := fmt.Sprintf("containers/%s/files/%s", containerID, fileID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, nil, opts...)
return
}
type ContainerFileNewResponse struct {
// Unique identifier for the file.
ID string `json:"id,required"`
// Size of the file in bytes.
Bytes int64 `json:"bytes,required"`
// The container this file belongs to.
ContainerID string `json:"container_id,required"`
// Unix timestamp (in seconds) when the file was created.
CreatedAt int64 `json:"created_at,required"`
// The type of this object (`container.file`).
Object constant.ContainerFile `json:"object,required"`
// Path of the file in the container.
Path string `json:"path,required"`
// Source of the file (e.g., `user`, `assistant`).
Source string `json:"source,required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
Bytes respjson.Field
ContainerID respjson.Field
CreatedAt respjson.Field
Object respjson.Field
Path respjson.Field
Source respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ContainerFileNewResponse) RawJSON() string { return r.JSON.raw }
func (r *ContainerFileNewResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type ContainerFileGetResponse struct {
// Unique identifier for the file.
ID string `json:"id,required"`
// Size of the file in bytes.
Bytes int64 `json:"bytes,required"`
// The container this file belongs to.
ContainerID string `json:"container_id,required"`
// Unix timestamp (in seconds) when the file was created.
CreatedAt int64 `json:"created_at,required"`
// The type of this object (`container.file`).
Object constant.ContainerFile `json:"object,required"`
// Path of the file in the container.
Path string `json:"path,required"`
// Source of the file (e.g., `user`, `assistant`).
Source string `json:"source,required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
Bytes respjson.Field
ContainerID respjson.Field
CreatedAt respjson.Field
Object respjson.Field
Path respjson.Field
Source respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ContainerFileGetResponse) RawJSON() string { return r.JSON.raw }
func (r *ContainerFileGetResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type ContainerFileListResponse struct {
// Unique identifier for the file.
ID string `json:"id,required"`
// Size of the file in bytes.
Bytes int64 `json:"bytes,required"`
// The container this file belongs to.
ContainerID string `json:"container_id,required"`
// Unix timestamp (in seconds) when the file was created.
CreatedAt int64 `json:"created_at,required"`
// The type of this object (`container.file`).
Object constant.ContainerFile `json:"object,required"`
// Path of the file in the container.
Path string `json:"path,required"`
// Source of the file (e.g., `user`, `assistant`).
Source string `json:"source,required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
Bytes respjson.Field
ContainerID respjson.Field
CreatedAt respjson.Field
Object respjson.Field
Path respjson.Field
Source respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ContainerFileListResponse) RawJSON() string { return r.JSON.raw }
func (r *ContainerFileListResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type ContainerFileNewParams struct {
// Name of the file to create.
FileID param.Opt[string] `json:"file_id,omitzero"`
// The File object (not file name) to be uploaded.
File io.Reader `json:"file,omitzero" format:"binary"`
paramObj
}
func (r ContainerFileNewParams) MarshalMultipart() (data []byte, contentType string, err error) {
buf := bytes.NewBuffer(nil)
writer := multipart.NewWriter(buf)
err = apiform.MarshalRoot(r, writer)
if err == nil {
err = apiform.WriteExtras(writer, r.ExtraFields())
}
if err != nil {
writer.Close()
return nil, "", err
}
err = writer.Close()
if err != nil {
return nil, "", err
}
return buf.Bytes(), writer.FormDataContentType(), nil
}
type ContainerFileListParams 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 ContainerFileListParamsOrder `query:"order,omitzero" json:"-"`
paramObj
}
// URLQuery serializes [ContainerFileListParams]'s query parameters as
// `url.Values`.
func (r ContainerFileListParams) 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 ContainerFileListParamsOrder string
const (
ContainerFileListParamsOrderAsc ContainerFileListParamsOrder = "asc"
ContainerFileListParamsOrderDesc ContainerFileListParamsOrder = "desc"
)

127
containerfile_test.go Normal file
View File

@@ -0,0 +1,127 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package openai_test
import (
"bytes"
"context"
"errors"
"io"
"os"
"testing"
"github.com/openai/openai-go"
"github.com/openai/openai-go/internal/testutil"
"github.com/openai/openai-go/option"
)
func TestContainerFileNewWithOptionalParams(t *testing.T) {
baseURL := "http://localhost:4010"
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
baseURL = envURL
}
if !testutil.CheckTestServer(t, baseURL) {
return
}
client := openai.NewClient(
option.WithBaseURL(baseURL),
option.WithAPIKey("My API Key"),
)
_, err := client.Containers.Files.New(
context.TODO(),
"container_id",
openai.ContainerFileNewParams{
File: io.Reader(bytes.NewBuffer([]byte("some file contents"))),
FileID: openai.String("file_id"),
},
)
if err != nil {
var apierr *openai.Error
if errors.As(err, &apierr) {
t.Log(string(apierr.DumpRequest(true)))
}
t.Fatalf("err should be nil: %s", err.Error())
}
}
func TestContainerFileGet(t *testing.T) {
baseURL := "http://localhost:4010"
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
baseURL = envURL
}
if !testutil.CheckTestServer(t, baseURL) {
return
}
client := openai.NewClient(
option.WithBaseURL(baseURL),
option.WithAPIKey("My API Key"),
)
_, err := client.Containers.Files.Get(
context.TODO(),
"container_id",
"file_id",
)
if err != nil {
var apierr *openai.Error
if errors.As(err, &apierr) {
t.Log(string(apierr.DumpRequest(true)))
}
t.Fatalf("err should be nil: %s", err.Error())
}
}
func TestContainerFileListWithOptionalParams(t *testing.T) {
baseURL := "http://localhost:4010"
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
baseURL = envURL
}
if !testutil.CheckTestServer(t, baseURL) {
return
}
client := openai.NewClient(
option.WithBaseURL(baseURL),
option.WithAPIKey("My API Key"),
)
_, err := client.Containers.Files.List(
context.TODO(),
"container_id",
openai.ContainerFileListParams{
After: openai.String("after"),
Limit: openai.Int(0),
Order: openai.ContainerFileListParamsOrderAsc,
},
)
if err != nil {
var apierr *openai.Error
if errors.As(err, &apierr) {
t.Log(string(apierr.DumpRequest(true)))
}
t.Fatalf("err should be nil: %s", err.Error())
}
}
func TestContainerFileDelete(t *testing.T) {
baseURL := "http://localhost:4010"
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
baseURL = envURL
}
if !testutil.CheckTestServer(t, baseURL) {
return
}
client := openai.NewClient(
option.WithBaseURL(baseURL),
option.WithAPIKey("My API Key"),
)
err := client.Containers.Files.Delete(
context.TODO(),
"container_id",
"file_id",
)
if err != nil {
var apierr *openai.Error
if errors.As(err, &apierr) {
t.Log(string(apierr.DumpRequest(true)))
}
t.Fatalf("err should be nil: %s", err.Error())
}
}

49
containerfilecontent.go Normal file
View File

@@ -0,0 +1,49 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package openai
import (
"context"
"errors"
"fmt"
"net/http"
"github.com/openai/openai-go/internal/requestconfig"
"github.com/openai/openai-go/option"
)
// ContainerFileContentService 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 [NewContainerFileContentService] method instead.
type ContainerFileContentService struct {
Options []option.RequestOption
}
// NewContainerFileContentService 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 NewContainerFileContentService(opts ...option.RequestOption) (r ContainerFileContentService) {
r = ContainerFileContentService{}
r.Options = opts
return
}
// Retrieve Container File Content
func (r *ContainerFileContentService) Get(ctx context.Context, containerID string, fileID 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
}
if fileID == "" {
err = errors.New("missing required file_id parameter")
return
}
path := fmt.Sprintf("containers/%s/files/%s/content", containerID, fileID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, nil, opts...)
return
}

View File

@@ -0,0 +1,40 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package openai_test
import (
"context"
"errors"
"os"
"testing"
"github.com/openai/openai-go"
"github.com/openai/openai-go/internal/testutil"
"github.com/openai/openai-go/option"
)
func TestContainerFileContentGet(t *testing.T) {
baseURL := "http://localhost:4010"
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
baseURL = envURL
}
if !testutil.CheckTestServer(t, baseURL) {
return
}
client := openai.NewClient(
option.WithBaseURL(baseURL),
option.WithAPIKey("My API Key"),
)
err := client.Containers.Files.Content.Get(
context.TODO(),
"container_id",
"file_id",
)
if err != nil {
var apierr *openai.Error
if errors.As(err, &apierr) {
t.Log(string(apierr.DumpRequest(true)))
}
t.Fatalf("err should be nil: %s", err.Error())
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -129,3 +129,25 @@ func TestResponseDelete(t *testing.T) {
t.Fatalf("err should be nil: %s", err.Error())
}
}
func TestResponseCancel(t *testing.T) {
baseURL := "http://localhost:4010"
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
baseURL = envURL
}
if !testutil.CheckTestServer(t, baseURL) {
return
}
client := openai.NewClient(
option.WithBaseURL(baseURL),
option.WithAPIKey("My API Key"),
)
err := client.Responses.Cancel(context.TODO(), "resp_677efb5139a88190b512bc3fef8e535d")
if err != nil {
var apierr *openai.Error
if errors.As(err, &apierr) {
t.Log(string(apierr.DumpRequest(true)))
}
t.Fatalf("err should be nil: %s", err.Error())
}
}

View File

@@ -33,6 +33,7 @@ type CodeInterpreterCall string // Always "code_interpreter_
type ComputerCallOutput string // Always "computer_call_output"
type ComputerScreenshot string // Always "computer_screenshot"
type ComputerUsePreview string // Always "computer_use_preview"
type ContainerFile string // Always "container.file"
type Content string // Always "content"
type Developer string // Always "developer"
type DoubleClick string // Always "double_click"
@@ -216,6 +217,7 @@ func (c CodeInterpreterCall) Default() CodeInterpreterCall { return "code_in
func (c ComputerCallOutput) Default() ComputerCallOutput { return "computer_call_output" }
func (c ComputerScreenshot) Default() ComputerScreenshot { return "computer_screenshot" }
func (c ComputerUsePreview) Default() ComputerUsePreview { return "computer_use_preview" }
func (c ContainerFile) Default() ContainerFile { return "container.file" }
func (c Content) Default() Content { return "content" }
func (c Developer) Default() Developer { return "developer" }
func (c DoubleClick) Default() DoubleClick { return "double_click" }
@@ -489,6 +491,7 @@ func (c CodeInterpreterCall) MarshalJSON() ([]byte, error) { r
func (c ComputerCallOutput) MarshalJSON() ([]byte, error) { return marshalString(c) }
func (c ComputerScreenshot) MarshalJSON() ([]byte, error) { return marshalString(c) }
func (c ComputerUsePreview) MarshalJSON() ([]byte, error) { return marshalString(c) }
func (c ContainerFile) MarshalJSON() ([]byte, error) { return marshalString(c) }
func (c Content) MarshalJSON() ([]byte, error) { return marshalString(c) }
func (c Developer) MarshalJSON() ([]byte, error) { return marshalString(c) }
func (c DoubleClick) MarshalJSON() ([]byte, error) { return marshalString(c) }