Skip to content

Commit 0e8b8cd

Browse files
matthew29tangcopybara-github
authored andcommitted
chore: Deflake test_generative_models system tests by allowing empty text with finish reason
PiperOrigin-RevId: 636700923
1 parent 1cc22c3 commit 0e8b8cd

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

tests/system/vertexai/test_generative_models.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,11 @@ def test_generate_content_streaming(self):
112112
generation_config=generative_models.GenerationConfig(temperature=0),
113113
)
114114
for chunk in stream:
115-
assert chunk.text
115+
assert (
116+
chunk.text
117+
or chunk.candidates[0].finish_reason
118+
is generative_models.FinishReason.STOP
119+
)
116120

117121
@pytest.mark.asyncio
118122
async def test_generate_content_streaming_async(self):
@@ -123,7 +127,11 @@ async def test_generate_content_streaming_async(self):
123127
generation_config=generative_models.GenerationConfig(temperature=0),
124128
)
125129
async for chunk in async_stream:
126-
assert chunk.text
130+
assert (
131+
chunk.text
132+
or chunk.candidates[0].finish_reason
133+
is generative_models.FinishReason.STOP
134+
)
127135

128136
def test_generate_content_with_parameters(self):
129137
model = generative_models.GenerativeModel(
@@ -241,7 +249,11 @@ def test_grounding_google_search_retriever(self):
241249
tools=[google_search_retriever_tool],
242250
generation_config=generative_models.GenerationConfig(temperature=0),
243251
)
244-
assert response.text
252+
assert (
253+
response.candidates[0].finish_reason
254+
is generative_models.FinishReason.RECITATION
255+
or response.text
256+
)
245257

246258
# Chat
247259

0 commit comments

Comments
 (0)