Skip to content

Commit

Permalink
chore(types): define FilePurpose enum (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] committed Aug 15, 2024
1 parent 9300063 commit 1daff0f
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
```

Expand Down
4 changes: 4 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ Methods:

# Files

Params 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#FilePurpose">FilePurpose</a>

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#FileDeleted">FileDeleted</a>
Expand Down
52 changes: 26 additions & 26 deletions file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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) {
Expand All @@ -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"`
Expand Down
2 changes: 1 addition & 1 deletion file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 1 addition & 22 deletions upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
2 changes: 1 addition & 1 deletion upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1daff0f

Please sign in to comment.