openai / openai-node

The official Node.js / Typescript library for the OpenAI API
https://www.npmjs.com/package/openai
Apache License 2.0
7.36k stars 770 forks source link

No Function Arguments in toolCallDone Stream Event Hook #790

Closed neilord closed 1 week ago

neilord commented 2 months ago

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

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

rattrayalex commented 2 months ago

Thanks for reporting, we'll look into it!

romdotdog commented 2 months ago

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

egamma commented 2 months ago

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.

Omicrxn commented 1 month ago

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.

matheuscorreiacardoso commented 1 month ago

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

Is there an bug?

neilord commented 1 month ago

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.

matheuscorreiacardoso commented 1 month ago

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

rattrayalex commented 1 week ago

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