Skip to content

Commit

Permalink
fix: add flag to disable retrieval augmented code completion and set … (
Browse files Browse the repository at this point in the history
#580)

* fix: add flag to disable retrieval augmented code completion and set it in golden test

* update
  • Loading branch information
wsxiaoys authored Oct 17, 2023
1 parent 981133d commit 99d1bf3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
19 changes: 18 additions & 1 deletion crates/tabby/src/serve/completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions crates/tabby/tests/goldentests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 99d1bf3

Please sign in to comment.