From 5c3f3acd6a6602e8374b326d59628fd83dcf27e4 Mon Sep 17 00:00:00 2001 From: dal Date: Mon, 24 Feb 2025 08:07:42 -0700 Subject: [PATCH] returning appropriately --- api/src/routes/rest/routes/chats/post_chat.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/api/src/routes/rest/routes/chats/post_chat.rs b/api/src/routes/rest/routes/chats/post_chat.rs index 07bbbb7f9..206bd1d93 100644 --- a/api/src/routes/rest/routes/chats/post_chat.rs +++ b/api/src/routes/rest/routes/chats/post_chat.rs @@ -102,20 +102,19 @@ async fn process_chat(request: ChatCreateNewChat, user: User) -> Result { + while let Ok(message) = rx.recv().await { + match message { + Ok(msg) => { match msg { AgentMessage::Assistant { content: Some(content), tool_calls: None, .. } => { - // Store the final message content + // Store the final message and break immediately final_message = Some(content); + break; } _ => messages.push(msg), } } - Ok(Err(e)) => return Err(e.into()), - Err(broadcast::error::RecvError::Closed) => break, - Err(e) => return Err(anyhow!(e)), + Err(e) => return Err(e.into()), } }