Skip to content

Possible error in "_resize" function from langchain_openai.chat_models.base: wrong "new height" when width < height #34191

@gabrielagu

Description

@gabrielagu

Checked other resources

  • This is a bug, not a usage question.
  • I added a clear and descriptive title that summarizes this issue.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
  • This is not related to the langchain-community package.
  • I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.

Package (Required)

  • langchain
  • langchain-openai
  • langchain-anthropic
  • langchain-classic
  • langchain-core
  • langchain-cli
  • langchain-model-profiles
  • langchain-tests
  • langchain-text-splitters
  • langchain-chroma
  • langchain-deepseek
  • langchain-exa
  • langchain-fireworks
  • langchain-groq
  • langchain-huggingface
  • langchain-mistralai
  • langchain-nomic
  • langchain-ollama
  • langchain-perplexity
  • langchain-prompty
  • langchain-qdrant
  • langchain-xai
  • Other / not sure / general

Example Code (Python)

from langchain_openai.chat_models.base import _resize

result = _resize(width=2048, height=4096)
print(result)

Error Message and Stack Trace (if applicable)

Description

From what I understand reading the documentation from openai, the result should be "(768, 1536)", but is returning "(768, 384)" instead.

Probably the function should be:

def _resize(width: int, height: int) -> tuple[int, int]:
    # larger side must be <= 2048
    if width > 2048 or height > 2048:
        if width > height:
            height = (height * 2048) // width
            width = 2048
        else:
            width = (width * 2048) // height
            height = 2048
    # smaller side must be <= 768
    if width > 768 and height > 768:
        if width > height:
            width = (width * 768) // height
            height = 768
        else:
           # height = (width * 768) // height  # Current version
           height = (height * 768) // width  # Correction
            width = 768
    return width, height

System Info

System Information

OS: Linux
OS Version: #132-Ubuntu SMP Thu Aug 29 13:45:52 UTC 2024
Python Version: 3.11.4 (main, Jun 13 2023, 15:34:37) [GCC 8.3.0]

Package Information

langchain_core: 1.1.0
langchain: 1.1.0
langsmith: 0.4.6
langchain_openai: 1.1.0
langchain_text_splitters: 0.3.8
langgraph_sdk: 0.2.12
langserve: 0.3.1

Other Dependencies

fastapi: 0.116.1
httpx: 0.27.2
jsonpatch: 1.33
langgraph: 1.0.4
openai: 2.8.1
opentelemetry-api: 1.38.0
opentelemetry-exporter-otlp-proto-http: 1.38.0
opentelemetry-sdk: 1.38.0
orjson: 3.11.0
packaging: 25.0
pydantic: 2.11.7
pyyaml: 6.0.2
requests: 2.32.4
requests-toolbelt: 1.0.0
rich: 14.2.0
tenacity: 9.1.2
tiktoken: 0.8.0
typing-extensions: 4.14.1
zstandard: 0.23.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugRelated to a bug, vulnerability, unexpected error with an existing featureopenai

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions