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

No Function Arguments in toolCallDone Stream Event Hook

Open neilord opened this issue 1 year ago • 3 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

The ".on('toolCallDone') used on the stream returned by ai.beta.threads.runs.stream" does not return arguments (empty string), only function name:

{
  index: 0,
  id: 'call_id',
  type: 'function',
  function: { name: 'functionName', arguments: '', output: null }
}

To Reproduce

  1. Retrieve a run stream with ai.beta.threads.runs.stream
  2. Add the .on('toolCallDone') hook.
  3. Wait for the response, it does not return with what arguments should the function be called.

Code snippets

const stream = ai.beta.threads.runs.stream(threadId, {
    assistant_id: assistantId,
});
stream.on('toolCallDone', (toolCall) => {
    console.log(toolCall); // no arguments for function
});

OS

macOS

Node version

v20.11.1

Library version

openai v4.36.0

neilord avatar Apr 20 '24 10:04 neilord

Thanks for reporting, we'll look into it!

rattrayalex avatar Apr 22 '24 21:04 rattrayalex

Isn't this a duplicate of my issue #771?

romdotdog avatar Apr 27 '24 16:04 romdotdog

Just for completeness. In the toolCallDone event with the toolCall.type === code_interpreter, then toolCall.code_interpreter.input is also empty.

As a workaround I'm listening to the event thread.run.step.completed and handling runStep.step_details.type === 'tool_calls' then the input and output properties are both not empty for function and code_interpreter.

egamma avatar May 02 '24 07:05 egamma

Also, aside from this still happening 100% of the times a tool is called, I would also like to add that once the tool output is submitted, the assistant doesn't respond with anything, or at least it is not shown by .on('messageDone') nor with any other .on() listener.

Omicrxn avatar May 22 '24 21:05 Omicrxn

When i have multiple function calls, toolCallDone is called once just with first functionCall.

Is there an bug?

matheuscorreiacardoso avatar May 23 '24 19:05 matheuscorreiacardoso

When i have multiple function calls, toolCallDone is called once just with first functionCall.

Is there an bug?

That is correct that toolCallDone is called once, it is supposed to be the event triggered once AI finished writing the tool call (see docs). The current bug (unless fixed already, probably not) is that toolCallDone is not usable because when I was testing it, it had the empty function.arguments parameter.

neilord avatar May 23 '24 20:05 neilord

When i have multiple function calls, toolCallDone is called once just with first functionCall. Is there an bug?

That is correct that toolCallDone is called once, it is supposed to be the event triggered once AI finished writing the tool call (see docs). The current bug (unless fixed already, probably not) is that toolCallDone is not usable because when I was testing it, it had the empty function.arguments parameter.

Wich one is called for all tool calls?

Actually im using generic events like:

if (event.event === 'thread.run.requires_action') {
            const run = event.data;
            run.required_action.submit_tool_outputs.tool_calls.map((toolCall) => {
                if (toolCall.type === 'function') {
                    const assistantResponse = {
                        id: toolCall.id,
                        role: 'tool',
                        type: 'FUNCTION',
                        content: toolCall.function,
                        status: 'waiting',
                    };
                    this.emit('assistantResponse', assistantResponse);
                }
            });

            this.emit('requiresAction');
        }

And submitting all tool calls to my sistems

matheuscorreiacardoso avatar May 26 '24 01:05 matheuscorreiacardoso

Closing as a duplicate of https://github.com/openai/openai-node/issues/771

rattrayalex avatar Jul 08 '24 18:07 rattrayalex