Code 400 when defined multiple functions in tools

When multiple functions are defined in the tools, the call results in a code 400 invalid argument error. The strange thing is that when tools contains only one of the functions, it works perfectly fine.
This is the tools definition I have defined

tools=[
   {
      "function":{
         "description":"select the url of a given music",
         "name":"get_music",
         "parameters":{
            "properties":{
               "music_name":{
                  "description":"The music name, e.g. Never Gonna Give You Up",
                  "type":"string"
               },
               "artist_name":{
                  "description":"The artist name, e.g. The Weeknd",
                  "type":"string"
               }
            },
            "required":[
               "music_name"
            ],
            "type":"object"
         }
      },
      "type":"function"
   },
    {
      "function":{
         "description":"Get the weather in a given location.",
         "name":"get_weather",
         "parameters":{
            "properties":{
               "cityname":{
                  "description":"The city name, e.g.default today's weather",
                  "type":"string"
               },
               "unit": {
                  "type": "string",
                  "format": "enum",
                  "enum": ["celsius", "fahrenheit"]
          }
            },
            "required":[
               "cityname"
            ],
            "type":"object"
         }
      },
      "type":"function"
   }
]

I call Gemini using a POST request, following the OpenAI standard.

    async with httpx.AsyncClient(proxies=proxies) as client:

        response = await client.post(
            f"{base_url}chat/completions",
            headers={"Authorization": f"Bearer {api_key}"},
            json={
                "model": "gemini-1.5-flash-002",  # 使用您选择的模型
                "messages": conversation_history,
                "tools": tools,
                "tool_choice": "required"
            }
        )

I would greatly appreciate it if you could help me.

Hi @vilperg

I have reproduced the issue and seems like there is issue when we define multiple functions. Thanks for pointing this out, I have escalated it to the team.

2 Likes

Thank you for your work:-)

1 Like

Hi @GUNAND_MAYANGLAMBAM,

Do you have an update on the ETA for the fix here? This’s blocking me at the moment.

Thanks,
Ahmed

Hi @Ahmed_Helil , I can’t give the exact timeline, but the team is working on it.