Unverified Commit a5e1d45e authored by Jacky's avatar Jacky Committed by GitHub
Browse files

fix: Polling from exhausted stream in preprocessor (#3349)


Signed-off-by: default avatarJacky <18255193+kthui@users.noreply.github.com>
parent 5194acbd
......@@ -550,11 +550,14 @@ impl OpenAIPreprocessor {
Some((response, inner))
} else {
// Stream has ended - check if we need to send a usage chunk
// Stream has ended - must set finished to true to prevent unfold from polling
// again. The stream is exhausted and will panic if polled after None.
inner.finished = true;
// Check if we need to send a usage chunk
if inner.response_generator.is_usage_enabled()
&& inner.finish_reason_sent
&& !inner.usage_chunk_sent
&& !inner.finished
{
inner.usage_chunk_sent = true;
......@@ -575,7 +578,6 @@ impl OpenAIPreprocessor {
Some((annotated_usage, inner))
} else {
// stream closed
inner.finished = true; // Mark as finished
None
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment