Parallel Function Calling

Given the current documentation described [here] (https://platform.openai.com/docs/api-reference/chat/create#chat-create-tool_choice), regarding the use of parallel function calling.

I have 5 different function with the following format:

tools = [
{"type":"function",
"function":{
"name":"<function_a>"
...
},{
....
},
...
]

as is described by the docs. I am assuming that since I have specified the function signature, i should expect GPT to call all 5 functions.

def response_generator():
    response = client.chat.completions.create(
        model="gpt-3.5-turbo-1106",
        temperature=0,
        messages=messages,
        tools=tools,
        tool_choice="auto",
    )
    return response

Problem is the response object has only 2 objects in the tool_calls attribute, although i want all 5 to be called.

Do i have to specify something in the prompt or not put “auto” in the tool_choice parameter. If not, what should i put there?

What am i missing?

Any help is appreciated. Thank you.

Few things … if you ALWAYS want all 5 to be called why not create on function. That would be way more efficient.

Functions will be called based on their instructions (What is in the function description) and your prompt. So you CAN instruct the model to ALWAYS call all five.

2 Likes

I have found that the AI just seems not to be trained on using its multi_tool_use wrapper to call different functions at the same time. It will do parallel calls to the same function almost too easily though.

For example, I have both a float and an int random number generator function:

  • ask the AI to roll four dice and give results: four functions in tool calls.
  • ask the AI to just give a random int and a random float: just one function.

Adding “Can operate in parallel with other function types.” to all function descriptions? No difference.

Unlike “devday”, the AI isn’t going to lock your car and roll up the windows in the same tool_call unless the parameters are in the same function.

I finally got this to go with the additional description on gpt-4-turbo-preview:


        "tool_calls": [
          {
            "id": "call_Z8jTwVecJP7o4Tot5tD3suMo",
            "function": {
              "arguments": "{\"range_start\": 0, \"range_end\": 66}",
              "name": "get_random_float"
            },
            "type": "function"
          },
          {
            "id": "call_AeiKMGkPzxzZosOuVlsexbEg",
            "function": {
              "arguments": "{\"range_start\": 1, \"range_end\": 33}",
              "name": "get_random_int"
            },
            "type": "function"
          }
        ]
1 Like

Hi! thanks for the input and suggestions ! I’ll give it a go