Skip to content

Commit

Permalink
Merge pull request #6 from mohankumarelec/wsl-issues
Browse files Browse the repository at this point in the history
Fixed token count calculation for completions
  • Loading branch information
mohankumarelec authored Nov 13, 2024
2 parents c1a9d03 + e80619e commit 0c2912e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "flexpilot-vscode-extension",
"displayName": "Flexpilot",
"description": "Open-Source, Native and a True GitHub Copilot Alternative for VS Code",
"version": "1.95.1",
"version": "1.95.2",
"icon": "assets/logo.png",
"license": "GPL-3.0-only",
"pricing": "Free",
Expand Down Expand Up @@ -158,6 +158,13 @@
"default": 0.1,
"description": "The randomness of completions, with 0.0 being deterministic and 1.0 being random."
},
"flexpilot.completions.maxTokenUsage": {
"type": "number",
"maximum": 128000,
"minimum": 500,
"default": 4000,
"description": "Maximum number of tokens (prompt + output) allowed for generating completions. This will help control the usage cost."
},
"flexpilot.panelChat.temperature": {
"type": "number",
"maximum": 1,
Expand Down
8 changes: 6 additions & 2 deletions src/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ class InlineCompletionProvider implements vscode.InlineCompletionItemProvider {

// Limit the number of tokens for prompt
const promptTokenLimit =
provider.config.contextWindow - this.maxOutputTokens;
Math.min(
storage.workspace.get<number>("flexpilot.completions.maxTokenUsage"),
provider.config.contextWindow,
) - this.maxOutputTokens;

// Get the prefix for prompt
let prefixRange = new vscode.Range(0, 0, position.line, 0);
Expand Down Expand Up @@ -188,7 +191,8 @@ class InlineCompletionProvider implements vscode.InlineCompletionItemProvider {
"flexpilot.completions.contextPrefixWeight",
) * promptTokenLimit,
) - headerTokens.length;
const maxSuffixLength = promptTokenLimit - maxPrefixLength;
const maxSuffixLength =
promptTokenLimit - maxPrefixLength - headerTokens.length;
if (
prefixTokens.length > maxPrefixLength &&
suffixTokens.length > maxSuffixLength
Expand Down
6 changes: 3 additions & 3 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ export const PROVIDER_TYPES = ["chat", "completion"] as const;
export const ALLOWED_COMPLETION_MODELS = [
{
regex: "^gpt-3.5-turbo-.*instruct",
contextWindow: 3500,
contextWindow: 4000,
tokenizerUrl:
"https://cdn.jsdelivr.net/gh/flexpilot-ai/vscode-extension/tokenizers/cl100k_base.json",
},
{
regex: "^codestral-(?!.*mamba)",
contextWindow: 30000,
contextWindow: 31500,
tokenizerUrl:
"https://cdn.jsdelivr.net/gh/flexpilot-ai/vscode-extension/tokenizers/codestral-v0.1.json",
},
{
regex: "^gpt-35-turbo-.*instruct",
contextWindow: 3500,
contextWindow: 4000,
tokenizerUrl:
"https://cdn.jsdelivr.net/gh/flexpilot-ai/vscode-extension/tokenizers/cl100k_base.json",
},
Expand Down

0 comments on commit 0c2912e

Please sign in to comment.