Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

default maxTokens setting for autocomplete #4448

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions core/autocomplete/CompletionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { DEFAULT_AUTOCOMPLETE_OPTS } from "../util/parameters.js";

import { shouldCompleteMultiline } from "./classification/shouldCompleteMultiline.js";
import { ContextRetrievalService } from "./context/ContextRetrievalService.js";

Check warning on line 8 in core/autocomplete/CompletionProvider.ts

View workflow job for this annotation

GitHub Actions / core-checks

There should be no empty line within import group

import { BracketMatchingService } from "./filtering/BracketMatchingService.js";
import { CompletionStreamer } from "./generation/CompletionStreamer.js";
Expand Down Expand Up @@ -175,12 +175,20 @@
this.ide.getWorkspaceDirs(),
]);

const { prompt, prefix, suffix, completionOptions } = renderPrompt({
const { prompt, prefix, suffix, completionOptions: _completionOptions } = renderPrompt({
snippetPayload,
workspaceDirs,
helper,
});

// Default maxTokens for autocomplete set in core/llm/llms/index.ts llmFromDescription()
const completionOptions = {
..._completionOptions,
maxTokens: _completionOptions?.maxTokens ||
llm.completionOptions.autoCompleteMaxTokens ||
llm.completionOptions.maxTokens
};

// Completion
let completion: string | undefined = "";

Expand Down Expand Up @@ -220,11 +228,11 @@

const processedCompletion = helper.options.transform
? postprocessCompletion({
completion,
prefix: helper.prunedPrefix,
suffix: helper.prunedSuffix,
llm,
})
completion,
prefix: helper.prunedPrefix,
suffix: helper.prunedSuffix,
llm,
})
: completion;

completion = processedCompletion;
Expand Down Expand Up @@ -257,7 +265,7 @@

// Save to cache
if (!outcome.cacheHit && helper.options.useCache) {
(await this.autocompleteCache).put(outcome.prefix, outcome.completion);

Check warning on line 268 in core/autocomplete/CompletionProvider.ts

View workflow job for this annotation

GitHub Actions / core-checks

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
}

// When using the JetBrains extension, Mark as displayed
Expand Down
1 change: 1 addition & 0 deletions core/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,7 @@ export interface BaseCompletionOptions {
mirostat?: number;
stop?: string[];
maxTokens?: number;
autoCompleteMaxTokens?: number;
numThreads?: number;
useMmap?: boolean;
keepAlive?: number;
Expand Down
10 changes: 8 additions & 2 deletions core/llm/llms/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import Cohere from "./Cohere";
import DeepInfra from "./DeepInfra";
import Deepseek from "./Deepseek";
import Fireworks from "./Fireworks";
import NCompass from "./NCompass";
import Flowise from "./Flowise";
import FreeTrial from "./FreeTrial";
import FunctionNetwork from "./FunctionNetwork";
Expand All @@ -35,7 +34,9 @@ import Mistral from "./Mistral";
import MockLLM from "./Mock";
import Moonshot from "./Moonshot";
import Msty from "./Msty";
import NCompass from "./NCompass";
import Nebius from "./Nebius";
import Novita from "./Novita";
import Nvidia from "./Nvidia";
import Ollama from "./Ollama";
import OpenAI from "./OpenAI";
Expand All @@ -49,7 +50,6 @@ import ContinueProxy from "./stubs/ContinueProxy";
import TestLLM from "./Test";
import TextGenWebUI from "./TextGenWebUI";
import Together from "./Together";
import Novita from "./Novita";
import VertexAI from "./VertexAI";
import Vllm from "./Vllm";
import WatsonX from "./WatsonX";
Expand Down Expand Up @@ -112,6 +112,7 @@ export async function llmFromDescription(
writeLog: (log: string) => Promise<void>,
completionOptions?: BaseCompletionOptions,
systemMessage?: string,
isAutocomplete = false
): Promise<BaseLLM | undefined> {
const cls = LLMClasses.find((llm) => llm.providerName === desc.provider);

Expand All @@ -137,6 +138,11 @@ export async function llmFromDescription(
maxTokens:
finalCompletionOptions.maxTokens ??
cls.defaultOptions?.completionOptions?.maxTokens,
autoCompleteMaxTokens:
finalCompletionOptions.autoCompleteMaxTokens ??
finalCompletionOptions.maxTokens ??
cls.defaultOptions?.completionOptions?.autoCompleteMaxTokens ??
256
},
systemMessage,
writeLog,
Expand Down
Loading