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
This commit is contained in:
Cole Miller 2024-12-12 11:39:35 -05:00 committed by GitHub
parent b4c8e04544
commit ee6f834028
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -147,7 +147,7 @@ pub trait LanguageModel: Send + Sync {
let events = self.stream_completion(request, cx); let events = self.stream_completion(request, cx);
async move { async move {
let mut events = events.await?; let mut events = events.await?.fuse();
let mut message_id = None; let mut message_id = None;
let mut first_item_text = None; let mut first_item_text = None;