Streaming function calls does not return an id with tool_calls

As far as I understand, in order to send a follow-up message from GPT after running a function call, you need to pass an object like this:

      messages.push({
        tool_call_id: toolCall.id,
        role: "tool",
        name: functionName,
        content: functionResponse,
      }); 

The issue is, when streaming, I don’t see an id call_... in the streaming response:

{
  id: 'chatcmpl-8mzIGYpyMzCMxE1KDv3Kt9IcfaSzX',
  object: 'chat.completion.chunk',
  created: 1706686048,
  model: 'gpt-3.5-turbo-1106',
  system_fingerprint: 'fp_b57c83dd65',
  choices: [
  {
    index: 0,
    delta: { tool_calls: [ { index: 0, function: { arguments: ' my' } } ] },
    logprobs: null,
    finish_reason: null
  }]
}

Is this a known issue? Or am I missing something about how to get the tool_call_id?

It’s been a little while, but if you haven’t figured it out, I found that in the first chunk that comes back, the structure includes a tool call ID.

{
    "id": "chatcmpl-8ruxmT0SbZYoS6jQmDzyJzyp0K4n0",
    "object": "chat.completion.chunk",
    "created": 1707861042,
    "model": "gpt-3.5-turbo-0613",
    "system_fingerprint": null,
    "choices": [
      {
        "index": 0,
        "delta": {
          "role": "assistant",
          "content": null,
          "tool_calls": [
            {
              "index": 0,
              "id": "call_KxcsHbt88vrVefLY6j01Ezci",
              "type": "function",
              "function": {
                "name": "some_function",
                "arguments": ""
              }
            }
          ]
        },
        "logprobs": null,
        "finish_reason": null
      }
    ]
  }
2 Likes

It also is strategic, in that you can use the initial delta to stop playing the stream and instead throw up a progress report to indicate what is happening, to enhance user experience.

1 Like

Glad I checked back in, this works! Thank you