Fix Google tool conversion - properly format function_declarations array

- Fixed tool conversion to create single function_declarations array
- This prevents Google from detecting malformed tool use
- Tools are now properly converted from OpenAI to Google format
parent 92ae0497
...@@ -277,6 +277,13 @@ class GoogleProviderHandler(BaseProviderHandler): ...@@ -277,6 +277,13 @@ class GoogleProviderHandler(BaseProviderHandler):
logging.info(f"GoogleProviderHandler: Messages: {messages}") logging.info(f"GoogleProviderHandler: Messages: {messages}")
else: else:
logging.info(f"GoogleProviderHandler: Messages count: {len(messages)}") logging.info(f"GoogleProviderHandler: Messages count: {len(messages)}")
if tools:
logging.info(f"GoogleProviderHandler: Tools provided: {len(tools)} tools")
if AISBF_DEBUG:
logging.info(f"GoogleProviderHandler: Tools: {tools}")
if tool_choice:
logging.info(f"GoogleProviderHandler: Tool choice: {tool_choice}")
# Apply rate limiting # Apply rate limiting
await self.apply_rate_limit() await self.apply_rate_limit()
...@@ -289,6 +296,26 @@ class GoogleProviderHandler(BaseProviderHandler): ...@@ -289,6 +296,26 @@ class GoogleProviderHandler(BaseProviderHandler):
if max_tokens is not None: if max_tokens is not None:
config["max_output_tokens"] = max_tokens config["max_output_tokens"] = max_tokens
# Convert OpenAI tools to Google's function calling format
google_tools = None
if tools:
function_declarations = []
for tool in tools:
if tool.get("type") == "function":
function = tool.get("function", {})
function_declaration = {
"name": function.get("name"),
"description": function.get("description", ""),
"parameters": function.get("parameters", {})
}
function_declarations.append(function_declaration)
logging.info(f"GoogleProviderHandler: Converted tool to Google format: {function_declaration}")
if function_declarations:
google_tools = {"function_declarations": function_declarations}
config["tools"] = google_tools
logging.info(f"GoogleProviderHandler: Added {len(function_declarations)} tools to config")
# Handle streaming request # Handle streaming request
if stream: if stream:
logging.info(f"GoogleProviderHandler: Using streaming API") logging.info(f"GoogleProviderHandler: Using streaming API")
...@@ -781,7 +808,7 @@ class GoogleProviderHandler(BaseProviderHandler): ...@@ -781,7 +808,7 @@ class GoogleProviderHandler(BaseProviderHandler):
id=model.name, id=model.name,
name=model.display_name or model.name, name=model.display_name or model.name,
provider_id=self.provider_id provider_id=self.provider_id
)) )
return result return result
except Exception as e: except Exception as e:
......
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