openai
Version:
The official TypeScript library for the OpenAI API
60 lines • 3.06 kB
JavaScript
// File generated from our OpenAPI spec by Castiron. See CONTRIBUTING.md for details.
import { APIResource } from "../core/resource.mjs";
import { multipartFormRequestOptions } from "../internal/uploads.mjs";
function resolveResourceRequestOptions(options, buildOptions) {
return Promise.resolve(options).then(buildOptions);
}
function withBodyFinalization(options, finalization) {
return { ...options, __metadata: { ...options.__metadata, ...finalization } };
}
/**
* Given a prompt and/or an input image, the model will generate a new image.
*/
export class Images extends APIResource {
/**
* This endpoint is retired and no longer available. Use the image edits endpoint
* with a GPT Image model and a prompt to create a variation of an image. The
* request and response schemas below describe the legacy contract.
*
* @deprecated
*/
createVariation(body, options) {
return this._client.post('/images/variations', resolveResourceRequestOptions(options, (options) => multipartFormRequestOptions({ body, ...options, __security: { bearerAuth: true } }, this._client)));
}
edit(body, options) {
return this._client.post('/images/edits', resolveResourceRequestOptions(options, (options) => multipartFormRequestOptions(withBodyFinalization(((requestOptions) => {
const omitNulls = (value, paths) => {
if (value === null || typeof value !== 'object' || Array.isArray(value))
return value;
return Object.fromEntries(Object.entries(value).map(([key, field]) => {
const selected = paths.filter((path) => path[0] === key);
if (field === null && selected.some((path) => path.length === 1))
return [key, undefined];
const children = selected.filter((path) => path.length > 1).map((path) => path.slice(1));
return [key, children.length === 0 ? field : omitNulls(field, children)];
}));
};
return {
...requestOptions,
body: omitNulls(requestOptions.body ?? {}, [
['safety_identifier'],
['complexity'],
['frame_count'],
['frame_duration_ms'],
['svg'],
['svg', 'reasoning'],
]),
};
})({
body,
...options,
stream: body.stream ?? false,
__metadata: { ...options?.__metadata, ...(body.model == null ? {} : { model: body.model }) },
__security: { bearerAuth: true },
}), { streamFromBody: true }), this._client)));
}
generate(body, options) {
return this._client.post('/images/generations', resolveResourceRequestOptions(options, (options) => withBodyFinalization({ body, ...options, stream: body.stream ?? false, __security: { bearerAuth: true } }, { streamFromBody: true })));
}
}
//# sourceMappingURL=images.mjs.map