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

Closed
1 task done
romdotdog opened this issue Apr 16, 2024 · 4 comments
Closed
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

@rattrayalex
Copy link
Collaborator

Sorry for the bug here – we hope to take a look at the community PR soon.

@Omicrxn
Copy link

Omicrxn commented Sep 3, 2024

What is the state of this issue? it's been a couple months since the streaming api doesn't provide arguments on toolCallDone or toolCallCreated, however on toolCallDelta it provides the arguments.

stainless-app bot pushed a commit that referenced this issue Sep 3, 2024
* fix(accumulateDelta): AssistantStream accumulateDelta toolCall (#771)

* minor style changes

---------

Co-authored-by: A4F54B <[email protected]>
@RobertCraigie
Copy link
Collaborator

Really sorry for the delay here, this will be fixed in the next release #1028

@Omicrxn
Copy link

Omicrxn commented Sep 3, 2024

Nice to hear that! Thanks @RobertCraigie

stainless-app bot pushed a commit that referenced this issue Sep 3, 2024
* fix(accumulateDelta): AssistantStream accumulateDelta toolCall (#771)

* minor style changes

---------

Co-authored-by: A4F54B <[email protected]>
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

4 participants