Skip to content

Commit 99551c9

Browse files
sasha-gitgcopybara-github
authored andcommitted
feat: Enable url_context for Vertex
PiperOrigin-RevId: 767303435
1 parent 42be92b commit 99551c9

File tree

5 files changed

+37
-5
lines changed

5 files changed

+37
-5
lines changed

google/genai/_live_converters.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,13 @@ def _Tool_to_vertex(
981981
)
982982

983983
if getv(from_object, ['url_context']) is not None:
984-
raise ValueError('url_context parameter is not supported in Vertex AI.')
984+
setv(
985+
to_object,
986+
['urlContext'],
987+
_UrlContext_to_vertex(
988+
api_client, getv(from_object, ['url_context']), to_object
989+
),
990+
)
985991

986992
if getv(from_object, ['code_execution']) is not None:
987993
setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))

google/genai/_tokens_converters.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,13 @@ def _Tool_to_vertex(
981981
)
982982

983983
if getv(from_object, ['url_context']) is not None:
984-
raise ValueError('url_context parameter is not supported in Vertex AI.')
984+
setv(
985+
to_object,
986+
['urlContext'],
987+
_UrlContext_to_vertex(
988+
api_client, getv(from_object, ['url_context']), to_object
989+
),
990+
)
985991

986992
if getv(from_object, ['code_execution']) is not None:
987993
setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))

google/genai/caches.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,13 @@ def _Tool_to_vertex(
10921092
)
10931093

10941094
if getv(from_object, ['url_context']) is not None:
1095-
raise ValueError('url_context parameter is not supported in Vertex AI.')
1095+
setv(
1096+
to_object,
1097+
['urlContext'],
1098+
_UrlContext_to_vertex(
1099+
api_client, getv(from_object, ['url_context']), to_object
1100+
),
1101+
)
10961102

10971103
if getv(from_object, ['code_execution']) is not None:
10981104
setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))

google/genai/models.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1985,7 +1985,13 @@ def _Tool_to_vertex(
19851985
)
19861986

19871987
if getv(from_object, ['url_context']) is not None:
1988-
raise ValueError('url_context parameter is not supported in Vertex AI.')
1988+
setv(
1989+
to_object,
1990+
['urlContext'],
1991+
_UrlContext_to_vertex(
1992+
api_client, getv(from_object, ['url_context']), to_object
1993+
),
1994+
)
19891995

19901996
if getv(from_object, ['code_execution']) is not None:
19911997
setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))
@@ -4298,6 +4304,15 @@ def _Candidate_from_vertex(
42984304
if getv(from_object, ['finishReason']) is not None:
42994305
setv(to_object, ['finish_reason'], getv(from_object, ['finishReason']))
43004306

4307+
if getv(from_object, ['urlContextMetadata']) is not None:
4308+
setv(
4309+
to_object,
4310+
['url_context_metadata'],
4311+
_UrlContextMetadata_from_vertex(
4312+
api_client, getv(from_object, ['urlContextMetadata']), to_object
4313+
),
4314+
)
4315+
43014316
if getv(from_object, ['avgLogprobs']) is not None:
43024317
setv(to_object, ['avg_logprobs'], getv(from_object, ['avgLogprobs']))
43034318

google/genai/tests/models/test_generate_content_tools.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,6 @@ def divide_floats(a: float, b: float) -> float:
295295
),
296296
config={'tools': [{'url_context': {}}]},
297297
),
298-
exception_if_vertex='not supported in Vertex AI',
299298
),
300299
pytest_helper.TestTableItem(
301300
# https://github.com/googleapis/python-genai/issues/830

0 commit comments

Comments
 (0)