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
-
AbstractModel
<OpenAIImageGenerationSettings
>↳
OpenAIImageGenerationModel
Implements
Accessors
modelInformation
• get
modelInformation(): ModelInformation
Returns
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
Name | Type |
---|---|
settings | OpenAIImageGenerationSettings |
Returns
Overrides
AbstractModel<OpenAIImageGenerationSettings>.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
Name | Type |
---|---|
prompt | string |
callOptions | FunctionCallOptions |
options | Object |
options.responseFormat | OpenAIImageGenerationResponseFormatType <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
Name | Type |
---|---|
prompt | string |
options | FunctionCallOptions |
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
Name | Type |
---|---|
promptTemplate | PromptTemplate <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
Name | Type |
---|---|
additionalSettings | Partial <OpenAIImageGenerationSettings > |
Returns
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
Inherited from
AbstractModel.settings