mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-06 08:16:43 +00:00
fix(image_gen): report the requested output_format on gpt-image responses
This commit is contained in:
parent
e1b2d9de3c
commit
4d3c1998af
2 changed files with 39 additions and 1 deletions
|
|
@ -84,6 +84,6 @@ class GPTImageGenerationConfig(BaseImageGenerationConfig):
|
|||
# set optional params
|
||||
image_response.size = optional_params.get("size", "1024x1024") # default is always 1024x1024
|
||||
image_response.quality = optional_params.get("quality", "high") # always hd for dall-e-3
|
||||
image_response.output_format = optional_params.get("response_format", "png") # always png for dall-e-3
|
||||
image_response.output_format = optional_params.get("output_format", "png")
|
||||
|
||||
return image_response
|
||||
|
|
|
|||
|
|
@ -0,0 +1,38 @@
|
|||
from unittest.mock import MagicMock
|
||||
|
||||
import httpx
|
||||
import pytest
|
||||
|
||||
from litellm.llms.azure.image_generation.gpt_transformation import AzureGPTImageGenerationConfig
|
||||
from litellm.llms.openai.image_generation.gpt_transformation import GPTImageGenerationConfig
|
||||
from litellm.types.utils import ImageResponse
|
||||
|
||||
|
||||
@pytest.mark.parametrize("config", [GPTImageGenerationConfig(), AzureGPTImageGenerationConfig()])
|
||||
def test_transform_image_generation_response_reports_requested_output_format(config):
|
||||
raw_response = httpx.Response(
|
||||
status_code=200,
|
||||
json={
|
||||
"created": 1788457009,
|
||||
"data": [{"b64_json": "/9j/4AAQSkZJRg=="}],
|
||||
"output_format": "jpeg",
|
||||
"background": "opaque",
|
||||
"quality": "low",
|
||||
"size": "1024x1024",
|
||||
},
|
||||
request=httpx.Request("POST", "https://api.openai.com/v1/images/generations"),
|
||||
)
|
||||
|
||||
image_response = config.transform_image_generation_response(
|
||||
model="gpt-image-2",
|
||||
raw_response=raw_response,
|
||||
model_response=ImageResponse(),
|
||||
logging_obj=MagicMock(),
|
||||
request_data={"prompt": "a red apple", "output_format": "jpeg"},
|
||||
optional_params={"output_format": "jpeg"},
|
||||
litellm_params={},
|
||||
encoding=None,
|
||||
)
|
||||
|
||||
assert image_response.output_format == "jpeg"
|
||||
assert image_response.background == "opaque"
|
||||
Loading…
Add table
Reference in a new issue