Skip to content

Commit 7e4ec28

Browse files
jaycee-licopybara-github
authored andcommitted
feat: Support exclude_domains in Google Search and Enterprise Web Search
PiperOrigin-RevId: 794663752
1 parent 3719e77 commit 7e4ec28

7 files changed

Lines changed: 104 additions & 2 deletions

File tree

google/genai/_live_converters.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,11 @@ def _GoogleSearch_to_mldev(
312312
_Interval_to_mldev(getv(from_object, ['time_range_filter']), to_object),
313313
)
314314

315+
if getv(from_object, ['exclude_domains']) is not None:
316+
raise ValueError(
317+
'exclude_domains parameter is not supported in Gemini API.'
318+
)
319+
315320
return to_object
316321

317322

@@ -1461,6 +1466,9 @@ def _GoogleSearch_to_vertex(
14611466
),
14621467
)
14631468

1469+
if getv(from_object, ['exclude_domains']) is not None:
1470+
setv(to_object, ['excludeDomains'], getv(from_object, ['exclude_domains']))
1471+
14641472
return to_object
14651473

14661474

@@ -1504,6 +1512,8 @@ def _EnterpriseWebSearch_to_vertex(
15041512
parent_object: Optional[dict[str, Any]] = None,
15051513
) -> dict[str, Any]:
15061514
to_object: dict[str, Any] = {}
1515+
if getv(from_object, ['exclude_domains']) is not None:
1516+
setv(to_object, ['excludeDomains'], getv(from_object, ['exclude_domains']))
15071517

15081518
return to_object
15091519

google/genai/_tokens_converters.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,11 @@ def _GoogleSearch_to_mldev(
312312
_Interval_to_mldev(getv(from_object, ['time_range_filter']), to_object),
313313
)
314314

315+
if getv(from_object, ['exclude_domains']) is not None:
316+
raise ValueError(
317+
'exclude_domains parameter is not supported in Gemini API.'
318+
)
319+
315320
return to_object
316321

317322

google/genai/batches.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,11 @@ def _GoogleSearch_to_mldev(
338338
_Interval_to_mldev(getv(from_object, ['time_range_filter']), to_object),
339339
)
340340

341+
if getv(from_object, ['exclude_domains']) is not None:
342+
raise ValueError(
343+
'exclude_domains parameter is not supported in Gemini API.'
344+
)
345+
341346
return to_object
342347

343348

google/genai/caches.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,11 @@ def _GoogleSearch_to_mldev(
231231
_Interval_to_mldev(getv(from_object, ['time_range_filter']), to_object),
232232
)
233233

234+
if getv(from_object, ['exclude_domains']) is not None:
235+
raise ValueError(
236+
'exclude_domains parameter is not supported in Gemini API.'
237+
)
238+
234239
return to_object
235240

236241

@@ -828,6 +833,9 @@ def _GoogleSearch_to_vertex(
828833
),
829834
)
830835

836+
if getv(from_object, ['exclude_domains']) is not None:
837+
setv(to_object, ['excludeDomains'], getv(from_object, ['exclude_domains']))
838+
831839
return to_object
832840

833841

@@ -871,6 +879,8 @@ def _EnterpriseWebSearch_to_vertex(
871879
parent_object: Optional[dict[str, Any]] = None,
872880
) -> dict[str, Any]:
873881
to_object: dict[str, Any] = {}
882+
if getv(from_object, ['exclude_domains']) is not None:
883+
setv(to_object, ['excludeDomains'], getv(from_object, ['exclude_domains']))
874884

875885
return to_object
876886

google/genai/models.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,11 @@ def _GoogleSearch_to_mldev(
340340
_Interval_to_mldev(getv(from_object, ['time_range_filter']), to_object),
341341
)
342342

343+
if getv(from_object, ['exclude_domains']) is not None:
344+
raise ValueError(
345+
'exclude_domains parameter is not supported in Gemini API.'
346+
)
347+
343348
return to_object
344349

345350

@@ -1702,6 +1707,9 @@ def _GoogleSearch_to_vertex(
17021707
),
17031708
)
17041709

1710+
if getv(from_object, ['exclude_domains']) is not None:
1711+
setv(to_object, ['excludeDomains'], getv(from_object, ['exclude_domains']))
1712+
17051713
return to_object
17061714

17071715

