From 9ef419b1ca1cf7aeeb0dcfe495531c4e4365fc98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Tetsing?= Date: Wed, 24 Jul 2024 11:42:27 +0200 Subject: [PATCH] single request Remix AI except completions --- .../src/app/plugins/remixAIPlugin.tsx | 46 +++++++++++++++++-- .../remixdesktop/src/plugins/remixAIDektop.ts | 14 ++++-- 2 files changed, 50 insertions(+), 10 deletions(-) diff --git a/apps/remix-ide/src/app/plugins/remixAIPlugin.tsx b/apps/remix-ide/src/app/plugins/remixAIPlugin.tsx index 7f8dfd1d08..06f0cb54d9 100644 --- a/apps/remix-ide/src/app/plugins/remixAIPlugin.tsx +++ b/apps/remix-ide/src/app/plugins/remixAIPlugin.tsx @@ -50,14 +50,31 @@ export class RemixAIPlugin extends ViewPlugin { async initialize(model1?:IModel, model2?:IModel, remoteModel?:IRemoteModel){ if (this.isOnDesktop) { - this.call(this.remixDesktopPluginName, 'initializeModelBackend', false, model1, model2) - this.on(this.remixDesktopPluginName, 'onStreamResult', (value) => { - this.call('terminal', 'log', { type: 'log', value: value }) - }) + const res = await this.call(this.remixDesktopPluginName, 'initializeModelBackend', false, model1, model2) + if (res) { + this.on(this.remixDesktopPluginName, 'onStreamResult', (value) => { + this.call('terminal', 'log', { type: 'log', value: value }) + }) + + this.on(this.remixDesktopPluginName, 'onInference', () => { + this.isInferencing = true + }) + + this.on(this.remixDesktopPluginName, 'onInferenceDone', () => { + this.isInferencing = false + }) + } + } else { // on browser console.log('Initializing RemixAIPlugin on browser') this.remoteInferencer = new RemoteInferencer(remoteModel?.apiUrl, remoteModel?.completionUrl) + this.remoteInferencer.event.on('onInference', () => { + this.isInferencing = true + }) + this.remoteInferencer.event.on('onInferenceDone', () => { + this.isInferencing = false + }) } this.aiIsActivated = true @@ -65,7 +82,11 @@ export class RemixAIPlugin extends ViewPlugin { } async code_generation(prompt: string): Promise { - console.log('code_generation') + if (this.isInferencing) { + this.call('terminal', 'log', { type: 'aitypewriterwarning', value: "RemixAI is already busy!" }) + return + } + if (this.isOnDesktop) { return await this.call(this.remixDesktopPluginName, 'code_generation', prompt) } else { @@ -82,6 +103,11 @@ export class RemixAIPlugin extends ViewPlugin { } async solidity_answer(prompt: string): Promise { + if (this.isInferencing) { + this.call('terminal', 'log', { type: 'aitypewriterwarning', value: "RemixAI is already busy!" }) + return + } + this.call('terminal', 'log', { type: 'aitypewriterwarning', value: `\n\nWaiting for RemixAI answer...` }) let result @@ -95,6 +121,11 @@ export class RemixAIPlugin extends ViewPlugin { } async code_explaining(prompt: string): Promise { + if (this.isInferencing) { + this.call('terminal', 'log', { type: 'aitypewriterwarning', value: "RemixAI is already busy!" }) + return + } + this.call('terminal', 'log', { type: 'aitypewriterwarning', value: `\n\nWaiting for RemixAI answer...` }) let result @@ -109,6 +140,11 @@ export class RemixAIPlugin extends ViewPlugin { } async error_explaining(prompt: string): Promise { + if (this.isInferencing) { + this.call('terminal', 'log', { type: 'aitypewriterwarning', value: "RemixAI is already busy!" }) + return + } + this.call('terminal', 'log', { type: 'aitypewriterwarning', value: `\n\nWaiting for RemixAI answer...` }) let result diff --git a/apps/remixdesktop/src/plugins/remixAIDektop.ts b/apps/remixdesktop/src/plugins/remixAIDektop.ts index 8a0175d6c3..3898ecaf96 100644 --- a/apps/remixdesktop/src/plugins/remixAIDektop.ts +++ b/apps/remixdesktop/src/plugins/remixAIDektop.ts @@ -68,15 +68,18 @@ class RemixAIDesktopPluginClient extends ElectronBasePluginClient { if (local){ console.log('Initializing Inference model locally') this.desktopInferencer = new RemoteInferencer() - } else { + } else if (generalModel || completionModel){ if (!this.desktopInferencer){ console.log('Initializing Inference model') this.desktopInferencer = InferenceManager.getInstance(this.modelCacheDir) + if (this.desktopInferencer instanceof InferenceManager && generalModel) await this.desktopInferencer.init(generalModel) + if (this.desktopInferencer instanceof InferenceManager && completionModel) await this.desktopInferencer.init(completionModel) } else { console.log('Inference model already initialized') + return false // do not set event listener twice } - if (this.desktopInferencer instanceof InferenceManager && generalModel) await this.desktopInferencer.init(generalModel) - if (this.desktopInferencer instanceof InferenceManager && completionModel) await this.desktopInferencer.init(completionModel) + } else { + throw new Error('No model provided') } // set event listeners @@ -86,9 +89,10 @@ class RemixAIDesktopPluginClient extends ElectronBasePluginClient { this.desktopInferencer.event.on('onInference', () => { this.emit('onInference') }) - this.desktopInferencer.event.on('onInfrenceDone', () => { - this.emit('onInfrenceDone') + this.desktopInferencer.event.on('onInferenceDone', () => { + this.emit('onInferenceDone') }) + return true } async code_completion(context: any) {