diff --git a/litellm/llms/prompt_templates/factory.py b/litellm/llms/prompt_templates/factory.py index d86c19c5cb5..41ecb486ce7 100644 --- a/litellm/llms/prompt_templates/factory.py +++ b/litellm/llms/prompt_templates/factory.py @@ -126,7 +126,7 @@ def convert_to_ollama_image(openai_image_url: str): else: base64_data = openai_image_url - return base64_data; + return base64_data except Exception as e: if "Error: Unable to fetch image from URL" in str(e): raise e @@ -134,6 +134,7 @@ def convert_to_ollama_image(openai_image_url: str): """Image url not in expected format. Example Expected input - "image_url": "data:image/jpeg;base64,{base64_image}". """ ) + def ollama_pt( model, messages ): # https://github.com/ollama/ollama/blob/af4cf55884ac54b9e637cd71dadfe9b7a5685877/docs/modelfile.md#template @@ -166,7 +167,9 @@ def ollama_pt( if element["type"] == "text": prompt += element["text"] elif element["type"] == "image_url": - base64_image = convert_to_ollama_image(element["image_url"]["url"]) + base64_image = convert_to_ollama_image( + element["image_url"]["url"] + ) images.append(base64_image) return {"prompt": prompt, "images": images} else: @@ -1528,11 +1531,12 @@ def _gemini_vision_convert_messages(messages: list): raise Exception( "gemini image conversion failed please run `pip install Pillow`" ) - + if "base64" in img: # Case 2: Base64 image data import base64 import io + # Extract the base64 image data base64_data = img.split("base64,")[1]