Function Calling - Bad Request Error

Hi there, I’m trying to understand how I can get parallel function calling working. I have defined tool to get stock data but can’t get stock data of two entities at the same time.

You need to share the underlying calls.

Otherwise I would say the error is self evident?

Here’s a successful parallel call to prompt What is the cube root of 7 and separately the cube root of 8?

[
  {
    "role": "assistant",
    "content": "",
    "tool_calls": [
      {
        "id": "call_PfQMhLHCs0QhbzHCdNVKhaKl",
        "type": "function",
        "function": {
          "name": "calculate",
          "arguments": "{\"input\": \"Math.cbrt(7)\"}"
        }
      },
      {
        "id": "call_JHHh8Yj4qJQl3iSy7Pvw8SZQ",
        "type": "function",
        "function": {
          "name": "calculate",
          "arguments": "{\"input\": \"Math.cbrt(8)\"}"
        }
      }
    ]
  },
  {
    "role": "tool",
    "tool_call_id": "call_PfQMhLHCs0QhbzHCdNVKhaKl",
    "content": "1.912931182772389"
  },
  {
    "role": "tool",
    "tool_call_id": "call_JHHh8Yj4qJQl3iSy7Pvw8SZQ",
    "content": "2.0"
  }
]

Do you utilize parallel tool calls as described in the OpenAI documentation (https://platform.openai.com/docs/api-reference/chat/create#chat-create-tool_choice)?

If not, there’s no clear justification for calling a tool sequentially. A language model should only call the same tool multiple times if there’s a specific reason to do so. In such cases, an assistant message should be included between successive tool calls to provide context or explain the rationale.

Hi, this is a section of my code to deal with function calls. There is no difference between parallel an non-parallel calls, just they are one or more than one calls in a list, and you must perform every one and give some response using it identifier. My code is c#,think on it as pseudo-code, as it uses resource names and objets not listed in the fragment:

… Here you have launched a thread run, and you have received a run response:

                            if (run.Status == RUNST_requires_action)
                            {
                                if ((run.RequiredAction != null) && (run.RequiredAction.Type == RACTION_submit_tool_outputs))
                                {
                                    ToolOutputs to = new ToolOutputs();
                                    string callblock = run.Id;
                                    foreach (ToolCall tc in run.RequiredAction.SubmitToolOutputs.ToolCalls)
                                    {
                                        string fresult = "";
                                        if (AppAutomation != null)
                                        {
                                            FunctionResponse resp = await AppAutomation.CallFunction(this, tc.Function.Name, tc.Function.Arguments, callblock);
                                            fresult = resp.Result;
                                        }
                                        else
                                        {
                                            fresult = string.Format(ERR_NoAppAutomation, tc.Function.Name);
                                        }
                                        to.ToolOutputsList.Add(new ToolOutput()
                                        {
                                            ToolCallId = tc.Id,
                                            Output = fresult
                                        });
                                    }
                                    endpoint = _settings.GetEndpoint(SECTION_assistantthreads, EPNAME_SubmitToolOutputs);
                                    ow = await APIManager.APICallAsync(client, to, string.Format(endpoint.URL, othread.Id, run.Id), new HttpMethod(endpoint.Method), endpoint.returnType);
                                    run = ow.Implementation as Run;
                                }
                            }

… continue procesing

1 Like

Yep, I figured it out. Thank you!

Please format your Post putting the json into a markdown code block.

Done!
Sorry for not removing left spaces.

1 Like