OpenAI: add gpt-image-1 model
| @@ -930,6 +930,10 @@ const resolutionOptions = { | |||
| 930 | sd_res_768x1344: { width: 768, height: 1344, name: '768x1344 (3:4, SDXL)' }, | 930 | sd_res_768x1344: { width: 768, height: 1344, name: '768x1344 (3:4, SDXL)' }, |
| 931 | sd_res_1536x640: { width: 1536, height: 640, name: '1536x640 (24:10, SDXL)' }, | 931 | sd_res_1536x640: { width: 1536, height: 640, name: '1536x640 (24:10, SDXL)' }, |
| 932 | sd_res_640x1536: { width: 640, height: 1536, name: '640x1536 (10:24, SDXL)' }, | 932 | sd_res_640x1536: { width: 640, height: 1536, name: '640x1536 (10:24, SDXL)' }, |
| 933 | sd_res_1536x1024: { width: 1536, height: 1024, name: '1536x1024 (3:2, ChatGPT)' }, | ||
| 934 | sd_res_1024x1536: { width: 1024, height: 1536, name: '1024x1536 (2:3, ChatGPT)' }, | ||
| 935 | sd_res_1024x1792: { width: 1024, height: 1792, name: '1024x1792 (4:7, DALL-E)' }, | ||
| 936 | sd_res_1792x1024: { width: 1792, height: 1024, name: '1792x1024 (7:4, DALL-E)' }, | ||
| 933 | }; | 937 | }; |
| 934 | 938 | ||
| 935 | function onResolutionChange() { | 939 | function onResolutionChange() { |
| @@ -1947,8 +1951,9 @@ async function loadDrawthingsModels() { | |||
| 1947 | 1951 | ||
| 1948 | async function loadOpenAiModels() { | 1952 | async function loadOpenAiModels() { |
| 1949 | return [ | 1953 | return [ |
| 1950 | { value: 'dall-e-3', text: 'DALL-E 3' }, | 1954 | { value: 'gpt-image-1', text: 'gpt-image-1' }, |
| 1951 | { value: 'dall-e-2', text: 'DALL-E 2' }, | 1955 | { value: 'dall-e-3', text: 'dall-e-3' }, |
| 1956 | { value: 'dall-e-2', text: 'dall-e-2' }, | ||
| 1952 | ]; | 1957 | ]; |
| 1953 | } | 1958 | } |
| 1954 | 1959 | ||
| @@ -3250,9 +3255,11 @@ function getNovelParams() { | |||
| 3250 | async function generateOpenAiImage(prompt, signal) { | 3255 | async function generateOpenAiImage(prompt, signal) { |
| 3251 | const dalle2PromptLimit = 1000; | 3256 | const dalle2PromptLimit = 1000; |
| 3252 | const dalle3PromptLimit = 4000; | 3257 | const dalle3PromptLimit = 4000; |
| 3258 | const gptImgPromptLimit = 32000; | ||
| 3253 | 3259 | ||
| 3254 | const isDalle2 = extension_settings.sd.model === 'dall-e-2'; | 3260 | const isDalle2 = extension_settings.sd.model === 'dall-e-2'; |
| 3255 | const isDalle3 = extension_settings.sd.model === 'dall-e-3'; | 3261 | const isDalle3 = extension_settings.sd.model === 'dall-e-3'; |
| 3262 | const isGptImg = extension_settings.sd.model === 'gpt-image-1'; | ||
| 3256 | 3263 | ||
| 3257 | if (isDalle2 && prompt.length > dalle2PromptLimit) { | 3264 | if (isDalle2 && prompt.length > dalle2PromptLimit) { |
| 3258 | prompt = prompt.substring(0, dalle2PromptLimit); | 3265 | prompt = prompt.substring(0, dalle2PromptLimit); |
| @@ -3262,6 +3269,10 @@ async function generateOpenAiImage(prompt, signal) { | |||
| 3262 | prompt = prompt.substring(0, dalle3PromptLimit); | 3269 | prompt = prompt.substring(0, dalle3PromptLimit); |
| 3263 | } | 3270 | } |
| 3264 | 3271 | ||
| 3272 | if (isGptImg && prompt.length > gptImgPromptLimit) { | ||
| 3273 | prompt = prompt.substring(0, gptImgPromptLimit); | ||
| 3274 | } | ||
| 3275 | |||
| 3265 | let width = 1024; | 3276 | let width = 1024; |
| 3266 | let height = 1024; | 3277 | let height = 1024; |
| 3267 | let aspectRatio = extension_settings.sd.width / extension_settings.sd.height; | 3278 | let aspectRatio = extension_settings.sd.width / extension_settings.sd.height; |
| @@ -3274,6 +3285,14 @@ async function generateOpenAiImage(prompt, signal) { | |||
| 3274 | width = 1792; | 3285 | width = 1792; |
| 3275 | } | 3286 | } |
| 3276 | 3287 | ||
| 3288 | if (isGptImg && aspectRatio < 1) { | ||
| 3289 | height = 1536; | ||
| 3290 | } | ||
| 3291 | |||
| 3292 | if (isGptImg && aspectRatio > 1) { | ||
| 3293 | width = 1536; | ||
| 3294 | } | ||
| 3295 | |||
| 3277 | if (isDalle2 && (extension_settings.sd.width <= 512 && extension_settings.sd.height <= 512)) { | 3296 | if (isDalle2 && (extension_settings.sd.width <= 512 && extension_settings.sd.height <= 512)) { |
| 3278 | width = 512; | 3297 | width = 512; |
| 3279 | height = 512; | 3298 | height = 512; |
| @@ -3290,7 +3309,8 @@ async function generateOpenAiImage(prompt, signal) { | |||
| 3290 | n: 1, | 3309 | n: 1, |
| 3291 | quality: isDalle3 ? extension_settings.sd.openai_quality : undefined, | 3310 | quality: isDalle3 ? extension_settings.sd.openai_quality : undefined, |
| 3292 | style: isDalle3 ? extension_settings.sd.openai_style : undefined, | 3311 | style: isDalle3 ? extension_settings.sd.openai_style : undefined, |
| 3293 | response_format: 'b64_json', | 3312 | response_format: isDalle2 || isDalle3 ? 'b64_json' : undefined, |
| 3313 | moderation: isGptImg ? 'low' : undefined, | ||
| 3294 | }), | 3314 | }), |
| 3295 | }); | 3315 | }); |
| 3296 | 3316 | ||
| @@ -45,7 +45,7 @@ | |||
| 45 | <option value="huggingface">HuggingFace Inference API (serverless)</option> | 45 | <option value="huggingface">HuggingFace Inference API (serverless)</option> |
| 46 | <option value="nanogpt">NanoGPT</option> | 46 | <option value="nanogpt">NanoGPT</option> |
| 47 | <option value="novel">NovelAI Diffusion</option> | 47 | <option value="novel">NovelAI Diffusion</option> |
| 48 | <option value="openai">OpenAI (DALL-E)</option> | 48 | <option value="openai">OpenAI</option> |
| 49 | <option value="pollinations">Pollinations</option> | 49 | <option value="pollinations">Pollinations</option> |
| 50 | <option value="vlad">SD.Next (vladmandic)</option> | 50 | <option value="vlad">SD.Next (vladmandic)</option> |
| 51 | <option value="stability">Stability AI</option> | 51 | <option value="stability">Stability AI</option> |