diff --git a/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py b/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py index ba57c8d225..d4c74f4910 100644 --- a/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py +++ b/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py @@ -587,14 +587,15 @@ class VertexGeminiConfig(VertexAIBaseConfig, BaseConfig): _content_str += "data:{};base64,{}".format( part["inlineData"]["mimeType"], part["inlineData"]["data"] ) - if part.get("thought") is True: - if reasoning_content_str is None: - reasoning_content_str = "" - reasoning_content_str += _content_str - else: - if content_str is None: - content_str = "" - content_str += _content_str + if len(_content_str) > 0: + if part.get("thought") is True: + if reasoning_content_str is None: + reasoning_content_str = "" + reasoning_content_str += _content_str + else: + if content_str is None: + content_str = "" + content_str += _content_str return content_str, reasoning_content_str diff --git a/tests/litellm/llms/vertex_ai/gemini/test_vertex_and_google_ai_studio_gemini.py b/tests/litellm/llms/vertex_ai/gemini/test_vertex_and_google_ai_studio_gemini.py index bb00ff3ba0..0c6a95a97b 100644 --- a/tests/litellm/llms/vertex_ai/gemini/test_vertex_and_google_ai_studio_gemini.py +++ b/tests/litellm/llms/vertex_ai/gemini/test_vertex_and_google_ai_studio_gemini.py @@ -239,3 +239,23 @@ def test_vertex_ai_thinking_output_part(): content, reasoning_content = v.get_assistant_content_message(parts=parts) assert content == "Hello world" assert reasoning_content == "I'm thinking..." + + +def test_vertex_ai_empty_content(): + from litellm.llms.vertex_ai.gemini.vertex_and_google_ai_studio_gemini import ( + VertexGeminiConfig, + ) + from litellm.types.llms.vertex_ai import HttpxPartType + + v = VertexGeminiConfig() + parts = [ + HttpxPartType( + functionCall={ + "name": "get_current_weather", + "arguments": "{}", + }, + ), + ] + content, reasoning_content = v.get_assistant_content_message(parts=parts) + assert content is None + assert reasoning_content is None