feat: ctrl-c interrupts ongoing prompt in a session, but lets the user inject more instructions mid-stream
This commit is contained in:
+18
-1
@@ -493,13 +493,30 @@ pub async fn call_chat_completions_streaming(
|
|||||||
render_stream(rx, client.app_config(), abort_signal.clone(), silent),
|
render_stream(rx, client.app_config(), abort_signal.clone(), silent),
|
||||||
);
|
);
|
||||||
|
|
||||||
if handler.abort().aborted() {
|
let aborted_ctrlc = handler.abort().aborted_ctrlc();
|
||||||
|
let aborted_ctrld = handler.abort().aborted_ctrld();
|
||||||
|
|
||||||
|
if aborted_ctrld {
|
||||||
bail!("Aborted.");
|
bail!("Aborted.");
|
||||||
}
|
}
|
||||||
|
|
||||||
render_ret?;
|
render_ret?;
|
||||||
|
|
||||||
let (text, tool_calls, thinking) = handler.take();
|
let (text, tool_calls, thinking) = handler.take();
|
||||||
|
|
||||||
|
if aborted_ctrlc {
|
||||||
|
if text.is_empty() || !ctx.working_mode.is_repl() || ctx.session.is_none() {
|
||||||
|
bail!("Aborted.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if !silent && *IS_STDOUT_TERMINAL {
|
||||||
|
println!();
|
||||||
|
eprintln!("{}", error_text("Response interrupted"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok((text, vec![]));
|
||||||
|
}
|
||||||
|
|
||||||
match send_ret {
|
match send_ret {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
if !silent && !text.is_empty() && !text.ends_with('\n') {
|
if !silent && !text.is_empty() && !text.ends_with('\n') {
|
||||||
|
|||||||
Reference in New Issue
Block a user