# @aibrow/node-llama-cpp 中文文档

规范地址：https://npmcn.com/package/%40aibrow/node-llama-cpp/

版本：1\.7\.0
npm 元数据更新时间：2025-07-11T12:31:03.884Z
中文译文更新时间：2026-11-09T21:48:39.004Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40aibrow/node-llama-cpp
原文对照：https://npmcn.com/package/%40aibrow/node-llama-cpp/?lang=original
项目主页：https://node-llama-cpp.withcat.ai/
源码仓库：https://github.com/axonzeta/node-llama-cpp

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：27.2 MB，858 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- Node.js 要求：\>=20\.0\.0
- 运行依赖：30 个
- peer 依赖：typescript \>=5\.0\.0
- 首次发布：2025-05-09T17:43:48.158Z
- 最新版本发布：2025-07-11T12:31:03.657Z
- 近 30 天下载量：1713（2026-10-05 至 2026-11-03，npm 官方下载统计）
- 已发布版本数：12（近 12 个月 0 个）

## 中文简介

在您的机器上运行本地的 AI 模型,并带有 lama.cpp 的节点.js 绑定. 在生成层的模型输出上执行 JSON 计划

## 安装

```sh
npm install @aibrow/node-llama-cpp
```

也可以使用：`pnpm add @aibrow/node-llama-cpp`、`yarn add @aibrow/node-llama-cpp`、`bun add @aibrow/node-llama-cpp`

## README

# @aibrow/node-lama-cpp (英语)

这是叉子 [节点-lama-cpp](https://github.com/withcatai/node-llama-cpp) 拟与 [爱浏览](https://aibrow.ai/)。 。 。 .

请用官来 [与catai/node-lama-cpp相通](https://github.com/withcatai/node-llama-cpp) GitHub 重现和 [节点-lama-cpp](https://www.npmjs.com/package/node-llama-cpp) 用于您自己的项目的 npm 软件包 .

[![node-llama-cpp Logo](https://raw.githubusercontent.com/withcatai/node-llama-cpp/master/assets/logo.v3.roundEdges.avif)](https://node-llama-cpp.withcat.ai/)

# 节点-lama-cpp

在您的机器上运行 AI 模型

预建的装订品从原地向建筑物提供回落式装订品

[![Build](https://github.com/withcatai/node-llama-cpp/actions/workflows/build.yml/badge.svg)](https://github.com/withcatai/node-llama-cpp/actions/workflows/build.yml) [![License](https://badgen.net/badge/color/MIT/green?label=license)](https://www.npmjs.com/package/node-llama-cpp) [![Types](https://badgen.net/badge/color/TypeScript/blue?label=types)](https://www.npmjs.com/package/node-llama-cpp) [![Version](https://badgen.net/npm/v/node-llama-cpp)](https://www.npmjs.com/package/node-llama-cpp)

✨ [Depseek R1来了!](https://node-llama-cpp.withcat.ai/blog/v3.6-deepseek-r1) ✨

## 特征

-   在您的机器上本地运行 LLMS
-   [金属、CUDA和Vulkan支持](https://node-llama-cpp.withcat.ai/guide/#gpu-support)
-   [提供预建二进制](https://node-llama-cpp.withcat.ai/guide/building-from-source),从源头返回到建筑 _**无**_ `node-gyp` 或 Python 键
-   [自动适应您的硬件](https://node-llama-cpp.withcat.ai/guide/#gpu-support),不需要配置任何东西
-   在您的项目中使用 LLMS 所需的全部软件包
-   [使用 CLI 与模型聊天而不写入任何代码](https://npmcn.com/package/%40aibrow/node-llama-cpp/#readme-try-it-without-installing)
-   最新数据 `llama.cpp`。下载和汇编最新版本,其中包含 [单 CLI 命令](https://node-llama-cpp.withcat.ai//guide/building-from-source#downloading-a-release)
-   执行一个模型以解析格式生成输出, [像JSON一样](https://node-llama-cpp.withcat.ai/guide/chat-session#json-response),甚至强迫它 [遵循特定的 JSON 方案](https://node-llama-cpp.withcat.ai/guide/chat-session#response-json-schema)
-   [提供模式,使其具有可按要求调用的职能](https://node-llama-cpp.withcat.ai/guide/chat-session#function-calling) 以获取信息或执行动作
-   [嵌入和重新排序支持](https://node-llama-cpp.withcat.ai/guide/embedding)
-   [安全免受特制注射攻击](https://node-llama-cpp.withcat.ai/guide/llama-text#input-safety-in-node-llama-cpp)
-   开发者在全面TypeScript支持方面的更大经验,以及 [完整文档](https://node-llama-cpp.withcat.ai/guide/)
-   远远不止

## [文档](https://node-llama-cpp.withcat.ai/)

-   [正在获取指南](https://node-llama-cpp.withcat.ai/guide/)
-   [API 参考](https://node-llama-cpp.withcat.ai/api/functions/getLlama)
-   [CLI 帮助](https://node-llama-cpp.withcat.ai/cli/)
-   [博客](https://node-llama-cpp.withcat.ai/blog/)
-   [更改日志](https://github.com/withcatai/node-llama-cpp/releases)
-   [路线图](https://github.com/orgs/withcatai/projects/1)

## 在不安装的情况下尝试

在终端上使用一个模型聊天 [单一命令](https://node-llama-cpp.withcat.ai/cli/chat)数字 :

```bash
npx -y node-llama-cpp chat
```

## 安装

```bash
npm install node-llama-cpp
```

[此软件包带有预建的二进制](https://node-llama-cpp.withcat.ai/guide/building-from-source) 用于macOS,Linux和Windows.

如果无法为您的平台提供二进制, 下载发布会回落 `llama.cpp` 从源头构建它 `cmake`。 。 。 . 要禁用此行为, 请设置环境变量 `NODE_LLAMA_CPP_SKIP_DOWNLOAD` 改为 `true`。 。 。 .

## 使用量

```typescript
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);
```

> 更多例子,见 [正在获取指南](https://node-llama-cpp.withcat.ai/guide/)

## 捐款

协助: `node-llama-cpp` 读取 [捐款指南](https://node-llama-cpp.withcat.ai/guide/contributing)。 。 。 .

## 鸣谢

-   拉玛.cpp: [(原始内容存档于2017-09-26). ggml-org/lama.cpp](https://github.com/ggml-org/llama.cpp)

  

![Star please](https://raw.githubusercontent.com/withcatai/node-llama-cpp/master/assets/star.please.roundEdges.png)  

_如果你喜欢这回波,就拍它_

## 常见问题

### @aibrow/node-llama-cpp 是什么？

在您的机器上运行本地的 AI 模型,并带有 lama\.cpp 的节点\.js 绑定\. 在生成层的模型输出上执行 JSON 计划

### 如何安装 @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 和提交记录判断。

