Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AssistantStream.accumulateDelta does not cover accumulating toolCall #771

Open
1 task done
romdotdog opened this issue Apr 16, 2024 · 0 comments
Open
1 task done
Labels
bug Something isn't working

Comments

@romdotdog
Copy link

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

  • This is an issue with the Node library

Describe the bug

Say we have a delta like

{"delta":{"step_details":{"type":"tool_calls","tool_calls":[{"index":0,"type":"function","function":{"arguments":"{}"}}]}}}

You're missing functionality here:

https://github.com/openai/openai-node/blob/116e38aae33a2d7b88c27d783a95b41e56500600/src/lib/AssistantStream.ts#L686C1-L691C8

I recommend adding something like

} else if (
    Array.isArray(accValue) &&
    Array.isArray(deltaValue)
) {
    if (
        accValue.every(
            x => typeof x === "string" || typeof x === "number"
        )
    ) {
        accValue.push(...deltaValue); // Use spread syntax for efficient addition
        continue;
    // new code below
    } else if (
        deltaValue.every(
            x =>
                isObj(x) &&
                x.hasOwnProperty("index") &&
                typeof x.index === "number"
        )
    ) {
        for (let i = 0; i < deltaValue.length; i++) {
            const index = deltaValue[i].index;
            accValue[index] = this.accumulateDelta(
                accValue[index],
                deltaValue[i]
            );
        }
        continue;
    }
    // end of new code
}

To Reproduce

Any streamed tool call with arguments will do. Notice how the argument field is empty in the toolCall parameter from the event "toolCallDone"

Code snippets

No response

OS

Linux

Node version

Node v20.11.1

Library version

openai v4.34.0

@romdotdog romdotdog added the bug Something isn't working label Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant