mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-09 03:18:44 +00:00
fix(azure-ai): coerce FLUX controls and preserve response dimensions
This commit is contained in:
parent
3821e5ace6
commit
4595b4f62f
4 changed files with 34 additions and 4 deletions
|
|
@ -85,6 +85,11 @@ class AzureFoundryFluxImageGenerationConfig(GPTImageGenerationConfig):
|
|||
|
||||
@staticmethod
|
||||
def _map_parameter(name: str, value: object) -> tuple[tuple[str, object], ...]:
|
||||
if isinstance(value, str):
|
||||
if name in ("n", "num_images", "width", "height", "steps", "seed", "safety_tolerance"):
|
||||
return (("num_images" if name == "n" else name, int(value)),)
|
||||
if name == "guidance":
|
||||
return ((name, float(value)),)
|
||||
if name == "n":
|
||||
return (("num_images", value),)
|
||||
if name != "size":
|
||||
|
|
|
|||
|
|
@ -82,7 +82,14 @@ class GPTImageGenerationConfig(BaseImageGenerationConfig):
|
|||
)
|
||||
|
||||
# set optional params
|
||||
image_response.size = image_response.size or optional_params.get("size", "1024x1024")
|
||||
width: Final = optional_params.get("width")
|
||||
height: Final = optional_params.get("height")
|
||||
requested_size: Final = (
|
||||
f"{width}x{height}"
|
||||
if isinstance(width, int) and isinstance(height, int)
|
||||
else optional_params.get("size", "1024x1024")
|
||||
)
|
||||
image_response.size = image_response.size or requested_size
|
||||
image_response.quality = image_response.quality or optional_params.get("quality", "high")
|
||||
image_response.output_format = image_response.output_format or optional_params.get("output_format", "png")
|
||||
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ def test_flux2_image_edit_rejects_too_many_references(model: str, reference_imag
|
|||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("dimensions", ({"size": "2048x1024"}, {"width": 2048, "height": 1024}))
|
||||
@pytest.mark.parametrize("dimensions", ({"size": "2048x1024"}, {"width": 2048, "height": 1024}, {"width": "2048", "height": "1024"}))
|
||||
@pytest.mark.usefixtures("local_model_cost_map")
|
||||
def test_flux2_image_edit_preserves_controls_and_pixel_cost(dimensions: Mapping[str, int | str]):
|
||||
def respond(request: httpx.Request) -> httpx.Response:
|
||||
|
|
@ -170,8 +170,8 @@ def test_flux2_image_edit_preserves_controls_and_pixel_cost(dimensions: Mapping[
|
|||
api_base="https://example.services.ai.azure.com",
|
||||
client=client,
|
||||
n=2,
|
||||
guidance=4.5,
|
||||
steps=32,
|
||||
guidance="4.5",
|
||||
steps="32",
|
||||
**dimensions,
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -170,3 +170,21 @@ def test_flux2_cost_uses_mapped_dimensions_after_response_transformation(dimensi
|
|||
optional_params=params,
|
||||
call_type="image_generation",
|
||||
) == pytest.approx(5e-08 * 2048 * 1024 * 2)
|
||||
|
||||
|
||||
def test_flux2_response_preserves_mapped_dimensions():
|
||||
config = AzureFoundryFluxImageGenerationConfig()
|
||||
params = config.map_openai_params(
|
||||
non_default_params={"size": "2048x1024"}, optional_params={}, model="FLUX.2-flex", drop_params=False
|
||||
)
|
||||
response = config.transform_image_generation_response(
|
||||
model="FLUX.2-flex",
|
||||
raw_response=httpx.Response(200, json={"data": [{"b64_json": "aW1n"}]}),
|
||||
model_response=ImageResponse(),
|
||||
logging_obj=MagicMock(),
|
||||
request_data={"prompt": "A landscape"},
|
||||
optional_params=params,
|
||||
litellm_params={},
|
||||
encoding=None,
|
||||
)
|
||||
assert response.size == "2048x1024"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue