mirror of
https://github.com/hwchase17/langchain.git
synced 2026-06-09 18:50:33 +00:00
fix(openai): correct image resize aspect ratio caps (#34192)
This commit is contained in:
@@ -3529,7 +3529,7 @@ def _resize(width: int, height: int) -> tuple[int, int]:
|
||||
width = (width * 768) // height
|
||||
height = 768
|
||||
else:
|
||||
height = (width * 768) // height
|
||||
height = (height * 768) // width
|
||||
width = 768
|
||||
return width, height
|
||||
|
||||
|
||||
@@ -76,6 +76,7 @@ from langchain_openai.chat_models.base import (
|
||||
_make_computer_call_output_from_message,
|
||||
_model_prefers_responses_api,
|
||||
_oai_structured_outputs_parser,
|
||||
_resize,
|
||||
)
|
||||
|
||||
|
||||
@@ -1068,6 +1069,12 @@ def test__create_usage_metadata_responses() -> None:
|
||||
)
|
||||
|
||||
|
||||
def test__resize_caps_dimensions_preserving_ratio() -> None:
|
||||
"""Larger side capped at 2048 then smaller at 768 keeping aspect ratio."""
|
||||
assert _resize(2048, 4096) == (768, 1536)
|
||||
assert _resize(4096, 2048) == (1536, 768)
|
||||
|
||||
|
||||
def test__convert_to_openai_response_format() -> None:
|
||||
# Test response formats that aren't tool-like.
|
||||
response_format: dict = {
|
||||
|
||||
Reference in New Issue
Block a user