-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimage.go
126 lines (100 loc) · 4.46 KB
/
image.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
package openai_gosdk
const imageGenerationsURL = "https://api.openai.com/v1/images/generations"
type RequestImageGenerations 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 , , or .256x256 512x512 1024x1024
Size string `json:"size,omitempty"`
// string Optional Defaults to url
// The format in which the generated images are returned. Must be one of or .url 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/end-user-ids.
User string `json:"user,omitempty"`
}
type ResponseImageGenerations struct {
Created int `json:"created"`
Data []struct {
Url string `json:"url"`
} `json:"data"`
}
func NewImageGenerations(baseOpenAI BaseOpenAI) OpenAI[RequestImageGenerations, ResponseImageGenerations] {
return OpenAI[RequestImageGenerations, ResponseImageGenerations]{
BaseOpenAI: baseOpenAI,
TargetURL: imageGenerationsURL,
Method: POST,
}
}
const imageEditURL = "https://api.openai.com/v1/images/edits"
type RequestImageEdit 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 should be edited. Must be a valid PNG file, less than 4MB, and have the same dimensions as . image 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 , , or .256x256 512x512 1024x1024
Size string `json:"size,omitempty"`
// string Optional Defaults to url
// The format in which the generated images are returned. Must be one of or .url 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/end-user-ids.
User string `json:"user,omitempty"`
}
type ResponseImageEdit struct {
Created int `json:"created"`
Data []struct {
Url string `json:"url"`
} `json:"data"`
}
func NewImageEdit(baseOpenAI BaseOpenAI) OpenAI[RequestImageEdit, ResponseImageEdit] {
return OpenAI[RequestImageEdit, ResponseImageEdit]{
BaseOpenAI: baseOpenAI,
Method: POST,
TargetURL: imageEditURL,
}
}
const imageVariationURL = "https://api.openai.com/v1/images/variations"
type RequestImageVariation 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 , , or .256x256 512x512 1024x1024
Size string `json:"size,omitempty"`
// string Optional Defaults to url
// The format in which the generated images are returned. Must be one of or .url 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/end-user-ids.
User string `json:"user,omitempty"`
}
type ResponseImageVariation struct {
Created int `json:"created"`
Data []struct {
Url string `json:"url"`
} `json:"data"`
}
func NewImageVariation(baseOpenAI BaseOpenAI) OpenAI[RequestImageVariation, ResponseImageVariation] {
return OpenAI[RequestImageVariation, ResponseImageVariation]{
BaseOpenAI: baseOpenAI,
Method: POST,
TargetURL: imageVariationURL,
}
}