From ddd7ecc1adcb983d6248dd35abc2f0dba195092b Mon Sep 17 00:00:00 2001 From: Pawan-Shahane Date: Sat, 19 Sep 2026 23:39:56 +0530 Subject: [PATCH] fix(ollama): address Greptile findings on image conversion Catch all exceptions on Pillow import, not just ImportError, so the helpful install hint always appears. Break a line that exceeded 120 characters --- litellm/llms/ollama/common_utils.py | 2 +- .../llms/ollama/test_ollama_completion_transformation.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/litellm/llms/ollama/common_utils.py b/litellm/llms/ollama/common_utils.py index 6237c641a71..9f46cbc5cd5 100644 --- a/litellm/llms/ollama/common_utils.py +++ b/litellm/llms/ollama/common_utils.py @@ -19,7 +19,7 @@ _JPEG_AND_PNG_SIGNATURES: Final = (b"\xff\xd8\xff", b"\x89PNG\r\n\x1a\n") def _reencode_as_jpeg(raw_image: bytes, original: str) -> str: try: from PIL import Image - except ImportError: + except Exception: raise Exception("ollama image conversion failed please run `pip install Pillow`") try: diff --git a/tests/test_litellm/llms/ollama/test_ollama_completion_transformation.py b/tests/test_litellm/llms/ollama/test_ollama_completion_transformation.py index 60cdcf62cca..28e86e40944 100644 --- a/tests/test_litellm/llms/ollama/test_ollama_completion_transformation.py +++ b/tests/test_litellm/llms/ollama/test_ollama_completion_transformation.py @@ -565,7 +565,10 @@ def _transform_image_request(image_base64: str, mime_subtype: str) -> dict: "role": "user", "content": [ {"type": "text", "text": "What colour is this?"}, - {"type": "image_url", "image_url": {"url": f"data:image/{mime_subtype};base64,{image_base64}"}}, + { + "type": "image_url", + "image_url": {"url": f"data:image/{mime_subtype};base64,{image_base64}"}, + }, ], } ],