Skip to content

Commit

Permalink
feat: add debug flag disable_prompt_rewrite (#545)
Browse files Browse the repository at this point in the history
  • Loading branch information
wsxiaoys authored Oct 13, 2023
1 parent 1ad871e commit 1a87c99
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions crates/tabby/src/serve/completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,25 @@ pub struct CompletionRequest {
/// When segments are set, the `prompt` is ignored during the inference.
segments: Option<Segments>,

// A unique identifier representing your end-user, which can help Tabby to monitor & generating
// reports.
/// A unique identifier representing your end-user, which can help Tabby to monitor & generating
/// reports.
user: Option<String>,

debug: Option<DebugRequest>,
}

#[derive(Serialize, ToSchema, Deserialize, Clone, Debug)]
pub struct DebugRequest {
// When true, returns debug_data in completion response.
/// When true, returns debug_data in completion response.
enabled: bool,

/// When true, turn off prompt rewrite with source code index.
#[serde(default = "default_false")]
disable_prompt_rewrite: bool,
}

fn default_false() -> bool {
false
}

#[derive(Serialize, Deserialize, ToSchema, Clone, Debug)]
Expand Down Expand Up @@ -128,7 +136,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
.as_ref()
.is_some_and(|x| x.disable_prompt_rewrite)
{
state.prompt_builder.collect(&language, &segments)
} else {
vec![]
};
let prompt = state
.prompt_builder
.build(&language, segments.clone(), &snippets);
Expand Down

0 comments on commit 1a87c99

Please sign in to comment.