Gemini doesn't accept parameterless functions

Hello,

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",
    }
  }
1 Like

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

Hello,

Thank you for your reply.

Tried. Got even worse response.

REQUEST:

{
  "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."}]
}, 
 	
}

RESPONSE:

[{
  "error": {
    "code": 400,
    "message": "Invalid JSON payload received. Unknown name \"function_declarations\" at 'tools': Cannot find field.",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.BadRequest",
        "fieldViolations": [
          {
            "field": "tools",
            "description": "Invalid JSON payload received. Unknown name \"function_declarations\" at 'tools': Cannot find field."
          }
        ]
      }
    ]
  }
}
]

Original format (compatible with OpenAI and xAI) works well. There’re only troubles with parameterless functions.

I tested it on my side, and it seems to be working. Here’s the link to the Colab gist:

Colab_Notebook

You guys are not on the same page. Gregory is using flash, and you are proving that pro works.

I tried with both the model and its working fine.

1 Like

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"}}]
        }'

and a responce:

[{
  "error": {
    "code": 400,
    "message": "Request contains an invalid argument.",
    "status": "INVALID_ARGUMENT"
  }
}
]

Got it. The issue happens when we try to pass a parameterless function using the OpenAI libraries with the Gemini API.

Thanks @Gregory_Ledenev , I have escalated this with the team.

2 Likes

Thank you very much. Appreciated it!

Can you also check this issue too? I can’t return back function calls results to Gemini…

1 Like

Hi, any ETA on the fix for this?

@GUNAND_MAYANGLAMBAM

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