Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions google/genai/_transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,10 @@ def t_tools(
function_tool.function_declarations += (
transformed_tool.function_declarations
)
tool_copy = transformed_tool.model_copy()
tool_copy.function_declarations = None
if tool_copy.model_dump(exclude_none=True):
tools.append(tool_copy)
else:
tools.append(transformed_tool)
if function_tool.function_declarations:
Expand Down
70 changes: 69 additions & 1 deletion google/genai/tests/models/test_generate_content_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,75 @@ def test_function_google_search(client):
# bad request to combine function call and google search retrieval
with pytest.raises(errors.ClientError):
client.models.generate_content(
model='gemini-2.5-flash',
model='gemini-3.5-flash',
contents=contents,
config=config,
)


def test_function_google_search_server_side_tool_invocations(client):
contents = (
'What is the weather in Buenos Aires? If it is raining, schedule a'
' meeting.'
)
schedule_meeting = {
'name': 'schedule_meeting',
'description': 'Schedule a meeting',
'parameters': {
'type': 'object',
'properties': {'reason': {'type': 'string'}},
'required': ['reason'],
},
}
config = types.GenerateContentConfig(
tools=[
types.Tool(
google_search=types.GoogleSearch(),
),
types.Tool(
function_declarations=[schedule_meeting],
),
],
tool_config=types.ToolConfig(
include_server_side_tool_invocations=True,
),
)
with pytest_helper.exception_if_vertex(client, ValueError):
client.models.generate_content(
model='gemini-3.5-flash',
contents=contents,
config=config,
)


def test_function_google_search_server_side_tool_invocations_one_tool(client):
contents = (
'What is the weather in Buenos Aires? If it is raining, schedule a'
' meeting.'
)
schedule_meeting = {
'name': 'schedule_meeting',
'description': 'Schedule a meeting',
'parameters': {
'type': 'object',
'properties': {'reason': {'type': 'string'}},
'required': ['reason'],
},
}
config = types.GenerateContentConfig(
tools=[
types.Tool(
google_search=types.GoogleSearch(),
function_declarations=[schedule_meeting],
),
],
tool_config=types.ToolConfig(
include_server_side_tool_invocations=True,
),
)
with pytest_helper.exception_if_vertex(client, ValueError):
client.models.generate_content(
model='gemini-3.5-flash',
contents=contents,
config=config,
)
Expand Down
Loading