fix: Content is marked non empty if its first part contains text or inline_data or file_data or func call/response

PiperOrigin-RevId: 835063599
This commit is contained in:
Google Team Member
2025-11-20 22:19:28 -08:00
committed by Copybara-Service
parent a3e4ad3cd1
commit 631b58336d
2 changed files with 66 additions and 2 deletions
@@ -465,6 +465,43 @@ async def test_events_with_empty_content_are_skipped():
author="user",
content=types.UserContent("How are you?"),
),
# Event with content that has only empty text part
Event(
invocation_id="inv6",
author="user",
content=types.Content(parts=[types.Part(text="")], role="model"),
),
# Event with content that has only inline data part
Event(
invocation_id="inv7",
author="user",
content=types.Content(
parts=[
types.Part(
inline_data=types.Blob(
data=b"test", mime_type="image/png"
)
)
],
role="user",
),
),
# Event with content that has only file data part
Event(
invocation_id="inv8",
author="user",
content=types.Content(
parts=[
types.Part(
file_data=types.FileData(
file_uri="gs://test_bucket/test_file.png",
mime_type="image/png",
)
)
],
role="user",
),
),
]
invocation_context.session.events = events
@@ -478,4 +515,23 @@ async def test_events_with_empty_content_are_skipped():
assert llm_request.contents == [
types.UserContent("Hello"),
types.UserContent("How are you?"),
types.Content(
parts=[
types.Part(
inline_data=types.Blob(data=b"test", mime_type="image/png")
)
],
role="user",
),
types.Content(
parts=[
types.Part(
file_data=types.FileData(
file_uri="gs://test_bucket/test_file.png",
mime_type="image/png",
)
)
],
role="user",
),
]