4444
4545pytest_plugins = ('pytest_asyncio' ,)
4646
47- # The only live model family currently served. It is audio-native and rejects a
48- # TEXT response modality outright ("The requested combination of response
49- # modalities (TEXT) is not supported by the model"), so these tests request
50- # AUDIO and turn on output transcription to get an assertable text signal.
51- LIVE_MODEL = 'gemini-3.1-flash-live-preview'
47+ # Live models are backend-specific: gemini-3.1-flash-live-preview is served only
48+ # on the Gemini API, and gemini-live-2.5-flash-native-audio only on Vertex, and
49+ # there only regionally -- see the location_override fixture in this package's
50+ # conftest. Both are audio-native and reject a TEXT response modality outright
51+ # ("The requested combination of response modalities (TEXT) is not supported by
52+ # the model"), so these tests request AUDIO and turn on output transcription to
53+ # get an assertable text signal.
54+ LIVE_MODELS = {
55+ False : 'gemini-3.1-flash-live-preview' ,
56+ True : 'gemini-live-2.5-flash-native-audio' ,
57+ }
5258
5359# A live turn is an open-ended stream with no built-in deadline. Without this
5460# bound a wedged receive would hang the nightly rather than fail it.
@@ -121,12 +127,13 @@ async def _say(session, text: str) -> None:
121127 )
122128
123129
130+ @pytest .mark .parametrize ('use_vertex' , [False , True ])
124131@pytest .mark .asyncio
125- async def test_text_input (client ):
132+ async def test_text_input (client , use_vertex ):
126133 """A single text turn produces audio output and a matching transcription."""
127134 try :
128135 async with client .aio .live .connect (
129- model = LIVE_MODEL , config = _base_config ()
136+ model = LIVE_MODELS [ use_vertex ] , config = _base_config ()
130137 ) as session :
131138 await _say (session , 'Say hello.' )
132139 turn = await _receive_turn (session )
@@ -138,12 +145,13 @@ async def test_text_input(client):
138145 raise
139146
140147
148+ @pytest .mark .parametrize ('use_vertex' , [False , True ])
141149@pytest .mark .asyncio
142- async def test_multi_turn (client ):
150+ async def test_multi_turn (client , use_vertex ):
143151 """A second turn in the same session can see the first turn's context."""
144152 try :
145153 async with client .aio .live .connect (
146- model = LIVE_MODEL , config = _base_config ()
154+ model = LIVE_MODELS [ use_vertex ] , config = _base_config ()
147155 ) as session :
148156 await _say (session , 'Remember the number 42. Just acknowledge it.' )
149157 first = await _receive_turn (session )
@@ -162,8 +170,9 @@ async def test_multi_turn(client):
162170 raise
163171
164172
173+ @pytest .mark .parametrize ('use_vertex' , [False , True ])
165174@pytest .mark .asyncio
166- async def test_function_calling (client ):
175+ async def test_function_calling (client , use_vertex ):
167176 """The model requests a declared tool, and the session accepts its result."""
168177 turn_on_the_lights = types .FunctionDeclaration (
169178 name = 'turn_on_the_lights' ,
@@ -176,7 +185,7 @@ async def test_function_calling(client):
176185
177186 try :
178187 async with client .aio .live .connect (
179- model = LIVE_MODEL , config = config
188+ model = LIVE_MODELS [ use_vertex ] , config = config
180189 ) as session :
181190 await _say (session , 'Please turn on the lights.' )
182191 turn = await _receive_turn (session )
@@ -194,20 +203,31 @@ async def test_function_calling(client):
194203 ]
195204 )
196205 follow_up = await _receive_turn (session )
197- assert follow_up .transcript .strip (), (
198- 'expected the model to respond after the tool result'
199- )
206+ if not use_vertex :
207+ # Vertex accepts the tool result and completes the turn, but emits an
208+ # empty transcription and no audio for it, so only the Gemini API can be
209+ # asserted on content here. Confirmed at the raw protocol level: the
210+ # follow-up carries outputTranscription with empty text, then
211+ # generationComplete and turnComplete.
212+ assert follow_up .transcript .strip (), (
213+ 'expected the model to respond after the tool result'
214+ )
200215 except Exception as e : # pylint: disable=broad-except
201216 _skip_if_quota_exhausted (e )
202217 raise
203218
204219
220+ @pytest .mark .parametrize ('use_vertex' , [False ])
205221@pytest .mark .asyncio
206- async def test_send_tool_response_without_id_raises (client ):
207- """The Gemini API backend requires an id on every FunctionResponse."""
222+ async def test_send_tool_response_without_id_raises (client , use_vertex ):
223+ """The Gemini API backend requires an id on every FunctionResponse.
224+
225+ Gemini API only: live.py:409 puts this validation in the non-vertexai branch
226+ of send_tool_response, so Vertex accepts an id-less FunctionResponse.
227+ """
208228 try :
209229 async with client .aio .live .connect (
210- model = LIVE_MODEL , config = _base_config ()
230+ model = LIVE_MODELS [ use_vertex ] , config = _base_config ()
211231 ) as session :
212232 with pytest .raises (ValueError , match = 'must have an `id` field' ):
213233 await session .send_tool_response (
0 commit comments