Fix Google tool calling - pass tools in config dict instead of as separate parameter

parent effd6447
...@@ -316,8 +316,12 @@ class GoogleProviderHandler(BaseProviderHandler): ...@@ -316,8 +316,12 @@ class GoogleProviderHandler(BaseProviderHandler):
if function_declarations: if function_declarations:
# Google API expects tools to be a Tool object with function_declarations # Google API expects tools to be a Tool object with function_declarations
from google.genai import types as genai_types from google.genai import types as genai_types
google_tools = [genai_types.Tool(function_declarations=function_declarations)] google_tools = genai_types.Tool(function_declarations=function_declarations)
logging.info(f"GoogleProviderHandler: Added {len(function_declarations)} tools to google_tools") logging.info(f"GoogleProviderHandler: Added {len(function_declarations)} tools to google_tools")
# Add tools to config for both streaming and non-streaming
config["tools"] = google_tools
logging.info(f"GoogleProviderHandler: Added tools to config")
# Handle streaming request # Handle streaming request
if stream: if stream:
...@@ -329,11 +333,11 @@ class GoogleProviderHandler(BaseProviderHandler): ...@@ -329,11 +333,11 @@ class GoogleProviderHandler(BaseProviderHandler):
# We need to iterate over the streaming response immediately without yielding control # We need to iterate over the streaming response immediately without yielding control
# to ensure the client stays alive # to ensure the client stays alive
chunks = [] chunks = []
for chunk in stream_client.models.generate_content_stream( for chunk in stream_client.models.generate_content_stream(
model=model, model=model,
contents=content, contents=content,
config=config, config=config
tools=google_tools
): ):
chunks.append(chunk) chunks.append(chunk)
...@@ -353,8 +357,7 @@ class GoogleProviderHandler(BaseProviderHandler): ...@@ -353,8 +357,7 @@ class GoogleProviderHandler(BaseProviderHandler):
response = self.client.models.generate_content( response = self.client.models.generate_content(
model=model, model=model,
contents=content, contents=content,
config=config, config=config
tools=google_tools
) )
logging.info(f"GoogleProviderHandler: Response received: {response}") logging.info(f"GoogleProviderHandler: Response received: {response}")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment