First upload version 0.0.1
This commit is contained in:
4
node_modules/node-llama-cpp/dist/cli/commands/source/SourceCommand.d.ts
generated
vendored
Normal file
4
node_modules/node-llama-cpp/dist/cli/commands/source/SourceCommand.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import { CommandModule } from "yargs";
|
||||
type SourceCommand = {};
|
||||
export declare const SourceCommand: CommandModule<object, SourceCommand>;
|
||||
export {};
|
||||
19
node_modules/node-llama-cpp/dist/cli/commands/source/SourceCommand.js
generated
vendored
Normal file
19
node_modules/node-llama-cpp/dist/cli/commands/source/SourceCommand.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
import { withCliCommandDescriptionDocsUrl } from "../../utils/withCliCommandDescriptionDocsUrl.js";
|
||||
import { documentationPageUrls } from "../../../config.js";
|
||||
import { DownloadCommand } from "./commands/DownloadCommand.js";
|
||||
import { BuildCommand } from "./commands/BuildCommand.js";
|
||||
import { ClearCommand } from "./commands/ClearCommand.js";
|
||||
export const SourceCommand = {
|
||||
command: "source <command>",
|
||||
describe: withCliCommandDescriptionDocsUrl("Manage `llama.cpp` source code", documentationPageUrls.CLI.Source.index),
|
||||
builder(yargs) {
|
||||
return yargs
|
||||
.command(DownloadCommand)
|
||||
.command(BuildCommand)
|
||||
.command(ClearCommand);
|
||||
},
|
||||
async handler() {
|
||||
// this function must exist, even though we do nothing here
|
||||
}
|
||||
};
|
||||
//# sourceMappingURL=SourceCommand.js.map
|
||||
1
node_modules/node-llama-cpp/dist/cli/commands/source/SourceCommand.js.map
generated
vendored
Normal file
1
node_modules/node-llama-cpp/dist/cli/commands/source/SourceCommand.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"SourceCommand.js","sourceRoot":"","sources":["../../../../src/cli/commands/source/SourceCommand.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,gCAAgC,EAAC,MAAM,iDAAiD,CAAC;AACjG,OAAO,EAAC,qBAAqB,EAAC,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAC,eAAe,EAAC,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAC,YAAY,EAAC,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAC,YAAY,EAAC,MAAM,4BAA4B,CAAC;AAMxD,MAAM,CAAC,MAAM,aAAa,GAAyC;IAC/D,OAAO,EAAE,kBAAkB;IAC3B,QAAQ,EAAE,gCAAgC,CACtC,gCAAgC,EAChC,qBAAqB,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CACzC;IACD,OAAO,CAAC,KAAK;QACT,OAAO,KAAK;aACP,OAAO,CAAC,eAAe,CAAC;aACxB,OAAO,CAAC,YAAY,CAAC;aACrB,OAAO,CAAC,YAAY,CAAC,CAAC;IAC/B,CAAC;IACD,KAAK,CAAC,OAAO;QACT,2DAA2D;IAC/D,CAAC;CACJ,CAAC"}
|
||||
16
node_modules/node-llama-cpp/dist/cli/commands/source/commands/BuildCommand.d.ts
generated
vendored
Normal file
16
node_modules/node-llama-cpp/dist/cli/commands/source/commands/BuildCommand.d.ts
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
import process from "process";
|
||||
import { CommandModule } from "yargs";
|
||||
import { BuildGpu } from "../../../../bindings/types.js";
|
||||
type BuildCommand = {
|
||||
arch?: typeof process.arch;
|
||||
nodeTarget?: string;
|
||||
gpu?: BuildGpu | "auto";
|
||||
noUsageExample?: boolean;
|
||||
};
|
||||
export declare const BuildCommand: CommandModule<object, BuildCommand>;
|
||||
export declare function BuildLlamaCppCommand({ arch, nodeTarget, gpu, noUsageExample,
|
||||
/** @internal */
|
||||
noCustomCmakeBuildOptionsInBinaryFolderName,
|
||||
/** @internal */
|
||||
ciMode }: BuildCommand): Promise<void>;
|
||||
export {};
|
||||
148
node_modules/node-llama-cpp/dist/cli/commands/source/commands/BuildCommand.js
generated
vendored
Normal file
148
node_modules/node-llama-cpp/dist/cli/commands/source/commands/BuildCommand.js
generated
vendored
Normal file
@@ -0,0 +1,148 @@
|
||||
import process from "process";
|
||||
import chalk from "chalk";
|
||||
import { compileLlamaCpp } from "../../../../bindings/utils/compileLLamaCpp.js";
|
||||
import withOra from "../../../../utils/withOra.js";
|
||||
import { clearTempFolder } from "../../../../utils/clearTempFolder.js";
|
||||
import { builtinLlamaCppGitHubRepo, builtinLlamaCppRelease, isCI, defaultLlamaCppGpuSupport, documentationPageUrls } from "../../../../config.js";
|
||||
import { downloadCmakeIfNeeded } from "../../../../utils/cmake.js";
|
||||
import withStatusLogs from "../../../../utils/withStatusLogs.js";
|
||||
import { logBinaryUsageExampleToConsole } from "../../../../bindings/utils/logBinaryUsageExampleToConsole.js";
|
||||
import { getPlatform } from "../../../../bindings/utils/getPlatform.js";
|
||||
import { resolveCustomCmakeOptions } from "../../../../bindings/utils/resolveCustomCmakeOptions.js";
|
||||
import { getClonedLlamaCppRepoReleaseInfo, isLlamaCppRepoCloned } from "../../../../bindings/utils/cloneLlamaCppRepo.js";
|
||||
import { nodeLlamaCppGpuOptions, parseNodeLlamaCppGpuOption } from "../../../../bindings/types.js";
|
||||
import { logUsedGpuTypeOption } from "../../../utils/logUsedGpuTypeOption.js";
|
||||
import { getGpuTypesToUseForOption } from "../../../../bindings/utils/getGpuTypesToUseForOption.js";
|
||||
import { getConsoleLogPrefix } from "../../../../utils/getConsoleLogPrefix.js";
|
||||
import { getPrettyBuildGpuName } from "../../../../bindings/consts.js";
|
||||
import { getPlatformInfo } from "../../../../bindings/utils/getPlatformInfo.js";
|
||||
import { withCliCommandDescriptionDocsUrl } from "../../../utils/withCliCommandDescriptionDocsUrl.js";
|
||||
export const BuildCommand = {
|
||||
command: "build",
|
||||
aliases: ["compile"],
|
||||
describe: withCliCommandDescriptionDocsUrl("Compile the currently downloaded `llama.cpp` source code", documentationPageUrls.CLI.Source.Build),
|
||||
builder(yargs) {
|
||||
return yargs
|
||||
.option("arch", {
|
||||
alias: "a",
|
||||
type: "string",
|
||||
coerce: (value) => value,
|
||||
description: "The architecture to compile llama.cpp for"
|
||||
})
|
||||
.option("nodeTarget", {
|
||||
alias: "t",
|
||||
type: "string",
|
||||
description: "The Node.js version to compile llama.cpp for. Example: `v18.0.0`"
|
||||
})
|
||||
.option("gpu", {
|
||||
type: "string",
|
||||
default: defaultLlamaCppGpuSupport,
|
||||
// yargs types don't support passing `false` as a choice, although it is supported by yargs
|
||||
choices: nodeLlamaCppGpuOptions,
|
||||
coerce: parseNodeLlamaCppGpuOption,
|
||||
description: "Compute layer implementation type to use for llama.cpp"
|
||||
})
|
||||
.option("noUsageExample", {
|
||||
alias: "nu",
|
||||
type: "boolean",
|
||||
default: false,
|
||||
description: "Don't print code usage example after building"
|
||||
})
|
||||
.option("noCustomCmakeBuildOptionsInBinaryFolderName", {
|
||||
type: "boolean",
|
||||
hidden: true, // this is only for the CI to use
|
||||
default: false,
|
||||
description: "Don't include custom CMake build options in build folder name"
|
||||
})
|
||||
.option("ciMode", {
|
||||
type: "boolean",
|
||||
hidden: true, // this is only for the CI to use
|
||||
default: false,
|
||||
description: "Enable CI only build options"
|
||||
});
|
||||
},
|
||||
handler: BuildLlamaCppCommand
|
||||
};
|
||||
export async function BuildLlamaCppCommand({ arch = undefined, nodeTarget = undefined, gpu = defaultLlamaCppGpuSupport, noUsageExample = false,
|
||||
/** @internal */
|
||||
noCustomCmakeBuildOptionsInBinaryFolderName = false,
|
||||
/** @internal */
|
||||
ciMode = false }) {
|
||||
if (!(await isLlamaCppRepoCloned())) {
|
||||
console.log(chalk.red('llama.cpp is not downloaded. Please run "node-llama-cpp source download" first'));
|
||||
process.exit(1);
|
||||
}
|
||||
const includeBuildOptionsInBinaryFolderName = !noCustomCmakeBuildOptionsInBinaryFolderName || !isCI;
|
||||
const clonedLlamaCppRepoReleaseInfo = await getClonedLlamaCppRepoReleaseInfo();
|
||||
const platform = getPlatform();
|
||||
const platformInfo = await getPlatformInfo();
|
||||
const customCmakeOptions = resolveCustomCmakeOptions();
|
||||
const buildGpusToTry = await getGpuTypesToUseForOption(gpu, { platform, arch });
|
||||
let downloadedCmake = false;
|
||||
for (let i = 0; i < buildGpusToTry.length; i++) {
|
||||
const gpuToTry = buildGpusToTry[i];
|
||||
const isLastItem = i === buildGpusToTry.length - 1;
|
||||
if (gpuToTry == null)
|
||||
continue;
|
||||
logUsedGpuTypeOption(gpuToTry);
|
||||
if (!downloadedCmake) {
|
||||
await downloadCmakeIfNeeded(true);
|
||||
downloadedCmake = true;
|
||||
}
|
||||
const buildOptions = {
|
||||
customCmakeOptions,
|
||||
progressLogs: true,
|
||||
platform,
|
||||
platformInfo,
|
||||
arch: arch
|
||||
? arch
|
||||
: process.arch,
|
||||
gpu: gpuToTry,
|
||||
llamaCpp: {
|
||||
repo: clonedLlamaCppRepoReleaseInfo?.llamaCppGithubRepo ?? builtinLlamaCppGitHubRepo,
|
||||
release: clonedLlamaCppRepoReleaseInfo?.tag ?? builtinLlamaCppRelease
|
||||
}
|
||||
};
|
||||
try {
|
||||
await withStatusLogs({
|
||||
loading: chalk.blue("Compiling llama.cpp"),
|
||||
success: chalk.blue("Compiled llama.cpp"),
|
||||
fail: chalk.blue("Failed to compile llama.cpp")
|
||||
}, async () => {
|
||||
await compileLlamaCpp(buildOptions, {
|
||||
nodeTarget: nodeTarget ? nodeTarget : undefined,
|
||||
updateLastBuildInfo: true,
|
||||
downloadCmakeIfNeeded: false,
|
||||
ensureLlamaCppRepoIsCloned: false,
|
||||
includeBuildOptionsInBinaryFolderName,
|
||||
ciMode: isCI && ciMode
|
||||
});
|
||||
});
|
||||
}
|
||||
catch (err) {
|
||||
console.error(getConsoleLogPrefix() +
|
||||
`Failed to build llama.cpp with ${getPrettyBuildGpuName(gpuToTry)} support. ` +
|
||||
(!isLastItem
|
||||
? `falling back to building llama.cpp with ${getPrettyBuildGpuName(buildGpusToTry[i + 1])} support. `
|
||||
: "") +
|
||||
"Error:", err);
|
||||
if (isLastItem)
|
||||
throw err;
|
||||
continue;
|
||||
}
|
||||
await withOra({
|
||||
loading: chalk.blue("Removing temporary files"),
|
||||
success: chalk.blue("Removed temporary files"),
|
||||
fail: chalk.blue("Failed to remove temporary files")
|
||||
}, async () => {
|
||||
await clearTempFolder();
|
||||
});
|
||||
if (!noUsageExample) {
|
||||
console.log();
|
||||
logBinaryUsageExampleToConsole(buildOptions, gpu !== "auto", true);
|
||||
console.log();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=BuildCommand.js.map
|
||||
1
node_modules/node-llama-cpp/dist/cli/commands/source/commands/BuildCommand.js.map
generated
vendored
Normal file
1
node_modules/node-llama-cpp/dist/cli/commands/source/commands/BuildCommand.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"BuildCommand.js","sourceRoot":"","sources":["../../../../../src/cli/commands/source/commands/BuildCommand.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,eAAe,EAAC,MAAM,+CAA+C,CAAC;AAC9E,OAAO,OAAO,MAAM,8BAA8B,CAAC;AACnD,OAAO,EAAC,eAAe,EAAC,MAAM,sCAAsC,CAAC;AACrE,OAAO,EAAC,yBAAyB,EAAE,sBAAsB,EAAE,IAAI,EAAE,yBAAyB,EAAE,qBAAqB,EAAC,MAAM,uBAAuB,CAAC;AAChJ,OAAO,EAAC,qBAAqB,EAAC,MAAM,4BAA4B,CAAC;AACjE,OAAO,cAAc,MAAM,qCAAqC,CAAC;AACjE,OAAO,EAAC,8BAA8B,EAAC,MAAM,8DAA8D,CAAC;AAC5G,OAAO,EAAC,WAAW,EAAC,MAAM,2CAA2C,CAAC;AACtE,OAAO,EAAC,yBAAyB,EAAC,MAAM,yDAAyD,CAAC;AAClG,OAAO,EAAC,gCAAgC,EAAE,oBAAoB,EAAC,MAAM,iDAAiD,CAAC;AACvH,OAAO,EAAyB,sBAAsB,EAAE,0BAA0B,EAAC,MAAM,+BAA+B,CAAC;AACzH,OAAO,EAAC,oBAAoB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AC;YACX,OAAO,CAAC,KAAK,CACT,mBAAmB,EAAE;gBACrB,kCAAkC,qBAAqB,CAAC,QAAQ,CAAC,YAAY;gBAC7E,CACI,CAAC,UAAU;oBACP,CAAC,CAAC,2CAA2C,qBAAqB,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,YAAY;oBACrG,CAAC,CAAC,EAAE,CACX;gBACD,QAAQ,EACR,GAAG,CACN,CAAC;YAEF,IAAI,UAAU;gBACV,MAAM,GAAG,CAAC;YAEd,SAAS;QACb,CAAC;QAED,MAAM,OAAO,CAAC;YACV,OAAO,EAAE,KAAK,CAAC,IAAI,CAAC,0BAA0B,CAAC;YAC/C,OAAO,EAAE,KAAK,CAAC,IAAI,CAAC,yBAAyB,CAAC;YAC9C,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,kCAAkC,CAAC;SACvD,EAAE,KAAK,IAAI,EAAE;YACV,MAAM,eAAe,EAAE,CAAC;QAC5B,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,cAAc,EAAE,CAAC;YAClB,OAAO,CAAC,GAAG,EAAE,CAAC;YACd,8BAA8B,CAAC,YAAY,EAAE,GAAG,KAAK,MAAM,EAAE,IAAI,CAAC,CAAC;YACnE,OAAO,CAAC,GAAG,EAAE,CAAC;QAClB,CAAC;QAED,MAAM;IACV,CAAC;AACL,CAAC"}
|
||||
7
node_modules/node-llama-cpp/dist/cli/commands/source/commands/ClearCommand.d.ts
generated
vendored
Normal file
7
node_modules/node-llama-cpp/dist/cli/commands/source/commands/ClearCommand.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import { CommandModule } from "yargs";
|
||||
type ClearCommand = {
|
||||
type: "source" | "builds" | "cmake" | "all";
|
||||
};
|
||||
export declare const ClearCommand: CommandModule<object, ClearCommand>;
|
||||
export declare function ClearLlamaCppBuildCommand({ type }: ClearCommand): Promise<void>;
|
||||
export {};
|
||||
54
node_modules/node-llama-cpp/dist/cli/commands/source/commands/ClearCommand.js
generated
vendored
Normal file
54
node_modules/node-llama-cpp/dist/cli/commands/source/commands/ClearCommand.js
generated
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
import fs from "fs-extra";
|
||||
import chalk from "chalk";
|
||||
import { documentationPageUrls, llamaCppDirectory, llamaCppDirectoryInfoFilePath } from "../../../../config.js";
|
||||
import withOra from "../../../../utils/withOra.js";
|
||||
import { clearAllLocalBuilds } from "../../../../bindings/utils/clearAllLocalBuilds.js";
|
||||
import { clearLocalCmake, fixXpackPermissions } from "../../../../utils/cmake.js";
|
||||
import { withCliCommandDescriptionDocsUrl } from "../../../utils/withCliCommandDescriptionDocsUrl.js";
|
||||
export const ClearCommand = {
|
||||
command: "clear [type]",
|
||||
aliases: ["clean"],
|
||||
describe: withCliCommandDescriptionDocsUrl("Clear files created by `node-llama-cpp`", documentationPageUrls.CLI.Source.Clear),
|
||||
builder(yargs) {
|
||||
return yargs
|
||||
.option("type", {
|
||||
type: "string",
|
||||
choices: ["source", "builds", "cmake", "all"],
|
||||
default: "all",
|
||||
description: "Files to clear"
|
||||
});
|
||||
},
|
||||
handler: ClearLlamaCppBuildCommand
|
||||
};
|
||||
export async function ClearLlamaCppBuildCommand({ type }) {
|
||||
if (type === "source" || type === "all") {
|
||||
await withOra({
|
||||
loading: chalk.blue("Clearing source"),
|
||||
success: chalk.blue("Cleared source"),
|
||||
fail: chalk.blue("Failed to clear source")
|
||||
}, async () => {
|
||||
await fs.remove(llamaCppDirectory);
|
||||
await fs.remove(llamaCppDirectoryInfoFilePath);
|
||||
});
|
||||
}
|
||||
if (type === "builds" || type === "all") {
|
||||
await withOra({
|
||||
loading: chalk.blue("Clearing all builds"),
|
||||
success: chalk.blue("Cleared all builds"),
|
||||
fail: chalk.blue("Failed to clear all builds")
|
||||
}, async () => {
|
||||
await clearAllLocalBuilds();
|
||||
});
|
||||
}
|
||||
if (type === "cmake" || type === "all") {
|
||||
await withOra({
|
||||
loading: chalk.blue("Clearing internal cmake"),
|
||||
success: chalk.blue("Cleared internal cmake"),
|
||||
fail: chalk.blue("Failed to clear internal cmake")
|
||||
}, async () => {
|
||||
await fixXpackPermissions();
|
||||
await clearLocalCmake();
|
||||
});
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=ClearCommand.js.map
|
||||
1
node_modules/node-llama-cpp/dist/cli/commands/source/commands/ClearCommand.js.map
generated
vendored
Normal file
1
node_modules/node-llama-cpp/dist/cli/commands/source/commands/ClearCommand.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"ClearCommand.js","sourceRoot":"","sources":["../../../../../src/cli/commands/source/commands/ClearCommand.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,qBAAqB,EAAE,iBAAiB,EAAE,6BAA6B,EAAC,MAAM,uBAAuB,CAAC;AAC9G,OAAO,OAAO,MAAM,8BAA8B,CAAC;AACnD,OAAO,EAAC,mBAAmB,EAAC,MAAM,mDAAmD,CAAC;AACtF,OAAO,EAAC,eAAe,EAAE,mBAAmB,EAAC,MAAM,4BAA4B,CAAC;AAChF,OAAO,EAAC,gCAAgC,EAAC,MAAM,oDAAoD,CAAC;AAMpG,MAAM,CAAC,MAAM,YAAY,GAAwC;IAC7D,OAAO,EAAE,cAAc;IACvB,OAAO,EAAE,CAAC,OAAO,CAAC;IAClB,QAAQ,EAAE,gCAAgC,CACtC,yCAAyC,EACzC,qBAAqB,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CACzC;IACD,OAAO,CAAC,KAAK;QACT,OAAO,KAAK;aACP,MAAM,CAAC,MAAM,EAAE;YACZ,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,CAAkC;YAC9E,OAAO,EAAE,KAA6B;YACtC,WAAW,EAAE,gBAAgB;SAChC,CAAC,CAAC;IACX,CAAC;IACD,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AE,CAAC;QAC5B,CAAC,CAAC,CAAC;IACP,CAAC;AACL,CAAC"}
|
||||
16
node_modules/node-llama-cpp/dist/cli/commands/source/commands/DownloadCommand.d.ts
generated
vendored
Normal file
16
node_modules/node-llama-cpp/dist/cli/commands/source/commands/DownloadCommand.d.ts
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
import process from "process";
|
||||
import { CommandModule } from "yargs";
|
||||
import { BuildGpu } from "../../../../bindings/types.js";
|
||||
type DownloadCommandArgs = {
|
||||
repo?: string;
|
||||
release?: "latest" | string;
|
||||
arch?: typeof process.arch;
|
||||
nodeTarget?: string;
|
||||
gpu?: BuildGpu | "auto";
|
||||
skipBuild?: boolean;
|
||||
noBundle?: boolean;
|
||||
noUsageExample?: boolean;
|
||||
};
|
||||
export declare const DownloadCommand: CommandModule<object, DownloadCommandArgs>;
|
||||
export declare function DownloadLlamaCppCommand(args: DownloadCommandArgs): Promise<void>;
|
||||
export {};
|
||||
219
node_modules/node-llama-cpp/dist/cli/commands/source/commands/DownloadCommand.js
generated
vendored
Normal file
219
node_modules/node-llama-cpp/dist/cli/commands/source/commands/DownloadCommand.js
generated
vendored
Normal file
@@ -0,0 +1,219 @@
|
||||
import process from "process";
|
||||
import fs from "fs-extra";
|
||||
import chalk from "chalk";
|
||||
import { defaultLlamaCppGitHubRepo, defaultLlamaCppRelease, isCI, llamaCppDirectory, llamaCppDirectoryInfoFilePath, defaultLlamaCppGpuSupport, documentationPageUrls } from "../../../../config.js";
|
||||
import { compileLlamaCpp } from "../../../../bindings/utils/compileLLamaCpp.js";
|
||||
import withOra from "../../../../utils/withOra.js";
|
||||
import { clearTempFolder } from "../../../../utils/clearTempFolder.js";
|
||||
import { setBinariesGithubRelease } from "../../../../bindings/utils/binariesGithubRelease.js";
|
||||
import { downloadCmakeIfNeeded } from "../../../../utils/cmake.js";
|
||||
import withStatusLogs from "../../../../utils/withStatusLogs.js";
|
||||
import { getIsInDocumentationMode } from "../../../../state.js";
|
||||
import { getGitBundlePathForRelease, unshallowAndSquashCurrentRepoAndSaveItAsReleaseBundle } from "../../../../utils/gitReleaseBundles.js";
|
||||
import { cloneLlamaCppRepo } from "../../../../bindings/utils/cloneLlamaCppRepo.js";
|
||||
import { getPlatform } from "../../../../bindings/utils/getPlatform.js";
|
||||
import { resolveCustomCmakeOptions } from "../../../../bindings/utils/resolveCustomCmakeOptions.js";
|
||||
import { logBinaryUsageExampleToConsole } from "../../../../bindings/utils/logBinaryUsageExampleToConsole.js";
|
||||
import { resolveGithubRelease } from "../../../../utils/resolveGithubRelease.js";
|
||||
import { nodeLlamaCppGpuOptions, parseNodeLlamaCppGpuOption } from "../../../../bindings/types.js";
|
||||
import { logUsedGpuTypeOption } from "../../../utils/logUsedGpuTypeOption.js";
|
||||
import { getGpuTypesToUseForOption } from "../../../../bindings/utils/getGpuTypesToUseForOption.js";
|
||||
import { getConsoleLogPrefix } from "../../../../utils/getConsoleLogPrefix.js";
|
||||
import { getPrettyBuildGpuName } from "../../../../bindings/consts.js";
|
||||
import { getPlatformInfo } from "../../../../bindings/utils/getPlatformInfo.js";
|
||||
import { withCliCommandDescriptionDocsUrl } from "../../../utils/withCliCommandDescriptionDocsUrl.js";
|
||||
export const DownloadCommand = {
|
||||
command: "download",
|
||||
describe: withCliCommandDescriptionDocsUrl("Download a release of `llama.cpp` and compile it", documentationPageUrls.CLI.Source.Download),
|
||||
builder(yargs) {
|
||||
const isInDocumentationMode = getIsInDocumentationMode();
|
||||
return yargs
|
||||
.option("repo", {
|
||||
type: "string",
|
||||
default: defaultLlamaCppGitHubRepo,
|
||||
description: "The GitHub repository to download a release of llama.cpp from. Can also be set via the `NODE_LLAMA_CPP_REPO` environment variable"
|
||||
})
|
||||
.option("release", {
|
||||
type: "string",
|
||||
default: isInDocumentationMode ? "<current build>" : defaultLlamaCppRelease,
|
||||
description: "The tag of the llama.cpp release to download. Set to `latest` to download the latest release. Can also be set via the `NODE_LLAMA_CPP_REPO_RELEASE` environment variable"
|
||||
})
|
||||
.option("arch", {
|
||||
alias: "a",
|
||||
type: "string",
|
||||
coerce: (value) => value,
|
||||
description: "The architecture to compile llama.cpp for"
|
||||
})
|
||||
.option("nodeTarget", {
|
||||
alias: "t",
|
||||
type: "string",
|
||||
description: "The Node.js version to compile llama.cpp for. Example: `v18.0.0`"
|
||||
})
|
||||
.option("gpu", {
|
||||
type: "string",
|
||||
default: defaultLlamaCppGpuSupport,
|
||||
// yargs types don't support passing `false` as a choice, although it is supported by yargs
|
||||
choices: nodeLlamaCppGpuOptions,
|
||||
coerce: parseNodeLlamaCppGpuOption,
|
||||
description: "Compute layer implementation type to use for llama.cpp"
|
||||
})
|
||||
.option("skipBuild", {
|
||||
alias: "sb",
|
||||
type: "boolean",
|
||||
default: false,
|
||||
description: "Skip building llama.cpp after downloading it"
|
||||
})
|
||||
.option("noBundle", {
|
||||
alias: "nb",
|
||||
type: "boolean",
|
||||
default: false,
|
||||
description: "Download a llama.cpp release only from GitHub, even if a local git bundle exists for the release"
|
||||
})
|
||||
.option("noUsageExample", {
|
||||
alias: "nu",
|
||||
type: "boolean",
|
||||
default: false,
|
||||
description: "Don't print code usage example after building"
|
||||
})
|
||||
.option("updateBinariesReleaseMetadataAndSaveGitBundle", {
|
||||
type: "boolean",
|
||||
hidden: true, // this is only for the CI to use
|
||||
default: false,
|
||||
description: "Update the binariesGithubRelease.json file with the release of llama.cpp that was downloaded"
|
||||
});
|
||||
},
|
||||
handler: DownloadLlamaCppCommand
|
||||
};
|
||||
export async function DownloadLlamaCppCommand(args) {
|
||||
const { repo = defaultLlamaCppGitHubRepo, release = defaultLlamaCppRelease, arch = undefined, nodeTarget = undefined, gpu = defaultLlamaCppGpuSupport, skipBuild = false, noBundle = false, noUsageExample = false, updateBinariesReleaseMetadataAndSaveGitBundle = false } = args;
|
||||
const useBundle = noBundle != true;
|
||||
const platform = getPlatform();
|
||||
const platformInfo = await getPlatformInfo();
|
||||
const customCmakeOptions = resolveCustomCmakeOptions();
|
||||
const buildGpusToTry = skipBuild
|
||||
? []
|
||||
: await getGpuTypesToUseForOption(gpu, { platform, arch });
|
||||
const [githubOwner, githubRepo] = repo.split("/");
|
||||
if (githubOwner == null || githubRepo == null)
|
||||
throw new Error(`Invalid GitHub repository: ${repo}`);
|
||||
let downloadedCmake = false;
|
||||
console.log(`${chalk.yellow("Repo:")} ${repo}`);
|
||||
console.log(`${chalk.yellow("Release:")} ${release}`);
|
||||
if (!skipBuild) {
|
||||
logUsedGpuTypeOption(buildGpusToTry[0]);
|
||||
}
|
||||
console.log();
|
||||
let githubReleaseTag = (useBundle && (await getGitBundlePathForRelease(githubOwner, githubRepo, release)) != null)
|
||||
? release
|
||||
: null;
|
||||
if (githubReleaseTag == null)
|
||||
await withOra({
|
||||
loading: chalk.blue("Fetching llama.cpp info"),
|
||||
success: chalk.blue("Fetched llama.cpp info"),
|
||||
fail: chalk.blue("Failed to fetch llama.cpp info")
|
||||
}, async () => {
|
||||
githubReleaseTag = await resolveGithubRelease(githubOwner, githubRepo, release);
|
||||
});
|
||||
await clearTempFolder();
|
||||
await withOra({
|
||||
loading: chalk.blue("Removing existing llama.cpp directory"),
|
||||
success: chalk.blue("Removed existing llama.cpp directory"),
|
||||
fail: chalk.blue("Failed to remove existing llama.cpp directory")
|
||||
}, async () => {
|
||||
await fs.remove(llamaCppDirectory);
|
||||
await fs.remove(llamaCppDirectoryInfoFilePath);
|
||||
});
|
||||
await cloneLlamaCppRepo(githubOwner, githubRepo, githubReleaseTag, useBundle);
|
||||
if (!skipBuild) {
|
||||
for (let i = 0; i < buildGpusToTry.length; i++) {
|
||||
const gpuToTry = buildGpusToTry[i];
|
||||
const isLastItem = i === buildGpusToTry.length - 1;
|
||||
if (gpuToTry == null)
|
||||
continue;
|
||||
if (i > 0) // we already logged the first gpu before
|
||||
logUsedGpuTypeOption(gpuToTry);
|
||||
if (!downloadedCmake) {
|
||||
await downloadCmakeIfNeeded(true);
|
||||
downloadedCmake = true;
|
||||
}
|
||||
const buildOptions = {
|
||||
customCmakeOptions,
|
||||
progressLogs: true,
|
||||
platform,
|
||||
platformInfo,
|
||||
arch: arch
|
||||
? arch
|
||||
: process.arch,
|
||||
gpu: gpuToTry,
|
||||
llamaCpp: {
|
||||
repo,
|
||||
release: githubReleaseTag
|
||||
}
|
||||
};
|
||||
try {
|
||||
await withStatusLogs({
|
||||
loading: chalk.blue("Compiling llama.cpp"),
|
||||
success: chalk.blue("Compiled llama.cpp"),
|
||||
fail: chalk.blue("Failed to compile llama.cpp")
|
||||
}, async () => {
|
||||
await compileLlamaCpp(buildOptions, {
|
||||
nodeTarget: nodeTarget ? nodeTarget : undefined,
|
||||
updateLastBuildInfo: true,
|
||||
downloadCmakeIfNeeded: false,
|
||||
ensureLlamaCppRepoIsCloned: false,
|
||||
includeBuildOptionsInBinaryFolderName: true
|
||||
});
|
||||
});
|
||||
}
|
||||
catch (err) {
|
||||
console.error(getConsoleLogPrefix() +
|
||||
`Failed to build llama.cpp with ${getPrettyBuildGpuName(gpuToTry)} support. ` +
|
||||
(!isLastItem
|
||||
? `falling back to building llama.cpp with ${getPrettyBuildGpuName(buildGpusToTry[i + 1])} support. `
|
||||
: "") +
|
||||
"Error:", err);
|
||||
if (isLastItem)
|
||||
throw err;
|
||||
continue;
|
||||
}
|
||||
if (!noUsageExample) {
|
||||
console.log();
|
||||
console.log();
|
||||
logBinaryUsageExampleToConsole(buildOptions, gpu !== "auto", true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (!noUsageExample) {
|
||||
const buildOptions = {
|
||||
customCmakeOptions,
|
||||
progressLogs: true,
|
||||
platform,
|
||||
platformInfo,
|
||||
arch: arch
|
||||
? arch
|
||||
: process.arch,
|
||||
gpu: buildGpusToTry[0],
|
||||
llamaCpp: {
|
||||
repo,
|
||||
release: githubReleaseTag
|
||||
}
|
||||
};
|
||||
console.log();
|
||||
console.log();
|
||||
logBinaryUsageExampleToConsole(buildOptions, gpu !== "auto", true);
|
||||
}
|
||||
if (isCI && updateBinariesReleaseMetadataAndSaveGitBundle) {
|
||||
await setBinariesGithubRelease(githubReleaseTag);
|
||||
await unshallowAndSquashCurrentRepoAndSaveItAsReleaseBundle();
|
||||
}
|
||||
console.log();
|
||||
console.log();
|
||||
console.log(`${chalk.yellow("Repo:")} ${repo}`);
|
||||
console.log(chalk.yellow("Release:") + " " + release + (release === "latest"
|
||||
? (" " + chalk.gray("(" + githubReleaseTag + ")"))
|
||||
: ""));
|
||||
console.log();
|
||||
console.log(chalk.green("Done"));
|
||||
}
|
||||
//# sourceMappingURL=DownloadCommand.js.map
|
||||
1
node_modules/node-llama-cpp/dist/cli/commands/source/commands/DownloadCommand.js.map
generated
vendored
Normal file
1
node_modules/node-llama-cpp/dist/cli/commands/source/commands/DownloadCommand.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user