Chat API and function calling returns no arguments

Hello :slight_smile:
I have an issue with function calling with the chat API:
it does return the function to call, however, there are no arguments.
For example, this is the data sent for a test:>

{“model”:“gpt-4-0125-preview”,“messages”:[{“role”:“user”,“content”:“What is the weather in Paris”}],“temperature”:0.3,“top_p”:0.5,“stream”:true,“presence_penalty”:0.1,“frequency_penalty”:0.1,“tools”:[{“type”:“function”,“function”:{“name”:“get_weather”,“description”:“Get the weather for a given location”,“parameters”:{“type”:“object”,“properties”:{“location”:{“type”:“string”,“description”:“Location to get the weather for e.g. Paris”,“properties”:{}}},“required”:[“location”]}}}]}

And this is the response I got:

{“id”:“chatcmpl-8sYbFw9PUJzxdwFAhDFe6D7MaJSDI”,“object”:“chat.completion.chunk”,“created”:1708013405,“model”:“gpt-4-0125-preview”,“system_fingerprint”:“fp_f084bcfc79”,“choices”:[{“index”:0,“delta”:{“role”:“assistant”,“content”:null,“tool_calls”:[{“index”:0,“id”:“call_eVltVXCdJ40Xv1ZD40wZ4RB5”,“type”:“function”,“function”:{“name”:“get_weather”,“arguments”:“”}}]},“logprobs”:null,“finish_reason”:null}]}

I’m a bit lost, if someone can help me, thank you! :slight_smile:

2 Likes

Having the same problem here! I am also using streaming, but otherwise same. Arguments just always returns as an empty string. Not sure why.

Just figured something out. Turns out since I’m doing streaming, the name of the tool call first comes in, then the argument starts streaming in chunk by chunk. Very peculiar. Gonna go and solve this now.

Holy shit, thank you man, I’ve literally spent an entire day trying to make this work thinking I did something wrong :see_no_evil:

1 Like

@arvi89 Hey, stuck on this same thing for a while. Can you share the work around code? I am using delta response and with_raw_response (legacy).

Bruh! You just saved my life lol… Thanks mate! :wink:

Seems like there is a bug. It makes sense that on toolCallCreated, there would be no arguments, but when you log out toolCallDone, the arguments are STILL empty.

 .on("toolCallDone", (toolCallDone) => {
    process.stdout.write(JSON.stringify(toolCallDone, null, 2));
 })

-> Outputs:
{
  "index": 0,
  "id": "call_CrFxNa5SQa5mqSucxzXznjGv",
  "type": "function",
  "function": {
    "name": "getWeather",
    "arguments": "",
    "output": null
  }
}

It seems they can only be accessed by capturing them from the toolCallDelta, which is an unneeded PITA for function calling (where 99% of the time, you’re going to wait until the response is complete to run the function).