feat: created the RenderMode enum to suppress stdout streaming during parallel graph super-steps
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use super::*;
|
||||
|
||||
use crate::config::paths;
|
||||
use crate::config::{paths, RenderMode};
|
||||
use crate::{
|
||||
config::{AppConfig, Input, RequestContext},
|
||||
function::{FunctionDeclaration, ToolCall, ToolResult, eval_tool_calls},
|
||||
@@ -459,6 +459,9 @@ pub async fn call_chat_completions_streaming(
|
||||
) -> Result<(String, Vec<ToolResult>)> {
|
||||
let (tx, rx) = unbounded_channel();
|
||||
let mut handler = SseHandler::new(tx, abort_signal.clone());
|
||||
if ctx.render_mode == RenderMode::Silent {
|
||||
handler.set_silent(true);
|
||||
}
|
||||
|
||||
let (send_ret, render_ret) = tokio::join!(
|
||||
client.chat_completions_streaming(input, &mut handler),
|
||||
|
||||
@@ -16,6 +16,7 @@ pub struct SseHandler {
|
||||
last_tool_calls: Vec<ToolCall>,
|
||||
max_call_repeats: usize,
|
||||
call_repeat_chain_len: usize,
|
||||
silent: bool,
|
||||
}
|
||||
|
||||
impl SseHandler {
|
||||
@@ -28,14 +29,28 @@ impl SseHandler {
|
||||
last_tool_calls: Vec::new(),
|
||||
max_call_repeats: 2,
|
||||
call_repeat_chain_len: 3,
|
||||
silent: false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Suppresses stdout streaming of incoming tokens. Tokens are still buffered
|
||||
/// internally (so the caller's `.take()` still returns the full response) —
|
||||
/// only the per-token send to the SSE renderer is skipped. Used by parallel
|
||||
/// graph super-step branches so concurrent LLM calls don't interleave on
|
||||
/// stdout.
|
||||
pub fn set_silent(&mut self, silent: bool) {
|
||||
self.silent = silent;
|
||||
}
|
||||
|
||||
pub fn text(&mut self, text: &str) -> Result<()> {
|
||||
if text.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
self.buffer.push_str(text);
|
||||
if self.silent {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let ret = self
|
||||
.sender
|
||||
.send(SseEvent::Text(text.to_string()))
|
||||
|
||||
Reference in New Issue
Block a user