Skip to content

Commit a3b1b0b

Browse files
authored
Implement test for receive input transcription in Gemini 3.1
Add test for input transcription handling in Gemini 3.1.
1 parent 63ffbb4 commit a3b1b0b

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

tests/unittests/models/test_gemini_llm_connection.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,3 +1676,69 @@ async def mock_receive_generator():
16761676
assert responses[1].partial is False
16771677
assert responses[2].turn_complete is True
16781678
assert responses[2].grounding_metadata is None
1679+
1680+
1681+
@pytest.mark.asyncio
1682+
async def test_receive_input_transcription_gemini_3_1(
1683+
mock_gemini_session,
1684+
):
1685+
"""Verify input_transcription yields finished=True immediately for Gemini 3.1."""
1686+
conn = GeminiLlmConnection(
1687+
mock_gemini_session,
1688+
model_version='gemini-3.1-flash-live-preview',
1689+
)
1690+
1691+
def make_msg(
1692+
input_text=None, output_text=None, output_finished=False, tc=False
1693+
):
1694+
msg = mock.create_autospec(types.LiveServerMessage, instance=True)
1695+
msg.usage_metadata = None
1696+
msg.tool_call = None
1697+
msg.session_resumption_update = None
1698+
msg.go_away = None
1699+
msg.server_content = mock.Mock()
1700+
msg.server_content.interrupted = False
1701+
msg.server_content.input_transcription = (
1702+
types.Transcription(text=input_text, finished=False)
1703+
if input_text
1704+
else None
1705+
)
1706+
msg.server_content.output_transcription = (
1707+
types.Transcription(text=output_text, finished=output_finished)
1708+
if output_text
1709+
else None
1710+
)
1711+
msg.server_content.generation_complete = False
1712+
msg.server_content.turn_complete = tc
1713+
msg.server_content.grounding_metadata = None
1714+
msg.server_content.model_turn = None
1715+
return msg
1716+
1717+
msg1 = make_msg(input_text='Hello')
1718+
msg2 = make_msg(output_text='Hi there!', output_finished=True)
1719+
msg3 = make_msg(tc=True)
1720+
1721+
async def mock_receive_generator():
1722+
yield msg1
1723+
yield msg2
1724+
yield msg3
1725+
1726+
mock_gemini_session.receive = mock.Mock(return_value=mock_receive_generator())
1727+
1728+
responses = [resp async for resp in conn.receive()]
1729+
1730+
assert len(responses) == 4
1731+
1732+
assert responses[0].input_transcription.text == 'Hello'
1733+
assert responses[0].input_transcription.finished is True
1734+
assert responses[0].partial is False
1735+
1736+
assert responses[1].output_transcription.text == 'Hi there!'
1737+
assert responses[1].output_transcription.finished is False
1738+
assert responses[1].partial is True
1739+
1740+
assert responses[2].output_transcription.text == 'Hi there!'
1741+
assert responses[2].output_transcription.finished is True
1742+
assert responses[2].partial is False
1743+
1744+
assert responses[3].turn_complete is True

0 commit comments

Comments
 (0)