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