ai icon indicating copy to clipboard operation
ai copied to clipboard

Setting the parameter n to greater than 1 and stream to true resulted in unordered messages being received.

Open moondie opened this issue 3 years ago • 2 comments

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 :

  1. when I set n to 3 or 5 or any number greater than 1 and set stream to true, I receive chunks of multiple replies mixed together with no way of distinguishing them. For example, if I send "Please reply 12345" with n set to 3, I get "111223234344555".

  2. when I set n to 3 or 5 or any number greater than 1 and set stream to false, I will only receive one response, as opposed to the expected three or five. For example, if I send "Please reply 12345" with n set 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.

moondie avatar Sep 05 '23 18:09 moondie

We have switched to providers in the meantime.

lgrammel avatar Sep 19 '24 16:09 lgrammel

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 > 1 and streaming enabled, chunks from separate completions are interleaved without preserving or exposing their identities.
  • With n > 1 and 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.

lgrammel avatar Jul 22 '26 18:07 lgrammel