fix(vertex_and_google_ai_studio.py): only set content if non-empty str

This commit is contained in:
Krrish Dholakia 2025-04-19 12:18:53 -07:00
parent dacc712522
commit e70d5710d2
2 changed files with 29 additions and 8 deletions

View file

@ -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

View file

@ -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