Hi everyone,
I’m trying to implement function calling using Gemini’s OpenAI compatibility layer with gemini-1.5-flash-002. While the basic example with a single function works perfectly, I’m getting an error when trying to add multiple functions to the tools array.
Here’s my code:
tools = [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the weather in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. Chicago, IL",
},
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
},
"required": ["location"],
},
}
},
{
"type": "function",
"function": {
"name": "get_weather_forecast",
"description": "Get the weather forecast for the next few days",
# ... similar parameters plus 'days'
}
}
]
This results in:
openai.BadRequestError: Error code: 400 - [{‘error’: {‘code’: 400, ‘message’: ‘Request contains an invalid argument.’, ‘status’: ‘INVALID_ARGUMENT’}}]
The same code works fine with a single function. Is there a current limitation on the number of functions supported in the OpenAI compatibility mode? The documentation doesn’t mention this as a limitation, but I noticed the examples only show single function usage.
Any insights or workarounds would be appreciated!