From 200f58c1e74dac57d303561518251a96a321de5f Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Sat, 20 Apr 2024 08:26:08 -0700 Subject: [PATCH] (fix) missing PIL import --- litellm/llms/prompt_templates/factory.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/litellm/llms/prompt_templates/factory.py b/litellm/llms/prompt_templates/factory.py index 52589d2de..176c81d5d 100644 --- a/litellm/llms/prompt_templates/factory.py +++ b/litellm/llms/prompt_templates/factory.py @@ -1122,12 +1122,6 @@ def _gemini_vision_convert_messages(messages: list): Returns: tuple: A tuple containing the prompt (a string) and the processed images (a list of objects representing the images). """ - try: - from PIL import Image - except: - raise Exception( - "gemini image conversion failed please run `pip install Pillow`" - ) try: # given messages for gpt-4 vision, convert them for gemini @@ -1154,6 +1148,12 @@ def _gemini_vision_convert_messages(messages: list): image = _load_image_from_url(img) processed_images.append(image) else: + try: + from PIL import Image + except: + raise Exception( + "gemini image conversion failed please run `pip install Pillow`" + ) # Case 2: Image filepath (e.g. temp.jpeg) given image = Image.open(img) processed_images.append(image)