diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 2437b419..bf0d0361 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "3.4.0" + ".": "3.5.0" } \ No newline at end of file diff --git a/.stats.yml b/.stats.yml index 02a20698..c3727615 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ -configured_endpoints: 123 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-104cced8f4c7436a76eea02e26307828166405ccfb296faffb008b72772c11a7.yml -openapi_spec_hash: fdc03ed84a65a31b80da909255e53924 -config_hash: 03b48e9b8c7231a902403210dbd7dfa0 +configured_endpoints: 122 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-f59befea071ed7729cbb7bce219e7f837eccfdb57e01698514e6a0bd6052ff60.yml +openapi_spec_hash: 49da48619d37932b2e257c532078b2bb +config_hash: 1af83449a09a3b4f276444dbcdd3eb67 diff --git a/CHANGELOG.md b/CHANGELOG.md index 7069999f..01f31201 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 3.5.0 (2025-10-17) + +Full Changelog: [v3.4.0...v3.5.0](https://github.com/openai/openai-go/compare/v3.4.0...v3.5.0) + +### Features + +* **api:** api update ([1aa78dd](https://github.com/openai/openai-go/commit/1aa78dda7aae7b72ce021250b5357ead8db36f46)) + ## 3.4.0 (2025-10-16) Full Changelog: [v3.3.0...v3.4.0](https://github.com/openai/openai-go/compare/v3.3.0...v3.4.0) diff --git a/README.md b/README.md index 214140f7..33cfaae2 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ Or to pin the version: ```sh -go get -u 'github.com/openai/openai-go/v2@v3.4.0' +go get -u 'github.com/openai/openai-go/v2@v3.5.0' ``` diff --git a/api.md b/api.md index 636d89b2..afcb87fd 100644 --- a/api.md +++ b/api.md @@ -441,13 +441,6 @@ Methods: Response Types: - openai.ChatKitWorkflow -- openai.FilePart -- openai.ImagePart -- openai.BetaChatKitUploadFileResponseUnion - -Methods: - -- client.Beta.ChatKit.UploadFile(ctx context.Context, body openai.BetaChatKitUploadFileParams) (openai.BetaChatKitUploadFileResponseUnion, error) ### Sessions diff --git a/betachatkit.go b/betachatkit.go index 4a0aa830..4ff2242f 100644 --- a/betachatkit.go +++ b/betachatkit.go @@ -3,20 +3,11 @@ package openai import ( - "bytes" - "context" "encoding/json" - "io" - "mime/multipart" - "net/http" - "slices" - "github.com/openai/openai-go/v3/internal/apiform" "github.com/openai/openai-go/v3/internal/apijson" - "github.com/openai/openai-go/v3/internal/requestconfig" "github.com/openai/openai-go/v3/option" "github.com/openai/openai-go/v3/packages/respjson" - "github.com/openai/openai-go/v3/shared/constant" ) // BetaChatKitService contains methods and other services that help with @@ -42,15 +33,6 @@ func NewBetaChatKitService(opts ...option.RequestOption) (r BetaChatKitService) return } -// Upload a ChatKit file -func (r *BetaChatKitService) UploadFile(ctx context.Context, body BetaChatKitUploadFileParams, opts ...option.RequestOption) (res *BetaChatKitUploadFileResponseUnion, err error) { - opts = slices.Concat(r.Options, opts) - opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "chatkit_beta=v1")}, opts...) - path := "chatkit/files" - err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...) - return -} - // Workflow metadata and state returned for the session. type ChatKitWorkflow struct { // Identifier of the workflow backing the session. @@ -141,165 +123,3 @@ func (r ChatKitWorkflowTracing) RawJSON() string { return r.JSON.raw } func (r *ChatKitWorkflowTracing) UnmarshalJSON(data []byte) error { return apijson.UnmarshalRoot(data, r) } - -// Metadata for a non-image file uploaded through ChatKit. -type FilePart struct { - // Unique identifier for the uploaded file. - ID string `json:"id,required"` - // MIME type reported for the uploaded file. Defaults to null when unknown. - MimeType string `json:"mime_type,required"` - // Original filename supplied by the uploader. Defaults to null when unnamed. - Name string `json:"name,required"` - // Type discriminator that is always `file`. - Type constant.File `json:"type,required"` - // Signed URL for downloading the uploaded file. Defaults to null when no download - // link is available. - UploadURL string `json:"upload_url,required"` - // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. - JSON struct { - ID respjson.Field - MimeType respjson.Field - Name respjson.Field - Type respjson.Field - UploadURL respjson.Field - ExtraFields map[string]respjson.Field - raw string - } `json:"-"` -} - -// Returns the unmodified JSON received from the API -func (r FilePart) RawJSON() string { return r.JSON.raw } -func (r *FilePart) UnmarshalJSON(data []byte) error { - return apijson.UnmarshalRoot(data, r) -} - -// Metadata for an image uploaded through ChatKit. -type ImagePart struct { - // Unique identifier for the uploaded image. - ID string `json:"id,required"` - // MIME type of the uploaded image. - MimeType string `json:"mime_type,required"` - // Original filename for the uploaded image. Defaults to null when unnamed. - Name string `json:"name,required"` - // Preview URL that can be rendered inline for the image. - PreviewURL string `json:"preview_url,required"` - // Type discriminator that is always `image`. - Type constant.Image `json:"type,required"` - // Signed URL for downloading the uploaded image. Defaults to null when no download - // link is available. - UploadURL string `json:"upload_url,required"` - // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. - JSON struct { - ID respjson.Field - MimeType respjson.Field - Name respjson.Field - PreviewURL respjson.Field - Type respjson.Field - UploadURL respjson.Field - ExtraFields map[string]respjson.Field - raw string - } `json:"-"` -} - -// Returns the unmodified JSON received from the API -func (r ImagePart) RawJSON() string { return r.JSON.raw } -func (r *ImagePart) UnmarshalJSON(data []byte) error { - return apijson.UnmarshalRoot(data, r) -} - -// BetaChatKitUploadFileResponseUnion contains all possible properties and values -// from [FilePart], [ImagePart]. -// -// Use the [BetaChatKitUploadFileResponseUnion.AsAny] method to switch on the -// variant. -// -// Use the methods beginning with 'As' to cast the union to one of its variants. -type BetaChatKitUploadFileResponseUnion struct { - ID string `json:"id"` - MimeType string `json:"mime_type"` - Name string `json:"name"` - // Any of "file", "image". - Type string `json:"type"` - UploadURL string `json:"upload_url"` - // This field is from variant [ImagePart]. - PreviewURL string `json:"preview_url"` - JSON struct { - ID respjson.Field - MimeType respjson.Field - Name respjson.Field - Type respjson.Field - UploadURL respjson.Field - PreviewURL respjson.Field - raw string - } `json:"-"` -} - -// anyBetaChatKitUploadFileResponse is implemented by each variant of -// [BetaChatKitUploadFileResponseUnion] to add type safety for the return type of -// [BetaChatKitUploadFileResponseUnion.AsAny] -type anyBetaChatKitUploadFileResponse interface { - implBetaChatKitUploadFileResponseUnion() -} - -func (FilePart) implBetaChatKitUploadFileResponseUnion() {} -func (ImagePart) implBetaChatKitUploadFileResponseUnion() {} - -// Use the following switch statement to find the correct variant -// -// switch variant := BetaChatKitUploadFileResponseUnion.AsAny().(type) { -// case openai.FilePart: -// case openai.ImagePart: -// default: -// fmt.Errorf("no variant present") -// } -func (u BetaChatKitUploadFileResponseUnion) AsAny() anyBetaChatKitUploadFileResponse { - switch u.Type { - case "file": - return u.AsFile() - case "image": - return u.AsImage() - } - return nil -} - -func (u BetaChatKitUploadFileResponseUnion) AsFile() (v FilePart) { - apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) - return -} - -func (u BetaChatKitUploadFileResponseUnion) AsImage() (v ImagePart) { - apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) - return -} - -// Returns the unmodified JSON received from the API -func (u BetaChatKitUploadFileResponseUnion) RawJSON() string { return u.JSON.raw } - -func (r *BetaChatKitUploadFileResponseUnion) UnmarshalJSON(data []byte) error { - return apijson.UnmarshalRoot(data, r) -} - -type BetaChatKitUploadFileParams struct { - // Binary file contents to store with the ChatKit session. Supports PDFs and PNG, - // JPG, JPEG, GIF, or WEBP images. - File io.Reader `json:"file,omitzero,required" format:"binary"` - paramObj -} - -func (r BetaChatKitUploadFileParams) 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 -} diff --git a/betachatkit_test.go b/betachatkit_test.go deleted file mode 100644 index 6424c349..00000000 --- a/betachatkit_test.go +++ /dev/null @@ -1,40 +0,0 @@ -// 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/v3" - "github.com/openai/openai-go/v3/internal/testutil" - "github.com/openai/openai-go/v3/option" -) - -func TestBetaChatKitUploadFile(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.Beta.ChatKit.UploadFile(context.TODO(), openai.BetaChatKitUploadFileParams{ - File: io.Reader(bytes.NewBuffer([]byte("some file contents"))), - }) - 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()) - } -} diff --git a/internal/version.go b/internal/version.go index f7182237..c28bbc2b 100644 --- a/internal/version.go +++ b/internal/version.go @@ -2,4 +2,4 @@ package internal -const PackageVersion = "3.4.0" // x-release-please-version +const PackageVersion = "3.5.0" // x-release-please-version diff --git a/scripts/detect-breaking-changes b/scripts/detect-breaking-changes index 2b966f60..7c37acf6 100755 --- a/scripts/detect-breaking-changes +++ b/scripts/detect-breaking-changes @@ -27,7 +27,6 @@ TEST_PATHS=( vectorstorefile_test.go vectorstorefilebatch_test.go webhooks/webhook_test.go - betachatkit_test.go betachatkitsession_test.go betachatkitthread_test.go betaassistant_test.go