Skip to content

Commit

Permalink
Make the code neater
Browse files Browse the repository at this point in the history
  • Loading branch information
Wzixiao committed Oct 31, 2023
1 parent fa3dbbe commit 2e98753
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
31 changes: 16 additions & 15 deletions packages/jupyter-ai/src/bigcode-Inline-completion-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ export class BigcodeInlineCompletionProvider
'"""This is the first line generated by the mockKeypressCompletionStreamr"""\n """This is the second line generated by the mockKeypressCompletionStream"""';

for (let i = 1; i <= testResultText.length; i++) {
await this.delay(25);
await this.delay(10);

if (this._streamStop) {
console.debug('_streamStop');
Expand Down Expand Up @@ -382,8 +382,7 @@ export class BigcodeInlineCompletionProvider
const { value, done } = await reader.read();

if (done || this._streamStop) {
this.setRequestFinish(false);
break;
return;
}

const strValue = decoder.decode(value, { stream: true });
Expand All @@ -397,15 +396,13 @@ export class BigcodeInlineCompletionProvider
) as BigCodeServiceStreamResponseItem;
const done = chunkData.token.special;

if (done) {
this.setRequestFinish(false);
} else {
if (!done) {
this._lastRequestInfo.insertText += chunkData.token.text;
}

yield {
response: {
isIncomplete: !chunkData.token.special,
isIncomplete: !done,
insertText: this._lastRequestInfo.insertText
}
};
Expand All @@ -417,14 +414,18 @@ export class BigcodeInlineCompletionProvider
async *automaticCompletionStream(
token: string
): AsyncGenerator<{ response: IInlineCompletionItem }, undefined, unknown> {
const reponseData = await bigcodeRequestInstance.fetchStream(false);
try {
const reponseData = await bigcodeRequestInstance.fetchStream(false);

yield {
response: {
token,
isIncomplete: false,
insertText: reponseData[0].generated_text
}
};
yield {
response: {
token,
isIncomplete: false,
insertText: reponseData[0].generated_text
}
};
} catch {
return;
}
}
}
2 changes: 1 addition & 1 deletion packages/jupyter-ai/src/utils/bigcode-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Bigcode {
'BigCode service URL or Huggingface Access Token not set.'
);
}
console.debug(this.prompt);

if (!this._prompt) {
throw new Error('Prompt is null');
}
Expand Down

0 comments on commit 2e98753

Please sign in to comment.