fix(gemini): ignore null text response parts (#30962)

This commit is contained in:
冯基魁 2026-06-23 21:06:26 +08:00 • committed by Sameer Kankute
parent 3bf41e0acf
commit 84eac5de06
No known key found for this signature in database
2 changed files with 21 additions and 0 deletions

View file

@ -1380,6 +1380,8 @@ class VertexGeminiConfig(VertexAIBaseConfig, BaseConfig):
_content_str = ""
if "text" in part:
text_content = part["text"]
if text_content is None:
continue
# Check if text content is audio data URI - if so, exclude from text content
if text_content.startswith("data:audio") and ";base64," in text_content:
try:

View file

@ -441,6 +441,25 @@ def test_vertex_ai_empty_content():
assert reasoning_content is None
def test_vertex_ai_null_text_part_is_ignored():
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 = cast(
List[HttpxPartType],
[
{"text": None},
{"text": "Generated image"},
],
)
content, reasoning_content = v.get_assistant_content_message(parts=parts)
assert content == "Generated image"
assert reasoning_content is None
@pytest.mark.parametrize(
"usage_metadata, inclusive, expected_usage",
[