-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfiles.go
116 lines (94 loc) · 3.26 KB
/
files.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package openai_gosdk
import "fmt"
const filesURL = "https://api.openai.com/v1/files"
type RequestFiles struct {
}
type ResponseFiles struct {
Data []struct {
Id string `json:"id"`
Object string `json:"object"`
Bytes int `json:"bytes"`
CreatedAt int `json:"created_at"`
Filename string `json:"filename"`
Purpose string `json:"purpose"`
} `json:"data"`
Object string `json:"object"`
}
func NewFiles(baseOpenAI BaseOpenAI) OpenAI[RequestFiles, ResponseFiles] {
return OpenAI[RequestFiles, ResponseFiles]{
BaseOpenAI: baseOpenAI,
TargetURL: filesURL,
Method: GET,
}
}
const uploadFileURL = "https://api.openai.com/v1/files"
type RequestUploadFile struct {
// string Required
// Name of the JSON Lines https://jsonlines.readthedocs.io/en/latest/ file to be uploaded.
//
// If the is set to "fine-tune", each line is a JSON record with "prompt" and "completion" fields representing your training examples https://jsonlines.readthedocs.io/en/latest/.purpose
File *string `json:"file"`
// string Required
// The intended purpose of the uploaded documents.
//
// Use "fine-tune" for Fine-tuning https://platform.openai.com/docs/api-reference/fine-tunes. This allows us to validate the format of the uploaded file.
Purpose *string `json:"purpose"`
}
type ResponseUploadFile struct {
Id string `json:"id"`
Object string `json:"object"`
Bytes int `json:"bytes"`
CreatedAt int `json:"created_at"`
Filename string `json:"filename"`
Purpose string `json:"purpose"`
}
func NewUploadFile(baseOpenAI BaseOpenAI) OpenAI[RequestUploadFile, ResponseUploadFile] {
return OpenAI[RequestUploadFile, ResponseUploadFile]{
BaseOpenAI: baseOpenAI,
TargetURL: uploadFileURL,
Method: POST,
}
}
const deleteFileURL = "https://api.openai.com/v1/files/"
type RequestDeleteFile struct{}
type ResponseDeleteFile struct {
Id string `json:"id"`
Object string `json:"object"`
Deleted bool `json:"deleted"`
}
func NewDeleteFile(baseOpenAI BaseOpenAI, fileID string) OpenAI[RequestDeleteFile, ResponseDeleteFile] {
return OpenAI[RequestDeleteFile, ResponseDeleteFile]{
BaseOpenAI: baseOpenAI,
TargetURL: deleteFileURL + fileID,
Method: DELETE,
}
}
const retrieveFileURL = "https://api.openai.com/v1/files/"
type RequestRetrieveFile struct{}
type ResponseRetrieveFile struct {
Id string `json:"id"`
Object string `json:"object"`
Bytes int `json:"bytes"`
CreatedAt int `json:"created_at"`
Filename string `json:"filename"`
Purpose string `json:"purpose"`
}
func NewRetrieveFile(baseOpenAI BaseOpenAI, fileID string) OpenAI[RequestRetrieveFile, ResponseRetrieveFile] {
return OpenAI[RequestRetrieveFile, ResponseRetrieveFile]{
BaseOpenAI: baseOpenAI,
TargetURL: retrieveFileURL + fileID,
Method: GET,
}
}
const retrieveFileContentURL = "https://api.openai.com/v1/files/%s/content"
type RequestRetrieveFileContent struct{}
type ResponseRetrieveFileContent struct {
// TODO
}
func NewRetrieveFileContent(baseOpenAI BaseOpenAI, fileID string) OpenAI[RequestRetrieveFileContent, ResponseRetrieveFileContent] {
return OpenAI[RequestRetrieveFileContent, ResponseRetrieveFileContent]{
BaseOpenAI: baseOpenAI,
TargetURL: fmt.Sprintf(retrieveFileContentURL, fileID),
Method: GET,
}
}