mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-25 01:02:15 +00:00
fix: align ChatGPT image edit drop params behavior
This commit is contained in:
parent
e9094c1907
commit
db3eda4bb9
2 changed files with 67 additions and 12 deletions
|
|
@ -30,7 +30,10 @@ class ChatGPTImageEditConfig(BaseImageEditConfig):
|
|||
self.image_generation_config = ChatGPTImageGenerationConfig()
|
||||
|
||||
def get_supported_openai_params(self, model: str) -> List[str]:
|
||||
return ["size"]
|
||||
return [
|
||||
str(param)
|
||||
for param in self.image_generation_config.get_supported_openai_params(model)
|
||||
]
|
||||
|
||||
def map_openai_params(
|
||||
self,
|
||||
|
|
@ -39,11 +42,19 @@ class ChatGPTImageEditConfig(BaseImageEditConfig):
|
|||
drop_params: bool,
|
||||
) -> Dict[str, Any]:
|
||||
supported_params = self.get_supported_openai_params(model)
|
||||
return {
|
||||
key: value
|
||||
for key, value in image_edit_optional_params.items()
|
||||
if key in supported_params
|
||||
}
|
||||
mapped_params: Dict[str, Any] = {}
|
||||
for key, value in image_edit_optional_params.items():
|
||||
if key in supported_params:
|
||||
mapped_params[key] = value
|
||||
elif drop_params:
|
||||
continue
|
||||
else:
|
||||
raise ValueError(
|
||||
f"Parameter {key} is not supported for model {model}. "
|
||||
f"Supported parameters are {supported_params}. "
|
||||
"Set drop_params=True to drop unsupported parameters."
|
||||
)
|
||||
return mapped_params
|
||||
|
||||
def validate_environment(
|
||||
self,
|
||||
|
|
|
|||
|
|
@ -100,12 +100,6 @@ def test_chatgpt_image_edit_delegates_environment_and_url():
|
|||
|
||||
config.image_generation_config = cast(Any, FakeImageGenerationConfig())
|
||||
|
||||
assert config.get_supported_openai_params("gpt-image-2") == ["size"]
|
||||
assert config.map_openai_params(
|
||||
image_edit_optional_params={"size": "1024x1024", "quality": "high"},
|
||||
model="gpt-image-2",
|
||||
drop_params=False,
|
||||
) == {"size": "1024x1024"}
|
||||
assert config.validate_environment(
|
||||
headers={},
|
||||
model="gpt-image-2",
|
||||
|
|
@ -123,6 +117,56 @@ def test_chatgpt_image_edit_delegates_environment_and_url():
|
|||
)
|
||||
|
||||
|
||||
def test_chatgpt_image_edit_supports_image_generation_params():
|
||||
config = ChatGPTImageEditConfig()
|
||||
|
||||
assert config.get_supported_openai_params("gpt-image-2") == [
|
||||
"output_format",
|
||||
"size",
|
||||
]
|
||||
assert config.map_openai_params(
|
||||
image_edit_optional_params={
|
||||
"output_format": "png",
|
||||
"size": "1024x1024",
|
||||
},
|
||||
model="gpt-image-2",
|
||||
drop_params=False,
|
||||
) == {
|
||||
"output_format": "png",
|
||||
"size": "1024x1024",
|
||||
}
|
||||
|
||||
|
||||
def test_chatgpt_image_edit_drops_unsupported_params_when_requested():
|
||||
config = ChatGPTImageEditConfig()
|
||||
|
||||
assert config.map_openai_params(
|
||||
image_edit_optional_params={
|
||||
"output_format": "png",
|
||||
"size": "1024x1024",
|
||||
"quality": "high",
|
||||
"n": 2,
|
||||
},
|
||||
model="gpt-image-2",
|
||||
drop_params=True,
|
||||
) == {
|
||||
"output_format": "png",
|
||||
"size": "1024x1024",
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("param", ["quality", "n"])
|
||||
def test_chatgpt_image_edit_rejects_unsupported_params_by_default(param):
|
||||
config = ChatGPTImageEditConfig()
|
||||
|
||||
with pytest.raises(ValueError, match=f"Parameter {param} is not supported"):
|
||||
config.map_openai_params(
|
||||
image_edit_optional_params={param: "unsupported"},
|
||||
model="gpt-image-2",
|
||||
drop_params=False,
|
||||
)
|
||||
|
||||
|
||||
def test_chatgpt_image_edit_transform_response_and_error_class():
|
||||
config = ChatGPTImageEditConfig()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue