zeta: Show timestamps and latency in rating modal (#21863)
Release Notes: - N/A --------- Co-authored-by: Antonio <antonio@zed.dev> Co-authored-by: Bennet <bennet@zed.dev> Co-authored-by: Cole <cole@zed.dev>
This commit is contained in:
parent
543a3ef5e4
commit
227f21f035
2 changed files with 44 additions and 12 deletions
|
@ -5,8 +5,8 @@ use gpui::{
|
||||||
HighlightStyle, Model, StyledText, TextStyle, View, ViewContext,
|
HighlightStyle, Model, StyledText, TextStyle, View, ViewContext,
|
||||||
};
|
};
|
||||||
use language::{language_settings, OffsetRangeExt};
|
use language::{language_settings, OffsetRangeExt};
|
||||||
|
|
||||||
use settings::Settings;
|
use settings::Settings;
|
||||||
|
use std::time::Duration;
|
||||||
use theme::ThemeSettings;
|
use theme::ThemeSettings;
|
||||||
use ui::{prelude::*, KeyBinding, List, ListItem, ListItemSpacing, TintColor, Tooltip};
|
use ui::{prelude::*, KeyBinding, List, ListItem, ListItemSpacing, TintColor, Tooltip};
|
||||||
use workspace::{ModalView, Workspace};
|
use workspace::{ModalView, Workspace};
|
||||||
|
@ -530,6 +530,7 @@ impl Render for RateCompletionModal {
|
||||||
});
|
});
|
||||||
let rated =
|
let rated =
|
||||||
self.zeta.read(cx).is_completion_rated(completion.id);
|
self.zeta.read(cx).is_completion_rated(completion.id);
|
||||||
|
|
||||||
ListItem::new(completion.id)
|
ListItem::new(completion.id)
|
||||||
.inset(true)
|
.inset(true)
|
||||||
.spacing(ListItemSpacing::Sparse)
|
.spacing(ListItemSpacing::Sparse)
|
||||||
|
@ -542,16 +543,17 @@ impl Render for RateCompletionModal {
|
||||||
} else {
|
} else {
|
||||||
Icon::new(IconName::FileDiff).color(Color::Accent).size(IconSize::Small)
|
Icon::new(IconName::FileDiff).color(Color::Accent).size(IconSize::Small)
|
||||||
})
|
})
|
||||||
.child(Label::new(
|
|
||||||
completion.path.to_string_lossy().to_string(),
|
|
||||||
).size(LabelSize::Small))
|
|
||||||
.child(
|
.child(
|
||||||
div()
|
v_flex()
|
||||||
.overflow_hidden()
|
.child(Label::new(completion.path.to_string_lossy().to_string()).size(LabelSize::Small))
|
||||||
.text_ellipsis()
|
.child(div()
|
||||||
.child(Label::new(format!("({})", completion.id))
|
.overflow_hidden()
|
||||||
.color(Color::Muted)
|
.text_ellipsis()
|
||||||
.size(LabelSize::XSmall)),
|
.child(Label::new(format!("{} ago, {:.2?}", format_time_ago(completion.response_received_at.elapsed()), completion.latency()))
|
||||||
|
.color(Color::Muted)
|
||||||
|
.size(LabelSize::XSmall)
|
||||||
|
)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
.on_click(cx.listener(move |this, _, cx| {
|
.on_click(cx.listener(move |this, _, cx| {
|
||||||
this.select_completion(Some(completion.clone()), true, cx);
|
this.select_completion(Some(completion.clone()), true, cx);
|
||||||
|
@ -574,3 +576,20 @@ impl FocusableView for RateCompletionModal {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ModalView for RateCompletionModal {}
|
impl ModalView for RateCompletionModal {}
|
||||||
|
|
||||||
|
fn format_time_ago(elapsed: Duration) -> String {
|
||||||
|
let seconds = elapsed.as_secs();
|
||||||
|
if seconds < 120 {
|
||||||
|
"1 minute".to_string()
|
||||||
|
} else if seconds < 3600 {
|
||||||
|
format!("{} minutes", seconds / 60)
|
||||||
|
} else if seconds < 7200 {
|
||||||
|
"1 hour".to_string()
|
||||||
|
} else if seconds < 86400 {
|
||||||
|
format!("{} hours", seconds / 3600)
|
||||||
|
} else if seconds < 172800 {
|
||||||
|
"1 day".to_string()
|
||||||
|
} else {
|
||||||
|
format!("{} days", seconds / 86400)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -76,9 +76,16 @@ pub struct InlineCompletion {
|
||||||
input_events: Arc<str>,
|
input_events: Arc<str>,
|
||||||
input_excerpt: Arc<str>,
|
input_excerpt: Arc<str>,
|
||||||
output_excerpt: Arc<str>,
|
output_excerpt: Arc<str>,
|
||||||
|
request_sent_at: Instant,
|
||||||
|
response_received_at: Instant,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InlineCompletion {
|
impl InlineCompletion {
|
||||||
|
fn latency(&self) -> Duration {
|
||||||
|
self.response_received_at
|
||||||
|
.duration_since(self.request_sent_at)
|
||||||
|
}
|
||||||
|
|
||||||
fn interpolate(&self, new_snapshot: BufferSnapshot) -> Option<Vec<(Range<Anchor>, String)>> {
|
fn interpolate(&self, new_snapshot: BufferSnapshot) -> Option<Vec<(Range<Anchor>, String)>> {
|
||||||
let mut edits = Vec::new();
|
let mut edits = Vec::new();
|
||||||
|
|
||||||
|
@ -282,7 +289,7 @@ impl Zeta {
|
||||||
let llm_token = self.llm_token.clone();
|
let llm_token = self.llm_token.clone();
|
||||||
|
|
||||||
cx.spawn(|this, mut cx| async move {
|
cx.spawn(|this, mut cx| async move {
|
||||||
let start = std::time::Instant::now();
|
let request_sent_at = Instant::now();
|
||||||
|
|
||||||
let mut input_events = String::new();
|
let mut input_events = String::new();
|
||||||
for event in events {
|
for event in events {
|
||||||
|
@ -304,7 +311,6 @@ impl Zeta {
|
||||||
let response = perform_predict_edits(client, llm_token, body).await?;
|
let response = perform_predict_edits(client, llm_token, body).await?;
|
||||||
|
|
||||||
let output_excerpt = response.output_excerpt;
|
let output_excerpt = response.output_excerpt;
|
||||||
log::debug!("prediction took: {:?}", start.elapsed());
|
|
||||||
log::debug!("completion response: {}", output_excerpt);
|
log::debug!("completion response: {}", output_excerpt);
|
||||||
|
|
||||||
let inline_completion = Self::process_completion_response(
|
let inline_completion = Self::process_completion_response(
|
||||||
|
@ -314,6 +320,7 @@ impl Zeta {
|
||||||
path,
|
path,
|
||||||
input_events,
|
input_events,
|
||||||
input_excerpt,
|
input_excerpt,
|
||||||
|
request_sent_at,
|
||||||
&cx,
|
&cx,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
@ -539,6 +546,7 @@ and then another
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn process_completion_response(
|
fn process_completion_response(
|
||||||
output_excerpt: String,
|
output_excerpt: String,
|
||||||
snapshot: &BufferSnapshot,
|
snapshot: &BufferSnapshot,
|
||||||
|
@ -546,6 +554,7 @@ and then another
|
||||||
path: Arc<Path>,
|
path: Arc<Path>,
|
||||||
input_events: String,
|
input_events: String,
|
||||||
input_excerpt: String,
|
input_excerpt: String,
|
||||||
|
request_sent_at: Instant,
|
||||||
cx: &AsyncAppContext,
|
cx: &AsyncAppContext,
|
||||||
) -> Task<Result<InlineCompletion>> {
|
) -> Task<Result<InlineCompletion>> {
|
||||||
let snapshot = snapshot.clone();
|
let snapshot = snapshot.clone();
|
||||||
|
@ -580,6 +589,8 @@ and then another
|
||||||
input_events: input_events.into(),
|
input_events: input_events.into(),
|
||||||
input_excerpt: input_excerpt.into(),
|
input_excerpt: input_excerpt.into(),
|
||||||
output_excerpt: output_excerpt.into(),
|
output_excerpt: output_excerpt.into(),
|
||||||
|
request_sent_at,
|
||||||
|
response_received_at: Instant::now(),
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1027,6 +1038,8 @@ mod tests {
|
||||||
input_events: "".into(),
|
input_events: "".into(),
|
||||||
input_excerpt: "".into(),
|
input_excerpt: "".into(),
|
||||||
output_excerpt: "".into(),
|
output_excerpt: "".into(),
|
||||||
|
request_sent_at: Instant::now(),
|
||||||
|
response_received_at: Instant::now(),
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue