From b918f5826229a538f90414cc02c4da2bf5b57627 Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Wed, 24 Apr 2024 09:23:15 -0700 Subject: [PATCH] fix(vertex_ai.py): raise explicit error when image url fails to download - prevents silent failure --- litellm/llms/vertex_ai.py | 9 +++++---- litellm/utils.py | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/litellm/llms/vertex_ai.py b/litellm/llms/vertex_ai.py index 62ab971f7..99f8e0a26 100644 --- a/litellm/llms/vertex_ai.py +++ b/litellm/llms/vertex_ai.py @@ -225,8 +225,7 @@ def _get_image_bytes_from_url(image_url: str) -> bytes: image_bytes = response.content return image_bytes except requests.exceptions.RequestException as e: - # Handle any request exceptions (e.g., connection error, timeout) - return b"" # Return an empty bytes object or handle the error as needed + raise Exception(f"An exception occurs with this image - {str(e)}") def _load_image_from_url(image_url: str): @@ -247,7 +246,8 @@ def _load_image_from_url(image_url: str): ) image_bytes = _get_image_bytes_from_url(image_url) - return Image.from_bytes(image_bytes) + + return Image.from_bytes(data=image_bytes) def _gemini_vision_convert_messages(messages: list): @@ -817,7 +817,7 @@ async def async_completion( """ try: if mode == "vision": - print_verbose("\nMaking VertexAI Gemini Pro Vision Call") + print_verbose("\nMaking VertexAI Gemini Pro/Vision Call") print_verbose(f"\nProcessing input messages = {messages}") tools = optional_params.pop("tools", None) @@ -836,6 +836,7 @@ async def async_completion( ) ## LLM Call + # print(f"final content: {content}") response = await llm_model._generate_content_async( contents=content, generation_config=optional_params, diff --git a/litellm/utils.py b/litellm/utils.py index cb8eb52e1..fa72c323b 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -5930,6 +5930,7 @@ def get_llm_provider( or model in litellm.vertex_code_text_models or model in litellm.vertex_language_models or model in litellm.vertex_embedding_models + or model in litellm.vertex_vision_models ): custom_llm_provider = "vertex_ai" ## ai21