Skip to content

Commit 88407ff

Browse files
fix: stream responses correctly, replace the message we send to the model on 'n' deny inputs (#336)
1 parent 51c48bf commit 88407ff

File tree

1 file changed

+13
-3
lines changed
  • crates/chat-cli/src/cli/chat

1 file changed

+13
-3
lines changed

crates/chat-cli/src/cli/chat/mod.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,6 +1403,16 @@ impl ChatSession {
14031403
self.tool_use_status = ToolUseStatus::Idle;
14041404

14051405
if self.pending_tool_index.is_some() {
1406+
// If the user just enters "n", replace the message we send to the model with
1407+
// something more substantial.
1408+
// TODO: Update this flow to something that does *not* require two requests just to
1409+
// get a meaningful response from the user - this is a short term solution before
1410+
// we decide on a better flow.
1411+
let user_input = if ["n", "N"].contains(&user_input.trim()) {
1412+
"I deny this tool request. Ask a follow up question clarifying the expected action".to_string()
1413+
} else {
1414+
user_input
1415+
};
14061416
self.conversation.abandon_tool_use(&self.tool_uses, user_input);
14071417
} else {
14081418
self.conversation.set_next_user_message(user_input).await;
@@ -1787,7 +1797,7 @@ impl ChatSession {
17871797
match interpret_markdown(input, &mut self.stdout, &mut state) {
17881798
Ok(parsed) => {
17891799
offset += parsed.offset_from(&input);
1790-
self.stderr.flush()?;
1800+
self.stdout.flush()?;
17911801
state.newline = state.set_newline;
17921802
state.set_newline = false;
17931803
},
@@ -1825,11 +1835,11 @@ impl ChatSession {
18251835
}
18261836

18271837
queue!(self.stderr, style::ResetColor, style::SetAttribute(Attribute::Reset))?;
1828-
execute!(self.stderr, style::Print("\n"))?;
1838+
execute!(self.stdout, style::Print("\n"))?;
18291839

18301840
for (i, citation) in &state.citations {
18311841
queue!(
1832-
self.stderr,
1842+
self.stdout,
18331843
style::Print("\n"),
18341844
style::SetForegroundColor(Color::Blue),
18351845
style::Print(format!("[^{i}]: ")),

0 commit comments

Comments
 (0)