Skip to main content

Class: OpenAIImageGenerationModel

Create an image generation model that calls the OpenAI AI image creation API.

See

https://platform.openai.com/docs/api-reference/images/create

Example

const image = await generateImage(
new OpenAIImageGenerationModel({ size: "512x512" }),
"the wicked witch of the west in the style of early 19th century painting"
);

Hierarchy

Implements

Accessors

modelInformation

get modelInformation(): ModelInformation

Returns

ModelInformation

Implementation of

ImageGenerationModel.modelInformation

Inherited from

AbstractModel.modelInformation

Defined in

packages/modelfusion/src/model-function/AbstractModel.ts:17


modelName

get modelName(): "dall-e-2" | "dall-e-3"

Returns

"dall-e-2" | "dall-e-3"

Overrides

AbstractModel.modelName

Defined in

packages/modelfusion/src/model-provider/openai/OpenAIImageGenerationModel.ts:55


settingsForEvent

get settingsForEvent(): Partial<OpenAIImageGenerationSettings>

Returns settings that should be recorded in observability events. Security-related settings (e.g. API keys) should not be included here.

Returns

Partial<OpenAIImageGenerationSettings>

Implementation of

ImageGenerationModel.settingsForEvent

Overrides

AbstractModel.settingsForEvent

Defined in

packages/modelfusion/src/model-provider/openai/OpenAIImageGenerationModel.ts:97

Constructors

constructor

new OpenAIImageGenerationModel(settings): OpenAIImageGenerationModel

Parameters

NameType
settingsOpenAIImageGenerationSettings

Returns

OpenAIImageGenerationModel

Overrides

AbstractModel&lt;OpenAIImageGenerationSettings&gt;.constructor

Defined in

packages/modelfusion/src/model-provider/openai/OpenAIImageGenerationModel.ts:50

Methods

callAPI

callAPI<RESULT>(prompt, callOptions, options): Promise<RESULT>

Type parameters

Name
RESULT

Parameters

NameType
promptstring
callOptionsFunctionCallOptions
optionsObject
options.responseFormatOpenAIImageGenerationResponseFormatType<RESULT>

Returns

Promise<RESULT>

Defined in

packages/modelfusion/src/model-provider/openai/OpenAIImageGenerationModel.ts:59


doGenerateImages

doGenerateImages(prompt, options): Promise<{ base64Images: string[] ; rawResponse: { created: number ; data: { b64_json: string }[] } }>

Parameters

NameType
promptstring
optionsFunctionCallOptions

Returns

Promise<{ base64Images: string[] ; rawResponse: { created: number ; data: { b64_json: string }[] } }>

Implementation of

ImageGenerationModel.doGenerateImages

Defined in

packages/modelfusion/src/model-provider/openai/OpenAIImageGenerationModel.ts:112


withPromptTemplate

withPromptTemplate<INPUT_PROMPT>(promptTemplate): PromptTemplateImageGenerationModel<INPUT_PROMPT, string, OpenAIImageGenerationSettings, OpenAIImageGenerationModel>

Type parameters

Name
INPUT_PROMPT

Parameters

NameType
promptTemplatePromptTemplate<INPUT_PROMPT, string>

Returns

PromptTemplateImageGenerationModel<INPUT_PROMPT, string, OpenAIImageGenerationSettings, OpenAIImageGenerationModel>

Implementation of

ImageGenerationModel.withPromptTemplate

Defined in

packages/modelfusion/src/model-provider/openai/OpenAIImageGenerationModel.ts:122


withSettings

withSettings(additionalSettings): OpenAIImageGenerationModel

The withSettings method creates a new model with the same configuration as the original model, but with the specified settings changed.

Parameters

NameType
additionalSettingsPartial<OpenAIImageGenerationSettings>

Returns

OpenAIImageGenerationModel

Example

const model = new OpenAICompletionModel({
model: "gpt-3.5-turbo-instruct",
maxGenerationTokens: 500,
});

const modelWithMoreTokens = model.withSettings({
maxGenerationTokens: 1000,
});

Implementation of

ImageGenerationModel.withSettings

Overrides

AbstractModel.withSettings

Defined in

packages/modelfusion/src/model-provider/openai/OpenAIImageGenerationModel.ts:136

Properties

provider

Readonly provider: "openai"

Overrides

AbstractModel.provider

Defined in

packages/modelfusion/src/model-provider/openai/OpenAIImageGenerationModel.ts:54


settings

Readonly settings: OpenAIImageGenerationSettings

Implementation of

ImageGenerationModel.settings

Inherited from

AbstractModel.settings

Defined in

packages/modelfusion/src/model-function/AbstractModel.ts:7