From 1daff0f73ce40ae61e2d4b217d22811cbb373c27 Mon Sep 17 00:00:00 2001
From: "stainless-app[bot]"
<142633134+stainless-app[bot]@users.noreply.github.com>
Date: Thu, 15 Aug 2024 21:59:18 +0000
Subject: [PATCH] chore(types): define FilePurpose enum (#22)
---
.stats.yml | 2 +-
README.md | 6 +++---
api.md | 4 ++++
file.go | 52 +++++++++++++++++++++++++-------------------------
file_test.go | 2 +-
upload.go | 23 +---------------------
upload_test.go | 2 +-
7 files changed, 37 insertions(+), 54 deletions(-)
diff --git a/.stats.yml b/.stats.yml
index 2371b7b..185585b 100644
--- a/.stats.yml
+++ b/.stats.yml
@@ -1,2 +1,2 @@
configured_endpoints: 68
-openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-285bce7dcdae7eea5fe84a8d6e5af2c1473d65ea193109370fb2257851eef7eb.yml
+openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-8ff62fa1091460d68fbd36d72c17d91b709917bebf2983c9c4de5784bc384a2e.yml
diff --git a/README.md b/README.md
index 6b5bb47..5ead87b 100644
--- a/README.md
+++ b/README.md
@@ -263,19 +263,19 @@ which can be used to wrap any `io.Reader` with the appropriate file name and con
file, err := os.Open("input.jsonl")
openai.FileNewParams{
File: openai.F[io.Reader](file),
- Purpose: openai.F(openai.FileNewParamsPurposeFineTune),
+ Purpose: openai.F(openai.FilePurposeFineTune),
}
// A file from a string
openai.FileNewParams{
File: openai.F[io.Reader](strings.NewReader("my file contents")),
- Purpose: openai.F(openai.FileNewParamsPurposeFineTune),
+ Purpose: openai.F(openai.FilePurposeFineTune),
}
// With a custom filename and contentType
openai.FileNewParams{
File: openai.FileParam(strings.NewReader(`{"hello": "foo"}`), "file.go", "application/json"),
- Purpose: openai.F(openai.FileNewParamsPurposeFineTune),
+ Purpose: openai.F(openai.FilePurposeFineTune),
}
```
diff --git a/api.md b/api.md
index ecec90f..4c35934 100644
--- a/api.md
+++ b/api.md
@@ -76,6 +76,10 @@ Methods:
# Files
+Params Types:
+
+- openai.FilePurpose
+
Response Types:
- openai.FileDeleted
diff --git a/file.go b/file.go
index 25d90bb..30dde49 100644
--- a/file.go
+++ b/file.go
@@ -269,6 +269,31 @@ func (r FileObjectStatus) IsKnown() bool {
return false
}
+// The intended purpose of the uploaded file.
+//
+// Use "assistants" for
+// [Assistants](https://platform.openai.com/docs/api-reference/assistants) and
+// [Message](https://platform.openai.com/docs/api-reference/messages) files,
+// "vision" for Assistants image file inputs, "batch" for
+// [Batch API](https://platform.openai.com/docs/guides/batch), and "fine-tune" for
+// [Fine-tuning](https://platform.openai.com/docs/api-reference/fine-tuning).
+type FilePurpose string
+
+const (
+ FilePurposeAssistants FilePurpose = "assistants"
+ FilePurposeBatch FilePurpose = "batch"
+ FilePurposeFineTune FilePurpose = "fine-tune"
+ FilePurposeVision FilePurpose = "vision"
+)
+
+func (r FilePurpose) IsKnown() bool {
+ switch r {
+ case FilePurposeAssistants, FilePurposeBatch, FilePurposeFineTune, FilePurposeVision:
+ return true
+ }
+ return false
+}
+
type FileNewParams struct {
// The File object (not file name) to be uploaded.
File param.Field[io.Reader] `json:"file,required" format:"binary"`
@@ -280,7 +305,7 @@ type FileNewParams struct {
// "vision" for Assistants image file inputs, "batch" for
// [Batch API](https://platform.openai.com/docs/guides/batch), and "fine-tune" for
// [Fine-tuning](https://platform.openai.com/docs/api-reference/fine-tuning).
- Purpose param.Field[FileNewParamsPurpose] `json:"purpose,required"`
+ Purpose param.Field[FilePurpose] `json:"purpose,required"`
}
func (r FileNewParams) MarshalMultipart() (data []byte, contentType string, err error) {
@@ -298,31 +323,6 @@ func (r FileNewParams) MarshalMultipart() (data []byte, contentType string, err
return buf.Bytes(), writer.FormDataContentType(), nil
}
-// The intended purpose of the uploaded file.
-//
-// Use "assistants" for
-// [Assistants](https://platform.openai.com/docs/api-reference/assistants) and
-// [Message](https://platform.openai.com/docs/api-reference/messages) files,
-// "vision" for Assistants image file inputs, "batch" for
-// [Batch API](https://platform.openai.com/docs/guides/batch), and "fine-tune" for
-// [Fine-tuning](https://platform.openai.com/docs/api-reference/fine-tuning).
-type FileNewParamsPurpose string
-
-const (
- FileNewParamsPurposeAssistants FileNewParamsPurpose = "assistants"
- FileNewParamsPurposeBatch FileNewParamsPurpose = "batch"
- FileNewParamsPurposeFineTune FileNewParamsPurpose = "fine-tune"
- FileNewParamsPurposeVision FileNewParamsPurpose = "vision"
-)
-
-func (r FileNewParamsPurpose) IsKnown() bool {
- switch r {
- case FileNewParamsPurposeAssistants, FileNewParamsPurposeBatch, FileNewParamsPurposeFineTune, FileNewParamsPurposeVision:
- return true
- }
- return false
-}
-
type FileListParams struct {
// Only return files with the given purpose.
Purpose param.Field[string] `query:"purpose"`
diff --git a/file_test.go b/file_test.go
index c5b5557..588a561 100644
--- a/file_test.go
+++ b/file_test.go
@@ -31,7 +31,7 @@ func TestFileNew(t *testing.T) {
)
_, err := client.Files.New(context.TODO(), openai.FileNewParams{
File: openai.F(io.Reader(bytes.NewBuffer([]byte("some file contents")))),
- Purpose: openai.F(openai.FileNewParamsPurposeAssistants),
+ Purpose: openai.F(openai.FilePurposeAssistants),
})
if err != nil {
var apierr *openai.Error
diff --git a/upload.go b/upload.go
index d39cbfd..fa5ebc4 100644
--- a/upload.go
+++ b/upload.go
@@ -193,34 +193,13 @@ type UploadNewParams struct {
//
// See the
// [documentation on File purposes](https://platform.openai.com/docs/api-reference/files/create#files-create-purpose).
- Purpose param.Field[UploadNewParamsPurpose] `json:"purpose,required"`
+ Purpose param.Field[FilePurpose] `json:"purpose,required"`
}
func (r UploadNewParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
-// The intended purpose of the uploaded file.
-//
-// See the
-// [documentation on File purposes](https://platform.openai.com/docs/api-reference/files/create#files-create-purpose).
-type UploadNewParamsPurpose string
-
-const (
- UploadNewParamsPurposeAssistants UploadNewParamsPurpose = "assistants"
- UploadNewParamsPurposeBatch UploadNewParamsPurpose = "batch"
- UploadNewParamsPurposeFineTune UploadNewParamsPurpose = "fine-tune"
- UploadNewParamsPurposeVision UploadNewParamsPurpose = "vision"
-)
-
-func (r UploadNewParamsPurpose) IsKnown() bool {
- switch r {
- case UploadNewParamsPurposeAssistants, UploadNewParamsPurposeBatch, UploadNewParamsPurposeFineTune, UploadNewParamsPurposeVision:
- return true
- }
- return false
-}
-
type UploadCompleteParams struct {
// The ordered list of Part IDs.
PartIDs param.Field[[]string] `json:"part_ids,required"`
diff --git a/upload_test.go b/upload_test.go
index 43d5d2e..e19a277 100644
--- a/upload_test.go
+++ b/upload_test.go
@@ -29,7 +29,7 @@ func TestUploadNew(t *testing.T) {
Bytes: openai.F(int64(0)),
Filename: openai.F("filename"),
MimeType: openai.F("mime_type"),
- Purpose: openai.F(openai.UploadNewParamsPurposeAssistants),
+ Purpose: openai.F(openai.FilePurposeAssistants),
})
if err != nil {
var apierr *openai.Error