Skip to content

Commit 20a9e8d

Browse files
committed
run autofix per pr comment
1 parent e462cc9 commit 20a9e8d

2 files changed

Lines changed: 29 additions & 8 deletions

File tree

src/google/adk/models/gemini_llm_connection.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,19 +122,15 @@ async def send_content(self, content: types.Content):
122122
is_gemini_api = self._api_backend == GoogleLLMVariant.GEMINI_API
123123

124124
# Route via send_realtime_input if audio is active OR if targeting 3.1 API
125-
if self._audio_active or (is_gemini_31 and is_gemini_api):
125+
if (self._audio_active or (is_gemini_31 and is_gemini_api)) and all(
126+
isinstance(part.text, str) for part in content.parts
127+
):
126128
logger.debug(
127129
'Routing text via send_realtime_input %s',
128130
content,
129131
)
130-
has_text = False
131132
for part in content.parts:
132-
if isinstance(part.text, str):
133-
await self._gemini_session.send_realtime_input(text=part.text)
134-
has_text = True
135-
136-
if not has_text:
137-
logger.warning('Encountered unsupported content in send_content')
133+
await self._gemini_session.send_realtime_input(text=part.text)
138134
else:
139135
logger.debug('Sending LLM new content %s', content)
140136
await self._gemini_session.send(

tests/unittests/models/test_gemini_llm_connection.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,31 @@ async def test_send_content_text_audio_active(
147147
mock_gemini_session.send.assert_not_called()
148148

149149

150+
@pytest.mark.asyncio
151+
async def test_send_content_mixed_audio_active(
152+
gemini_connection, mock_gemini_session, test_blob
153+
):
154+
"""Test send_content falls back to LiveClientContent for mixed modalities."""
155+
gemini_connection._audio_active = True
156+
157+
content = types.Content(
158+
role='user',
159+
parts=[
160+
types.Part.from_text(text='Hello'),
161+
types.Part(inline_data=test_blob)
162+
]
163+
)
164+
165+
await gemini_connection.send_content(content)
166+
167+
mock_gemini_session.send.assert_called_once()
168+
call_args = mock_gemini_session.send.call_args[1]
169+
assert 'input' in call_args
170+
assert call_args['input'].turns == [content]
171+
assert call_args['input'].turn_complete is True
172+
mock_gemini_session.send_realtime_input.assert_not_called()
173+
174+
150175
@pytest.mark.asyncio
151176
async def test_send_content_function_response(
152177
gemini_connection, mock_gemini_session

0 commit comments

Comments
 (0)