Setting the parameter n to greater than 1 and stream to true resulted in unordered messages being received.
When I do something like the sample code:
const res = await openai.createChatCompletion(parms);
const aistream = OpenAIStream(res);
return new StreamingTextResponse(aistream);
Normally everything works fine, but :
-
when I set
nto 3 or 5 or any number greater than 1 and setstreamtotrue, I receive chunks of multiple replies mixed together with no way of distinguishing them. For example, if I send "Please reply 12345" withnset to 3, I get "111223234344555". -
when I set
nto 3 or 5 or any number greater than 1 and setstreamtofalse, I will only receive one response, as opposed to the expected three or five. For example, if I send "Please reply 12345" withnset to 3, I get "12345".
I don't know if there are other solutions, but I think the goal of vercel's AI SDK is to allow users to get AI replies in the easiest way possible without having to care about specific implementation details.
We have switched to providers in the meantime.
Identify issue type
Identified as Bug
Confidence: High
Rationale
The issue reports concrete incorrect output when using an existing OpenAI completion parameter through the SDK, so it is a bug despite the implementation later being superseded.
Evidence
- With
n > 1and streaming enabled, chunks from separate completions are interleaved without preserving or exposing their identities. - With
n > 1and streaming disabled, only one completion is returned instead of the requested number. - The maintainer notes that the SDK later switched to providers, indicating the affected implementation may now be obsolete but not disputing the reported failure.