@@ -1745,6 +1753,8 @@ def _EnterpriseWebSearch_to_vertex(
17451753
parent_object: Optional[dict[str, Any]] = None,
17461754
) -> dict[str, Any]:
17471755
to_object: dict[str, Any] = {}
1756+
if getv(from_object, ['exclude_domains']) is not None:
1757+
setv(to_object, ['excludeDomains'], getv(from_object, ['exclude_domains']))
17481758

17491759
return to_object
17501760

google/genai/tests/models/test_generate_content.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,55 @@ class InstrumentEnum(Enum):
249249
),
250250
),
251251
),
252+
pytest_helper.TestTableItem(
253+
name='test_google_search_tool_with_exclude_domains',
254+
parameters=types._GenerateContentParameters(
255+
model='gemini-2.5-flash',
256+
contents=t.t_contents('Why is the sky blue?'),
257+
config=types.GenerateContentConfig(
258+
tools=[
259+
types.Tool(
260+
google_search=types.GoogleSearch(
261+
exclude_domains=['amazon.com', 'facebook.com']
262+
)
263+
)
264+
]
265+
),
266+
),
267+
exception_if_mldev='not supported in',
268+
),
269+
pytest_helper.TestTableItem(
270+
name='test_enterprise_web_search_tool',
271+
parameters=types._GenerateContentParameters(
272+
model='gemini-2.5-flash',
273+
contents=t.t_contents('Why is the sky blue?'),
274+
config=types.GenerateContentConfig(
275+
tools=[
276+
types.Tool(
277+
enterprise_web_search=types.EnterpriseWebSearch()
278+
)
279+
]
280+
),
281+
),
282+
exception_if_mldev='not supported in',
283+
),
284+
pytest_helper.TestTableItem(
285+
name='test_enterprise_web_search_tool_with_exclude_domains',
286+
parameters=types._GenerateContentParameters(
287+
model='gemini-2.5-flash',
288+
contents=t.t_contents('Why is the sky blue?'),
289+
config=types.GenerateContentConfig(
290+
tools=[
291+
types.Tool(
292+
enterprise_web_search=types.EnterpriseWebSearch(
293+
exclude_domains=['amazon.com', 'facebook.com']
294+
)
295+
)
296+
]
297+
),
298+
),
299+
exception_if_mldev='not supported in',
300+
),
252301
pytest_helper.TestTableItem(
253302
name='test_speech_with_config',
254303
parameters=types._GenerateContentParameters(

google/genai/types.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2366,6 +2366,11 @@ class GoogleSearch(_common.BaseModel):
23662366
If customers set a start time, they must set an end time (and vice versa).
23672367
""",
23682368
)
2369+
exclude_domains: Optional[list[str]] = Field(
2370+
default=None,
2371+
description="""Optional. List of domains to be excluded from the search results.
2372+
The default limit is 2000 domains.""",
2373+
)
23692374

23702375

23712376
class GoogleSearchDict(TypedDict, total=False):
@@ -2376,6 +2381,10 @@ class GoogleSearchDict(TypedDict, total=False):
23762381
If customers set a start time, they must set an end time (and vice versa).
23772382
"""
23782383

2384+
exclude_domains: Optional[list[str]]
2385+
"""Optional. List of domains to be excluded from the search results.
2386+
The default limit is 2000 domains."""
2387+
23792388

23802389
GoogleSearchOrDict = Union[GoogleSearch, GoogleSearchDict]
23812390

@@ -2432,13 +2441,17 @@ class GoogleSearchRetrievalDict(TypedDict, total=False):
24322441
class EnterpriseWebSearch(_common.BaseModel):
24332442
"""Tool to search public web data, powered by Vertex AI Search and Sec4 compliance."""
24342443

2435-
pass
2444+
exclude_domains: Optional[list[str]] = Field(
2445+
default=None,
2446+
description="""Optional. List of domains to be excluded from the search results. The default limit is 2000 domains.""",
2447+
)
24362448

24372449

24382450
class EnterpriseWebSearchDict(TypedDict, total=False):
24392451
"""Tool to search public web data, powered by Vertex AI Search and Sec4 compliance."""
24402452

2441-
pass
2453+
exclude_domains: Optional[list[str]]
2454+
"""Optional. List of domains to be excluded from the search results. The default limit is 2000 domains."""
24422455

24432456

24442457
EnterpriseWebSearchOrDict = Union[EnterpriseWebSearch, EnterpriseWebSearchDict]

0 commit comments

Comments
 (0)