mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-05 02:41:56 +00:00
fix(gemini): ignore null text response parts (#30962)
This commit is contained in:
parent
3bf41e0acf
commit
84eac5de06
2 changed files with 21 additions and 0 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
[
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue