Skip to content

Commit

Permalink
Use a throttler instead of a debouncer for code completion (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
brichet authored Oct 23, 2024
1 parent 0eb6e11 commit 6b2cae1
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
IInlineCompletionProvider
} from '@jupyterlab/completer';

import { Debouncer } from '@lumino/polling';
import { Throttler } from '@lumino/polling';

import MistralClient, { CompletionRequest } from '@mistralai/mistralai';

Expand All @@ -19,7 +19,7 @@ export class CodestralProvider implements IInlineCompletionProvider {

constructor(options: CodestralProvider.IOptions) {
this._mistralClient = options.mistralClient;
this._debouncer = new Debouncer(async (data: CompletionRequest) => {
this._throttler = new Throttler(async (data: CompletionRequest) => {
const response = await this._mistralClient.completion(data);
const items = response.choices.map((choice: any) => {
return { insertText: choice.message.content as string };
Expand Down Expand Up @@ -53,14 +53,14 @@ export class CodestralProvider implements IInlineCompletionProvider {
};

try {
return this._debouncer.invoke(data);
return this._throttler.invoke(data);
} catch (error) {
console.error('Error fetching completions', error);
return { items: [] };
}
}

private _debouncer: Debouncer;
private _throttler: Throttler;
private _mistralClient: MistralClient;
}

Expand Down

0 comments on commit 6b2cae1

Please sign in to comment.