From 02df3e345804c43ec0fd18af1b33c97a14a0df25 Mon Sep 17 00:00:00 2001 From: Krzysztof Czuszynski Date: Tue, 28 Oct 2025 23:40:38 +0100 Subject: [PATCH 1/2] fix not passing finished transcription flag --- src/google/adk/models/gemini_llm_connection.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/google/adk/models/gemini_llm_connection.py b/src/google/adk/models/gemini_llm_connection.py index f1470c0a29..e7dd3acd28 100644 --- a/src/google/adk/models/gemini_llm_connection.py +++ b/src/google/adk/models/gemini_llm_connection.py @@ -162,18 +162,12 @@ async def receive(self) -> AsyncGenerator[LlmResponse, None]: yield self.__build_full_text_response(text) text = '' yield llm_response - if ( - message.server_content.input_transcription - and message.server_content.input_transcription.text - ): + if message.server_content.input_transcription: llm_response = LlmResponse( input_transcription=message.server_content.input_transcription, ) yield llm_response - if ( - message.server_content.output_transcription - and message.server_content.output_transcription.text - ): + if message.server_content.output_transcription: llm_response = LlmResponse( output_transcription=message.server_content.output_transcription ) From b9feb2b6093803afc6cf04566f8224f74a569987 Mon Sep 17 00:00:00 2001 From: Krzysztof Czuszynski Date: Tue, 28 Oct 2025 23:42:12 +0100 Subject: [PATCH 2/2] add unittest to check the transcription finished flag is passed --- .../models/test_gemini_llm_connection.py | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/tests/unittests/models/test_gemini_llm_connection.py b/tests/unittests/models/test_gemini_llm_connection.py index 2327115033..1b4309ef65 100644 --- a/tests/unittests/models/test_gemini_llm_connection.py +++ b/tests/unittests/models/test_gemini_llm_connection.py @@ -109,3 +109,53 @@ async def test_close(gemini_connection, mock_gemini_session): await gemini_connection.close() mock_gemini_session.close.assert_called_once() + + +@pytest.mark.asyncio +@pytest.mark.parametrize('tx_direction', ['input', 'output']) +async def test_receive_transcript_finished( + gemini_connection, mock_gemini_session, tx_direction +): + """Test receive_transcript_finished for input and output transcription.""" + + finished_tx = types.Transcription(finished=True) + + class Msg: + + def __init__(self): + self.server_content = mock.Mock() + sc = self.server_content + sc.model_turn = None + if tx_direction == 'input': + sc.input_transcription = finished_tx + sc.output_transcription = None + else: + sc.input_transcription = None + sc.output_transcription = finished_tx + sc.interrupted = False + sc.turn_complete = False + self.tool_call = None + self.session_resumption_update = None + + async def gen(): + yield Msg() + + mock_gemini_session.receive = mock.Mock(return_value=gen()) + + responses = [] + async for r in gemini_connection.receive(): + responses.append(r) + + if tx_direction == 'input': + tx_resps = [r for r in responses if r.input_transcription] + else: + tx_resps = [r for r in responses if r.output_transcription] + + if tx_direction == 'input': + assert tx_resps, 'Excpected input transcription response' + assert tx_resps[0].input_transcription.finished is True + assert not tx_resps[0].input_transcription.text + else: + assert tx_resps, 'Expected output transcription response' + assert tx_resps[0].output_transcription.finished is True + assert not tx_resps[0].output_transcription.text