zeta: Reduce request payload (#35968)

1. Don't send diagnostics if there are more than 10 of them. This fixes
an issue with sending 100kb requests for projects with many warnings.

2. Don't send speculated_output and outline, as those are currently
unused.


Release Notes:

- Improved edit prediction latency
This commit is contained in:
Oleksiy Syvokon 2025-08-11 15:33:16 +03:00 committed by GitHub
parent a88c533ffc
commit d5ed569fad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 44 deletions

View file

@ -9,7 +9,6 @@ use std::{fmt::Write, ops::Range};
pub struct InputExcerpt { pub struct InputExcerpt {
pub editable_range: Range<Point>, pub editable_range: Range<Point>,
pub prompt: String, pub prompt: String,
pub speculated_output: String,
} }
pub fn excerpt_for_cursor_position( pub fn excerpt_for_cursor_position(
@ -46,7 +45,6 @@ pub fn excerpt_for_cursor_position(
let context_range = expand_range(snapshot, editable_range.clone(), context_token_limit); let context_range = expand_range(snapshot, editable_range.clone(), context_token_limit);
let mut prompt = String::new(); let mut prompt = String::new();
let mut speculated_output = String::new();
writeln!(&mut prompt, "```{path}").unwrap(); writeln!(&mut prompt, "```{path}").unwrap();
if context_range.start == Point::zero() { if context_range.start == Point::zero() {
@ -58,12 +56,6 @@ pub fn excerpt_for_cursor_position(
} }
push_editable_range(position, snapshot, editable_range.clone(), &mut prompt); push_editable_range(position, snapshot, editable_range.clone(), &mut prompt);
push_editable_range(
position,
snapshot,
editable_range.clone(),
&mut speculated_output,
);
for chunk in snapshot.chunks(editable_range.end..context_range.end, false) { for chunk in snapshot.chunks(editable_range.end..context_range.end, false) {
prompt.push_str(chunk.text); prompt.push_str(chunk.text);
@ -73,7 +65,6 @@ pub fn excerpt_for_cursor_position(
InputExcerpt { InputExcerpt {
editable_range, editable_range,
prompt, prompt,
speculated_output,
} }
} }

View file

@ -37,7 +37,6 @@ use release_channel::AppVersion;
use settings::WorktreeId; use settings::WorktreeId;
use std::str::FromStr; use std::str::FromStr;
use std::{ use std::{
borrow::Cow,
cmp, cmp,
fmt::Write, fmt::Write,
future::Future, future::Future,
@ -66,6 +65,7 @@ const ZED_PREDICT_DATA_COLLECTION_CHOICE: &str = "zed_predict_data_collection_ch
const MAX_CONTEXT_TOKENS: usize = 150; const MAX_CONTEXT_TOKENS: usize = 150;
const MAX_REWRITE_TOKENS: usize = 350; const MAX_REWRITE_TOKENS: usize = 350;
const MAX_EVENT_TOKENS: usize = 500; const MAX_EVENT_TOKENS: usize = 500;
const MAX_DIAGNOSTIC_GROUPS: usize = 10;
/// Maximum number of events to track. /// Maximum number of events to track.
const MAX_EVENT_COUNT: usize = 16; const MAX_EVENT_COUNT: usize = 16;
@ -1175,7 +1175,9 @@ pub fn gather_context(
cx.background_spawn({ cx.background_spawn({
let snapshot = snapshot.clone(); let snapshot = snapshot.clone();
async move { async move {
let diagnostic_groups = if diagnostic_groups.is_empty() { let diagnostic_groups = if diagnostic_groups.is_empty()
|| diagnostic_groups.len() >= MAX_DIAGNOSTIC_GROUPS
{
None None
} else { } else {
Some(diagnostic_groups) Some(diagnostic_groups)
@ -1189,21 +1191,16 @@ pub fn gather_context(
MAX_CONTEXT_TOKENS, MAX_CONTEXT_TOKENS,
); );
let input_events = make_events_prompt(); let input_events = make_events_prompt();
let input_outline = if can_collect_data {
prompt_for_outline(&snapshot)
} else {
String::new()
};
let editable_range = input_excerpt.editable_range.to_offset(&snapshot); let editable_range = input_excerpt.editable_range.to_offset(&snapshot);
let body = PredictEditsBody { let body = PredictEditsBody {
input_events, input_events,
input_excerpt: input_excerpt.prompt, input_excerpt: input_excerpt.prompt,
speculated_output: Some(input_excerpt.speculated_output),
outline: Some(input_outline),
can_collect_data, can_collect_data,
diagnostic_groups, diagnostic_groups,
git_info, git_info,
outline: None,
speculated_output: None,
}; };
Ok(GatherContextOutput { Ok(GatherContextOutput {
@ -1214,32 +1211,6 @@ pub fn gather_context(
}) })
} }
fn prompt_for_outline(snapshot: &BufferSnapshot) -> String {
let mut input_outline = String::new();
writeln!(
input_outline,
"```{}",
snapshot
.file()
.map_or(Cow::Borrowed("untitled"), |file| file
.path()
.to_string_lossy())
)
.unwrap();
if let Some(outline) = snapshot.outline(None) {
for item in &outline.items {
let spacing = " ".repeat(item.depth);
writeln!(input_outline, "{}{}", spacing, item.text).unwrap();
}
}
writeln!(input_outline, "```").unwrap();
input_outline
}
fn prompt_for_events(events: &VecDeque<Event>, mut remaining_tokens: usize) -> String { fn prompt_for_events(events: &VecDeque<Event>, mut remaining_tokens: usize) -> String {
let mut result = String::new(); let mut result = String::new();
for event in events.iter().rev() { for event in events.iter().rev() {