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

Allow to disable automatic inline completions #981

Merged
merged 2 commits into from
Sep 9, 2024
Merged
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
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
Loading