It seems I can not pass parameterless functions to Gemini. Error is as bad as usual: “Request contains an invalid argument.”.
{
"type":"function",
"function": {
"name": "get_current_time",
"description": "Get current date and time in 'yyyy-MM-dd HH:mm:ss' format. It also returns current time zone in GMT form",
"parameters": {
"type": "object",
"properties": {
}
}
}
}
If I provide a fake property it accepts the function.
{
"type":"function",
"function": {
"name": "get_current_time",
"description": "Get current date and time in 'yyyy-MM-dd HH:mm:ss' format. It also returns current time zone in GMT form",
"parameters": {
"type": "object",
"properties": {
"none": {
"type": "string",
"description": "Fake property"
}
}
}
}
}
If I get rid of parameters - it fails anyway:
{
"type":"function",
"function": {
"name": "get_current_time",
"description": "Get current date and time in 'yyyy-MM-dd HH:mm:ss' format. It also returns current time zone in GMT form",
}
}
Hey @Gregory_Ledenev , could you try passing the parameterless function using the format below?
tools = {
"function_declarations": [
{
"name": "get_current_time",
"description": "Get current date and time in 'yyyy-MM-dd HH:mm:ss' format.",
}
]
}
response = model.generate_content("What time is it right now?",tools=tools)
response
{
"model" : "gemini-1.5-flash",
"messages" : [{"content":"what time is it","role":"user"}],
"tools": {
"function_declarations": [{"name":"get_current_time","description":"Get current date and time in 'yyyy-MM-dd HH:mm:ss' format."}]
},
}
To be on the same page: please find below a curl call:
curl "https://generativelanguage.googleapis.com/v1beta/chat/completions?key=YOUR_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"model" : "gemini-1.5-flash",
"messages" : [{"content":"what time is it","role":"user"}],
"tools":[{"type":"function","function":{"name":"get_current_time","description":"Get current date and time. It also returns current time zone in GMT form"}}]
}'
FYI, this problem also exists when using using the google.generativeai library. For instance, when I pass this tool definition to the api
{
"name": "get_state",
"description": "Function to get the current state, as defined in <state>",
"parameters": {
"properties": {},
"type": "object"
}
}
i get the following error
raise exceptions.from_grpc_error(exc) from exc
google.api_core.exceptions.InvalidArgument: 400 * GenerateContentRequest.tools[0].function_declarations[4].parameters.properties: should be non-empty for OBJECT type
So I believe this is a server-side issue. It has nothing to do with openai library compatibility
@GUNAND_MAYANGLAMBAM Still doesn’t seem to be working. The example you provided isn’t really the same. What I am trying to do is define an object but not provide any predefined properties. The properties of the params object aren’t known in advance they are determined by the LLM at inference time so I want it to fill out parameters by itself.
I am trying this with gemini-2.0-flash-exp. Other LLM providers are handling this completely fine.
{
"type": "function",
"function": {
"name": "execute_operation",
"description": "Execute an operation",
"parameters": {
"type": "object",
"properties": {
"operation": {
"type": "string",
"description": "Name of the operation to execute"
},
"target": {
"type": "string",
"description": "Target of the operation"
},
"params": {
"type": "object",
"description": "Parameters for the operation"
}
},
"required": ["operation", "target", "params"]
}
}
}
This is the error that I am getting:
BadRequestError: Error code: 400 - [{'error': {'code': 400, 'message': '* GenerateContentRequest.tools[0].function_declarations[0].parameters.properties[params].properties: should be non-empty for OBJECT type\n', 'status': 'INVALID_ARGUMENT'}}]