-
Notifications
You must be signed in to change notification settings - Fork 76
TypeError
when handling streamed final usage chunk with choices: []
#107
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
Comments
TypeError
when handling streamed final usage chunk with choices: []
Hi @stanoswald ! I took a look at the code, and I believe this case is actually handled safely in the current implementation:
if (!chunk.choices?.[0]?.delta) continue; This means when Are you still experiencing the TypeError in your implementation? If so, could you share a minimal reproduction of the error? That would help identify if there might be a different issue at play. |
@actuallyzefe Hey there! Thanks for the quick reply! You're absolutely right - I took another look at the code and I totally missed the Thanks again for helping me spot that! 🙏 |
I was checking the compiled .mjs output locally and noticed it didn’t quite match what I was seeing in the codebase. After a bit of digging with git blame, turns out this has already been addressed in #92 #93 and should be fixed in the next release. All good now! Sorry for the extra noise—I totally missed the closed issue and PR. @actuallyzefe |
Please read this first
Describe the bug
When using an OpenAI-API compatible provider , the streamed response may include a final chunk with
choices: []
. TheconvertChatCompletionsStreamToResponses
function inopenaiChatCompletionsStreaming.ts
assumes chunk.choices[0] exists, and throws:This is due to this line:
This line assumes
chunk.choices
is non-empty, but according to the OpenAI Chat Completions Streaming API documentation:So
choices: []
seems a valid case, and should be handled gracefully by the SDK for compatibility with OpenAI-compatible providers.Debug information
v0.0.7
)Node.js 22.11.0
)The text was updated successfully, but these errors were encountered: