Log errors when a prediction fails (#22961)

Release Notes:

- N/A

---------

Co-authored-by: Thorsten <thorsten@zed.dev>
This commit is contained in:
Antonio Scandurra 2025-01-10 15:07:17 +01:00 committed by GitHub
parent 9e113bccd0
commit c3301077af
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 18 additions and 12 deletions

1
Cargo.lock generated
View file

@ -16517,6 +16517,7 @@ dependencies = [
"tree-sitter-go", "tree-sitter-go",
"tree-sitter-rust", "tree-sitter-rust",
"ui", "ui",
"util",
"uuid", "uuid",
"workspace", "workspace",
"worktree", "worktree",

View file

@ -477,7 +477,7 @@ async fn predict_edits(
open_ai::CompletionRequest { open_ai::CompletionRequest {
model: model.to_string(), model: model.to_string(),
prompt: prompt.clone(), prompt: prompt.clone(),
max_tokens: 1024, max_tokens: 2048,
temperature: 0., temperature: 0.,
prediction: Some(open_ai::Prediction::Content { prediction: Some(open_ai::Prediction::Content {
content: params.input_excerpt, content: params.input_excerpt,

View file

@ -39,6 +39,7 @@ telemetry.workspace = true
telemetry_events.workspace = true telemetry_events.workspace = true
theme.workspace = true theme.workspace = true
ui.workspace = true ui.workspace = true
util.workspace = true
uuid.workspace = true uuid.workspace = true
workspace.workspace = true workspace.workspace = true

View file

@ -30,6 +30,7 @@ use std::{
time::{Duration, Instant}, time::{Duration, Instant},
}; };
use telemetry_events::InlineCompletionRating; use telemetry_events::InlineCompletionRating;
use util::ResultExt;
use uuid::Uuid; use uuid::Uuid;
const CURSOR_MARKER: &'static str = "<|user_cursor_is_here|>"; const CURSOR_MARKER: &'static str = "<|user_cursor_is_here|>";
@ -975,7 +976,7 @@ impl CurrentInlineCompletion {
struct PendingCompletion { struct PendingCompletion {
id: usize, id: usize,
_task: Task<Result<()>>, _task: Task<()>,
} }
pub struct ZetaInlineCompletionProvider { pub struct ZetaInlineCompletionProvider {
@ -1053,13 +1054,16 @@ impl inline_completion::InlineCompletionProvider for ZetaInlineCompletionProvide
}) })
}); });
let mut completion = None; let completion = match completion_request {
if let Ok(completion_request) = completion_request { Ok(completion_request) => {
completion = Some(CurrentInlineCompletion { let completion_request = completion_request.await;
completion_request.map(|completion| CurrentInlineCompletion {
buffer_id: buffer.entity_id(), buffer_id: buffer.entity_id(),
completion: completion_request.await?, completion,
}); })
} }
Err(error) => Err(error),
};
this.update(&mut cx, |this, cx| { this.update(&mut cx, |this, cx| {
if this.pending_completions[0].id == pending_completion_id { if this.pending_completions[0].id == pending_completion_id {
@ -1068,7 +1072,8 @@ impl inline_completion::InlineCompletionProvider for ZetaInlineCompletionProvide
this.pending_completions.clear(); this.pending_completions.clear();
} }
if let Some(new_completion) = completion { if let Some(new_completion) = completion.context("zeta prediction failed").log_err()
{
if let Some(old_completion) = this.current_completion.as_ref() { if let Some(old_completion) = this.current_completion.as_ref() {
let snapshot = buffer.read(cx).snapshot(); let snapshot = buffer.read(cx).snapshot();
if new_completion.should_replace_completion(&old_completion, &snapshot) { if new_completion.should_replace_completion(&old_completion, &snapshot) {
@ -1083,12 +1088,11 @@ impl inline_completion::InlineCompletionProvider for ZetaInlineCompletionProvide
}); });
this.current_completion = Some(new_completion); this.current_completion = Some(new_completion);
} }
} else {
this.current_completion = None;
} }
cx.notify(); cx.notify();
}) })
.ok();
}); });
// We always maintain at most two pending completions. When we already // We always maintain at most two pending completions. When we already