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

Use a throttler instead of a debouncer for code completion #8

Merged
merged 1 commit into from
Oct 23, 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
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
Loading