mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-16 23:41:43 +00:00
fix(vertex): drop mixed search tools with functions
This commit is contained in:
parent
879d794630
commit
f778b43e60
2 changed files with 67 additions and 0 deletions
|
|
@ -1223,6 +1223,38 @@ class VertexGeminiConfig(VertexAIBaseConfig, BaseConfig):
|
|||
if "temperature" not in optional_params:
|
||||
optional_params["temperature"] = 1.0
|
||||
|
||||
# web_search_options can be added before function tools are mapped, so
|
||||
# strip any pre-existing search tools here as well to keep the request
|
||||
# valid regardless of parameter order.
|
||||
tools = optional_params.get("tools")
|
||||
if (
|
||||
isinstance(tools, list)
|
||||
and any("function_declarations" in tool for tool in tools)
|
||||
and not optional_params.get("include_server_side_tool_invocations", False)
|
||||
):
|
||||
filtered_tools = [
|
||||
tool
|
||||
for tool in tools
|
||||
if not any(
|
||||
search_tool in tool
|
||||
for search_tool in [
|
||||
VertexToolName.GOOGLE_SEARCH.value,
|
||||
VertexToolName.GOOGLE_SEARCH_RETRIEVAL.value,
|
||||
VertexToolName.ENTERPRISE_WEB_SEARCH.value,
|
||||
VertexToolName.URL_CONTEXT.value,
|
||||
]
|
||||
)
|
||||
]
|
||||
if len(filtered_tools) != len(tools):
|
||||
verbose_logger.warning(
|
||||
"Vertex AI does not support mixing function declarations with "
|
||||
"search tools (googleSearch, enterpriseWebSearch, urlContext, "
|
||||
"googleSearchRetrieval) in the same request. Dropping search "
|
||||
"tools and keeping function declarations. To use search tools, "
|
||||
"send a request without function calling tools."
|
||||
)
|
||||
optional_params["tools"] = filtered_tools
|
||||
|
||||
return optional_params
|
||||
|
||||
def get_mapped_special_auth_params(self) -> dict:
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
def test_vertex_ai_web_search_options_dropped_when_function_tools_are_present():
|
||||
"""Test that search tools are dropped even when web_search_options is mapped first."""
|
||||
from litellm.llms.vertex_ai.gemini.vertex_and_google_ai_studio_gemini import (
|
||||
VertexGeminiConfig,
|
||||
)
|
||||
|
||||
v = VertexGeminiConfig()
|
||||
|
||||
non_default_params = {
|
||||
"web_search_options": {},
|
||||
"tools": [
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "notion_search",
|
||||
"description": "Search Notion",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {"query": {"type": "string"}},
|
||||
},
|
||||
},
|
||||
}
|
||||
],
|
||||
}
|
||||
|
||||
result = v.map_openai_params(
|
||||
non_default_params=non_default_params,
|
||||
optional_params={},
|
||||
model="gemini-2.5-pro",
|
||||
drop_params=True,
|
||||
)
|
||||
|
||||
assert len(result["tools"]) == 1
|
||||
assert "function_declarations" in result["tools"][0]
|
||||
assert "googleSearch" not in result["tools"][0]
|
||||
Loading…
Add table
Reference in a new issue