Skip to content

Commit 20bd77d

Browse files
committed
merge
1 parent 1302928 commit 20bd77d

File tree

1 file changed

+7
-57
lines changed
  • crates/chat-cli/src/cli/chat

1 file changed

+7
-57
lines changed

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

Lines changed: 7 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,6 @@ use parser::{
9595
RecvErrorKind,
9696
ResponseParser,
9797
};
98-
use rand::distr::{
99-
Alphanumeric,
100-
SampleString,
101-
};
10298
use regex::Regex;
10399
use serde_json::Map;
104100
use spinners::{
@@ -146,7 +142,6 @@ use util::{
146142
animate_output,
147143
drop_matched_context_files,
148144
play_notification_bell,
149-
region_check,
150145
};
151146
use uuid::Uuid;
152147
use winnow::Partial;
@@ -171,7 +166,6 @@ use crate::telemetry::{
171166
TelemetryResult,
172167
TelemetryThread,
173168
};
174-
use crate::util::CLI_BINARY_NAME;
175169

176170
#[derive(Debug, Clone, PartialEq, Eq, Default, Args)]
177171
pub struct ChatArgs {
@@ -205,15 +199,6 @@ pub struct ChatArgs {
205199

206200
impl ChatArgs {
207201
pub async fn execute(self, database: &mut Database, telemetry: &TelemetryThread) -> Result<ExitCode> {
208-
if !crate::util::system_info::in_cloudshell() && !crate::auth::is_logged_in(database).await {
209-
bail!(
210-
"You are not logged in, please log in with {}",
211-
format!("{CLI_BINARY_NAME} login").bold()
212-
);
213-
}
214-
215-
region_check("chat")?;
216-
217202
let ctx = Context::new();
218203

219204
let stdin = std::io::stdin();
@@ -299,7 +284,8 @@ impl ChatArgs {
299284
// if let Some(ref id) = model_id {
300285
// database.set_last_used_model_id(id.clone())?;
301286
// }
302-
let conversation_id = Alphanumeric.sample_string(&mut rand::rng(), 9);
287+
288+
let conversation_id = uuid::Uuid::new_v4().to_string();
303289
info!(?conversation_id, "Generated new conversation id");
304290
let (prompt_request_sender, prompt_request_receiver) = std::sync::mpsc::channel::<Option<String>>();
305291
let (prompt_response_sender, prompt_response_receiver) = std::sync::mpsc::channel::<Vec<String>>();
@@ -1482,9 +1468,10 @@ impl ChatContext {
14821468
self.send_tool_use_telemetry(telemetry).await;
14831469

14841470
if self.interactive {
1485-
// Print newlines before starting the assistant response
1486-
execute!(self.output, style::Print("\n\n"))?;
1471+
queue!(self.output, style::SetForegroundColor(Color::Magenta))?;
1472+
queue!(self.output, style::SetForegroundColor(Color::Reset))?;
14871473
queue!(self.output, cursor::Hide)?;
1474+
execute!(self.output, style::Print("\n"))?;
14881475
self.spinner = Some(Spinner::new(Spinners::Dots, "Thinking...".to_owned()));
14891476
}
14901477

@@ -3382,18 +3369,6 @@ impl ChatContext {
33823369
)?;
33833370
}
33843371

3385-
// Add assistant indicator at the beginning of the response
3386-
if self.interactive {
3387-
queue!(
3388-
self.output,
3389-
style::SetForegroundColor(Color::Yellow),
3390-
style::SetAttribute(Attribute::Bold),
3391-
style::Print("Amazon Q > "),
3392-
style::SetAttribute(Attribute::Reset),
3393-
style::SetForegroundColor(Color::Reset),
3394-
)?;
3395-
}
3396-
33973372
loop {
33983373
match parser.recv().await {
33993374
Ok(msg_event) => {
@@ -3482,37 +3457,12 @@ impl ChatContext {
34823457
tool_use_id,
34833458
name,
34843459
message,
3485-
time_elapsed,
3460+
..
34863461
} => {
34873462
error!(
34883463
recv_error.request_id,
34893464
tool_use_id, name, "The response stream ended before the entire tool use was received"
34903465
);
3491-
if self.interactive {
3492-
drop(self.spinner.take());
3493-
queue!(
3494-
self.output,
3495-
terminal::Clear(terminal::ClearType::CurrentLine),
3496-
cursor::MoveToColumn(0),
3497-
style::SetForegroundColor(Color::Yellow),
3498-
style::SetAttribute(Attribute::Bold),
3499-
style::Print(format!(
3500-
"Warning: received an unexpected error from the model after {:.2}s",
3501-
time_elapsed.as_secs_f64()
3502-
)),
3503-
)?;
3504-
if let Some(request_id) = recv_error.request_id {
3505-
queue!(
3506-
self.output,
3507-
style::Print(format!("\n request_id: {}", request_id))
3508-
)?;
3509-
}
3510-
execute!(self.output, style::Print("\n\n"), style::SetAttribute(Attribute::Reset))?;
3511-
self.spinner = Some(Spinner::new(
3512-
Spinners::Dots,
3513-
"Trying to divide up the work...".to_string(),
3514-
));
3515-
}
35163466

35173467
self.conversation_state.push_assistant_message(*message, database);
35183468
let tool_results = vec![ToolUseResult {
@@ -3570,7 +3520,7 @@ impl ChatContext {
35703520

35713521
// TODO: We should buffer output based on how much we have to parse, not as a constant
35723522
// Do not remove unless you are nabochay :)
3573-
std::thread::sleep(Duration::from_millis(8));
3523+
tokio::time::sleep(Duration::from_millis(8)).await;
35743524
}
35753525

35763526
// Set spinner after showing all of the assistant text content so far.

0 commit comments

Comments
 (0)