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 63955cec1bf..1c13af7b03c 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 @@ -3014,7 +3014,13 @@ class ModelResponseIterator: hasattr(choice, "finish_reason") and choice.finish_reason == "stop" and hasattr(choice, "delta") - and (choice.delta is None or not choice.delta.tool_calls) + and ( + choice.delta is None + or ( + not choice.delta.tool_calls + and choice.delta.content is None + ) + ) ): choice.finish_reason = "tool_calls" diff --git a/tests/test_litellm/llms/vertex_ai/gemini/test_vertex_gemini_unbound_local_error.py b/tests/test_litellm/llms/vertex_ai/gemini/test_vertex_gemini_unbound_local_error.py index 23e16871c96..8722942dab0 100644 --- a/tests/test_litellm/llms/vertex_ai/gemini/test_vertex_gemini_unbound_local_error.py +++ b/tests/test_litellm/llms/vertex_ai/gemini/test_vertex_gemini_unbound_local_error.py @@ -13,7 +13,6 @@ Ref: https://github.com/BerriAI/litellm/issues/24442 import pytest -import litellm from litellm import ModelResponse from litellm.llms.vertex_ai.gemini.vertex_and_google_ai_studio_gemini import ( VertexGeminiConfig,