-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathimages.ts
More file actions
256 lines (223 loc) · 7.12 KB
/
images.ts
File metadata and controls
256 lines (223 loc) · 7.12 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from '../core/resource';
import * as ImagesAPI from './images';
import * as Shared from './shared';
import { APIPromise } from '../core/api-promise';
import { Stream } from '../core/streaming';
import { RequestOptions } from '../internal/request-options';
export class Images extends APIResource {
/**
* Creates a high-quality image from a text prompt using GPT-IMAGE-1, the latest
* image generation model with automatic prompt optimization and enhanced visual
* capabilities.
*
* @example
* ```ts
* const response = await client.images.generate({
* prompt:
* 'A cute baby sea otter floating on its back in calm blue water',
* });
* ```
*/
generate(
body: ImageGenerateParamsNonStreaming,
options?: RequestOptions,
): APIPromise<ImageGenerateResponse>;
generate(
body: ImageGenerateParamsStreaming,
options?: RequestOptions,
): APIPromise<Stream<Shared.ImageGenStreamEvent>>;
generate(
body: ImageGenerateParamsBase,
options?: RequestOptions,
): APIPromise<Stream<Shared.ImageGenStreamEvent> | ImageGenerateResponse>;
generate(
body: ImageGenerateParams,
options?: RequestOptions,
): APIPromise<ImageGenerateResponse> | APIPromise<Stream<Shared.ImageGenStreamEvent>> {
return this._client.post('/images/generations', {
body,
defaultBaseURL: '{inferenceEndpoint}/v1',
...options,
stream: body.stream ?? false,
}) as APIPromise<ImageGenerateResponse> | APIPromise<Stream<Shared.ImageGenStreamEvent>>;
}
}
/**
* The response from the image generation endpoint
*/
export interface ImageGenerateResponse {
/**
* The Unix timestamp (in seconds) of when the images were created
*/
created: number;
/**
* The list of generated images
*/
data: Array<ImageGenerateResponse.Data>;
/**
* The background setting used for the image generation
*/
background?: string | null;
/**
* The output format of the generated image
*/
output_format?: string | null;
/**
* The quality setting used for the image generation
*/
quality?: string | null;
/**
* The size of the generated image
*/
size?: string | null;
/**
* Usage statistics for the image generation request
*/
usage?: ImageGenerateResponse.Usage | null;
}
export namespace ImageGenerateResponse {
/**
* Represents the content of a generated image from GPT-IMAGE-1
*/
export interface Data {
/**
* The base64-encoded JSON of the generated image. GPT-IMAGE-1 returns images in
* b64_json format only.
*/
b64_json: string;
/**
* The optimized prompt that was used to generate the image. GPT-IMAGE-1
* automatically optimizes prompts for best results.
*/
revised_prompt?: string;
}
/**
* Usage statistics for the image generation request
*/
export interface Usage {
/**
* Number of tokens in the input prompt
*/
input_tokens: number;
/**
* Total number of tokens used (input + output)
*/
total_tokens: number;
/**
* Detailed breakdown of input tokens
*/
input_tokens_details?: Usage.InputTokensDetails | null;
/**
* Number of tokens in the generated output
*/
output_tokens?: number;
}
export namespace Usage {
/**
* Detailed breakdown of input tokens
*/
export interface InputTokensDetails {
/**
* Number of text tokens in the input
*/
text_tokens?: number;
}
}
}
export type ImageGenerateParams = ImageGenerateParamsNonStreaming | ImageGenerateParamsStreaming;
export interface ImageGenerateParamsBase {
/**
* A text description of the desired image(s). GPT-IMAGE-1 supports up to 32,000
* characters and provides automatic prompt optimization for best results.
*/
prompt: string;
/**
* The background setting for the image generation. GPT-IMAGE-1 supports:
* transparent, opaque, auto.
*/
background?: string | null;
/**
* The model to use for image generation. GPT-IMAGE-1 is the latest model offering
* the best quality with automatic optimization and enhanced capabilities.
*/
model?: string;
/**
* The moderation setting for the image generation. GPT-IMAGE-1 supports: low,
* auto.
*/
moderation?: string | null;
/**
* The number of images to generate. GPT-IMAGE-1 only supports n=1.
*/
n?: number | null;
/**
* The output compression for the image generation. GPT-IMAGE-1 supports: 0-100.
*/
output_compression?: number | null;
/**
* The output format for the image generation. GPT-IMAGE-1 supports: png, webp,
* jpeg.
*/
output_format?: string | null;
/**
* The number of partial image chunks to return during streaming generation. This
* parameter is optional with a default of 0. When stream=true, this must be
* greater than 0 to receive progressive updates of the image as it's being
* generated. Higher values provide more frequent updates but may increase response
* overhead.
*/
partial_images?: number | null;
/**
* The quality of the image that will be generated. GPT-IMAGE-1 supports: auto
* (automatically select best quality), high, medium, low.
*/
quality?: string | null;
/**
* The size of the generated images. GPT-IMAGE-1 supports: auto (automatically
* select best size), 1536x1024 (landscape), 1024x1536 (portrait).
*/
size?: string | null;
/**
* If set to true, partial image data will be streamed as the image is being
* generated. When streaming, the response will be sent as server-sent events with
* partial image chunks. When stream is true, partial_images must be greater
* than 0.
*/
stream?: boolean | null;
/**
* A unique identifier representing your end-user, which can help DigitalOcean to
* monitor and detect abuse.
*/
user?: string | null;
}
export namespace ImageGenerateParams {
export type ImageGenerateParamsNonStreaming = ImagesAPI.ImageGenerateParamsNonStreaming;
export type ImageGenerateParamsStreaming = ImagesAPI.ImageGenerateParamsStreaming;
}
export interface ImageGenerateParamsNonStreaming extends ImageGenerateParamsBase {
/**
* If set to true, partial image data will be streamed as the image is being
* generated. When streaming, the response will be sent as server-sent events with
* partial image chunks. When stream is true, partial_images must be greater
* than 0.
*/
stream?: false | null;
}
export interface ImageGenerateParamsStreaming extends ImageGenerateParamsBase {
/**
* If set to true, partial image data will be streamed as the image is being
* generated. When streaming, the response will be sent as server-sent events with
* partial image chunks. When stream is true, partial_images must be greater
* than 0.
*/
stream: true;
}
export declare namespace Images {
export {
type ImageGenerateResponse as ImageGenerateResponse,
type ImageGenerateParams as ImageGenerateParams,
type ImageGenerateParamsNonStreaming as ImageGenerateParamsNonStreaming,
type ImageGenerateParamsStreaming as ImageGenerateParamsStreaming,
};
}