From 0ffac273e54b5ad91091ac6fcdb6e59be78af7af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Krassowski?= <5832902+krassowski@users.noreply.github.com> Date: Mon, 9 Sep 2024 22:05:13 +0100 Subject: [PATCH] Allow to disable automatic inline completions (#981) * Allow to disable automatic inline completions * Lint --- .../jupyter-ai/src/completions/provider.ts | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/packages/jupyter-ai/src/completions/provider.ts b/packages/jupyter-ai/src/completions/provider.ts index 786ced851..80c199f5a 100644 --- a/packages/jupyter-ai/src/completions/provider.ts +++ b/packages/jupyter-ai/src/completions/provider.ts @@ -54,6 +54,17 @@ export class JaiInlineProvider request: CompletionHandler.IRequest, context: IInlineCompletionContext ): Promise> { + const allowedTriggerKind = this._settings.triggerKind; + const triggerKind = context.triggerKind; + if ( + allowedTriggerKind === 'manual' && + triggerKind !== InlineCompletionTriggerKind.Invoke + ) { + // Short-circuit if user requested to only invoke inline completions + // on manual trigger for jupyter-ai. Users may still get completions + // from other (e.g. less expensive or faster) providers. + return { items: [] }; + } const mime = request.mimeType ?? 'text/plain'; const language = this.options.languageRegistry.findByMIME(mime); if (!language) { @@ -142,6 +153,16 @@ export class JaiInlineProvider const knownLanguages = this.options.languageRegistry.getLanguages(); return { properties: { + triggerKind: { + title: 'Inline completions trigger', + type: 'string', + oneOf: [ + { const: 'any', title: 'Automatic (on typing or invocation)' }, + { const: 'manual', title: 'Only when invoked manually' } + ], + description: + 'When to trigger inline completions when using jupyter-ai.' + }, maxPrefix: { title: 'Maximum prefix length', minimum: 1, @@ -275,6 +296,7 @@ export namespace JaiInlineProvider { } export interface ISettings { + triggerKind: 'any' | 'manual'; maxPrefix: number; maxSuffix: number; debouncerDelay: number; @@ -284,6 +306,7 @@ export namespace JaiInlineProvider { } export const DEFAULT_SETTINGS: ISettings = { + triggerKind: 'any', maxPrefix: 10000, maxSuffix: 10000, // The debouncer delay handling is implemented upstream in JupyterLab;