Skip to content

Commit

Permalink
Allow to disable automatic inline completions (#981)
Browse files Browse the repository at this point in the history
* Allow to disable automatic inline completions

* Lint
  • Loading branch information
krassowski authored Sep 9, 2024
1 parent ad6f3a3 commit 43e6acc
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions packages/jupyter-ai/src/completions/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ export class JaiInlineProvider
request: CompletionHandler.IRequest,
context: IInlineCompletionContext
): Promise<IInlineCompletionList<IInlineCompletionItem>> {
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) {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -275,6 +296,7 @@ export namespace JaiInlineProvider {
}

export interface ISettings {
triggerKind: 'any' | 'manual';
maxPrefix: number;
maxSuffix: number;
debouncerDelay: number;
Expand All @@ -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;
Expand Down

0 comments on commit 43e6acc

Please sign in to comment.