withcatai/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

What it solves

It provides a way to run Large Language Models (LLMs) locally on a machine using Node.js, removing the need for complex setup or external API dependencies. It simplifies the process of integrating local AI models into JavaScript/TypeScript projects by providing pre-built binaries and automatic hardware adaptation.

How it works

The project acts as a set of bindings for llama.cpp, allowing Node.js applications to interact with AI models. It automatically detects and utilizes available hardware acceleration (such as Metal, CUDA, and Vulkan) and can either use pre-built binaries or compile the latest llama.cpp release from source using cmake if necessary.

Who it’s for

Developers using Node.js and TypeScript who want to integrate local LLMs into their applications without managing the underlying C++ build process or complex hardware configurations.

Highlights

  • Hardware Acceleration: Automatic support for Metal, CUDA, and Vulkan.
  • Structured Output: Ability to force models to generate parseable JSON or follow a specific JSON schema.
  • Advanced AI Capabilities: Support for function calling, embeddings, and reranking.
  • Developer Experience: Full TypeScript support and a CLI for chatting with models without writing code.
  • Security: Built-in protection against special token injection attacks.

Related

  • Project
  • Project
  • Project
  • Project
  • Project