Skip to content
Snippets Groups Projects
Commit e385df45 authored by ali asaria's avatar ali asaria
Browse files

update autosetup and connect with more detailed steps

parent 186de543
No related branches found
No related tags found
No related merge requests found
......@@ -5,7 +5,7 @@
"requires": true,
"packages": {
"": {
"version": "0.1.6",
"version": "0.2.2",
"hasInstallScript": true,
"license": "MIT",
"dependencies": {
......@@ -26,6 +26,7 @@
"@uppy/xhr-upload": "^3.3.2",
"basic-auth": "~2.0.1",
"cidr-matcher": "^2.1.1",
"command-exists": "^1.2.9",
"debug": "^4.3.4",
"easy-peasy": "^6.0.2",
"electron-debug": "^3.2.0",
......@@ -7438,6 +7439,11 @@
"url": "https://github.com/sponsors/wooorm"
}
},
"node_modules/command-exists": {
"version": "1.2.9",
"resolved": "https://registry.npmjs.org/command-exists/-/command-exists-1.2.9.tgz",
"integrity": "sha512-LTQ/SGc+s0Xc0Fu5WaKnR0YiygZkm9eKFvyS+fRsU7/ZWFF8ykFM6Pc9aCVf1+xasOOZpO3BAVgVrKvsqKHV7w=="
},
"node_modules/commander": {
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-5.1.0.tgz",
......
......@@ -106,6 +106,7 @@
"@uppy/xhr-upload": "^3.3.2",
"basic-auth": "~2.0.1",
"cidr-matcher": "^2.1.1",
"command-exists": "^1.2.9",
"debug": "^4.3.4",
"easy-peasy": "^6.0.2",
"electron-debug": "^3.2.0",
......
......@@ -23,6 +23,9 @@ import {
installLocalServer,
killLocalServer,
executeInstallStep,
checkIfShellCommandExists,
checkIfCondaEnvironmentExists,
checkDependencies,
} from './util';
// ////////////
......@@ -68,19 +71,42 @@ ipcMain.handle('server:InstallLocally', (event) => {
});
ipcMain.handle('server:install_download', (event) => {
return executeInstallStep('download_transformer_lab');
return executeInstallStep('download_transformer_lab', false);
});
ipcMain.handle('server:install_conda', (event) => {
return executeInstallStep('install_conda');
ipcMain.handle('server:install_conda', async (event) => {
console.log('** Installing conda');
await executeInstallStep('install_conda', true);
console.log('Finishing installing conda');
return;
});
ipcMain.handle('server:install_create-conda-environment', (event) => {
return executeInstallStep('create_conda_environment');
ipcMain.handle('server:install_create-conda-environment', async (event) => {
return executeInstallStep('create_conda_environment', true);
});
ipcMain.handle('server:install_install-dependencies', (event) => {
return executeInstallStep('install_dependencies');
ipcMain.handle('server:install_install-dependencies', async (event) => {
return executeInstallStep('install_dependencies', true);
});
ipcMain.handle('server:checkIfCondaExists', async (event) => {
const r = checkIfShellCommandExists('conda');
console.log('conda exists', r);
return r;
});
ipcMain.handle('server:checkIfCondaEnvironmentExists', async (event) => {
const envList = await checkIfCondaEnvironmentExists();
console.log('envList', envList);
return envList;
});
ipcMain.handle('server:checkIfUvicornExists', async (event) => {
return checkIfShellCommandExists('uvicorn');
});
ipcMain.handle('server:checkDependencies', async (event) => {
return await checkDependencies();
});
class AppUpdater {
......
......@@ -21,7 +21,11 @@ export type Channels =
| 'server:install_download'
| 'server:install_conda'
| 'server:install_create-conda-environment'
| 'server:install_install-dependencies';
| 'server:install_install-dependencies'
| 'server:checkIfCondaExists'
| 'server:checkIfCondaEnvironmentExists'
| 'server:checkIfUvicornExists'
| 'server:checkDependencies';
const electronHandler = {
ipcRenderer: {
......
......@@ -4,8 +4,11 @@ import path from 'path';
const fs = require('fs');
const os = require('os');
const { spawn, exec, ChildProcess } = require('child_process');
const util = require('node:util');
const awaitExec = util.promisify(require('node:child_process').exec);
const homeDir = os.homedir();
const transformerLabDir = path.join(homeDir, '.transformerlab/src/');
const commandExistsSync = require('command-exists').sync;
var localServer: typeof ChildProcess = null;
......@@ -124,24 +127,104 @@ export function installLocalServer() {
}
}
export function executeInstallStep(argument: string) {
console.log('Downloading transformerlab-api to ~/.transformerlab/src');
export function checkIfShellCommandExists(command: string) {
if (commandExistsSync(command)) {
return true;
} else {
return false;
}
}
export async function checkDependencies() {
// First activate the transformerlab environment
// Then run pip list
// Then compare the output to the list of dependencies
// If any are missing, return the missing ones
// If all are present, manually check if the uvicorn command is present
const uvicornExists = checkIfShellCommandExists('uvicorn');
const command =
'eval "$(conda shell.bash hook)" && conda activate transformerlab && pip list --format json';
const options = { shell: '/bin/bash' };
try {
const child = exec(
`curl https://raw.githubusercontent.com/transformerlab/transformerlab-api/main/install.sh | bash -s -- ${argument}`,
options,
(error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
console.log(`stdout: ${stdout}`);
console.error(`stderr: ${stderr}`);
}
const { stdout, stderr } = await awaitExec(command, options).catch((err) => {
console.log('Error running pip list', err);
});
console.log('stdout:', stdout);
console.error('stderr:', stderr);
const pipList = JSON.parse(stdout);
const pipListNames = pipList.map((x) => x.name);
const keyDependencies = [
'fastapi',
'pydantic',
'transformers',
'uvicorn',
'sentencepiece',
'torch',
'transformers',
'peft',
'packaging',
'fschat',
];
//compare the list of dependencies to the keyDependencies
let missingDependencies = [];
for (let i = 0; i < keyDependencies.length; i++) {
if (!pipListNames.includes(keyDependencies[i])) {
missingDependencies.push(keyDependencies[i]);
}
}
console.log('missingDependencies', missingDependencies);
return missingDependencies;
}
export async function checkIfCondaEnvironmentExists() {
const options = { shell: '/bin/bash' };
console.log('Checking if Conda environment "transformerlab" exists');
const { stdout, stderr } = await awaitExec(`conda env list`, options).catch(
(err) => {
console.log('Error running conda env list', err);
}
);
console.log('stdout:', stdout);
console.error('stderr:', stderr);
// search for the string "transformerlab" in the output
if (stdout.includes('transformerlab')) {
return true;
} else {
return false;
}
}
export async function executeInstallStep(
argument: string,
useLocalInstallSh = false
) {
const options = { shell: '/bin/bash' };
console.log('Running install.sh ' + argument);
if (useLocalInstallSh) {
console.log(
`Using local install.sh and running: ~/.transformerlab/src/install.sh ${argument}`
);
} catch (err) {
console.log('Failed to download Transformer Lab API', err);
const { stdout, stderr } = await awaitExec(
`~/.transformerlab/src/install.sh ${argument}`,
options
).catch((err) => {
console.log('Error running install.sh', err);
});
console.log('stdout:', stdout);
console.error('stderr:', stderr);
} else {
const { stdout, stderr } = await awaitExec(
`curl https://raw.githubusercontent.com/transformerlab/transformerlab-api/main/install.sh | bash -s -- ${argument}`,
options
).catch((err) => {
console.log('Error running install.sh', err);
});
console.log('stdout:', stdout);
console.error('stderr:', stderr);
}
}
This diff is collapsed.
......@@ -96,12 +96,12 @@ export default function LoginModal({
aria-labelledby="basic-modal-dialog-title"
aria-describedby="basic-modal-dialog-description"
sx={{
top: '10vh', // Sit 20% from the top of the screen
top: '5vh', // Sit 20% from the top of the screen
margin: 'auto',
transform: 'translateX(-50%)', // This undoes the default translateY that centers vertically
width: '55vw',
maxWidth: '700px',
maxHeight: '70vh',
maxHeight: '90vh',
}}
>
<Tabs
......@@ -115,7 +115,15 @@ export default function LoginModal({
<Tab>Remote Connection</Tab>
{/* <Tab value="SSH">Connect via SSH</Tab> */}
</TabList>
<TabPanel value={0} sx={{ p: 2, overflowY: 'auto' }}>
<TabPanel
value={0}
sx={{
p: 2,
overflowY: 'hidden',
display: 'flex',
flexDirection: 'column',
}}
>
<LocalConnection setServer={setServer} />
</TabPanel>
<TabPanel value={1} sx={{ p: 2 }}>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment