From 3e6b3a69ac53e1869bab9d75d01f0e097d0fcc16 Mon Sep 17 00:00:00 2001 From: Logan King Date: Sat, 19 Jul 2025 19:06:45 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=84=20Improve=20token=20streaming=20fl?= =?UTF-8?q?ush?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assistant_v2/src/main.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/assistant_v2/src/main.rs b/assistant_v2/src/main.rs index 4b280bf..7867429 100644 --- a/assistant_v2/src/main.rs +++ b/assistant_v2/src/main.rs @@ -20,6 +20,7 @@ use std::path::PathBuf; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::{Arc, Mutex}; use std::time::Instant; +use std::io::{stdout, Write}; use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt, EnvFilter}; use tracing::info; @@ -411,6 +412,7 @@ async fn main() -> Result<(), Box> { displayed_ai_label = true; } print!("{}", text); + stdout().flush().unwrap(); speak_stream_cloned.lock().unwrap().add_token(&text); } } @@ -771,6 +773,7 @@ async fn handle_requires_action( displayed_ai_label = true; } print!("{}", text); + stdout().flush().unwrap(); speak_stream.lock().unwrap().add_token(text); } } @@ -895,6 +898,7 @@ async fn submit_tool_outputs( if let Some(text) = text.text { if let Some(text) = text.value { print!("{}", text); + stdout().flush().unwrap(); speak_stream.lock().unwrap().add_token(&text); } }