Team Ai
Datasetpublic

Brunobkr/llama.cpp_AlgMor24_github

ΩFFFΣLLIa • llama.cpp • AlgMor24 ██████╗ ███████╗███████╗███████╗██╗ ██╗ ██╗ █████╗ ██╔═══██╗██╔════╝██╔════╝██╔════╝██║ ██║ ██║██╔══██╗ ██║ ██║█████╗ █████╗ █████╗ ██║ ██║ ██║███████║ ██║ ██║██╔══╝ ██╔══╝ ██╔══╝ ██║ ██║ ██║██╔══██║ ╚██████╔╝██║ ██║ ███████╗███████╗███████╗██║██║ ██║ ╚═════╝ ╚═╝ ╚═╝ ╚══════╝╚══════╝╚══════╝╚═╝╚═╝ ╚═╝ High-Performance LLM / VLM Inference & Autonomous Agentic Ecosystem… See the full description on the dataset page: https://huggingface.co/datasets/Brunobkr/llama.cpp_AlgMor24_github.

sourceHugging Faceupdated 2mo agoView on Hugging Face
0likes3.1kdownloads
index.js367 linesDownload Raw Back to open
1import process from 'node:process';2import {Buffer} from 'node:buffer';3import path from 'node:path';4import {fileURLToPath} from 'node:url';5import {promisify} from 'node:util';6import childProcess from 'node:child_process';7import fs, {constants as fsConstants} from 'node:fs/promises';8import {isWsl, powerShellPath} from 'wsl-utils';9import defineLazyProperty from 'define-lazy-prop';10import defaultBrowser from 'default-browser';11import isInsideContainer from 'is-inside-container';12 13const execFile = promisify(childProcess.execFile);14 15// Path to included `xdg-open`.16const __dirname = path.dirname(fileURLToPath(import.meta.url));17const localXdgOpenPath = path.join(__dirname, 'xdg-open');18 19const {platform, arch} = process;20 21/**22Get the default browser name in Windows from WSL.23 24@returns {Promise<string>} Browser name.25*/26async function getWindowsDefaultBrowserFromWsl() {27	const powershellPath = await powerShellPath();28	const rawCommand = String.raw`(Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice").ProgId`;29	const encodedCommand = Buffer.from(rawCommand, 'utf16le').toString('base64');30 31	const {stdout} = await execFile(32		powershellPath,33		[34			'-NoProfile',35			'-NonInteractive',36			'-ExecutionPolicy',37			'Bypass',38			'-EncodedCommand',39			encodedCommand,40		],41		{encoding: 'utf8'},42	);43 44	const progId = stdout.trim();45 46	// Map ProgId to browser IDs47	const browserMap = {48		ChromeHTML: 'com.google.chrome',49		BraveHTML: 'com.brave.Browser',50		MSEdgeHTM: 'com.microsoft.edge',51		FirefoxURL: 'org.mozilla.firefox',52	};53 54	return browserMap[progId] ? {id: browserMap[progId]} : {};55}56 57const pTryEach = async (array, mapper) => {58	let latestError;59 60	for (const item of array) {61		try {62			return await mapper(item); // eslint-disable-line no-await-in-loop63		} catch (error) {64			latestError = error;65		}66	}67 68	throw latestError;69};70 71// eslint-disable-next-line complexity72const baseOpen = async options => {73	options = {74		wait: false,75		background: false,76		newInstance: false,77		allowNonzeroExitCode: false,78		...options,79	};80 81	if (Array.isArray(options.app)) {82		return pTryEach(options.app, singleApp => baseOpen({83			...options,84			app: singleApp,85		}));86	}87 88	let {name: app, arguments: appArguments = []} = options.app ?? {};89	appArguments = [...appArguments];90 91	if (Array.isArray(app)) {92		return pTryEach(app, appName => baseOpen({93			...options,94			app: {95				name: appName,96				arguments: appArguments,97			},98		}));99	}100 101	if (app === 'browser' || app === 'browserPrivate') {102		// IDs from default-browser for macOS and windows are the same103		const ids = {104			'com.google.chrome': 'chrome',105			'google-chrome.desktop': 'chrome',106			'com.brave.Browser': 'brave',107			'org.mozilla.firefox': 'firefox',108			'firefox.desktop': 'firefox',109			'com.microsoft.msedge': 'edge',110			'com.microsoft.edge': 'edge',111			'com.microsoft.edgemac': 'edge',112			'microsoft-edge.desktop': 'edge',113		};114 115		// Incognito flags for each browser in `apps`.116		const flags = {117			chrome: '--incognito',118			brave: '--incognito',119			firefox: '--private-window',120			edge: '--inPrivate',121		};122 123		const browser = isWsl ? await getWindowsDefaultBrowserFromWsl() : await defaultBrowser();124		if (browser.id in ids) {125			const browserName = ids[browser.id];126 127			if (app === 'browserPrivate') {128				appArguments.push(flags[browserName]);129			}130 131			return baseOpen({132				...options,133				app: {134					name: apps[browserName],135					arguments: appArguments,136				},137			});138		}139 140		throw new Error(`${browser.name} is not supported as a default browser`);141	}142 143	let command;144	const cliArguments = [];145	const childProcessOptions = {};146 147	if (platform === 'darwin') {148		command = 'open';149 150		if (options.wait) {151			cliArguments.push('--wait-apps');152		}153 154		if (options.background) {155			cliArguments.push('--background');156		}157 158		if (options.newInstance) {159			cliArguments.push('--new');160		}161 162		if (app) {163			cliArguments.push('-a', app);164		}165	} else if (platform === 'win32' || (isWsl && !isInsideContainer() && !app)) {166		command = await powerShellPath();167 168		cliArguments.push(169			'-NoProfile',170			'-NonInteractive',171			'-ExecutionPolicy',172			'Bypass',173			'-EncodedCommand',174		);175 176		if (!isWsl) {177			childProcessOptions.windowsVerbatimArguments = true;178		}179 180		const encodedArguments = ['Start'];181 182		if (options.wait) {183			encodedArguments.push('-Wait');184		}185 186		if (app) {187			// Double quote with double quotes to ensure the inner quotes are passed through.188			// Inner quotes are delimited for PowerShell interpretation with backticks.189			encodedArguments.push(`"\`"${app}\`""`);190			if (options.target) {191				appArguments.push(options.target);192			}193		} else if (options.target) {194			encodedArguments.push(`"${options.target}"`);195		}196 197		if (appArguments.length > 0) {198			appArguments = appArguments.map(argument => `"\`"${argument}\`""`);199			encodedArguments.push('-ArgumentList', appArguments.join(','));200		}201 202		// Using Base64-encoded command, accepted by PowerShell, to allow special characters.203		options.target = Buffer.from(encodedArguments.join(' '), 'utf16le').toString('base64');204	} else {205		if (app) {206			command = app;207		} else {208			// When bundled by Webpack, there's no actual package file path and no local `xdg-open`.209			const isBundled = !__dirname || __dirname === '/';210 211			// Check if local `xdg-open` exists and is executable.212			let exeLocalXdgOpen = false;213			try {214				await fs.access(localXdgOpenPath, fsConstants.X_OK);215				exeLocalXdgOpen = true;216			} catch {}217 218			const useSystemXdgOpen = process.versions.electron219				?? (platform === 'android' || isBundled || !exeLocalXdgOpen);220			command = useSystemXdgOpen ? 'xdg-open' : localXdgOpenPath;221		}222 223		if (appArguments.length > 0) {224			cliArguments.push(...appArguments);225		}226 227		if (!options.wait) {228			// `xdg-open` will block the process unless stdio is ignored229			// and it's detached from the parent even if it's unref'd.230			childProcessOptions.stdio = 'ignore';231			childProcessOptions.detached = true;232		}233	}234 235	if (platform === 'darwin' && appArguments.length > 0) {236		cliArguments.push('--args', ...appArguments);237	}238 239	// This has to come after `--args`.240	if (options.target) {241		cliArguments.push(options.target);242	}243 244	const subprocess = childProcess.spawn(command, cliArguments, childProcessOptions);245 246	if (options.wait) {247		return new Promise((resolve, reject) => {248			subprocess.once('error', reject);249 250			subprocess.once('close', exitCode => {251				if (!options.allowNonzeroExitCode && exitCode > 0) {252					reject(new Error(`Exited with code ${exitCode}`));253					return;254				}255 256				resolve(subprocess);257			});258		});259	}260 261	subprocess.unref();262 263	return subprocess;264};265 266const open = (target, options) => {267	if (typeof target !== 'string') {268		throw new TypeError('Expected a `target`');269	}270 271	return baseOpen({272		...options,273		target,274	});275};276 277export const openApp = (name, options) => {278	if (typeof name !== 'string' && !Array.isArray(name)) {279		throw new TypeError('Expected a valid `name`');280	}281 282	const {arguments: appArguments = []} = options ?? {};283	if (appArguments !== undefined && appArguments !== null && !Array.isArray(appArguments)) {284		throw new TypeError('Expected `appArguments` as Array type');285	}286 287	return baseOpen({288		...options,289		app: {290			name,291			arguments: appArguments,292		},293	});294};295 296function detectArchBinary(binary) {297	if (typeof binary === 'string' || Array.isArray(binary)) {298		return binary;299	}300 301	const {[arch]: archBinary} = binary;302 303	if (!archBinary) {304		throw new Error(`${arch} is not supported`);305	}306 307	return archBinary;308}309 310function detectPlatformBinary({[platform]: platformBinary}, {wsl}) {311	if (wsl && isWsl) {312		return detectArchBinary(wsl);313	}314 315	if (!platformBinary) {316		throw new Error(`${platform} is not supported`);317	}318 319	return detectArchBinary(platformBinary);320}321 322export const apps = {};323 324defineLazyProperty(apps, 'chrome', () => detectPlatformBinary({325	darwin: 'google chrome',326	win32: 'chrome',327	linux: ['google-chrome', 'google-chrome-stable', 'chromium'],328}, {329	wsl: {330		ia32: '/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe',331		x64: ['/mnt/c/Program Files/Google/Chrome/Application/chrome.exe', '/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe'],332	},333}));334 335defineLazyProperty(apps, 'brave', () => detectPlatformBinary({336	darwin: 'brave browser',337	win32: 'brave',338	linux: ['brave-browser', 'brave'],339}, {340	wsl: {341		ia32: '/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe',342		x64: ['/mnt/c/Program Files/BraveSoftware/Brave-Browser/Application/brave.exe', '/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe'],343	},344}));345 346defineLazyProperty(apps, 'firefox', () => detectPlatformBinary({347	darwin: 'firefox',348	win32: String.raw`C:\Program Files\Mozilla Firefox\firefox.exe`,349	linux: 'firefox',350}, {351	wsl: '/mnt/c/Program Files/Mozilla Firefox/firefox.exe',352}));353 354defineLazyProperty(apps, 'edge', () => detectPlatformBinary({355	darwin: 'microsoft edge',356	win32: 'msedge',357	linux: ['microsoft-edge', 'microsoft-edge-dev'],358}, {359	wsl: '/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe',360}));361 362defineLazyProperty(apps, 'browser', () => 'browser');363 364defineLazyProperty(apps, 'browserPrivate', () => 'browserPrivate');365 366export default open;367 
Brunobkr/llama.cpp_AlgMor24_github · Team Ai