Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/google/adk/models/gemini_llm_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,15 @@ async def send_realtime(self, input: RealtimeInput):
input: The input to send to the model.
"""
if isinstance(input, types.Blob):
input_blob = input.model_dump()
# The blob is binary and is very large. So let's not log it.
logger.debug('Sending LLM Blob.')
await self._gemini_session.send(input=input_blob)

logger.debug('Sending LLM Blob: %s', input)
await self._gemini_session.send_realtime_input(media=input)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

While this change to use send_realtime_input is correct for handling types.Blob, the associated unit test has not been updated. The test test_send_realtime_default_behavior in tests/unittests/models/test_gemini_llm_connection.py still asserts that mock_gemini_session.send is called, which will now fail.

Please update the test to verify that mock_gemini_session.send_realtime_input is called instead. Here is a suggested update for the test:

@pytest.mark.asyncio
async def test_send_realtime_blob(gemini_connection, mock_gemini_session, test_blob):
  """Test send_realtime with a blob."""
  await gemini_connection.send_realtime(test_blob)

  mock_gemini_session.send_realtime_input.assert_called_once_with(media=test_blob)
  mock_gemini_session.send.assert_not_called()

Failing to update tests alongside code changes can lead to a brittle test suite and hide potential regressions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi ! This is done ! Thanks

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you help explain why we migrate to this method and not others:
("Please use one of the more specific methods: send_client_content, send_realtime_input, or send_tool_response instead.
await self._gemini_session.send(input=input_blob)")


# input_blob = input.model_dump()
# # The blob is binary and is very large. So let's not log it.
# logger.debug('Sending LLM Blob.')
# await self._gemini_session.send(input=input_blob)

elif isinstance(input, types.ActivityStart):
logger.debug('Sending LLM activity start signal.')
await self._gemini_session.send_realtime_input(activity_start=input)
Expand Down
6 changes: 5 additions & 1 deletion tests/unittests/models/test_gemini_llm_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ async def test_send_realtime_default_behavior(
await gemini_connection.send_realtime(test_blob)

# Should call send once
mock_gemini_session.send.assert_called_once_with(input=test_blob.model_dump())
mock_gemini_session.send_realtime_input.assert_called_once_with(
media=test_blob
)
# Should not call .send function
mock_gemini_session.send.assert_not_called()


@pytest.mark.asyncio
Expand Down
Loading