diff --git a/crates/tabby/src/serve/completions.rs b/crates/tabby/src/serve/completions.rs index af8307c6d223..f9f5b0500b89 100644 --- a/crates/tabby/src/serve/completions.rs +++ b/crates/tabby/src/serve/completions.rs @@ -43,7 +43,16 @@ pub struct CompletionRequest { #[derive(Serialize, Deserialize, ToSchema, Clone, Debug)] pub struct DebugOptions { /// When true, returns debug_data in completion response. + #[serde(default = "default_false")] enabled: bool, + + /// When true, disable retrieval augmented code completion. + #[serde(default = "default_false")] + disable_retrieval_augmented_code_completion: bool, +} + +fn default_false() -> bool { + false } #[derive(Serialize, Deserialize, ToSchema, Clone, Debug)] @@ -126,7 +135,15 @@ pub async fn completions( }; debug!("PREFIX: {}, SUFFIX: {:?}", segments.prefix, segments.suffix); - let snippets = state.prompt_builder.collect(&language, &segments); + let snippets = if !request + .debug_options + .as_ref() + .is_some_and(|x| x.disable_retrieval_augmented_code_completion) + { + state.prompt_builder.collect(&language, &segments) + } else { + vec![] + }; let prompt = state .prompt_builder .build(&language, segments.clone(), &snippets); diff --git a/crates/tabby/tests/goldentests.rs b/crates/tabby/tests/goldentests.rs index 098cfb6b9610..93edc9d97020 100644 --- a/crates/tabby/tests/goldentests.rs +++ b/crates/tabby/tests/goldentests.rs @@ -3,6 +3,7 @@ use std::path::PathBuf; use assert_json_diff::assert_json_include; use lazy_static::lazy_static; use serde::Deserialize; +use serde_json::json; use tokio::{ process::Command, time::{sleep, Duration}, @@ -68,6 +69,14 @@ async fn wait_for_server() { } async fn golden_test(body: serde_json::Value, expected: serde_json::Value) { + let mut body = body.clone(); + body.as_object_mut().unwrap().insert( + "debug_options".to_owned(), + json!({ + "disable_retrieval_augmented_code_completion": true + }), + ); + let actual: serde_json::Value = CLIENT .post("http://localhost:9090/v1/completions") .json(&body)