Skip to content

Commit

Permalink
development > main (#342)
Browse files Browse the repository at this point in the history
* Add configuration setting to enable/disable completions per-language (#340)

* Add `twinny.enabledLanguages` configuration

* Skip completions if document language is disabled

* enable update without reload, lint

* 3.17.21

---------

Co-authored-by: Kyle Lacy <[email protected]>
  • Loading branch information
rjmacarthy and kylewlacy authored Oct 7, 2024
1 parent 95f3751 commit e0a1269
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 22 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 31 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "twinny",
"displayName": "twinny - AI Code Completion and Chat",
"description": "Locally hosted AI code completion plugin for vscode",
"version": "3.17.20",
"version": "3.17.21",
"icon": "assets/icon.png",
"keywords": [
"code-inference",
Expand Down Expand Up @@ -288,35 +288,46 @@
"default": true,
"description": "Activates or deactivates the Twinny extension."
},
"twinny.autoSuggestEnabled": {
"twinny.enabledLanguages": {
"order": 1,
"type": "object",
"additionalProperties": {
"type": "boolean"
},
"default": {
"*": true
},
"markdownDescription": "Languages to enable completions with Twinny for. `*` is used as the default."
},
"twinny.autoSuggestEnabled": {
"order": 2,
"type": "boolean",
"default": true,
"description": "Enable automatic completion suggestions, manual trigger (default shortcut Alt+\\)."
},
"twinny.contextLength": {
"order": 2,
"order": 3,
"type": "number",
"default": 100,
"description": "Defines the number of lines before and after the current line to include in FIM prompts.",
"required": true
},
"twinny.debounceWait": {
"order": 3,
"order": 4,
"type": "number",
"default": 300,
"description": "Delay in milliseconds before triggering the next completion.",
"required": true
},
"twinny.temperature": {
"order": 4,
"order": 5,
"type": "number",
"default": 0.2,
"description": "Sets the model's creativity level (temperature) for generating completions.",
"required": true
},
"twinny.multilineCompletionsEnabled": {
"order": 5,
"order": 6,
"type": "boolean",
"default": true,
"description": "Experimental feature: enables the generation of multi-line completions."
Expand All @@ -325,90 +336,90 @@
"dependencies": {
"twinny.multilineCompletionsEnabled": true
},
"order": 6,
"order": 7,
"type": "number",
"default": 30,
"description": "Maximum number of lines to use for multi line completions. Applicable only when multilineCompletionsEnabled is enabled."
},
"twinny.fileContextEnabled": {
"order": 8,
"order": 9,
"type": "boolean",
"default": false,
"description": "Enables scanning of neighbouring documents to enhance completion prompts. (Experimental)"
},
"twinny.completionCacheEnabled": {
"order": 9,
"order": 10,
"type": "boolean",
"default": false,
"description": "Caches FIM completions for identical prompts to enhance performance."
},
"twinny.numPredictChat": {
"order": 10,
"order": 11,
"type": "number",
"default": 512,
"description": "Maximum token limit for chat completions.",
"required": true
},
"twinny.numPredictFim": {
"order": 11,
"order": 12,
"type": "number",
"default": 512,
"description": "Maximum token limit for FIM completions. Set to -1 for no limit. Twinny should stop at logical line breaks.",
"required": true
},
"twinny.enableSubsequentCompletions": {
"order": 12,
"order": 13,
"type": "boolean",
"default": true,
"description": "Enable this setting to allow twinny to keep making subsequent completion requests to the API after the last completion request was accepted."
},
"twinny.ollamaHostname": {
"order": 13,
"order": 14,
"type": "string",
"default": "0.0.0.0",
"description": "Hostname for Ollama API.",
"required": true
},
"twinny.ollamaApiPort": {
"order": 14,
"order": 15,
"type": "number",
"default": 11434,
"description": "The API port usually `11434`",
"required": false
},
"twinny.embeddingModel": {
"order": 15,
"order": 16,
"type": "string",
"default": "nomic-embed-text",
"description": "The embedding model to use (Ollama only)",
"required": false
},
"twinny.keepAlive": {
"order": 16,
"order": 17,
"type": "string",
"default": "5m",
"description": "Keep models in memory by making requests with keep_alive=-1. Applicable only for Ollama API."
},
"twinny.ollamaUseTls": {
"order": 17,
"order": 18,
"type": "boolean",
"default": false,
"description": "Enables TLS encryption Ollama API connections."
},
"twinny.enableLogging": {
"order": 18,
"order": 19,
"type": "boolean",
"default": true,
"description": "Enable twinny debug mode"
},
"twinny.symmetryServerKey": {
"order": 19,
"order": 20,
"type": "string",
"description": "The symmetry master server key.",
"default": "4b4a9cc325d134dee6679e9407420023531fd7e96c563f6c5d00fd5549b77435"
},
"twinny.githubToken": {
"order": 27,
"order": 28,
"type": "string",
"default": "",
"description": "Your GitHub token. Used for fetching GitHub data."
Expand Down
15 changes: 15 additions & 0 deletions src/extension/providers/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ export class CompletionProvider implements InlineCompletionItemProvider {
private _fileContextEnabled = this._config.get(
'fileContextEnabled'
) as boolean
private _enabledLanguages = this._config.get('enabledLanguages') as Record<
string,
boolean
>
private _usingFimTemplate = false
private _provider: TwinnyProvider | undefined

Expand Down Expand Up @@ -141,6 +145,13 @@ export class CompletionProvider implements InlineCompletionItemProvider {
position
)

const languageEnabled =
this._enabledLanguages[document.languageId] ??
this._enabledLanguages['*'] ??
true

if (!languageEnabled) return

const cachedCompletion = cache.getCache(this._prefixSuffix)
if (cachedCompletion && this._completionCacheEnabled) {
this._completion = cachedCompletion
Expand Down Expand Up @@ -661,6 +672,10 @@ export class CompletionProvider implements InlineCompletionItemProvider {
this._numLineContext = this._config.get('contextLength') as number
this._numPredictFim = this._config.get('numPredictFim') as number
this._temperature = this._config.get('temperature') as number
this._enabledLanguages = this._config.get('enabledLanguages') as Record<
string,
boolean
>
this._fileContextEnabled = this._config.get('fileContextEnabled') as boolean
this._multilineCompletionsEnabled = this._config.get(
'multilineCompletionsEnabled'
Expand Down

0 comments on commit e0a1269

Please sign in to comment.