Skip to content

Commit

Permalink
Added option to delay completion request
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevsnz committed Feb 6, 2024
1 parent 9288c45 commit 3d81cc9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@
"default": 256,
"description": "Max number of new tokens to be generated.",
"order": 7
},
"inference.delay": {
"type": "number",
"default": 250,
"description": "Completion request delay in milliseconds (0 - no delay, -1 - no completions).",
"order": 8,
"minimum": -1,
"maximum": 5000
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,16 @@ class Config {
}
}

let delay = config.get('delay') as number;

return {
endpoint,
maxLines,
maxTokens,
temperature,
modelName,
modelFormat
modelFormat,
delay
};
}

Expand Down
23 changes: 14 additions & 9 deletions src/prompts/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,21 @@ export class PromptProvider implements vscode.InlineCompletionItemProvider {
this.context = context;
}

async delayCompletion(delay: number, token: vscode.CancellationToken): Promise<boolean> {
if (config.inference.delay < 0) {
return false;
}
await new Promise(p => setTimeout(p, delay));
if (token.isCancellationRequested) {
return false;
}
return true;
}

async provideInlineCompletionItems(document: vscode.TextDocument, position: vscode.Position, context: vscode.InlineCompletionContext, token: vscode.CancellationToken): Promise<vscode.InlineCompletionItem[] | vscode.InlineCompletionList | undefined | null> {
if (!await this.delayCompletion(config.inference.delay, token)) {
return;
}

try {

Expand Down Expand Up @@ -66,15 +80,6 @@ export class PromptProvider implements vscode.InlineCompletionItemProvider {

// Config
let inferenceConfig = config.inference;
// let config = vscode.workspace.getConfiguration('inference');
// let endpoint = config.get('endpoint') as string;
// let model = config.get('model') as string;
// let maxLines = config.get('maxLines') as number;
// let maxTokens = config.get('maxTokens') as number;
// let temperature = config.get('temperature') as number;
// if (endpoint.endsWith('/')) {
// endpoint = endpoint.slice(0, endpoint.length - 1);
// }

// Update status
this.statusbar.text = `$(sync~spin) Llama Coder`;
Expand Down

0 comments on commit 3d81cc9

Please sign in to comment.