@aibrow/node-llama-cpp

中文文档
1.7.0发布于 2025/07/11MITTypeScriptES Module近 30 天下载 1713

Run AI models locally on your machine with node.js bindings for llama.cpp. Enforce a JSON schema on the model output on the generation level

原始使用文档
文档目录7 节
  1. Features
  2. Documentation
  3. Try It Without Installing
  4. Installation
  5. Usage
  6. Contributing
  7. Acknowledgements

@aibrow/node-llama-cpp

This is a fork of node-llama-cpp intended for use with AiBrow.

Please use the official withcatai/node-llama-cpp GitHub repo and node-llama-cpp npm package for your own projects.

node-llama-cpp Logo

node-llama-cpp

Run AI models locally on your machine

Pre-built bindings are provided with a fallback to building from source with cmake

Build License Types Version

✨ DeepSeek R1 is here! ✨

Features

Documentation

Try It Without Installing

Chat with a model in your terminal using a single command:

npx -y node-llama-cpp chat

Installation

npm install node-llama-cpp

This package comes with pre-built binaries for macOS, Linux and Windows.

If binaries are not available for your platform, it'll fallback to download a release of llama.cpp and build it from source with cmake. To disable this behavior, set the environment variable NODE_LLAMA_CPP_SKIP_DOWNLOAD to true.

Usage

import {fileURLToPath} from "url";
import path from "path";
import {getLlama, LlamaChatSession} from "node-llama-cpp";

const __dirname = path.dirname(fileURLToPath(import.meta.url));

const llama = await getLlama();
const model = await llama.loadModel({
    modelPath: path.join(__dirname, "models", "Meta-Llama-3.1-8B-Instruct.Q4_K_M.gguf")
});
const context = await model.createContext();
const session = new LlamaChatSession({
    contextSequence: context.getSequence()
});


const q1 = "Hi there, how are you?";
console.log("User: " + q1);

const a1 = await session.prompt(q1);
console.log("AI: " + a1);


const q2 = "Summarize what you said";
console.log("User: " + q2);

const a2 = await session.prompt(q2);
console.log("AI: " + a2);

For more examples, see the getting started guide

Contributing

To contribute to node-llama-cpp read the contribution guide.

Acknowledgements


Star please

If you like this repo, star it ✨                                                    

版本与发布记录

@aibrow/node-llama-cpp 共发布 12 个版本,首次发布于 2025/05/10;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.7.0latest2025/07/111.3 年前
1.6.02025/06/291.4 年前
1.5.02025/06/111.4 年前
1.4.02025/06/051.4 年前
1.3.32025/05/221.5 年前
1.3.22025/05/221.5 年前

关于 @aibrow/node-llama-cpp 的常见问题

@aibrow/node-llama-cpp 是什么?

Run AI models locally on your machine with node.js bindings for llama.cpp. Enforce a JSON schema on the model output on the generation level

如何安装 @aibrow/node-llama-cpp?

在项目目录运行 npm install @aibrow/node-llama-cpp,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 node-llama-cpp、nlc,可以用 npx node-llama-cpp 直接运行。

@aibrow/node-llama-cpp 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@aibrow/node-llama-cpp 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@aibrow/node-llama-cpp 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@aibrow/node-llama-cpp 可以商用吗?

@aibrow/node-llama-cpp 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@aibrow/node-llama-cpp 的下载量有多少?

根据 npm 官方下载统计,@aibrow/node-llama-cpp 在 2026/10/05 – 2026/11/03 这 30 天内被下载 1,713 次,日均约 57 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@aibrow/node-llama-cpp 还在维护吗?

最新版本 1.7.0 发布于 2025/07/11(1.3 年前);至今共发布 12 个版本,其中过去 12 个月发布了 0 个;首次发布于 2025/05/10。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。