Include prediction ID on edit prediction accepted/discarded events (#24480)
This PR updates the edit predictions to include the prediction ID returned from the server on the resulting telemetry events indicating whether the prediction was accepted or discarded. The `prediction_id` on the events can then be correlated with the `request_id` on the server-side prediction events. Release Notes: - N/A
This commit is contained in:
parent
ed5656813c
commit
e17e838c07
8 changed files with 47 additions and 20 deletions
5
Cargo.lock
generated
5
Cargo.lock
generated
|
@ -16757,12 +16757,13 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zed_llm_client"
|
name = "zed_llm_client"
|
||||||
version = "0.3.0"
|
version = "0.4.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "656118e6b072924d28815cb892278f12c2548117794e733bd2c075ef4a0427e8"
|
checksum = "614669bead4741b2fc352ae1967318be16949cf46f59013e548c6dbfdfc01252"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
"uuid",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -561,7 +561,7 @@ wasmtime = { version = "24", default-features = false, features = [
|
||||||
wasmtime-wasi = "24"
|
wasmtime-wasi = "24"
|
||||||
which = "6.0.0"
|
which = "6.0.0"
|
||||||
wit-component = "0.201"
|
wit-component = "0.201"
|
||||||
zed_llm_client = "0.3"
|
zed_llm_client = "0.4"
|
||||||
zstd = "0.11"
|
zstd = "0.11"
|
||||||
metal = "0.31"
|
metal = "0.31"
|
||||||
|
|
||||||
|
|
|
@ -242,6 +242,7 @@ impl EditPredictionProvider for CopilotCompletionProvider {
|
||||||
} else {
|
} else {
|
||||||
let position = cursor_position.bias_right(buffer);
|
let position = cursor_position.bias_right(buffer);
|
||||||
Some(InlineCompletion {
|
Some(InlineCompletion {
|
||||||
|
id: None,
|
||||||
edits: vec![(position..position, completion_text.into())],
|
edits: vec![(position..position, completion_text.into())],
|
||||||
edit_preview: None,
|
edit_preview: None,
|
||||||
})
|
})
|
||||||
|
|
|
@ -490,6 +490,7 @@ enum InlineCompletion {
|
||||||
struct InlineCompletionState {
|
struct InlineCompletionState {
|
||||||
inlay_ids: Vec<InlayId>,
|
inlay_ids: Vec<InlayId>,
|
||||||
completion: InlineCompletion,
|
completion: InlineCompletion,
|
||||||
|
completion_id: Option<SharedString>,
|
||||||
invalidation_range: Range<Anchor>,
|
invalidation_range: Range<Anchor>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4893,7 +4894,11 @@ impl Editor {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
self.report_inline_completion_event(true, cx);
|
self.report_inline_completion_event(
|
||||||
|
active_inline_completion.completion_id.clone(),
|
||||||
|
true,
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
|
||||||
match &active_inline_completion.completion {
|
match &active_inline_completion.completion {
|
||||||
InlineCompletion::Move { target, .. } => {
|
InlineCompletion::Move { target, .. } => {
|
||||||
|
@ -4942,7 +4947,11 @@ impl Editor {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.report_inline_completion_event(true, cx);
|
self.report_inline_completion_event(
|
||||||
|
active_inline_completion.completion_id.clone(),
|
||||||
|
true,
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
|
||||||
match &active_inline_completion.completion {
|
match &active_inline_completion.completion {
|
||||||
InlineCompletion::Move { target, .. } => {
|
InlineCompletion::Move { target, .. } => {
|
||||||
|
@ -5000,7 +5009,12 @@ impl Editor {
|
||||||
cx: &mut Context<Self>,
|
cx: &mut Context<Self>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
if should_report_inline_completion_event {
|
if should_report_inline_completion_event {
|
||||||
self.report_inline_completion_event(false, cx);
|
let completion_id = self
|
||||||
|
.active_inline_completion
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|active_completion| active_completion.completion_id.clone());
|
||||||
|
|
||||||
|
self.report_inline_completion_event(completion_id, false, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(provider) = self.edit_prediction_provider() {
|
if let Some(provider) = self.edit_prediction_provider() {
|
||||||
|
@ -5010,7 +5024,7 @@ impl Editor {
|
||||||
self.take_active_inline_completion(cx)
|
self.take_active_inline_completion(cx)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn report_inline_completion_event(&self, accepted: bool, cx: &App) {
|
fn report_inline_completion_event(&self, id: Option<SharedString>, accepted: bool, cx: &App) {
|
||||||
let Some(provider) = self.edit_prediction_provider() else {
|
let Some(provider) = self.edit_prediction_provider() else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
@ -5035,6 +5049,7 @@ impl Editor {
|
||||||
telemetry::event!(
|
telemetry::event!(
|
||||||
event_type,
|
event_type,
|
||||||
provider = provider.name(),
|
provider = provider.name(),
|
||||||
|
prediction_id = id,
|
||||||
suggestion_accepted = accepted,
|
suggestion_accepted = accepted,
|
||||||
file_extension = extension,
|
file_extension = extension,
|
||||||
);
|
);
|
||||||
|
@ -5250,6 +5265,7 @@ impl Editor {
|
||||||
self.active_inline_completion = Some(InlineCompletionState {
|
self.active_inline_completion = Some(InlineCompletionState {
|
||||||
inlay_ids,
|
inlay_ids,
|
||||||
completion,
|
completion,
|
||||||
|
completion_id: inline_completion.id,
|
||||||
invalidation_range,
|
invalidation_range,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -333,6 +333,7 @@ fn propose_edits<T: ToOffset>(
|
||||||
cx.update(|_, cx| {
|
cx.update(|_, cx| {
|
||||||
provider.update(cx, |provider, _| {
|
provider.update(cx, |provider, _| {
|
||||||
provider.set_inline_completion(Some(inline_completion::InlineCompletion {
|
provider.set_inline_completion(Some(inline_completion::InlineCompletion {
|
||||||
|
id: None,
|
||||||
edits: edits.collect(),
|
edits: edits.collect(),
|
||||||
edit_preview: None,
|
edit_preview: None,
|
||||||
}))
|
}))
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use gpui::{App, Context, Entity};
|
use gpui::{App, Context, Entity, SharedString};
|
||||||
use language::Buffer;
|
use language::Buffer;
|
||||||
use project::Project;
|
use project::Project;
|
||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
|
@ -15,6 +15,8 @@ pub enum Direction {
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct InlineCompletion {
|
pub struct InlineCompletion {
|
||||||
|
/// The ID of the completion, if it has one.
|
||||||
|
pub id: Option<SharedString>,
|
||||||
pub edits: Vec<(Range<language::Anchor>, String)>,
|
pub edits: Vec<(Range<language::Anchor>, String)>,
|
||||||
pub edit_preview: Option<language::EditPreview>,
|
pub edit_preview: Option<language::EditPreview>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,6 +92,7 @@ fn completion_from_diff(
|
||||||
}
|
}
|
||||||
|
|
||||||
InlineCompletion {
|
InlineCompletion {
|
||||||
|
id: None,
|
||||||
edits,
|
edits,
|
||||||
edit_preview: None,
|
edit_preview: None,
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,12 +81,6 @@ impl std::fmt::Display for InlineCompletionId {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InlineCompletionId {
|
|
||||||
fn new() -> Self {
|
|
||||||
Self(Uuid::new_v4())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct ZetaGlobal(Entity<Zeta>);
|
struct ZetaGlobal(Entity<Zeta>);
|
||||||
|
|
||||||
|
@ -452,11 +446,10 @@ impl Zeta {
|
||||||
|
|
||||||
let response = perform_predict_edits(client, llm_token, is_staff, body).await?;
|
let response = perform_predict_edits(client, llm_token, is_staff, body).await?;
|
||||||
|
|
||||||
let output_excerpt = response.output_excerpt;
|
log::debug!("completion response: {}", &response.output_excerpt);
|
||||||
log::debug!("completion response: {}", output_excerpt);
|
|
||||||
|
|
||||||
Self::process_completion_response(
|
Self::process_completion_response(
|
||||||
output_excerpt,
|
response,
|
||||||
buffer,
|
buffer,
|
||||||
&snapshot,
|
&snapshot,
|
||||||
values.editable_range,
|
values.editable_range,
|
||||||
|
@ -495,6 +488,7 @@ impl Zeta {
|
||||||
&buffer,
|
&buffer,
|
||||||
position,
|
position,
|
||||||
PredictEditsResponse {
|
PredictEditsResponse {
|
||||||
|
request_id: Uuid::parse_str("e7861db5-0cea-4761-b1c5-ad083ac53a80").unwrap(),
|
||||||
output_excerpt: format!("{EDITABLE_REGION_START_MARKER}
|
output_excerpt: format!("{EDITABLE_REGION_START_MARKER}
|
||||||
a longggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg line
|
a longggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg line
|
||||||
[here's an edit]
|
[here's an edit]
|
||||||
|
@ -511,6 +505,7 @@ and then another
|
||||||
&buffer,
|
&buffer,
|
||||||
position,
|
position,
|
||||||
PredictEditsResponse {
|
PredictEditsResponse {
|
||||||
|
request_id: Uuid::parse_str("077c556a-2c49-44e2-bbc6-dafc09032a5e").unwrap(),
|
||||||
output_excerpt: format!(r#"{EDITABLE_REGION_START_MARKER}
|
output_excerpt: format!(r#"{EDITABLE_REGION_START_MARKER}
|
||||||
a longggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg line
|
a longggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg line
|
||||||
And maybe a short line
|
And maybe a short line
|
||||||
|
@ -527,6 +522,7 @@ and then another
|
||||||
&buffer,
|
&buffer,
|
||||||
position,
|
position,
|
||||||
PredictEditsResponse {
|
PredictEditsResponse {
|
||||||
|
request_id: Uuid::parse_str("df8c7b23-3d1d-4f99-a306-1f6264a41277").unwrap(),
|
||||||
output_excerpt: format!(r#"{EDITABLE_REGION_START_MARKER}
|
output_excerpt: format!(r#"{EDITABLE_REGION_START_MARKER}
|
||||||
a longggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg line
|
a longggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg line
|
||||||
And maybe a short line
|
And maybe a short line
|
||||||
|
@ -544,6 +540,7 @@ and then another
|
||||||
&buffer,
|
&buffer,
|
||||||
position,
|
position,
|
||||||
PredictEditsResponse {
|
PredictEditsResponse {
|
||||||
|
request_id: Uuid::parse_str("c743958d-e4d8-44a8-aa5b-eb1e305c5f5c").unwrap(),
|
||||||
output_excerpt: format!(r#"{EDITABLE_REGION_START_MARKER}
|
output_excerpt: format!(r#"{EDITABLE_REGION_START_MARKER}
|
||||||
a longggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg line
|
a longggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg line
|
||||||
And maybe a short line
|
And maybe a short line
|
||||||
|
@ -561,6 +558,7 @@ and then another
|
||||||
&buffer,
|
&buffer,
|
||||||
position,
|
position,
|
||||||
PredictEditsResponse {
|
PredictEditsResponse {
|
||||||
|
request_id: Uuid::parse_str("ff5cd7ab-ad06-4808-986e-d3391e7b8355").unwrap(),
|
||||||
output_excerpt: format!(r#"{EDITABLE_REGION_START_MARKER}
|
output_excerpt: format!(r#"{EDITABLE_REGION_START_MARKER}
|
||||||
a longggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg line
|
a longggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg line
|
||||||
And maybe a short line
|
And maybe a short line
|
||||||
|
@ -577,6 +575,7 @@ and then another
|
||||||
&buffer,
|
&buffer,
|
||||||
position,
|
position,
|
||||||
PredictEditsResponse {
|
PredictEditsResponse {
|
||||||
|
request_id: Uuid::parse_str("83cafa55-cdba-4b27-8474-1865ea06be94").unwrap(),
|
||||||
output_excerpt: format!(r#"{EDITABLE_REGION_START_MARKER}
|
output_excerpt: format!(r#"{EDITABLE_REGION_START_MARKER}
|
||||||
a longggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg line
|
a longggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg line
|
||||||
And maybe a short line
|
And maybe a short line
|
||||||
|
@ -592,6 +591,7 @@ and then another
|
||||||
&buffer,
|
&buffer,
|
||||||
position,
|
position,
|
||||||
PredictEditsResponse {
|
PredictEditsResponse {
|
||||||
|
request_id: Uuid::parse_str("d5bd3afd-8723-47c7-bd77-15a3a926867b").unwrap(),
|
||||||
output_excerpt: format!(r#"{EDITABLE_REGION_START_MARKER}
|
output_excerpt: format!(r#"{EDITABLE_REGION_START_MARKER}
|
||||||
a longggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg line
|
a longggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg line
|
||||||
And maybe a short line
|
And maybe a short line
|
||||||
|
@ -703,7 +703,7 @@ and then another
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn process_completion_response(
|
fn process_completion_response(
|
||||||
output_excerpt: String,
|
prediction_response: PredictEditsResponse,
|
||||||
buffer: Entity<Buffer>,
|
buffer: Entity<Buffer>,
|
||||||
snapshot: &BufferSnapshot,
|
snapshot: &BufferSnapshot,
|
||||||
editable_range: Range<usize>,
|
editable_range: Range<usize>,
|
||||||
|
@ -716,6 +716,8 @@ and then another
|
||||||
cx: &AsyncApp,
|
cx: &AsyncApp,
|
||||||
) -> Task<Result<Option<InlineCompletion>>> {
|
) -> Task<Result<Option<InlineCompletion>>> {
|
||||||
let snapshot = snapshot.clone();
|
let snapshot = snapshot.clone();
|
||||||
|
let request_id = prediction_response.request_id;
|
||||||
|
let output_excerpt = prediction_response.output_excerpt;
|
||||||
cx.spawn(|cx| async move {
|
cx.spawn(|cx| async move {
|
||||||
let output_excerpt: Arc<str> = output_excerpt.into();
|
let output_excerpt: Arc<str> = output_excerpt.into();
|
||||||
|
|
||||||
|
@ -746,7 +748,7 @@ and then another
|
||||||
let edit_preview = edit_preview.await;
|
let edit_preview = edit_preview.await;
|
||||||
|
|
||||||
Ok(Some(InlineCompletion {
|
Ok(Some(InlineCompletion {
|
||||||
id: InlineCompletionId::new(),
|
id: InlineCompletionId(request_id),
|
||||||
path,
|
path,
|
||||||
excerpt_range: editable_range,
|
excerpt_range: editable_range,
|
||||||
cursor_offset,
|
cursor_offset,
|
||||||
|
@ -1550,6 +1552,7 @@ impl inline_completion::EditPredictionProvider for ZetaInlineCompletionProvider
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(inline_completion::InlineCompletion {
|
Some(inline_completion::InlineCompletion {
|
||||||
|
id: Some(completion.id.to_string().into()),
|
||||||
edits: edits[edit_start_ix..edit_end_ix].to_vec(),
|
edits: edits[edit_start_ix..edit_end_ix].to_vec(),
|
||||||
edit_preview: Some(completion.edit_preview.clone()),
|
edit_preview: Some(completion.edit_preview.clone()),
|
||||||
})
|
})
|
||||||
|
@ -1598,7 +1601,7 @@ mod tests {
|
||||||
edit_preview,
|
edit_preview,
|
||||||
path: Path::new("").into(),
|
path: Path::new("").into(),
|
||||||
snapshot: cx.read(|cx| buffer.read(cx).snapshot()),
|
snapshot: cx.read(|cx| buffer.read(cx).snapshot()),
|
||||||
id: InlineCompletionId::new(),
|
id: InlineCompletionId(Uuid::new_v4()),
|
||||||
excerpt_range: 0..0,
|
excerpt_range: 0..0,
|
||||||
cursor_offset: 0,
|
cursor_offset: 0,
|
||||||
input_outline: "".into(),
|
input_outline: "".into(),
|
||||||
|
@ -1717,6 +1720,8 @@ mod tests {
|
||||||
.status(200)
|
.status(200)
|
||||||
.body(
|
.body(
|
||||||
serde_json::to_string(&PredictEditsResponse {
|
serde_json::to_string(&PredictEditsResponse {
|
||||||
|
request_id: Uuid::parse_str("7e86480f-3536-4d2c-9334-8213e3445d45")
|
||||||
|
.unwrap(),
|
||||||
output_excerpt: completion_response.to_string(),
|
output_excerpt: completion_response.to_string(),
|
||||||
})
|
})
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue