From d9c9cadb41c93f59e7d06e2cbda6bd0479344a8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Tetsing?= Date: Mon, 12 Aug 2024 16:13:15 +0200 Subject: [PATCH] added platform bins --- .../src/app/plugins/remixAIPlugin.tsx | 4 +- .../src/lib/InferenceServerManager.ts | 38 +++++++++++++++++-- .../remix-ai/src/lib/components/Default.tsx | 2 +- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/apps/remix-ide/src/app/plugins/remixAIPlugin.tsx b/apps/remix-ide/src/app/plugins/remixAIPlugin.tsx index 06f0cb54d9..8e053408bb 100644 --- a/apps/remix-ide/src/app/plugins/remixAIPlugin.tsx +++ b/apps/remix-ide/src/app/plugins/remixAIPlugin.tsx @@ -116,7 +116,7 @@ export class RemixAIPlugin extends ViewPlugin { } else { result = await this.remoteInferencer.solidity_answer(prompt) } - this.call('terminal', 'log', { type: 'aitypewriterwarning', value: result }) + if (result) this.call('terminal', 'log', { type: 'aitypewriterwarning', value: result }) this.call('terminal', 'log', { type: 'aitypewriterwarning', value: "RemixAI Done" }) } @@ -153,7 +153,7 @@ export class RemixAIPlugin extends ViewPlugin { } else { result = await this.remoteInferencer.error_explaining(prompt) } - this.call('terminal', 'log', { type: 'aitypewriterwarning', value: result }) + if (result) this.call('terminal', 'log', { type: 'aitypewriterwarning', value: result }) this.call('terminal', 'log', { type: 'aitypewriterwarning', value: "RemixAI Done" }) } diff --git a/apps/remixdesktop/src/lib/InferenceServerManager.ts b/apps/remixdesktop/src/lib/InferenceServerManager.ts index e6119692a4..e2798b70c0 100644 --- a/apps/remixdesktop/src/lib/InferenceServerManager.ts +++ b/apps/remixdesktop/src/lib/InferenceServerManager.ts @@ -194,13 +194,43 @@ export class InferenceManager implements ICompletions { } } - getPythonScriptPath() { - return path.join(process.cwd(), 'dist', 'InferenceServer'); + private _getServerPath() { + // get cpu arch + const arch = process.arch + let exec_suffix = '' + + if (arch === 'x64') { + exec_suffix = 'x64' + } else if (arch === 'arm' || arch === 'arm64') { + exec_suffix = 'arm' + } else { + throw new Error('Unsupported CPU architecture') + } + + // get platform name and return the path to the python script + let exec_name = '' + if (process.platform === 'win32') { + exec_name = 'InferenceServer_' + process.platform + exec_suffix + '.exe' + } else if (process.platform === 'linux') { + exec_name = 'InferenceServer_' + process.platform + exec_suffix + } else if (process.platform === 'darwin') { + exec_name = 'InferenceServer_' + process.platform + exec_suffix + } else { + throw new Error('Unsupported platform') + } + return path.join(process.cwd(), 'dist', exec_name); + } private _startServer() { return new Promise((resolve, reject) => { - const serverPath = this.getPythonScriptPath(); + let serverPath = "" + try { + serverPath = this._getServerPath(); + } catch (error) { + console.error('Error script path:', error); + return reject(error) + } // Check if the file exists if (!fs.existsSync(serverPath)) { @@ -231,7 +261,7 @@ export class InferenceManager implements ICompletions { console.error(`Inference log: ${data}`); if (data.includes('Address already in use')) { console.error(`Port ${this.port} is already in use. Please stop the existing server and try again`); - reject(new Error(`Port ${this.port} is already in use`)); + return reject(new Error(`Port ${this.port} is already in use`)); } resolve(); }); diff --git a/libs/remix-ui/remix-ai/src/lib/components/Default.tsx b/libs/remix-ui/remix-ai/src/lib/components/Default.tsx index 29f53f16cf..fe19b868e2 100644 --- a/libs/remix-ui/remix-ai/src/lib/components/Default.tsx +++ b/libs/remix-ui/remix-ai/src/lib/components/Default.tsx @@ -70,7 +70,7 @@ export const Default = (props) => {