OpenAI: add gpt-image-1 model

This commit is contained in:
Cohee
2025-05-23 20:33:27 +03:00
parent 58832d1a75
commit ed2e6fff6e
2 changed files with 24 additions and 4 deletions

View File

@ -930,6 +930,10 @@ const resolutionOptions = {
sd_res_768x1344: { width: 768, height: 1344, name: '768x1344 (3:4, SDXL)' },
sd_res_1536x640: { width: 1536, height: 640, name: '1536x640 (24:10, SDXL)' },
sd_res_640x1536: { width: 640, height: 1536, name: '640x1536 (10:24, SDXL)' },
sd_res_1536x1024: { width: 1536, height: 1024, name: '1536x1024 (3:2, ChatGPT)' },
sd_res_1024x1536: { width: 1024, height: 1536, name: '1024x1536 (2:3, ChatGPT)' },
sd_res_1024x1792: { width: 1024, height: 1792, name: '1024x1792 (4:7, DALL-E)' },
sd_res_1792x1024: { width: 1792, height: 1024, name: '1792x1024 (7:4, DALL-E)' },
};
function onResolutionChange() {
@ -1947,8 +1951,9 @@ async function loadDrawthingsModels() {
async function loadOpenAiModels() {
return [
{ value: 'dall-e-3', text: 'DALL-E 3' },
{ value: 'dall-e-2', text: 'DALL-E 2' },
{ value: 'gpt-image-1', text: 'gpt-image-1' },
{ value: 'dall-e-3', text: 'dall-e-3' },
{ value: 'dall-e-2', text: 'dall-e-2' },
];
}
@ -3250,9 +3255,11 @@ function getNovelParams() {
async function generateOpenAiImage(prompt, signal) {
const dalle2PromptLimit = 1000;
const dalle3PromptLimit = 4000;
const gptImgPromptLimit = 32000;
const isDalle2 = extension_settings.sd.model === 'dall-e-2';
const isDalle3 = extension_settings.sd.model === 'dall-e-3';
const isGptImg = extension_settings.sd.model === 'gpt-image-1';
if (isDalle2 && prompt.length > dalle2PromptLimit) {
prompt = prompt.substring(0, dalle2PromptLimit);
@ -3262,6 +3269,10 @@ async function generateOpenAiImage(prompt, signal) {
prompt = prompt.substring(0, dalle3PromptLimit);
}
if (isGptImg && prompt.length > gptImgPromptLimit) {
prompt = prompt.substring(0, gptImgPromptLimit);
}
let width = 1024;
let height = 1024;
let aspectRatio = extension_settings.sd.width / extension_settings.sd.height;
@ -3274,6 +3285,14 @@ async function generateOpenAiImage(prompt, signal) {
width = 1792;
}
if (isGptImg && aspectRatio < 1) {
height = 1536;
}
if (isGptImg && aspectRatio > 1) {
width = 1536;
}
if (isDalle2 && (extension_settings.sd.width <= 512 && extension_settings.sd.height <= 512)) {
width = 512;
height = 512;
@ -3290,7 +3309,8 @@ async function generateOpenAiImage(prompt, signal) {
n: 1,
quality: isDalle3 ? extension_settings.sd.openai_quality : undefined,
style: isDalle3 ? extension_settings.sd.openai_style : undefined,
response_format: 'b64_json',
response_format: isDalle2 || isDalle3 ? 'b64_json' : undefined,
moderation: isGptImg ? 'low' : undefined,
}),
});