Skip to content

Commit 1daff0f

Browse files
chore(types): define FilePurpose enum (openai#22)
1 parent 9300063 commit 1daff0f

7 files changed

+37
-54
lines changed

.stats.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
configured_endpoints: 68
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-285bce7dcdae7eea5fe84a8d6e5af2c1473d65ea193109370fb2257851eef7eb.yml
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-8ff62fa1091460d68fbd36d72c17d91b709917bebf2983c9c4de5784bc384a2e.yml

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -263,19 +263,19 @@ which can be used to wrap any `io.Reader` with the appropriate file name and con
263263
file, err := os.Open("input.jsonl")
264264
openai.FileNewParams{
265265
File: openai.F[io.Reader](file),
266-
Purpose: openai.F(openai.FileNewParamsPurposeFineTune),
266+
Purpose: openai.F(openai.FilePurposeFineTune),
267267
}
268268

269269
// A file from a string
270270
openai.FileNewParams{
271271
File: openai.F[io.Reader](strings.NewReader("my file contents")),
272-
Purpose: openai.F(openai.FileNewParamsPurposeFineTune),
272+
Purpose: openai.F(openai.FilePurposeFineTune),
273273
}
274274

275275
// With a custom filename and contentType
276276
openai.FileNewParams{
277277
File: openai.FileParam(strings.NewReader(`{"hello": "foo"}`), "file.go", "application/json"),
278-
Purpose: openai.F(openai.FileNewParamsPurposeFineTune),
278+
Purpose: openai.F(openai.FilePurposeFineTune),
279279
}
280280
```
281281

api.md

+4
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ Methods:
7676

7777
# Files
7878

79+
Params Types:
80+
81+
- <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>
82+
7983
Response Types:
8084

8185
- <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>

file.go

+26-26
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,31 @@ func (r FileObjectStatus) IsKnown() bool {
269269
return false
270270
}
271271

272+
// The intended purpose of the uploaded file.
273+
//
274+
// Use "assistants" for
275+
// [Assistants](https://platform.openai.com/docs/api-reference/assistants) and
276+
// [Message](https://platform.openai.com/docs/api-reference/messages) files,
277+
// "vision" for Assistants image file inputs, "batch" for
278+
// [Batch API](https://platform.openai.com/docs/guides/batch), and "fine-tune" for
279+
// [Fine-tuning](https://platform.openai.com/docs/api-reference/fine-tuning).
280+
type FilePurpose string
281+
282+
const (
283+
FilePurposeAssistants FilePurpose = "assistants"
284+
FilePurposeBatch FilePurpose = "batch"
285+
FilePurposeFineTune FilePurpose = "fine-tune"
286+
FilePurposeVision FilePurpose = "vision"
287+
)
288+
289+
func (r FilePurpose) IsKnown() bool {
290+
switch r {
291+
case FilePurposeAssistants, FilePurposeBatch, FilePurposeFineTune, FilePurposeVision:
292+
return true
293+
}
294+
return false
295+
}
296+
272297
type FileNewParams struct {
273298
// The File object (not file name) to be uploaded.
274299
File param.Field[io.Reader] `json:"file,required" format:"binary"`
@@ -280,7 +305,7 @@ type FileNewParams struct {
280305
// "vision" for Assistants image file inputs, "batch" for
281306
// [Batch API](https://platform.openai.com/docs/guides/batch), and "fine-tune" for
282307
// [Fine-tuning](https://platform.openai.com/docs/api-reference/fine-tuning).
283-
Purpose param.Field[FileNewParamsPurpose] `json:"purpose,required"`
308+
Purpose param.Field[FilePurpose] `json:"purpose,required"`
284309
}
285310

286311
func (r FileNewParams) MarshalMultipart() (data []byte, contentType string, err error) {
@@ -298,31 +323,6 @@ func (r FileNewParams) MarshalMultipart() (data []byte, contentType string, err
298323
return buf.Bytes(), writer.FormDataContentType(), nil
299324
}
300325

301-
// The intended purpose of the uploaded file.
302-
//
303-
// Use "assistants" for
304-
// [Assistants](https://platform.openai.com/docs/api-reference/assistants) and
305-
// [Message](https://platform.openai.com/docs/api-reference/messages) files,
306-
// "vision" for Assistants image file inputs, "batch" for
307-
// [Batch API](https://platform.openai.com/docs/guides/batch), and "fine-tune" for
308-
// [Fine-tuning](https://platform.openai.com/docs/api-reference/fine-tuning).
309-
type FileNewParamsPurpose string
310-
311-
const (
312-
FileNewParamsPurposeAssistants FileNewParamsPurpose = "assistants"
313-
FileNewParamsPurposeBatch FileNewParamsPurpose = "batch"
314-
FileNewParamsPurposeFineTune FileNewParamsPurpose = "fine-tune"
315-
FileNewParamsPurposeVision FileNewParamsPurpose = "vision"
316-
)
317-
318-
func (r FileNewParamsPurpose) IsKnown() bool {
319-
switch r {
320-
case FileNewParamsPurposeAssistants, FileNewParamsPurposeBatch, FileNewParamsPurposeFineTune, FileNewParamsPurposeVision:
321-
return true
322-
}
323-
return false
324-
}
325-
326326
type FileListParams struct {
327327
// Only return files with the given purpose.
328328
Purpose param.Field[string] `query:"purpose"`

file_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func TestFileNew(t *testing.T) {
3131
)
3232
_, err := client.Files.New(context.TODO(), openai.FileNewParams{
3333
File: openai.F(io.Reader(bytes.NewBuffer([]byte("some file contents")))),
34-
Purpose: openai.F(openai.FileNewParamsPurposeAssistants),
34+
Purpose: openai.F(openai.FilePurposeAssistants),
3535
})
3636
if err != nil {
3737
var apierr *openai.Error

upload.go

+1-22
Original file line numberDiff line numberDiff line change
@@ -193,34 +193,13 @@ type UploadNewParams struct {
193193
//
194194
// See the
195195
// [documentation on File purposes](https://platform.openai.com/docs/api-reference/files/create#files-create-purpose).
196-
Purpose param.Field[UploadNewParamsPurpose] `json:"purpose,required"`
196+
Purpose param.Field[FilePurpose] `json:"purpose,required"`
197197
}
198198

199199
func (r UploadNewParams) MarshalJSON() (data []byte, err error) {
200200
return apijson.MarshalRoot(r)
201201
}
202202

203-
// The intended purpose of the uploaded file.
204-
//
205-
// See the
206-
// [documentation on File purposes](https://platform.openai.com/docs/api-reference/files/create#files-create-purpose).
207-
type UploadNewParamsPurpose string
208-
209-
const (
210-
UploadNewParamsPurposeAssistants UploadNewParamsPurpose = "assistants"
211-
UploadNewParamsPurposeBatch UploadNewParamsPurpose = "batch"
212-
UploadNewParamsPurposeFineTune UploadNewParamsPurpose = "fine-tune"
213-
UploadNewParamsPurposeVision UploadNewParamsPurpose = "vision"
214-
)
215-
216-
func (r UploadNewParamsPurpose) IsKnown() bool {
217-
switch r {
218-
case UploadNewParamsPurposeAssistants, UploadNewParamsPurposeBatch, UploadNewParamsPurposeFineTune, UploadNewParamsPurposeVision:
219-
return true
220-
}
221-
return false
222-
}
223-
224203
type UploadCompleteParams struct {
225204
// The ordered list of Part IDs.
226205
PartIDs param.Field[[]string] `json:"part_ids,required"`

upload_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func TestUploadNew(t *testing.T) {
2929
Bytes: openai.F(int64(0)),
3030
Filename: openai.F("filename"),
3131
MimeType: openai.F("mime_type"),
32-
Purpose: openai.F(openai.UploadNewParamsPurposeAssistants),
32+
Purpose: openai.F(openai.FilePurposeAssistants),
3333
})
3434
if err != nil {
3535
var apierr *openai.Error

0 commit comments

Comments
 (0)