mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-11 03:38:38 +00:00
fix(openrouter): map ImageGenerationRequestQuality members to a gemini tier
litellm.image_generation takes quality as a string or an ImageGenerationRequestQuality member. The tier lookup used str(quality), which gives "ImageGenerationRequestQuality.MEDIUM" for a member, so low, medium, high and auto got no tier on google/ models and quality was dropped. The lookup now uses the value itself, as the chat-based path did
This commit is contained in:
parent
9fe0022696
commit
090d675e3c
2 changed files with 23 additions and 1 deletions
|
|
@ -118,7 +118,8 @@ class OpenRouterImageGenerationConfig(BaseImageGenerationConfig):
|
|||
ratio of an OpenAI pixel size. A tier size or an image_config set by the caller wins
|
||||
"""
|
||||
size: Final = str(mapped_params.get("size") or "")
|
||||
tier: Final = QUALITY_RESOLUTION_TIERS.get(str(mapped_params["quality"]))
|
||||
quality: Final = mapped_params["quality"]
|
||||
tier: Final = QUALITY_RESOLUTION_TIERS.get(quality) if isinstance(quality, str) else None
|
||||
params: Final = {key: value for key, value in mapped_params.items() if key != "quality"}
|
||||
if tier is None or (size and PIXEL_SIZE.fullmatch(size) is None):
|
||||
return params
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ from litellm.llms.openrouter.common_utils import OpenRouterException
|
|||
from litellm.llms.openrouter.image_generation.transformation import (
|
||||
OpenRouterImageGenerationConfig,
|
||||
)
|
||||
from litellm.types.llms.openai import ImageGenerationRequestQuality
|
||||
from litellm.types.utils import ImageResponse, ImageUsage, ImageUsageInputTokensDetails
|
||||
|
||||
CONFIG: Final = OpenRouterImageGenerationConfig()
|
||||
|
|
@ -235,6 +236,26 @@ def test_map_openai_params_quality_tier_yields_to_an_image_config_already_set():
|
|||
assert mapped == {"image_config": {"image_size": "1K"}, "quality": "high", "size": "1536x1024"}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("quality", list(ImageGenerationRequestQuality))
|
||||
def test_map_openai_params_reads_a_quality_enum_member_like_its_string(quality: ImageGenerationRequestQuality):
|
||||
"""litellm.image_generation takes ImageGenerationRequestQuality members as quality"""
|
||||
from_enum = CONFIG.map_openai_params(
|
||||
non_default_params={"quality": quality, "size": "1024x1024"},
|
||||
optional_params={},
|
||||
model=RESOLUTION_TIER_MODEL,
|
||||
drop_params=False,
|
||||
)
|
||||
from_string = CONFIG.map_openai_params(
|
||||
non_default_params={"quality": quality.value, "size": "1024x1024"},
|
||||
optional_params={},
|
||||
model=RESOLUTION_TIER_MODEL,
|
||||
drop_params=False,
|
||||
)
|
||||
|
||||
assert from_enum == from_string
|
||||
assert "image_size" in from_enum["image_config"]
|
||||
|
||||
|
||||
@patch("litellm.llms.openrouter.image_generation.transformation.get_secret_str")
|
||||
def test_validate_environment_with_api_key(mock_get_secret: MagicMock):
|
||||
result = CONFIG.validate_environment(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue