diff --git a/packages/jupyter-ai/src/bigcode-Inline-completion-provider.ts b/packages/jupyter-ai/src/bigcode-Inline-completion-provider.ts index faeeefe63..57090097b 100644 --- a/packages/jupyter-ai/src/bigcode-Inline-completion-provider.ts +++ b/packages/jupyter-ai/src/bigcode-Inline-completion-provider.ts @@ -21,6 +21,7 @@ export class BigcodeInlineCompletionProvider { readonly identifier = '@jupyterlab/inline-completer:bigcode'; private _trans: TranslationBundle; + // Used to record information from the last user request private _lastRequestInfo: { insertText: string; cellCode: string; @@ -29,10 +30,15 @@ export class BigcodeInlineCompletionProvider cellCode: '' }; private _requesting = false; + // Change it in "fetch" and then use this field in "stream" to call a different function private _requestMode: InlineCompletionTriggerKind = 0; + // Whether to stop the stream immediately, When the stream is in progress, the user requests to change this field to true, and then interrupts the stream request. private _streamStop = false; + // Whether to finish for request private _finish = false; + // Debounce use private _timeoutId: number | null = null; + // Debounce use private _callCounter = 0; get finish(): boolean { @@ -61,6 +67,9 @@ export class BigcodeInlineCompletionProvider this._finish = !error; } + /** + * When the user executes the "accept" function, this function will be called to clear the status. + */ clearState(): void { this._streamStop = true; this._finish = false; @@ -226,6 +235,7 @@ export class BigcodeInlineCompletionProvider ); const items: IInlineCompletionItem[] = []; + // Determine whether the keyboard pressed by the user is the beginning of ghost text if ( this._lastRequestInfo.insertText.startsWith(newAddedCodeText) && newAddedCodeText !== '' @@ -382,7 +392,7 @@ export class BigcodeInlineCompletionProvider let reponseData: ReadableStream | null = null; try { - reponseData = await bigcodeRequestInstance.fetchStream(true); + reponseData = await bigcodeRequestInstance.send(true); } catch { yield { response: { @@ -434,7 +444,7 @@ export class BigcodeInlineCompletionProvider token: string ): AsyncGenerator<{ response: IInlineCompletionItem }, undefined, unknown> { try { - const reponseData = await bigcodeRequestInstance.fetchStream(false); + const reponseData = await bigcodeRequestInstance.send(false); yield { response: { diff --git a/packages/jupyter-ai/src/index.ts b/packages/jupyter-ai/src/index.ts index 20633f6f6..a2a608330 100644 --- a/packages/jupyter-ai/src/index.ts +++ b/packages/jupyter-ai/src/index.ts @@ -65,9 +65,10 @@ const plugin: JupyterFrontEndPlugin = { } }; -const bigcodeCodeCompletion: JupyterFrontEndPlugin = { - id: 'jupyter_ai:plugin:inline-bigcode', - description: 'Adds inline completion provider suggesting code from bigcode.', +const inlineCompletionPlugin: JupyterFrontEndPlugin = { + id: 'jupyter_ai:plugin:inline-completion', + description: + 'Adding an inline completion provider suggestion comes from jupyter-ai.', requires: [ICompletionProviderManager], optional: [ILayoutRestorer], autoStart: true, @@ -116,6 +117,6 @@ const bigcodeCodeCompletion: JupyterFrontEndPlugin = { } }; -const plugins: JupyterFrontEndPlugin[] = [plugin, bigcodeCodeCompletion]; +const plugins: JupyterFrontEndPlugin[] = [plugin, inlineCompletionPlugin]; export default plugins; diff --git a/packages/jupyter-ai/src/utils/bigcode-request.ts b/packages/jupyter-ai/src/utils/bigcode-request.ts index 3b44d851e..4b3517b96 100644 --- a/packages/jupyter-ai/src/utils/bigcode-request.ts +++ b/packages/jupyter-ai/src/utils/bigcode-request.ts @@ -19,13 +19,6 @@ export type BigCodeServiceNotStreamResponse = { generated_text: string; }[]; -/** - * Generates the appropriate prompt string based on the cell type. - * The cell type can be either 'code' or 'markdown'. - * - * @param {ICell} cell - The cell object which includes the type and content. - * @returns {string} The generated prompt string for the cell. - */ class Bigcode { spaceCount: number; private _prompt: string; @@ -52,9 +45,9 @@ class Bigcode { return this._prompt; } - async fetchStream(stream: true): Promise>; - async fetchStream(stream: false): Promise; - async fetchStream( + async send(stream: true): Promise>; + async send(stream: false): Promise; + async send( stream = false ): Promise | BigCodeServiceNotStreamResponse> { if (!this.bigcodeUrl || !this.accessToken) {