Skip to content

Commit 13815b8

Browse files
Annhiluccopybara-github
authored andcommitted
feat: Support new enum types for UrlRetrievalStatus
PiperOrigin-RevId: 791793857
1 parent 76e9b13 commit 13815b8

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

google/genai/tests/models/test_generate_content_tools.py

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,28 @@ def divide_floats(a: float, b: float) -> float:
294294
config={'tools': [{'url_context': {}}]},
295295
),
296296
),
297-
pytest_helper.TestTableItem(
297+
pytest_helper.TestTableItem(
298+
name='test_url_context_paywall_status',
299+
parameters=types._GenerateContentParameters(
300+
model='gemini-2.5-flash',
301+
contents=t.t_contents(
302+
'Read the content of this URL:'
303+
' https://unsplash.com/photos/portrait-of-an-adorable-golden-retriever-puppy-studio-shot-isolated-on-black-yRYCnnQASnc'
304+
),
305+
config={'tools': [{'url_context': {}}]},
306+
),
307+
),
308+
pytest_helper.TestTableItem(
309+
name='test_url_context_unsafe_status',
310+
parameters=types._GenerateContentParameters(
311+
model='gemini-2.5-flash',
312+
contents=t.t_contents(
313+
'Fetch the content of http://0k9.me/test.html'
314+
),
315+
config={'tools': [{'url_context': {}}]},
316+
),
317+
),
318+
pytest_helper.TestTableItem(
298319
# https://github.com/googleapis/python-genai/issues/830
299320
# - models started returning empty thought in response to queries
300321
# containing tools.
@@ -304,11 +325,13 @@ def divide_floats(a: float, b: float) -> float:
304325
# them?
305326
# - This is also important to configm forward compatibility.
306327
# when the models start returning thought_signature, those will get
307-
# dropped by the SDK leaving a `{'thought: True}` part.
328+
# dropped by the SDK leaving a `{'thought: True}` part.
308329
name='test_chat_tools_empty_thoughts',
309330
parameters=types._GenerateContentParameters(
310331
model='gemini-2.5-flash-preview-05-20',
311-
contents=[types.Content.model_validate(item) for item in [
332+
contents=[
333+
types.Content.model_validate(item)
334+
for item in [
312335
{
313336
'parts': [{'text': 'Who won the 1955 world cup?'}],
314337
'role': 'user',
@@ -333,7 +356,8 @@ def divide_floats(a: float, b: float) -> float:
333356
}],
334357
'role': 'user',
335358
},
336-
]],
359+
]
360+
],
337361
config={
338362
'tools': [{'function_declarations': function_declarations}],
339363
},
@@ -1417,7 +1441,7 @@ def test_tools_chat_curation(client, caplog):
14171441
sdk_logger = logging.getLogger('google_genai.models')
14181442
sdk_logger.setLevel(logging.ERROR)
14191443

1420-
config={
1444+
config = {
14211445
'tools': [{'function_declarations': function_declarations}],
14221446
}
14231447

@@ -1427,11 +1451,11 @@ def test_tools_chat_curation(client, caplog):
14271451
)
14281452

14291453
response = chat.send_message(
1430-
message='Who won the 1955 world cup?',
1454+
message='Who won the 1955 world cup?',
14311455
)
14321456

14331457
response = chat.send_message(
1434-
message='What was the population of canada in 1955?',
1458+
message='What was the population of canada in 1955?',
14351459
)
14361460

14371461
history = chat.get_history(curated=True)

google/genai/types.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,10 @@ class UrlRetrievalStatus(_common.CaseInSensitiveEnum):
241241
"""Url retrieval is successful."""
242242
URL_RETRIEVAL_STATUS_ERROR = 'URL_RETRIEVAL_STATUS_ERROR'
243243
"""Url retrieval is failed due to error."""
244+
URL_RETRIEVAL_STATUS_PAYWALL = 'URL_RETRIEVAL_STATUS_PAYWALL'
245+
"""Url retrieval is failed because the content is behind paywall."""
246+
URL_RETRIEVAL_STATUS_UNSAFE = 'URL_RETRIEVAL_STATUS_UNSAFE'
247+
"""Url retrieval is failed because the content is unsafe."""
244248

245249

246250
class FinishReason(_common.CaseInSensitiveEnum):

0 commit comments

Comments
 (0)