Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions crates/cloud_llm_client/src/cloud_llm_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,17 @@ pub struct PredictEditsBody {
/// Info about the git repository state, only present when can_collect_data is true.
#[serde(skip_serializing_if = "Option::is_none", default)]
pub git_info: Option<PredictEditsGitInfo>,
/// The trigger for this request.
#[serde(default)]
pub trigger: PredictEditsRequestTrigger,
}

#[derive(Default, Debug, Clone, Copy, Serialize, Deserialize)]
pub enum PredictEditsRequestTrigger {
Diagnostics,
Cli,
#[default]
Other,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down
4 changes: 3 additions & 1 deletion crates/cloud_llm_client/src/predict_edits_v3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{
use strum::EnumIter;
use uuid::Uuid;

use crate::PredictEditsGitInfo;
use crate::{PredictEditsGitInfo, PredictEditsRequestTrigger};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PlanContextRetrievalRequest {
Expand Down Expand Up @@ -53,6 +53,8 @@ pub struct PredictEditsRequest {
pub prompt_max_bytes: Option<usize>,
#[serde(default)]
pub prompt_format: PromptFormat,
#[serde(default)]
pub trigger: PredictEditsRequestTrigger,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down
35 changes: 30 additions & 5 deletions crates/zeta/src/zeta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use cloud_llm_client::predict_edits_v3::{self, Event, PromptFormat, Signature};
use cloud_llm_client::{
AcceptEditPredictionBody, EXPIRED_LLM_TOKEN_HEADER_NAME, EditPredictionRejectReason,
EditPredictionRejection, MAX_EDIT_PREDICTION_REJECTIONS_PER_REQUEST,
MINIMUM_REQUIRED_VERSION_HEADER_NAME, RejectEditPredictionsBody, ZED_VERSION_HEADER_NAME,
MINIMUM_REQUIRED_VERSION_HEADER_NAME, PredictEditsRequestTrigger, RejectEditPredictionsBody,
ZED_VERSION_HEADER_NAME,
};
use cloud_zeta2_prompt::retrieval_prompt::{SearchToolInput, SearchToolQuery};
use cloud_zeta2_prompt::{CURSOR_MARKER, DEFAULT_MAX_PROMPT_BYTES};
Expand Down Expand Up @@ -1016,7 +1017,13 @@ impl Zeta {
self.queue_prediction_refresh(project.clone(), buffer.entity_id(), cx, move |this, cx| {
let Some(request_task) = this
.update(cx, |this, cx| {
this.request_prediction(&project, &buffer, position, cx)
this.request_prediction(
&project,
&buffer,
position,
PredictEditsRequestTrigger::Other,
cx,
)
})
.log_err()
else {
Expand Down Expand Up @@ -1083,7 +1090,13 @@ impl Zeta {

let Some(prediction_result) = this
.update(cx, |this, cx| {
this.request_prediction(&project, &jump_buffer, jump_position, cx)
this.request_prediction(
&project,
&jump_buffer,
jump_position,
PredictEditsRequestTrigger::Diagnostics,
cx,
)
})?
.await?
else {
Expand Down Expand Up @@ -1264,12 +1277,14 @@ impl Zeta {
project: &Entity<Project>,
active_buffer: &Entity<Buffer>,
position: language::Anchor,
trigger: PredictEditsRequestTrigger,
cx: &mut Context<Self>,
) -> Task<Result<Option<EditPredictionResult>>> {
self.request_prediction_internal(
project.clone(),
active_buffer.clone(),
position,
trigger,
cx.has_flag::<Zeta2FeatureFlag>(),
cx,
)
Expand All @@ -1280,6 +1295,7 @@ impl Zeta {
project: Entity<Project>,
active_buffer: Entity<Buffer>,
position: language::Anchor,
trigger: PredictEditsRequestTrigger,
allow_jump: bool,
cx: &mut Context<Self>,
) -> Task<Result<Option<EditPredictionResult>>> {
Expand All @@ -1305,6 +1321,7 @@ impl Zeta {
snapshot.clone(),
position,
events,
trigger,
cx,
),
ZetaEditPredictionModel::Zeta2 => self.request_prediction_with_zeta2(
Expand All @@ -1313,6 +1330,7 @@ impl Zeta {
snapshot.clone(),
position,
events,
trigger,
cx,
),
ZetaEditPredictionModel::Sweep => self.sweep_ai.request_prediction_with_sweep(
Expand Down Expand Up @@ -1349,6 +1367,7 @@ impl Zeta {
project,
jump_buffer,
jump_position,
trigger,
false,
cx,
)
Expand Down Expand Up @@ -1449,6 +1468,7 @@ impl Zeta {
active_snapshot: BufferSnapshot,
position: language::Anchor,
events: Vec<Arc<Event>>,
trigger: PredictEditsRequestTrigger,
cx: &mut Context<Self>,
) -> Task<Result<Option<EditPredictionResult>>> {
let project_state = self.projects.get(&project.entity_id());
Expand Down Expand Up @@ -1621,6 +1641,7 @@ impl Zeta {
signatures: vec![],
excerpt_parent: None,
git_info: None,
trigger,
}
}
ContextMode::Syntax(context_options) => {
Expand All @@ -1647,6 +1668,7 @@ impl Zeta {
index_state.as_deref(),
Some(options.max_prompt_bytes),
options.prompt_format,
trigger,
)
}
};
Expand Down Expand Up @@ -2416,6 +2438,7 @@ impl Zeta {
index_state.as_deref(),
Some(options.max_prompt_bytes),
options.prompt_format,
PredictEditsRequestTrigger::Other,
)
})
})
Expand Down Expand Up @@ -2574,6 +2597,7 @@ fn make_syntax_context_cloud_request(
index_state: Option<&SyntaxIndexState>,
prompt_max_bytes: Option<usize>,
prompt_format: PromptFormat,
trigger: PredictEditsRequestTrigger,
) -> predict_edits_v3::PredictEditsRequest {
let mut signatures = Vec::new();
let mut declaration_to_signature_index = HashMap::default();
Expand Down Expand Up @@ -2653,6 +2677,7 @@ fn make_syntax_context_cloud_request(
debug_info,
prompt_max_bytes,
prompt_format,
trigger,
}
}

Expand Down Expand Up @@ -3072,7 +3097,7 @@ mod tests {
let position = snapshot.anchor_before(language::Point::new(1, 3));

let prediction_task = zeta.update(cx, |zeta, cx| {
zeta.request_prediction(&project, &buffer, position, cx)
zeta.request_prediction(&project, &buffer, position, Default::default(), cx)
});

let (_, respond_tx) = requests.predict.next().await.unwrap();
Expand Down Expand Up @@ -3145,7 +3170,7 @@ mod tests {
let position = snapshot.anchor_before(language::Point::new(1, 3));

let prediction_task = zeta.update(cx, |zeta, cx| {
zeta.request_prediction(&project, &buffer, position, cx)
zeta.request_prediction(&project, &buffer, position, Default::default(), cx)
});

let (request, respond_tx) = requests.predict.next().await.unwrap();
Expand Down
7 changes: 6 additions & 1 deletion crates/zeta/src/zeta1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use crate::{
};
use anyhow::{Context as _, Result};
use cloud_llm_client::{
PredictEditsBody, PredictEditsGitInfo, PredictEditsResponse, predict_edits_v3::Event,
PredictEditsBody, PredictEditsGitInfo, PredictEditsRequestTrigger, PredictEditsResponse,
predict_edits_v3::Event,
};
use gpui::{App, AppContext as _, AsyncApp, Context, Entity, SharedString, Task};
use input_excerpt::excerpt_for_cursor_position;
Expand All @@ -35,6 +36,7 @@ pub(crate) fn request_prediction_with_zeta1(
snapshot: BufferSnapshot,
position: language::Anchor,
events: Vec<Arc<Event>>,
trigger: PredictEditsRequestTrigger,
cx: &mut Context<Zeta>,
) -> Task<Result<Option<EditPredictionResult>>> {
let buffer = buffer.clone();
Expand Down Expand Up @@ -70,6 +72,7 @@ pub(crate) fn request_prediction_with_zeta1(
&snapshot,
cursor_point,
prompt_for_events,
trigger,
cx,
);

Expand Down Expand Up @@ -402,6 +405,7 @@ pub fn gather_context(
snapshot: &BufferSnapshot,
cursor_point: language::Point,
prompt_for_events: impl FnOnce() -> (String, usize) + Send + 'static,
trigger: PredictEditsRequestTrigger,
cx: &App,
) -> Task<Result<GatherContextOutput>> {
cx.background_spawn({
Expand All @@ -425,6 +429,7 @@ pub fn gather_context(
git_info: None,
outline: None,
speculated_output: None,
trigger,
};

Ok(GatherContextOutput {
Expand Down
2 changes: 1 addition & 1 deletion crates/zeta/src/zeta_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ async fn run_edit_prediction(
zeta.update(cx, |zeta, cx| zeta.register_buffer(buffer, &project, cx));
cx.background_executor.run_until_parked();
let prediction_task = zeta.update(cx, |zeta, cx| {
zeta.request_prediction(&project, buffer, cursor, cx)
zeta.request_prediction(&project, buffer, cursor, Default::default(), cx)
});
prediction_task.await.unwrap().unwrap().prediction.unwrap()
}
Expand Down
1 change: 1 addition & 0 deletions crates/zeta_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ async fn zeta1_context(
&snapshot,
clipped_cursor,
prompt_for_events,
cloud_llm_client::PredictEditsRequestTrigger::Cli,
cx,
)
})?
Expand Down
8 changes: 7 additions & 1 deletion crates/zeta_cli/src/predict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,13 @@ pub async fn perform_predict(

let prediction = zeta
.update(cx, |zeta, cx| {
zeta.request_prediction(&project, &cursor_buffer, cursor_anchor, cx)
zeta.request_prediction(
&project,
&cursor_buffer,
cursor_anchor,
cloud_llm_client::PredictEditsRequestTrigger::Cli,
cx,
)
})?
.await?;

Expand Down
Loading