mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-05 08:07:05 +00:00
fix(images): forward gpt-image supported params like background to OpenAI and Azure
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
658f50663d
commit
e1b2d9de3c
4 changed files with 48 additions and 4 deletions
|
|
@ -2543,6 +2543,7 @@ class ImageResponse(OpenAIImageResponse, BaseLiteLLMOpenAIResponseObject):
|
|||
)
|
||||
super().__init__(created=created, data=_data, usage=_usage)
|
||||
|
||||
self.background = kwargs.get("background", None)
|
||||
self.quality = kwargs.get("quality", None)
|
||||
self.output_format = kwargs.get("output_format", None)
|
||||
self.size = kwargs.get("size", None)
|
||||
|
|
|
|||
|
|
@ -3338,6 +3338,9 @@ def get_optional_params_image_gen(
|
|||
continue
|
||||
passed_params[k] = v
|
||||
|
||||
provider_supported_params: Final[tuple[str, ...]] = (
|
||||
tuple(provider_config.get_supported_openai_params(model=model or "")) if provider_config is not None else ()
|
||||
)
|
||||
default_params: Final = {
|
||||
"n": None,
|
||||
"quality": None,
|
||||
|
|
@ -3348,6 +3351,7 @@ def get_optional_params_image_gen(
|
|||
"imageConfig": None,
|
||||
"tools": None,
|
||||
"web_search_options": None,
|
||||
**{k: None for k in provider_supported_params},
|
||||
}
|
||||
|
||||
non_default_params: Final = _get_non_default_params(
|
||||
|
|
@ -3407,10 +3411,9 @@ def get_optional_params_image_gen(
|
|||
if size is not None:
|
||||
optional_params["aspectRatio"] = _map_openai_size_to_vertex_ai_aspect_ratio(size)
|
||||
|
||||
openai_params: list[str] = list(default_params.keys())
|
||||
if provider_config is not None:
|
||||
supported_params = provider_config.get_supported_openai_params(model=model or "")
|
||||
openai_params = list(supported_params)
|
||||
openai_params: Final[list[str]] = (
|
||||
list(provider_supported_params) if provider_config is not None else list(default_params.keys())
|
||||
)
|
||||
|
||||
optional_params = add_provider_specific_params_to_optional_params(
|
||||
optional_params=optional_params,
|
||||
|
|
|
|||
|
|
@ -330,6 +330,37 @@ def test_get_optional_params_image_gen():
|
|||
assert optional_params["n"] == 3
|
||||
|
||||
|
||||
@pytest.mark.parametrize("custom_llm_provider", ["openai", "azure"])
|
||||
def test_get_optional_params_image_gen_keeps_gpt_image_supported_params(custom_llm_provider):
|
||||
"""https://github.com/BerriAI/litellm/issues/38649"""
|
||||
from litellm.types.utils import LlmProviders
|
||||
|
||||
provider_config = ProviderConfigManager.get_provider_image_generation_config(
|
||||
model="gpt-image-2", provider=LlmProviders(custom_llm_provider)
|
||||
)
|
||||
optional_params = get_optional_params_image_gen(
|
||||
model="gpt-image-2",
|
||||
n=1,
|
||||
size="1024x1024",
|
||||
custom_llm_provider=custom_llm_provider,
|
||||
provider_config=provider_config,
|
||||
background="transparent",
|
||||
output_format="png",
|
||||
moderation="low",
|
||||
output_compression=50,
|
||||
unknown_param="kept-in-extra-body",
|
||||
)
|
||||
assert optional_params == {
|
||||
"n": 1,
|
||||
"size": "1024x1024",
|
||||
"background": "transparent",
|
||||
"output_format": "png",
|
||||
"moderation": "low",
|
||||
"output_compression": 50,
|
||||
"extra_body": {"unknown_param": "kept-in-extra-body"},
|
||||
}
|
||||
|
||||
|
||||
def test_get_optional_params_image_gen_vertex_ai_size():
|
||||
"""Test that Vertex AI image generation properly handles size parameter and maps it to aspectRatio"""
|
||||
# Test with various size parameters
|
||||
|
|
|
|||
|
|
@ -759,3 +759,12 @@ def test_delta_function_tool_call_unchanged_by_custom_support():
|
|||
delta = Delta(tool_calls=[{"index": 0, "id": "c2", "type": "function", "function": {"name": "g", "arguments": ""}}])
|
||||
assert isinstance(delta.tool_calls[0], ChatCompletionDeltaToolCall)
|
||||
assert "custom" not in delta.model_dump()["tool_calls"][0]
|
||||
|
||||
|
||||
def test_image_response_keeps_background():
|
||||
"""https://github.com/BerriAI/litellm/issues/38649"""
|
||||
from litellm.types.utils import ImageResponse
|
||||
|
||||
response = ImageResponse(created=1, data=[{"b64_json": "aGk="}], background="transparent", output_format="png")
|
||||
assert response.background == "transparent"
|
||||
assert response.model_dump()["background"] == "transparent"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue