From ee6f8340280aab33a39b3b38176d5f6b40c4662f Mon Sep 17 00:00:00 2001 From: Cole Miller Date: Thu, 12 Dec 2024 11:39:35 -0500 Subject: [PATCH] Fuse LLM completion stream to avoid a panic (#21914) `LanguageModel::stream_completion_text` can poll the `stream_completion` stream (ultimately a `futures::Unfold`) after it's returned `Ready(None)`, which leads to a panic; avoid this by fusing the stream. Release Notes: - Fixed a panic when streaming language model completions --- crates/language_model/src/language_model.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/language_model/src/language_model.rs b/crates/language_model/src/language_model.rs index 83f0b50321..a10c743b35 100644 --- a/crates/language_model/src/language_model.rs +++ b/crates/language_model/src/language_model.rs @@ -147,7 +147,7 @@ pub trait LanguageModel: Send + Sync { let events = self.stream_completion(request, cx); async move { - let mut events = events.await?; + let mut events = events.await?.fuse(); let mut message_id = None; let mut first_item_text = None;