diff --git a/litellm/proxy/image_endpoints/endpoints.py b/litellm/proxy/image_endpoints/endpoints.py index c6b7e3d5468..4dc147b6687 100644 --- a/litellm/proxy/image_endpoints/endpoints.py +++ b/litellm/proxy/image_endpoints/endpoints.py @@ -1,6 +1,8 @@ import asyncio import io from collections.abc import Sequence +from itertools import chain +from types import MappingProxyType from typing import Final, get_type_hints import orjson @@ -36,6 +38,7 @@ from litellm.types.llms.openai import ChatCompletionUserMessage router: Final = APIRouter() IMAGE_EDIT_NUMERIC_FORM_FIELDS: Final = numeric_form_fields(get_type_hints(ImageEditRequestParams)) +IMAGE_EDIT_OPTIONAL_FIELD_DEFAULTS: Final = MappingProxyType({"prompt": None, "image": None}) IMAGE_ARRAY_FIELD: Final = "image[]" MASK_ARRAY_FIELD: Final = "mask[]" @@ -299,9 +302,9 @@ async def image_edit_api( numeric_fields=IMAGE_EDIT_NUMERIC_FORM_FIELDS, ) data: Final = { - "prompt": None, - "image": None, - **{key: value for key, value in form_fields.items() if key not in BRACKETED_FILE_FIELDS}, + key: value + for key, value in chain(IMAGE_EDIT_OPTIONAL_FIELD_DEFAULTS.items(), form_fields.items()) + if key not in BRACKETED_FILE_FIELDS } image_files: Final = await batch_to_bytesio(image) mask_files: Final = await batch_to_bytesio(mask) diff --git a/tests/test_litellm/proxy/batches_endpoints/test_endpoints.py b/tests/test_litellm/proxy/batches_endpoints/test_endpoints.py index 2d597abf3b8..f2422d4d22e 100644 --- a/tests/test_litellm/proxy/batches_endpoints/test_endpoints.py +++ b/tests/test_litellm/proxy/batches_endpoints/test_endpoints.py @@ -1034,6 +1034,7 @@ def _raw_batches_request(body: Dict[str, Any]) -> MagicMock: request.url.__str__.return_value = "http://localhost/v1/batches" request.url.path = "/v1/batches" request.method = "POST" + request.scope = {"type": "http", "path": "/v1/batches", "method": "POST"} request.query_params = {} request.headers = {"Content-Type": "application/json"} request.client = MagicMock() diff --git a/tests/unit/proxy/google_endpoints/test_google_endpoint_routing.py b/tests/unit/proxy/google_endpoints/test_google_endpoint_routing.py index 3dcfede92ea..b19678ffb59 100644 --- a/tests/unit/proxy/google_endpoints/test_google_endpoint_routing.py +++ b/tests/unit/proxy/google_endpoints/test_google_endpoint_routing.py @@ -39,6 +39,7 @@ def mock_request(request): mock_req.headers = Headers({"content-type": "application/json"}) mock_req.method = "POST" mock_req.url.path = request.param.get("path") + mock_req.scope = {"type": "http", "path": request.param.get("path"), "method": "POST"} async def mock_body(): return json.dumps(request.param.get("payload", {})).encode("utf-8")