-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimages.go
132 lines (106 loc) · 4.44 KB
/
images.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package openai_gosdk
const (
createImageURL = "https://api.openai.com/v1/images/generations"
)
type RequestCreateImage struct {
// string Required
// A text description of the desired image(s). The maximum length is 1000 characters.
Prompt *string `json:"prompt"`
// integer Optional Defaults to 1
// The number of images to generate. Must be between 1 and 10.
N int `json:"n,omitempty"`
// string Optional Defaults to 1024x1024
// The size of the generated images. Must be one of 256x256, 512x512, or 1024x1024.
Size string `json:"size,omitempty"`
// string Optional Defaults to url
// The format in which the generated images are returned. Must be one of url or b64_json.
ResponseFormat string `json:"response_format,omitempty"`
// string Optional
// A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. Learn more. https://platform.openai.com/docs/guides/safety-best-practices
User string `json:"user,omitempty"`
}
type ResponseCreateImage struct {
Created int `json:"created"`
Data []struct {
Url string `json:"url"`
} `json:"data"`
}
func NewCreateImage(baseOpenAI BaseOpenAI) OpenAI[RequestCreateImage, ResponseCreateImage] {
return OpenAI[RequestCreateImage, ResponseCreateImage]{
BaseOpenAI: baseOpenAI,
TargetURL: createImageURL,
Method: POST,
}
}
const (
editImageURL = "https://api.openai.com/v1/images/edits"
)
type RequestEditImage struct {
// string Required
// The image to edit. Must be a valid PNG file, less than 4MB, and square. If mask is not provided, image must have transparency, which will be used as the mask.
Image *string `json:"image"`
// string Optional
// An additional image whose fully transparent areas (e.g. where alpha is zero) indicate where image should be edited. Must be a valid PNG file, less than 4MB, and have the same dimensions as image.
Mask string `json:"mask,omitempty"`
// string Required
// A text description of the desired image(s). The maximum length is 1000 characters.
Prompt *string `json:"prompt"`
// integer Optional Defaults to 1
// The number of images to generate. Must be between 1 and 10.
N int `json:"n,omitempty"`
// string Optional Defaults to 1024x1024
// The size of the generated images. Must be one of 256x256, 512x512, or 1024x1024.
Size string `json:"size,omitempty"`
// string Optional Defaults to url
// The format in which the generated images are returned. Must be one of url or b64_json.
ResponseFormat string `json:"response_format,omitempty"`
// string Optional
// A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. Learn more. https://platform.openai.com/docs/guides/safety-best-practices
User string `json:"user,omitempty"`
}
type ResponseEditImage struct {
Created int `json:"created"`
Data []struct {
Url string `json:"url"`
} `json:"data"`
}
func NewEditImage(baseOpenAI BaseOpenAI) OpenAI[RequestEditImage, ResponseEditImage] {
return OpenAI[RequestEditImage, ResponseEditImage]{
BaseOpenAI: baseOpenAI,
TargetURL: editImageURL,
Method: POST,
}
}
const (
createVariationImageURL = "https://api.openai.com/v1/images/variations"
)
type RequestCreateVariationImage struct {
// string Required
// The image to use as the basis for the variation(s). Must be a valid PNG file, less than 4MB, and square.
Image *string `json:"image"`
// integer Optional Defaults to 1
// The number of images to generate. Must be between 1 and 10.
N int `json:"n,omitempty"`
// string Optional Defaults to 1024x1024
// The size of the generated images. Must be one of 256x256, 512x512, or 1024x1024.
Size string `json:"size,omitempty"`
// string Optional Defaults to url
// The format in which the generated images are returned. Must be one of url or b64_json.
ResponseFormat string `json:"response_format,omitempty"`
// string Optional
// A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. Learn more. https://platform.openai.com/docs/guides/safety-best-practices
User string `json:"user,omitempty"`
}
type ResponseCreateVariationImage struct {
Created int `json:"created"`
Data []struct {
Url string `json:"url"`
} `json:"data"`
}
func NewCreateVariationImage(baseOpenAI BaseOpenAI) OpenAI[RequestCreateVariationImage, ResponseCreateVariationImage] {
return OpenAI[RequestCreateVariationImage, ResponseCreateVariationImage]{
BaseOpenAI: baseOpenAI,
TargetURL: createVariationImageURL,
Method: POST,
}
}