From 403e7a3f6837b808909caab2e7d36ea4bbff14be Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 9 Nov 2023 12:58:52 +0100 Subject: [PATCH] linting --- .../suggestion-service/copilot-suggestion.ts | 2 +- .../suggestion-service/suggestion-service.ts | 70 +++++----- .../copilot/suggestion-service/worker.js | 128 +++++++++--------- 3 files changed, 100 insertions(+), 100 deletions(-) diff --git a/apps/remix-ide/src/app/plugins/copilot/suggestion-service/copilot-suggestion.ts b/apps/remix-ide/src/app/plugins/copilot/suggestion-service/copilot-suggestion.ts index 2c326e7115..e3d46db7ad 100644 --- a/apps/remix-ide/src/app/plugins/copilot/suggestion-service/copilot-suggestion.ts +++ b/apps/remix-ide/src/app/plugins/copilot/suggestion-service/copilot-suggestion.ts @@ -41,7 +41,7 @@ export class CopilotSuggestion extends Plugin { } async init() { - return this.service.init() + return this.service.init() } async uninstall() { diff --git a/apps/remix-ide/src/app/plugins/copilot/suggestion-service/suggestion-service.ts b/apps/remix-ide/src/app/plugins/copilot/suggestion-service/suggestion-service.ts index 374b4434fe..305cf4bd6f 100644 --- a/apps/remix-ide/src/app/plugins/copilot/suggestion-service/suggestion-service.ts +++ b/apps/remix-ide/src/app/plugins/copilot/suggestion-service/suggestion-service.ts @@ -8,7 +8,7 @@ export class SuggestionService { events: EventEmitter constructor() { this.worker = new Worker(new URL('./worker.js', import.meta.url), { - type: 'module' + type: 'module' }); this.events = new EventEmitter() this.responses = [] @@ -17,46 +17,46 @@ export class SuggestionService { async init() { const onMessageReceived = (e) => { switch (e.data.status) { - case 'initiate': - console.log(e.data) - this.events.emit(e.data.status, e.data) - // Model file start load: add a new progress item to the list. - break; + case 'initiate': + console.log(e.data) + this.events.emit(e.data.status, e.data) + // Model file start load: add a new progress item to the list. + break; - case 'progress': - this.events.emit(e.data.status, e.data) - console.log(e.data) - // Model file progress: update one of the progress items. - break; + case 'progress': + this.events.emit(e.data.status, e.data) + console.log(e.data) + // Model file progress: update one of the progress items. + break; - case 'done': - this.events.emit(e.data.status, e.data) - console.log(e.data) - // Model file loaded: remove the progress item from the list. - break; + case 'done': + this.events.emit(e.data.status, e.data) + console.log(e.data) + // Model file loaded: remove the progress item from the list. + break; - case 'ready': - this.events.emit(e.data.status, e.data) - console.log(e.data) - // Pipeline ready: the worker is ready to accept messages. - break; + case 'ready': + this.events.emit(e.data.status, e.data) + console.log(e.data) + // Pipeline ready: the worker is ready to accept messages. + break; - case 'update': - this.events.emit(e.data.status, e.data) - console.log(e.data) - // Generation update: update the output text. - break; + case 'update': + this.events.emit(e.data.status, e.data) + console.log(e.data) + // Generation update: update the output text. + break; - case 'complete': - console.log(e.data) - if (this.responses[e.data.id]) { - this.responses[e.data.id](null, e.data) - } else { - console.log('no callback for', e.data) - } + case 'complete': + console.log(e.data) + if (this.responses[e.data.id]) { + this.responses[e.data.id](null, e.data) + } else { + console.log('no callback for', e.data) + } - // Generation complete: re-enable the "Generate" button - break; + // Generation complete: re-enable the "Generate" button + break; } }; diff --git a/apps/remix-ide/src/app/plugins/copilot/suggestion-service/worker.js b/apps/remix-ide/src/app/plugins/copilot/suggestion-service/worker.js index b70758f232..3b6524b03c 100644 --- a/apps/remix-ide/src/app/plugins/copilot/suggestion-service/worker.js +++ b/apps/remix-ide/src/app/plugins/copilot/suggestion-service/worker.js @@ -8,82 +8,82 @@ const instance = null * This class uses the Singleton pattern to ensure that only one instance of the pipeline is loaded. */ class CodeCompletionPipeline { - static task = 'text-generation'; - static model = null - static instance = null; + static task = 'text-generation'; + static model = null + static instance = null; - static async getInstance(progress_callback = null) { - if (this.instance === null) { - this.instance = pipeline(this.task, this.model, { progress_callback }); - } - - return this.instance; + static async getInstance(progress_callback = null) { + if (this.instance === null) { + this.instance = pipeline(this.task, this.model, { progress_callback }); } + + return this.instance; + } } // Listen for messages from the main thread self.addEventListener('message', async (event) => { - const { - id, model, text, max_new_tokens, cmd, + const { + id, model, text, max_new_tokens, cmd, - // Generation parameters - temperature, - top_k, - do_sample, - } = event.data; + // Generation parameters + temperature, + top_k, + do_sample, + } = event.data; - if (cmd === 'init') { - // Retrieve the code-completion pipeline. When called for the first time, - // this will load the pipeline and save it for future use. - CodeCompletionPipeline.model = model - await CodeCompletionPipeline.getInstance(x => { - // We also add a progress callback to the pipeline so that we can - // track model loading. - self.postMessage(x); - }); - return - } + if (cmd === 'init') { + // Retrieve the code-completion pipeline. When called for the first time, + // this will load the pipeline and save it for future use. + CodeCompletionPipeline.model = model + await CodeCompletionPipeline.getInstance(x => { + // We also add a progress callback to the pipeline so that we can + // track model loading. + self.postMessage(x); + }); + return + } - if (!CodeCompletionPipeline.instance) { - // Send the output back to the main thread - self.postMessage({ - id, - status: 'error', - message: 'model not yet loaded' - }); - } + if (!CodeCompletionPipeline.instance) { + // Send the output back to the main thread + self.postMessage({ + id, + status: 'error', + message: 'model not yet loaded' + }); + } - if (cmd === 'suggest') { - // Retrieve the code-completion pipeline. When called for the first time, - // this will load the pipeline and save it for future use. - let generator = await CodeCompletionPipeline.getInstance(x => { - // We also add a progress callback to the pipeline so that we can - // track model loading. - self.postMessage(x); - }); + if (cmd === 'suggest') { + // Retrieve the code-completion pipeline. When called for the first time, + // this will load the pipeline and save it for future use. + let generator = await CodeCompletionPipeline.getInstance(x => { + // We also add a progress callback to the pipeline so that we can + // track model loading. + self.postMessage(x); + }); - // Actually perform the code-completion - let output = await generator(text, { - max_new_tokens, - temperature, - top_k, - do_sample, + // Actually perform the code-completion + let output = await generator(text, { + max_new_tokens, + temperature, + top_k, + do_sample, - // Allows for partial output - callback_function: x => { - self.postMessage({ - id, - status: 'update', - output: generator.tokenizer.decode(x[0].output_token_ids, { skip_special_tokens: true }) - }); - } + // Allows for partial output + callback_function: x => { + self.postMessage({ + id, + status: 'update', + output: generator.tokenizer.decode(x[0].output_token_ids, { skip_special_tokens: true }) }); + } + }); - // Send the output back to the main thread - self.postMessage({ - id, - status: 'complete', - output: output, - }); - } + // Send the output back to the main thread + self.postMessage({ + id, + status: 'complete', + output: output, + }); + } }); \ No newline at end of file