Skip to content

Commit

Permalink
fix llm provider get stuck in empty completion frenzy
Browse files Browse the repository at this point in the history
  • Loading branch information
rjmacarthy committed Apr 24, 2024
1 parent 5394b5d commit 27fb027
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const SKIP_DECLARATION_SYMBOLS = ['=']
export const IMPORT_SEPARATOR = [',', '{']
export const SKIP_IMPORT_KEYWORDS_AFTER = ['from', 'as', 'import']
export const MIN_COMPLETION_CHUNKS = 2
export const MAX_EMPTY_COMPLETION_CHARS = 250

export const EVENT_NAME = {
twinngAddMessage: 'twinny-add-message',
Expand Down
4 changes: 2 additions & 2 deletions src/extension/parser-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export const getParser = async (
'tree-sitter-wasms',
`tree-sitter-${language}.wasm`
)
const Language = await Parser.Language.load(wasmPath)
parser.setLanguage(Language)
const parserLanguage = await Parser.Language.load(wasmPath)
parser.setLanguage(parserLanguage)

return parser
}
Expand Down
11 changes: 11 additions & 0 deletions src/extension/providers/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
FIM_TEMPLATE_FORMAT,
LINE_BREAK_REGEX,
MAX_CONTEXT_LINE_COUNT,
MAX_EMPTY_COMPLETION_CHARS,
MIN_COMPLETION_CHUNKS,
MULTI_LINE_DELIMITERS,
MULTILINE_INSIDE,
Expand Down Expand Up @@ -244,6 +245,16 @@ export class CompletionProvider implements InlineCompletionItemProvider {
this._completion = this._completion + providerFimData
this._chunkCount = this._chunkCount + 1

if (
this._completion.length > MAX_EMPTY_COMPLETION_CHARS &&
this._completion.trim().length === 0
) {
this.abortCompletion()
this._logger.log(
`Streaming response end as llm in empty completion loop: ${this._nonce}`
)
}

if (
!this._multilineCompletionsEnabled &&
this._chunkCount >= MIN_COMPLETION_CHUNKS &&
Expand Down

0 comments on commit 27fb027

Please sign in to comment.