Skip to content

Commit

Permalink
add force completion
Browse files Browse the repository at this point in the history
  • Loading branch information
reymondzzzz committed Oct 23, 2023
1 parent 24848d5 commit 9fa5e11
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/call_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ pub struct CodeCompletionPost {
pub scratchpad: String,
#[serde(default)]
pub stream: bool,
#[serde(default)]
pub no_cache: bool,
}

#[derive(Debug, Deserialize, Clone)]
Expand Down
18 changes: 10 additions & 8 deletions src/http_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,16 @@ pub async fn handle_v1_code_completion(

let cache_arc = global_context.read().await.completions_cache.clone();
let tele_storage = global_context.read().await.telemetry.clone();
let cache_key = completion_cache::cache_key_from_post(&code_completion_post);
let cached_maybe = completion_cache::cache_get(cache_arc.clone(), cache_key.clone());
if let Some(cached_json_value) = cached_maybe {
// info!("cache hit for key {:?}", cache_key.clone());
if !code_completion_post.stream {
return crate::restream::cached_not_stream(&cached_json_value).await;
} else {
return crate::restream::cached_stream(&cached_json_value).await;
if (!code_completion_post.no_cache) {
let cache_key = completion_cache::cache_key_from_post(&code_completion_post);
let cached_maybe = completion_cache::cache_get(cache_arc.clone(), cache_key.clone());
if let Some(cached_json_value) = cached_maybe {
// info!("cache hit for key {:?}", cache_key.clone());
if !code_completion_post.stream {
return crate::restream::cached_not_stream(&cached_json_value).await;
} else {
return crate::restream::cached_stream(&cached_json_value).await;
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ impl Backend {
model: "".to_string(),
scratchpad: "".to_string(),
stream: false,
}
no_cache: false
})
}

pub async fn get_completions(&self, params: CompletionParams1) -> Result<CompletionRes> {
Expand Down

0 comments on commit 9fa5e11

Please sign in to comment.