UNPKG

mlxmate

Version:

๐Ÿค– Your MLX-powered coding companion for Mac - AI assistant with Mistral

120 lines (105 loc) โ€ข 4.23 kB
#!/usr/bin/env node /** * MLXMate Installation Script * Handles Python dependencies and setup */ const { execSync, spawn } = require('child_process'); const fs = require('fs'); const path = require('path'); console.log('๐Ÿš€ Installing MLXMate...'); // Check if Python is available function checkPython() { try { const pythonVersion = execSync('python3 --version', { encoding: 'utf8' }); console.log(`โœ… Python found: ${pythonVersion.trim()}`); return 'python3'; } catch (error) { try { const pythonVersion = execSync('python --version', { encoding: 'utf8' }); console.log(`โœ… Python found: ${pythonVersion.trim()}`); return 'python'; } catch (error) { console.error('โŒ Python not found. Please install Python 3.8+ first.'); console.log('Visit: https://www.python.org/downloads/'); process.exit(1); } } } // Check if pip is available function checkPip(pythonCmd) { try { execSync(`${pythonCmd} -m pip --version`, { stdio: 'ignore' }); console.log('โœ… pip found'); return true; } catch (error) { console.error('โŒ pip not found. Please install pip first.'); process.exit(1); } } // Install Python dependencies function installDependencies(pythonCmd) { console.log('๐Ÿ“ฆ Installing Python dependencies...'); const requirementsPath = path.join(__dirname, '..', 'requirements.txt'); if (!fs.existsSync(requirementsPath)) { console.error('โŒ requirements.txt not found'); process.exit(1); } try { // Try installing with --user first try { execSync(`${pythonCmd} -m pip install --user -r "${requirementsPath}"`, { stdio: 'inherit' }); console.log('โœ… Python dependencies installed successfully with pip --user'); } catch (error) { // If --user fails, try without it try { console.log('โš ๏ธ --user installation failed, trying without --user...'); execSync(`${pythonCmd} -m pip install -r "${requirementsPath}"`, { stdio: 'inherit' }); console.log('โœ… Python dependencies installed successfully with pip'); } catch (error2) { // If that fails, try with --break-system-packages console.log('โš ๏ธ Standard installation failed, trying with --break-system-packages...'); execSync(`${pythonCmd} -m pip install --break-system-packages -r "${requirementsPath}"`, { stdio: 'inherit' }); console.log('โœ… Python dependencies installed successfully with --break-system-packages'); } } } catch (error) { console.error('โŒ Failed to install Python dependencies'); console.log('Try running: pip install --break-system-packages -r requirements.txt manually'); process.exit(1); } } // Test MLX installation function testMLX(pythonCmd) { console.log('๐Ÿงช Testing MLX installation...'); try { execSync(`${pythonCmd} -c "import mlx; import mlx_lm; print('โœ… MLX installed successfully')"`, { stdio: 'inherit' }); } catch (error) { console.error('โŒ MLX installation test failed'); console.log('Try running: pip install mlx mlx-lm manually'); process.exit(1); } } // Main installation function main() { console.log('๐Ÿค– MLXMate - Your MLX-powered coding companion'); console.log('=============================================\n'); const pythonCmd = checkPython(); checkPip(pythonCmd); installDependencies(pythonCmd); testMLX(pythonCmd); console.log('\n๐ŸŽ‰ Installation completed successfully!'); console.log('\n๐Ÿ“– Usage:'); console.log(' mlxmate # Start interactive chat'); console.log(' mlxmate help # Show all commands'); console.log(' mate # Short alias'); console.log('\n๐Ÿ”— Documentation: https://github.com/eshangulati/mlxmate'); } main();