Skip to content

Commit

Permalink
Animations now also exist on automatic requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Wzixiao committed Oct 26, 2023
1 parent 0c1a5be commit c8e6ddb
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 29 deletions.
75 changes: 48 additions & 27 deletions packages/jupyter-ai/src/bigcode-Inline-completion-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
IInlineCompletionContext,
IInlineCompletionItem,
IInlineCompletionList,
IInlineCompletionProvider
IInlineCompletionProvider,
InlineCompletionTriggerKind
} from '@jupyterlab/completer';
import { NotebookPanel } from '@jupyterlab/notebook';
import { nullTranslator, TranslationBundle } from '@jupyterlab/translation';
Expand Down Expand Up @@ -37,6 +38,7 @@ export class BigcodeInlineCompletionProvider
cellCode: ''
};
private _requesting = false;
private _requestMode: InlineCompletionTriggerKind = 0;
private _streamStop = false;
private _finish = false;
private _timeoutId: number | null = null;
Expand Down Expand Up @@ -112,6 +114,7 @@ export class BigcodeInlineCompletionProvider

if (prompt) {
this.setRequestFinish(true);
this._requestMode = 0;
this._lastRequestInfo = {
insertText: '',
cellCode: request.text.slice(0, request.offset)
Expand Down Expand Up @@ -166,22 +169,23 @@ export class BigcodeInlineCompletionProvider
}

const result = await this.simulateSingleRequest(prompt);

console.debug(result);
if (result === '<debounce>') {
return { items: [] };
} else {
}

if (result === '<auto_stream>') {
this._lastRequestInfo = {
insertText: result,
insertText: '',
cellCode: currentRoundCellCodeText
};

this.setRequestFinish(false);

this._requestMode = 1;
return {
items: [
{
isIncomplete: false,
insertText: result
token: prompt,
isIncomplete: true,
insertText: ''
}
]
};
Expand Down Expand Up @@ -255,7 +259,8 @@ export class BigcodeInlineCompletionProvider
if (this._callCounter === currentCallCount && !this._requesting) {
this._callCounter = 0;
this._requesting = true;
resolve('"""This is the result of a simulated automatic request"""');
// resolve('"""This is the result of a simulated automatic request"""');
resolve('<auto_stream>');
this._timeoutId = null;
} else {
resolve('<debounce>');
Expand All @@ -267,37 +272,53 @@ export class BigcodeInlineCompletionProvider
async *stream(
token: string
): AsyncGenerator<{ response: IInlineCompletionItem }, undefined, unknown> {
const testResultText =
'_world():\n print("Hello World!")\nhello_world()';
this._requesting = true;
for (let i = 1; i <= testResultText.length; i++) {
await this.delay(25);

if (this._streamStop) {
console.debug('_streamStop');
this.setRequestFinish(false);
if (this._requestMode === 0) {
const testResultText =
'_world():\n print("Hello World!")\nhello_world()';
for (let i = 1; i <= testResultText.length; i++) {
await this.delay(25);

if (this._streamStop) {
console.debug('_streamStop');
this.setRequestFinish(false);

yield {
response: {
isIncomplete: false,
insertText: this._lastRequestInfo.insertText
}
};
return;
}

const insertChar = testResultText.slice(i - 1, i);
this._lastRequestInfo.insertText += insertChar;

yield {
response: {
isIncomplete: false,
isIncomplete: i !== testResultText.length - 1,
insertText: this._lastRequestInfo.insertText
}
};
return;
}

const insertChar = testResultText.slice(i - 1, i);
this._lastRequestInfo.insertText += insertChar;

this.setRequestFinish(false);
} else if (this._requestMode === 1) {
await this.delay(1000);
const insertText =
'"""This is the result of a simulated automatic request"""';
this._lastRequestInfo.insertText = insertText;
yield {
response: {
isIncomplete: i !== testResultText.length - 1,
insertText: this._lastRequestInfo.insertText
token,
isIncomplete: false,
insertText: insertText
}
};
this.setRequestFinish(false);
return;
}

this.setRequestFinish(false);
}

// async *stream(
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2755,7 +2755,7 @@ __metadata:

"@jupyterlab/completer@file:../../../jupyterlab/packages/completer::locator=%40jupyter-ai%2Fcore%40workspace%3Apackages%2Fjupyter-ai":
version: 4.1.0-alpha.2
resolution: "@jupyterlab/completer@file:../../../jupyterlab/packages/completer#../../../jupyterlab/packages/completer::hash=eb1d7b&locator=%40jupyter-ai%2Fcore%40workspace%3Apackages%2Fjupyter-ai"
resolution: "@jupyterlab/completer@file:../../../jupyterlab/packages/completer#../../../jupyterlab/packages/completer::hash=9b45e2&locator=%40jupyter-ai%2Fcore%40workspace%3Apackages%2Fjupyter-ai"
dependencies:
"@codemirror/state": ^6.2.0
"@codemirror/view": ^6.9.6
Expand All @@ -2777,7 +2777,7 @@ __metadata:
"@lumino/messaging": ^2.0.1
"@lumino/signaling": ^2.1.2
"@lumino/widgets": ^2.3.1-alpha.0
checksum: 50d69b1c18e8f51b7abbcef78a548134dc9d7acee008ba350f47b328b6198484118f6017c33e1cceb2372e3fc689719991c325bd48586d16a81bb021bdc19b7d
checksum: 7403b41c82007202e83f17d8dbd24c005eee45921dc0fa69bffc4657317f43d3e65c480590e5d408ea91f46a734452b206a1f8f0510d495a7927ff7b562380ed
languageName: node
linkType: hard

Expand Down

0 comments on commit c8e6ddb

Please sign in to comment.