-
Notifications
You must be signed in to change notification settings - Fork 36
/
file.go
56 lines (47 loc) · 1.16 KB
/
file.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package openaigo
import (
"bytes"
"fmt"
"io"
"mime/multipart"
)
type FileListResponse struct {
Object string `json:"object"`
Data []FileData `json:"data"`
}
type FileData struct {
ID string `json:"id"`
Object string `json:"object"`
Bytes int64 `json:"bytes"`
CreatedAt int64 `json:"created_at"`
Filename string `json:"filename"`
Purpose string `json:"purpuse"`
}
type FileUploadRequestBody struct {
File io.Reader
Purpose string
}
func (body FileUploadRequestBody) ToMultipartFormData() (*bytes.Buffer, string, error) {
if body.File == nil {
return nil, "", fmt.Errorf("body.File must not be nil")
}
buf := bytes.NewBuffer(nil)
w := multipart.NewWriter(buf)
defer w.Close()
filew, err := w.CreateFormFile("file", "file.jsonl")
if err != nil {
return nil, "", err
}
if _, err := io.Copy(filew, body.File); err != nil {
return nil, "", err
}
w.WriteField("purpose", body.Purpose)
return buf, w.FormDataContentType(), err
}
type FileUploadResponse FileData
type FileDeleteResponse struct {
ID string `json:"id"`
Object string `json:"object"`
Deleted bool `json:"deleted"`
}
type FileRetrieveResponse FileData