Skip to content

Commit fc00312

Browse files
committed
Fix formatting changes
1 parent 4b52f4b commit fc00312

File tree

5 files changed

+65
-22
lines changed

5 files changed

+65
-22
lines changed

crates/chat-cli/src/api_client/model.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -667,8 +667,17 @@ impl From<amzn_codewhisperer_streaming_client::types::ChatResponseStream> for Ch
667667
cache_write_input_tokens: token_usage.as_ref().and_then(|t| t.cache_write_input_tokens),
668668
},
669669
amzn_codewhisperer_streaming_client::types::ChatResponseStream::MeteringEvent(
670-
amzn_codewhisperer_streaming_client::types::MeteringEvent { usage, unit, unit_plural, .. },
671-
) => ChatResponseStream::MeteringEvent { usage, unit, unit_plural },
670+
amzn_codewhisperer_streaming_client::types::MeteringEvent {
671+
usage,
672+
unit,
673+
unit_plural,
674+
..
675+
},
676+
) => ChatResponseStream::MeteringEvent {
677+
usage,
678+
unit,
679+
unit_plural,
680+
},
672681
amzn_codewhisperer_streaming_client::types::ChatResponseStream::ToolUseEvent(
673682
amzn_codewhisperer_streaming_client::types::ToolUseEvent {
674683
tool_use_id,
@@ -735,8 +744,17 @@ impl From<amzn_qdeveloper_streaming_client::types::ChatResponseStream> for ChatR
735744
cache_write_input_tokens: token_usage.as_ref().and_then(|t| t.cache_write_input_tokens),
736745
},
737746
amzn_qdeveloper_streaming_client::types::ChatResponseStream::MeteringEvent(
738-
amzn_qdeveloper_streaming_client::types::MeteringEvent { usage, unit, unit_plural, .. },
739-
) => ChatResponseStream::MeteringEvent { usage, unit, unit_plural },
747+
amzn_qdeveloper_streaming_client::types::MeteringEvent {
748+
usage,
749+
unit,
750+
unit_plural,
751+
..
752+
},
753+
) => ChatResponseStream::MeteringEvent {
754+
usage,
755+
unit,
756+
unit_plural,
757+
},
740758
amzn_qdeveloper_streaming_client::types::ChatResponseStream::ToolUseEvent(
741759
amzn_qdeveloper_streaming_client::types::ToolUseEvent {
742760
tool_use_id,

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,11 @@ impl UserTurnMetadata {
163163
}
164164

165165
pub fn add_usage(&mut self, value: f64, unit: String, unit_plural: String) {
166-
self.usage_info.push(MeteringUsageInfo { value, unit, unit_plural });
166+
self.usage_info.push(MeteringUsageInfo {
167+
value,
168+
unit,
169+
unit_plural,
170+
});
167171
}
168172

169173
pub fn total_usage(&self) -> Vec<MeteringUsageInfo> {

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ pub mod context;
1515
mod conversation;
1616
mod input_source;
1717
mod message;
18-
mod turn_summary;
1918
mod parse;
19+
mod turn_summary;
2020
use std::path::MAIN_SEPARATOR;
2121
pub mod checkpoint;
2222
mod line_tracker;
@@ -829,7 +829,7 @@ impl ChatSession {
829829
if self.tool_uses.is_empty() {
830830
turn_summary::display_turn_usage_summary(&mut self.stderr, &self.conversation.user_turn_metadata)?;
831831
}
832-
832+
833833
match (self.interactive, self.tool_uses.is_empty()) {
834834
(false, true) => {
835835
self.inner = Some(ChatState::Exit);
@@ -2813,8 +2813,14 @@ impl ChatSession {
28132813
trace!("Consumed: {:?}", msg_event);
28142814

28152815
match msg_event {
2816-
parser::ResponseEvent::MeteringUsage { value, unit, unit_plural } => {
2817-
self.conversation.user_turn_metadata.add_usage(value, unit.clone(), unit_plural.clone());
2816+
parser::ResponseEvent::MeteringUsage {
2817+
value,
2818+
unit,
2819+
unit_plural,
2820+
} => {
2821+
self.conversation
2822+
.user_turn_metadata
2823+
.add_usage(value, unit.clone(), unit_plural.clone());
28182824
},
28192825
parser::ResponseEvent::ToolUseStart { name } => {
28202826
// We need to flush the buffer here, otherwise text will not be

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

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -622,18 +622,25 @@ impl ResponseParser {
622622
ChatResponseStream::ToolUseEvent { input, .. } => {
623623
self.received_response_size += input.as_ref().map(String::len).unwrap_or_default();
624624
},
625-
ChatResponseStream::MeteringEvent { usage, unit, unit_plural } => {
625+
ChatResponseStream::MeteringEvent {
626+
usage,
627+
unit,
628+
unit_plural,
629+
} => {
626630
info!("GenerateAssistanceResponse - MeteringEvent");
627631
if let (Some(value), Some(unit), Some(unit_plural)) = (usage, unit, unit_plural) {
628-
let _ = self.event_tx.send(Ok(ResponseEvent::MeteringUsage {
629-
value: *value,
630-
unit: unit.clone(),
631-
unit_plural: unit_plural.clone()
632-
})).await;
632+
let _ = self
633+
.event_tx
634+
.send(Ok(ResponseEvent::MeteringUsage {
635+
value: *value,
636+
unit: unit.clone(),
637+
unit_plural: unit_plural.clone(),
638+
}))
639+
.await;
633640
}
634641
},
635642
_ => {
636-
warn!(?r, "received unexpected event from the response stream");
643+
warn!(?r, "received unexpected event from the response stream");
637644
},
638645
}
639646
}
@@ -702,7 +709,11 @@ pub enum ResponseEvent {
702709
request_metadata: RequestMetadata,
703710
},
704711
/// Metering usage consumed for this request
705-
MeteringUsage { value: f64, unit: String, unit_plural: String },
712+
MeteringUsage {
713+
value: f64,
714+
unit: String,
715+
unit_plural: String,
716+
},
706717
}
707718

708719
/// Metadata about the sent request and associated response stream.

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
use crossterm::{execute, style};
21
use std::io::Write;
32

3+
use crossterm::{
4+
execute,
5+
style,
6+
};
7+
48
use crate::cli::chat::conversation::UserTurnMetadata;
59

610
pub fn format_number(value: f64) -> String {
@@ -15,7 +19,7 @@ pub fn capitalize_first(s: &str) -> String {
1519
let mut result = first.to_uppercase().collect::<String>();
1620
result.push_str(chars.as_str());
1721
result
18-
}
22+
},
1923
}
2024
}
2125

@@ -36,19 +40,19 @@ pub fn display_turn_usage_summary<W: Write>(
3640
) -> Result<(), std::io::Error> {
3741
let totals = user_turn_metadata.total_usage();
3842
let mut parts = Vec::new();
39-
43+
4044
// Add usage info
4145
for usage in totals {
4246
let formatted = format_number(usage.value);
4347
let capitalized_unit = capitalize_first(&usage.unit_plural);
4448
parts.push(format!("{capitalized_unit} used: {formatted}"));
4549
}
46-
50+
4751
// Add elapsed time
4852
if let Some(elapsed_ms) = user_turn_metadata.total_elapsed_time_ms() {
4953
parts.push(format!("Elapsed time: {}", format_elapsed_time(elapsed_ms)));
5054
}
51-
55+
5256
if !parts.is_empty() {
5357
execute!(
5458
stderr,

0 commit comments

Comments
 (0)