openai-node icon indicating copy to clipboard operation
openai-node copied to clipboard

functionCallResult never get's called in the frontend with ChatCompletionStream

Open cosbgn opened this issue 1 year ago • 7 comments

Confirm this is a Node library issue and not an underlying OpenAI API issue

  • [X] This is an issue with the Node library

Describe the bug

In my backend I do:

const steam = client.beta.chat.completions.runTools({})
return steam.toReadableStream()

And in my frontend I do:

const runner = ChatCompletionStream.fromReadableStream( response.body )
runner.on('message', (message) => {
    messages.value.push(message)
})

This works but after the role:assistant with tool_calls it doesn't push the tool_call results to the messages array. In the frontend also runner.on('functionCallResult') never gets called.

This means that next calls fail because after a tool call we must pass the tool call results.

How can I get the tool call function response to show up in messages?

To Reproduce

  1. return a stream to the frontend:

const steam = client.beta.chat.completions.runTools({}) return steam.toReadableStream()

  1. read the stream with ChatCompletionStream

  2. fail to get the function response as message

P.s I've also tested with ChatCompletionStreamingRunner and it's the same

Code snippets

No response

OS

mac latest

Node version

22

Library version

latest

cosbgn avatar Sep 11 '24 15:09 cosbgn