refac: gpt-image support

This commit is contained in:
Timothy Jaeryang Baek
2025-12-20 17:56:46 +04:00
parent d4bd938a77
commit 4c2e5c93e9

View File

@@ -195,12 +195,12 @@ async def update_config(
set_image_model(request, form_data.IMAGE_GENERATION_MODEL) set_image_model(request, form_data.IMAGE_GENERATION_MODEL)
if ( if (
form_data.IMAGE_SIZE == "auto" form_data.IMAGE_SIZE == "auto"
and form_data.IMAGE_GENERATION_MODEL != "gpt-image-1" and not form_data.IMAGE_GENERATION_MODEL.startswith("gpt-image")
): ):
raise HTTPException( raise HTTPException(
status_code=400, status_code=400,
detail=ERROR_MESSAGES.INCORRECT_FORMAT( detail=ERROR_MESSAGES.INCORRECT_FORMAT(
" (auto is only allowed with gpt-image-1)." " (auto is only allowed with gpt-image models)."
), ),
) )
@@ -379,6 +379,7 @@ def get_models(request: Request, user=Depends(get_verified_user)):
{"id": "dall-e-2", "name": "DALL·E 2"}, {"id": "dall-e-2", "name": "DALL·E 2"},
{"id": "dall-e-3", "name": "DALL·E 3"}, {"id": "dall-e-3", "name": "DALL·E 3"},
{"id": "gpt-image-1", "name": "GPT-IMAGE 1"}, {"id": "gpt-image-1", "name": "GPT-IMAGE 1"},
{"id": "gpt-image-1.5", "name": "GPT-IMAGE 1.5"},
] ]
elif request.app.state.config.IMAGE_GENERATION_ENGINE == "gemini": elif request.app.state.config.IMAGE_GENERATION_ENGINE == "gemini":
return [ return [
@@ -563,7 +564,9 @@ async def image_generations(
), ),
**( **(
{} {}
if "gpt-image-1" in request.app.state.config.IMAGE_GENERATION_MODEL if request.app.state.config.IMAGE_GENERATION_MODEL.startswith(
"gpt-image"
)
else {"response_format": "b64_json"} else {"response_format": "b64_json"}
), ),
**( **(
@@ -866,7 +869,7 @@ async def image_edits(
**({"size": size} if size else {}), **({"size": size} if size else {}),
**( **(
{} {}
if "gpt-image-1" in request.app.state.config.IMAGE_EDIT_MODEL if request.app.state.config.IMAGE_EDIT_MODEL.startswith("gpt-image")
else {"response_format": "b64_json"} else {"response_format": "b64_json"}
), ),
} }