|
14 | 14 | from fastapi import APIRouter, Depends, HTTPException, Request, UploadFile |
15 | 15 | from fastapi.responses import FileResponse |
16 | 16 |
|
17 | | -from open_webui.config import CACHE_DIR |
| 17 | +from open_webui.config import CACHE_DIR, IMAGE_AUTO_SIZE_MODELS_REGEX_PATTERN, IMAGE_URL_RESPONSE_MODELS_REGEX_PATTERN |
18 | 18 | from open_webui.constants import ERROR_MESSAGES |
19 | 19 | from open_webui.retrieval.web.utils import validate_url |
20 | 20 | from open_webui.env import ENABLE_FORWARD_USER_INFO_HEADERS |
@@ -201,12 +201,12 @@ async def update_config( |
201 | 201 | set_image_model(request, form_data.IMAGE_GENERATION_MODEL) |
202 | 202 | if ( |
203 | 203 | form_data.IMAGE_SIZE == "auto" |
204 | | - and not form_data.IMAGE_GENERATION_MODEL.startswith("gpt-image") |
| 204 | + and not re.match(IMAGE_AUTO_SIZE_MODELS_REGEX_PATTERN, form_data.IMAGE_GENERATION_MODEL) |
205 | 205 | ): |
206 | 206 | raise HTTPException( |
207 | 207 | status_code=400, |
208 | 208 | detail=ERROR_MESSAGES.INCORRECT_FORMAT( |
209 | | - " (auto is only allowed with gpt-image models)." |
| 209 | + f" (auto is only allowed with models matching {IMAGE_AUTO_SIZE_MODELS_REGEX_PATTERN})." |
210 | 210 | ), |
211 | 211 | ) |
212 | 212 |
|
@@ -610,9 +610,7 @@ async def image_generations( |
610 | 610 | ), |
611 | 611 | **( |
612 | 612 | {} |
613 | | - if request.app.state.config.IMAGE_GENERATION_MODEL.startswith( |
614 | | - "gpt-image" |
615 | | - ) |
| 613 | + if re.match(IMAGE_URL_RESPONSE_MODELS_REGEX_PATTERN, request.app.state.config.IMAGE_GENERATION_MODEL) |
616 | 614 | else {"response_format": "b64_json"} |
617 | 615 | ), |
618 | 616 | **( |
@@ -949,7 +947,7 @@ def get_image_file_item(base64_string, param_name="image"): |
949 | 947 | **({"size": size} if size else {}), |
950 | 948 | **( |
951 | 949 | {} |
952 | | - if request.app.state.config.IMAGE_EDIT_MODEL.startswith("gpt-image") |
| 950 | + if re.match(IMAGE_URL_RESPONSE_MODELS_REGEX_PATTERN, request.app.state.config.IMAGE_EDIT_MODEL) |
953 | 951 | else {"response_format": "b64_json"} |
954 | 952 | ), |
955 | 953 | } |
|
0 commit comments