-
Notifications
You must be signed in to change notification settings - Fork 7
Add per-message timings #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| #[derive(Default)] | ||
| pub struct State { | ||
| pub show_reasoning: bool, | ||
| pub show_timing: bool, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,28 +38,41 @@ pub enum TimingState { | |
| ExecutingTools, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone)] | ||
| pub struct TimingStats { | ||
| #[derive(Clone, Debug, Default)] | ||
| pub struct TimingStat { | ||
| pub waiting_for_human: Duration, | ||
| pub ai_processing: Duration, | ||
| pub tool_execution: Duration, | ||
| } | ||
|
|
||
| impl std::ops::AddAssign for TimingStat { | ||
| fn add_assign(&mut self, rhs: Self) { | ||
| self.waiting_for_human += rhs.waiting_for_human; | ||
| self.ai_processing += rhs.ai_processing; | ||
| self.tool_execution += rhs.tool_execution; | ||
| } | ||
| } | ||
|
|
||
| #[derive(Debug, Clone)] | ||
| pub struct TimingStats { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A thought about naming: Could rename this to |
||
| message: TimingStat, | ||
| session: TimingStat, | ||
| current_state: TimingState, | ||
| state_start: Option<Instant>, | ||
| } | ||
|
|
||
| impl TimingStats { | ||
| fn new() -> Self { | ||
| Self { | ||
| waiting_for_human: Duration::ZERO, | ||
| ai_processing: Duration::ZERO, | ||
| tool_execution: Duration::ZERO, | ||
| message: TimingStat::default(), | ||
| session: TimingStat::default(), | ||
| current_state: TimingState::Idle, | ||
| state_start: Some(Instant::now()), | ||
| } | ||
| } | ||
|
|
||
| pub fn total_time(&self) -> Duration { | ||
| self.waiting_for_human + self.ai_processing + self.tool_execution | ||
| pub fn session(&self) -> TimingStat { | ||
| self.session.clone() | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -447,18 +460,23 @@ impl ActorState { | |
| let elapsed = start.elapsed(); | ||
| match self.timing_stats.current_state { | ||
| TimingState::WaitingForHuman => { | ||
| self.timing_stats.waiting_for_human += elapsed; | ||
| self.timing_stats.message.waiting_for_human += elapsed; | ||
| } | ||
| TimingState::ProcessingAI => { | ||
| self.timing_stats.ai_processing += elapsed; | ||
| self.timing_stats.message.ai_processing += elapsed; | ||
| } | ||
| TimingState::ExecutingTools => { | ||
| self.timing_stats.tool_execution += elapsed; | ||
| self.timing_stats.message.tool_execution += elapsed; | ||
| } | ||
| TimingState::Idle => {} | ||
| } | ||
| } | ||
|
|
||
| if matches!(new_state, TimingState::WaitingForHuman) { | ||
| let message = std::mem::replace(&mut self.timing_stats.message, TimingStat::default()); | ||
| self.timing_stats.session += message; | ||
| } | ||
|
|
||
| self.timing_stats.current_state = new_state; | ||
| self.timing_stats.state_start = Some(Instant::now()); | ||
| } | ||
|
|
@@ -517,6 +535,11 @@ async fn run_actor( | |
| } | ||
| } | ||
|
|
||
| state.event_sender.send(ChatEvent::TimingUpdate { | ||
| waiting_for_human: state.timing_stats.message.waiting_for_human, | ||
| ai_processing: state.timing_stats.message.ai_processing, | ||
| tool_execution: state.timing_stats.message.tool_execution, | ||
| }); | ||
| state.event_sender.set_typing(false); | ||
| state.transition_timing_state(TimingState::WaitingForHuman); | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated: I noticed local commands don't show up in /help. I started fixing it, but not relevant for this PR.