--- url: /cli/chat.md description: '''chat'' command reference' --- # `chat` command ## Usage --- --- url: /cli/complete.md description: '''complete'' command reference' --- # `complete` command ## Usage --- --- url: /cli/infill.md description: '''infill'' command reference' --- # `infill` command ## Usage --- --- url: /cli/init.md description: '''init'' command reference' --- # `init` command ::: info This command is also available via: ```shell npm create node-llama-cpp@latest [name] ``` ::: ## Usage --- --- url: /cli/inspect/estimate.md description: '''inspect estimate'' command reference' --- # `inspect estimate` command ## Usage --- --- url: /cli/inspect/gguf.md description: '''inspect gguf'' command reference' --- # `inspect gguf` command ## Usage --- --- url: /cli/inspect/gpu.md description: '''inspect gpu'' command reference' --- # `inspect gpu` command ## Usage --- --- url: /cli/inspect/measure.md description: '''inspect measure'' command reference' --- # `inspect measure` command ## Usage --- --- url: /cli/inspect.md description: '''inspect'' command reference' --- # `inspect` command ## Usage --- --- url: /cli/pull.md description: '''pull'' command reference' --- # `pull` command A wrapper around [`ipull`](https://www.npmjs.com/package/ipull) to download model files as fast as possible with parallel connections and other optimizations. Automatically handles split and binary-split models files, so only pass the URI to the first file of a model. If a file already exists and its size matches the expected size, it will not be downloaded again unless the `--override` flag is used. The supported URI schemes are: * **HTTP:** `https://`, `http://` * **Hugging Face:** `hf:/:` (`:` is optional, [but recommended](../guide/downloading-models.md#hf-scheme-specify-quant)) * **Hugging Face:** `hf://#` (`#` is optional) Learn more about using model URIs in the [Downloading Models guide](../guide/downloading-models.md#model-uris). > To programmatically download a model file in your code, use [`createModelDownloader()`](../api/functions/createModelDownloader.md) ## Usage --- --- url: /cli/source/build.md description: '''source build'' command reference' --- # `source build` command ::: info If the build fails on macOS with the error `"/usr/bin/cc" is not able to compile a simple test program`, try running `xcode-select --install` to install the Xcode command line tools. ::: ::: details Programmatically calling the `source build` command in your code To programmatically call this command in your code, call the `BuildLlamaCppCommand` function: ```typescript import {BuildLlamaCppCommand} from "node-llama-cpp/commands"; await BuildLlamaCppCommand({}); ``` > **Note:** The `node-llama-cpp/commands` import is subject to change and is unsupported inside Electron ::: ## Usage > To set custom cmake options that are supported by `llama.cpp`'s cmake build, > set an environment variable of the option prefixed with `NODE_LLAMA_CPP_CMAKE_OPTION_`. --- --- url: /cli/source/clear.md description: '''source clear'' command reference' --- # `source clear` command ::: details Programmatically calling the `source clear` command in your code To programmatically call this command in your code, call the `ClearLlamaCppBuildCommand` function: ```typescript import {ClearLlamaCppBuildCommand} from "node-llama-cpp/commands"; await ClearLlamaCppBuildCommand({type: "all"}); ``` > **Note:** The `node-llama-cpp/commands` import is subject to change and is unsupported inside Electron ::: ## Usage --- --- url: /cli/source/download.md description: '''source download'' command reference' --- # `source download` command ::: tip NOTE `node-llama-cpp` ships with a git bundle of the release of `llama.cpp` it was built with, so when you run the `source download` command without specifying a specific release or repo, it will use the bundled git bundle instead of downloading the release from GitHub. This is useful for building from source on machines that aren't connected to the internet. ::: ::: info If the build fails on macOS with the error `"/usr/bin/cc" is not able to compile a simple test program`, try running `xcode-select --install` to install the Xcode command line tools. ::: ::: details Programmatically calling the `source download` command in your code To programmatically call this command in your code, call the `DownloadLlamaCppCommand` function: ```typescript import {DownloadLlamaCppCommand} from "node-llama-cpp/commands"; await DownloadLlamaCppCommand({}); ``` > **Note:** The `node-llama-cpp/commands` import is subject to change and is unsupported inside Electron ::: ## Usage > To set custom cmake options that are supported by `llama.cpp`'s cmake build, > set an environment variable of the option prefixed with `NODE_LLAMA_CPP_CMAKE_OPTION_`. --- --- url: /cli/source.md description: '''source'' command reference' --- # `source` command ## Usage --- --- url: /api/classes/ChatWrapper.md --- # Abstract Class: ChatWrapper Defined in: [ChatWrapper.ts:14](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L14) ## Extended by * [`EmptyChatWrapper`](EmptyChatWrapper.md) * [`DeepSeekChatWrapper`](DeepSeekChatWrapper.md) * [`QwenChatWrapper`](QwenChatWrapper.md) * [`Llama3_2LightweightChatWrapper`](Llama3_2LightweightChatWrapper.md) * [`Llama3_1ChatWrapper`](Llama3_1ChatWrapper.md) * [`Llama3ChatWrapper`](Llama3ChatWrapper.md) * [`Llama2ChatWrapper`](Llama2ChatWrapper.md) * [`MistralChatWrapper`](MistralChatWrapper.md) * [`GeneralChatWrapper`](GeneralChatWrapper.md) * [`ChatMLChatWrapper`](ChatMLChatWrapper.md) * [`FalconChatWrapper`](FalconChatWrapper.md) * [`FunctionaryChatWrapper`](FunctionaryChatWrapper.md) * [`GemmaChatWrapper`](GemmaChatWrapper.md) * [`Gemma4ChatWrapper`](Gemma4ChatWrapper.md) * [`HarmonyChatWrapper`](HarmonyChatWrapper.md) * [`MuseChatWrapper`](MuseChatWrapper.md) * [`SeedChatWrapper`](SeedChatWrapper.md) * [`TemplateChatWrapper`](TemplateChatWrapper.md) * [`JinjaTemplateChatWrapper`](JinjaTemplateChatWrapper.md) ## Constructors ### Constructor ```ts new ChatWrapper(): ChatWrapper; ``` #### Returns `ChatWrapper` ## Properties ### defaultSettings ```ts static defaultSettings: ChatWrapperSettings; ``` Defined in: [ChatWrapper.ts:15](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L15) *** ### wrapperName ```ts abstract readonly wrapperName: string; ``` Defined in: [ChatWrapper.ts:35](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L35) *** ### settings ```ts readonly settings: ChatWrapperSettings = ChatWrapper.defaultSettings; ``` Defined in: [ChatWrapper.ts:36](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L36) ## Methods ### generateContextState() ```ts generateContextState(__namedParameters: ChatWrapperGenerateContextStateOptions): ChatWrapperGeneratedContextState; ``` Defined in: [ChatWrapper.ts:38](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L38) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | [`ChatWrapperGenerateContextStateOptions`](../type-aliases/ChatWrapperGenerateContextStateOptions.md) | #### Returns [`ChatWrapperGeneratedContextState`](../type-aliases/ChatWrapperGeneratedContextState.md) *** ### generateFunctionCallsAndResults() ```ts generateFunctionCallsAndResults(functionCalls: ChatModelFunctionCall[], useRawCall?: boolean): LlamaText; ``` Defined in: [ChatWrapper.ts:63](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L63) #### Parameters | Parameter | Type | Default value | | ------ | ------ | ------ | | `functionCalls` | [`ChatModelFunctionCall`](../type-aliases/ChatModelFunctionCall.md)\[] | `undefined` | | `useRawCall` | `boolean` | `true` | #### Returns [`LlamaText`](LlamaText.md) *** ### generateFunctionCall() ```ts generateFunctionCall(name: string, params: any): LlamaText; ``` Defined in: [ChatWrapper.ts:110](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L110) #### Parameters | Parameter | Type | | ------ | ------ | | `name` | `string` | | `params` | `any` | #### Returns [`LlamaText`](LlamaText.md) *** ### generateFunctionCallResult() ```ts generateFunctionCallResult( functionName: string, functionParams: any, result: any): LlamaText; ``` Defined in: [ChatWrapper.ts:127](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L127) #### Parameters | Parameter | Type | | ------ | ------ | | `functionName` | `string` | | `functionParams` | `any` | | `result` | `any` | #### Returns [`LlamaText`](LlamaText.md) *** ### generateModelResponseText() ```ts generateModelResponseText(modelResponse: ( | string | ChatModelFunctionCall | ChatModelSegment)[], useRawValues?: boolean): LlamaText; ``` Defined in: [ChatWrapper.ts:158](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L158) #### Parameters | Parameter | Type | Default value | | ------ | ------ | ------ | | `modelResponse` | ( | `string` | [`ChatModelFunctionCall`](../type-aliases/ChatModelFunctionCall.md) | [`ChatModelSegment`](../type-aliases/ChatModelSegment.md))\[] | `undefined` | | `useRawValues` | `boolean` | `true` | #### Returns [`LlamaText`](LlamaText.md) *** ### generateAvailableFunctionsSystemText() ```ts generateAvailableFunctionsSystemText(availableFunctions: ChatModelFunctions, __namedParameters: { documentParams?: boolean; }): LlamaText; ``` Defined in: [ChatWrapper.ts:243](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L243) #### Parameters | Parameter | Type | | ------ | ------ | | `availableFunctions` | [`ChatModelFunctions`](../type-aliases/ChatModelFunctions.md) | | `__namedParameters` | { `documentParams?`: `boolean`; } | | `__namedParameters.documentParams?` | `boolean` | #### Returns [`LlamaText`](LlamaText.md) *** ### addAvailableFunctionsSystemMessageToHistory() ```ts addAvailableFunctionsSystemMessageToHistory( history: readonly ChatHistoryItem[], availableFunctions?: ChatModelFunctions, __namedParameters?: { documentParams?: boolean; }): readonly ChatHistoryItem[]; ``` Defined in: [ChatWrapper.ts:269](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L269) #### Parameters | Parameter | Type | | ------ | ------ | | `history` | readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] | | `availableFunctions?` | [`ChatModelFunctions`](../type-aliases/ChatModelFunctions.md) | | `__namedParameters?` | { `documentParams?`: `boolean`; } | | `__namedParameters.documentParams?` | `boolean` | #### Returns readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] *** ### generateInitialChatHistory() ```ts generateInitialChatHistory(__namedParameters?: ChatWrapperGenerateInitialHistoryOptions): ChatHistoryItem[]; ``` Defined in: [ChatWrapper.ts:290](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L290) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | [`ChatWrapperGenerateInitialHistoryOptions`](../type-aliases/ChatWrapperGenerateInitialHistoryOptions.md) | #### Returns [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] --- --- url: /api/classes/TokenPredictor.md --- # Abstract Class: TokenPredictor Defined in: [evaluator/LlamaContext/TokenPredictor.ts:8](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/TokenPredictor.ts#L8) ## See [Using Token Predictors](https://node-llama-cpp.withcat.ai/guide/token-prediction#custom) ## Extended by * [`DraftSequenceTokenPredictor`](DraftSequenceTokenPredictor.md) * [`InputLookupTokenPredictor`](InputLookupTokenPredictor.md) ## Constructors ### Constructor ```ts new TokenPredictor(): TokenPredictor; ``` #### Returns `TokenPredictor` ## Methods ### reset() ```ts abstract reset(params: { targetSequence: LlamaContextSequence; stateTokens: Token[]; evaluateOptions: Readonly; }): | void | Promise; ``` Defined in: [evaluator/LlamaContext/TokenPredictor.ts:14](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/TokenPredictor.ts#L14) Resets the state of the predictor. Called before the generation starts. #### Parameters | Parameter | Type | Description | | ------ | ------ | ------ | | `params` | { `targetSequence`: [`LlamaContextSequence`](LlamaContextSequence.md); `stateTokens`: [`Token`](../type-aliases/Token.md)\[]; `evaluateOptions`: [`Readonly`](https://www.typescriptlang.org/docs/handbook/utility-types.html#readonlytype)<[`SequenceEvaluateOptions`](../type-aliases/SequenceEvaluateOptions.md)>; } | - | | `params.targetSequence` | [`LlamaContextSequence`](LlamaContextSequence.md) | The target sequence that this token predictor is generating tokens for | | `params.stateTokens` | [`Token`](../type-aliases/Token.md)\[] | The tokens that are or will be loaded into the state. The initial predictions should be based on these tokens. When additional tokens are pushed into the state, the `pushTokens` method will be called with those tokens. | | `params.evaluateOptions` | [`Readonly`](https://www.typescriptlang.org/docs/handbook/utility-types.html#readonlytype)<[`SequenceEvaluateOptions`](../type-aliases/SequenceEvaluateOptions.md)> | Options used for the evaluation on the target sequence. The `grammarEvaluationState` is cloned before being passed to the token predictor, so it can be modified without affecting the original state. | #### Returns | `void` | [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`> *** ### pushTokens() ```ts abstract pushTokens(tokens: Token[]): void; ``` Defined in: [evaluator/LlamaContext/TokenPredictor.ts:35](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/TokenPredictor.ts#L35) #### Parameters | Parameter | Type | | ------ | ------ | | `tokens` | [`Token`](../type-aliases/Token.md)\[] | #### Returns `void` *** ### predictTokens() ```ts abstract predictTokens(): | Token[] | Promise; ``` Defined in: [evaluator/LlamaContext/TokenPredictor.ts:46](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/TokenPredictor.ts#L46) Predicts the next tokens based on the current state. If the generation should wait until the minimum predications are ready, this method should return a promise that resolves when the minimum predictions are ready. A background prediction process can be started when this function is called, so that the next predictions will be ready when this function is called again. #### Returns | [`Token`](../type-aliases/Token.md)\[] | [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[`Token`](../type-aliases/Token.md)\[]> *** ### stop() ```ts stop(untilPredictionsExhausted?: boolean): | void | Promise; ``` Defined in: [evaluator/LlamaContext/TokenPredictor.ts:52](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/TokenPredictor.ts#L52) Stops the prediction process when it runs in the background. #### Parameters | Parameter | Type | Description | | ------ | ------ | ------ | | `untilPredictionsExhausted?` | `boolean` | If true, the prediction process should not resume until the current predictions are exhausted. | #### Returns | `void` | [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`> *** ### updateInputTokens() ```ts updateInputTokens(tokens: Token[]): void; ``` Defined in: [evaluator/LlamaContext/TokenPredictor.ts:57](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/TokenPredictor.ts#L57) Called with the input tokens before the generation starts when using `LlamaChatSession`, `LlamaChat`, and `LlamaCompletion`. #### Parameters | Parameter | Type | | ------ | ------ | | `tokens` | [`Token`](../type-aliases/Token.md)\[] | #### Returns `void` *** ### dispose() ```ts dispose(): | void | Promise; ``` Defined in: [evaluator/LlamaContext/TokenPredictor.ts:59](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/TokenPredictor.ts#L59) #### Returns | `void` | [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`> --- --- url: /guide/awesome.md description: Awesome projects that use node-llama-cpp --- # Awesome `node-llama-cpp` :sunglasses: Awesome projects that use `node-llama-cpp`. ## Open Source * [CatAI](https://github.com/withcatai/catai) - a simplified AI assistant API for Node.js, with REST API support * [QMD](https://github.com/tobi/qmd) (Query Markup Documents) - an on-device search engine for your markdown notes, meeting transcripts, documentation, and knowledge bases. Search with keywords or natural language * [Clippy](https://felixrieseberg.github.io/clippy/) ([GitHub](https://github.com/felixrieseberg/clippy)) - Clippy, resurrected from the 1990s, now with some AI ## Proprietary * [BashBuddy](https://bashbuddy.run) ([GitHub](https://github.com/wosherco/bashbuddy)) - write bash commands with natural language * [nutshell](https://withnutshell.com) - Private AI meeting notes processed completely on your device * [Manzoni](https://manzoni.app/) ([GitHub](https://github.com/gems-platforms/manzoni-app)) - a text editor running local LLMs *** > To add a project to this list, [open a PR](https://github.com/withcatai/node-llama-cpp/edit/master/docs/guide/awesome.md). > > To have a project listed here, it should clearly state that it uses `node-llama-cpp`. --- --- url: /blog.md description: node-llama-cpp blog --- --- --- url: /guide/building-from-source.md description: Building llama.cpp from source for node-llama-cpp --- # Building From Source `node-llama-cpp` ships with pre-built binaries for macOS, Linux and Windows. In case binaries are not available for your platform or fail to load, it'll fallback to download a release of `llama.cpp` and build it from source with `cmake`. ## Downloading a Release To download a release of `llama.cpp` and build it from source you can use the CLI [`source download`](../cli/source/download.md) command. ```shell npx --no node-llama-cpp source download ``` ::: tip NOTE `node-llama-cpp` ships with a git bundle of the release of `llama.cpp` it was built with, so when you run the [`source download`](../cli/source/download.md) command without specifying a specific release or repo, it will use the bundled git bundle instead of downloading the release from GitHub. This is useful for building from source on machines that aren't connected to the internet. ::: ::: info If `cmake` is not installed on your machine, `node-llama-cpp` will automatically download `cmake` to an internal directory and try to use it to build `llama.cpp` from source. If the build fails, make sure you have the required dependencies of `cmake` installed on your machine. More info is available [here](https://github.com/cmake-js/cmake-js#:~:text=%5Bstring%5D-,Requirements%3A,-CMake) (you don't have to install `cmake` or `cmake-js`, just the dependencies). ::: ::: details Dependencies for macOS If the build fails on macOS with the error `"/usr/bin/cc" is not able to compile a simple test program`, try running this command to install the Xcode command line tools: ```shell xcode-select --install ``` ::: ::: details Dependencies for Windows x64 If the build fails on your machine, ensure you have all the necessary build tools installed. You can install all the dependencies via [WinGet](https://learn.microsoft.com/en-us/windows/package-manager/winget/) using this command: ```shell winget install --id Microsoft.VisualStudio.2022.BuildTools --force --override "--add Microsoft.VisualStudio.Component.VC.CMake.Project Microsoft.VisualStudio.Component.VC.CoreBuildTools Microsoft.VisualStudio.Component.VC.Tools.x86.x64 Microsoft.VisualStudio.Component.VC.ATL Microsoft.VisualStudio.Component.VC.ATLMFC Microsoft.VisualStudio.Component.VC.Llvm.ClangToolset Microsoft.VisualStudio.Component.VC.Llvm.Clang Microsoft.VisualStudio.Component.VC.Redist.14.Latest Microsoft.Component.VC.Runtime.UCRTSDK Microsoft.VisualStudio.Component.Windows10SDK Microsoft.VisualStudio.Component.Windows10SDK.20348" ``` > WinGet is built-in on Windows 11 and modern Windows 10 versions *** You can also install all the dependencies manually using the [Visual C++ Build Tools installer](https://visualstudio.microsoft.com/visual-cpp-build-tools/): * **`Workloads` tab:** select `Desktop development with C++` * **`Individual components` tab**: select the following: * C++ ATL for latest v143 build tools (x86 & x64) * C++ MFC for latest v143 build tools (x86 & x64) * C++ CMake tools for Windows * C++ Clang Compiler for Windows * MSBuild support for LLVM (clang-cl) toolset * Windows Universal CRT SDK ::: ::: details Dependencies for Windows on Arm On Windows on Arm you need to install additional build tools to build `llama.cpp` from source. You can install all the dependencies via [WinGet](https://learn.microsoft.com/en-us/windows/package-manager/winget/) using this command: ```shell winget install --id Microsoft.VisualStudio.2022.BuildTools --force --override "--add Microsoft.VisualStudio.Component.VC.CMake.Project Microsoft.VisualStudio.Component.VC.CoreBuildTools Microsoft.VisualStudio.Component.VC.Tools.x86.x64 Microsoft.VisualStudio.Component.VC.Tools.ARM64 Microsoft.VisualStudio.Component.VC.ATL Microsoft.VisualStudio.Component.VC.ATL.ARM64 Microsoft.VisualStudio.Component.VC.ATLMFC Microsoft.VisualStudio.Component.VC.MFC.ARM64 Microsoft.VisualStudio.Component.VC.Llvm.ClangToolset Microsoft.VisualStudio.Component.VC.Llvm.Clang Microsoft.VisualStudio.Component.VC.Redist.14.Latest Microsoft.Component.VC.Runtime.UCRTSDK Microsoft.VisualStudio.Component.Windows10SDK Microsoft.VisualStudio.Component.Windows10SDK.20348" ``` > WinGet is built-in on Windows 11 and modern Windows 10 versions *** You can also install all the dependencies manually using the [Visual C++ Build Tools installer](https://visualstudio.microsoft.com/visual-cpp-build-tools/): * **`Workloads` tab:** select `Desktop development with C++` * **`Individual components` tab**: select the following: * MSVC v143 - VS 2022 C++ ARM64 build tools (latest) * C++ ATL for latest v143 build tools (ARM64/ARM64EC) * C++ MFC for latest v143 build tools (ARM64/ARM64EC) * C++ CMake tools for Windows * C++ Clang Compiler for Windows * MSBuild support for LLVM (clang-cl) toolset * Windows Universal CRT SDK ::: ## `source download` and `source build` Commands The difference between the [`source download`](../cli/source/download.md) and [`source build`](../cli/source/build.md) commands is that the `source download` command downloads a release of `llama.cpp` and builds it, while the `source build` command builds the `llama.cpp` release that's already downloaded. You can only use the `source build` command after you've already downloaded a release of `llama.cpp` with the `source download` command. To only download a release of `llama.cpp` without building it, use the `source download` command with the `--skipBuild` option: ```shell npx --no node-llama-cpp source download --skipBuild ``` ## Building Inside Your App The best way to use a customized build is by customizing the options passed to the [`getLlama`](../api/functions/getLlama.md). If there's no existing binary that matches the provided options (either a local build or a pre-built binary), it'll automatically download a release of `llama.cpp` (if it's not already downloaded) and build it from source. You can pass custom cmake options you want the binary be compiled with by using the [`cmakeOptions`](../api/type-aliases/LlamaOptions.md#cmakeoptions) option: ```typescript import {getLlama} from "node-llama-cpp"; // ---cut--- const llama = await getLlama({ cmakeOptions: { OPTION_NAME: "OPTION_VALUE" }, // force a build if the pre-built binary doesn't // match all the provided options, such as the cmakeOptions existingPrebuiltBinaryMustMatchBuildOptions: true }); ``` You can also force it to build a new binary by setting the [`build`](../api/type-aliases/LlamaOptions.md#build) option to `"forceRebuild"`: ```typescript import {getLlama} from "node-llama-cpp"; // ---cut--- const llama = await getLlama({ build: "forceRebuild" }); ``` ::: info Electron support for building from source When running in Electron, the [`build`](../api/type-aliases/LlamaOptions.md#build) option defaults to `"never"` as we cannot assume that the user has the necessary build tools installed on their machine, and the user won't be able to see the build process to troubleshoot any issues that may arise. You can manually set it to be `"auto"` to allow building from source in Electron. When running from inside an Asar archive in Electron, building from source is not possible, so it'll never build from source. To allow building from source in Electron apps, make sure you ship `node-llama-cpp` as an unpacked module. If you want to use a build with custom cmake options in your Electron app, make sure you build `node-llama-cpp` with your desired cmake options *before* building your Electron app, and make sure you pass the same cmake options to the [`getLlama`](../api/functions/getLlama.md) function in your Electron app so it'll use the binary you built. ::: ## Customizing the Build {#customize-build} > **Meta:** To configure Metal support see the [Metal support guide](./Metal.md). > > **CUDA:** To configure CUDA support see the [CUDA support guide](./CUDA.md). > > **Vulkan:** To configure Vulkan support see the [Vulkan support guide](./Vulkan.md). `llama.cpp` has CMake build options that can be configured to customize the build. :::details `llama.cpp` CMake build options > Source: `CMakeLists` ::: To build `node-llama-cpp` with any of these options, set an environment variable of an option prefixed with `NODE_LLAMA_CPP_CMAKE_OPTION_` before running the [`source download`](../cli/source/download.md) or [`source build`](../cli/source/build.md) commands. To use that customized build in your code, you can either use `getLlama("lastBuild")` to get the last build that was built, or pass the code snippet that is printed after the build finishes. ## Downloading a Newer Release {#download-new-release} Every new release of `node-llama-cpp` ships with the latest release of `llama.cpp` that was available at the time of the release, so relying on the latest version of `node-llama-cpp` should be enough for most use cases. However, you may want to download a newer release of `llama.cpp` ([`llama.cpp` releases](https://github.com/ggml-org/llama.cpp/releases)) and build it from source to get the latest features and bug fixes before a new version of `node-llama-cpp` is released. A new release may contain breaking changes, so it won't necessarily work properly or even compile at all, so do this with caution. You can do this by specifying the `--release` option with the release tag you want to download: ```shell npx --no node-llama-cpp source download --release "b1350" ``` > You can find the release tag on the [`llama.cpp` releases page](https://github.com/ggml-org/llama.cpp/releases): You can also opt to download the latest release available: ```shell npx --no node-llama-cpp source download --release latest ``` --- --- url: /guide/chat-context-shift.md --- # Chat Context Shift Strategy {#background} When the chat history gets longer than the sequence's context size, we have to remove the oldest tokens from the context state to make room for new tokens to be generated. This is called a context shift. `node-llama-cpp` has a smart mechanism to handle context shifts on the chat level, so the oldest messages are truncated (from their beginning) or removed from the context state, while keeping the system prompt in place to ensure the model follows the guidelines you set for it. You can override `node-llama-cpp`'s default context shift strategy when using [`LlamaChatSession`](../api/classes/LlamaChatSession.md) or [`LlamaChat`](../api/classes/LlamaChat.md) by providing a custom context shift strategy. ## The Default Context Shift Strategy {#default-strategy} The [default context shift strategy](../api/type-aliases/LLamaChatContextShiftOptions.md#strategy) is `eraseFirstResponseAndKeepFirstSystem`. This strategy attempts to truncate the oldest model responses (from their beginning) or remove them completely from the chat history while keeping the first system prompt in place. If a response is completely removed, the prompt that came before it will be removed as well. ## Implementing a Custom Context Shift Strategy {#custom-strategy} A [custom context shift strategy](../api/type-aliases/LLamaChatContextShiftOptions.md#strategy) is a function that receives the full chat history as input and returns a new chat history that when tokenized will result in an array of tokens shorter than the desired max size. The context shift strategy will be called only when the context state needs to be shifted. If the context shift strategy returns an invalid chat history (e.g., a chat history that is too long), the prompting function will abort the evaluation and throw an error. A custom context shift strategy can be a simple logic that prioritizes which data to remove, or it can even use a language model to summarize information to shorten the chat history. It's important to keep the last user prompt and model response as-is to prevent infinite generation loops. ```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(); // ---cut--- const session = new LlamaChatSession({ contextSequence: context.getSequence(), contextShift: { strategy({ chatHistory, chatWrapper, maxTokensCount, tokenizer, lastShiftMetadata }) { // clone the chat history to not mutate the original const newChatHistory = chatHistory.map( (item) => structuredClone(item) ); function getTokensLeftToRemove() { const { contextText } = chatWrapper.generateContextState({chatHistory}); const tokenUsage = contextText.tokenize(tokenizer).length; return Math.max(0, tokenUsage - maxTokensCount); } while (getTokensLeftToRemove() > 0 && newChatHistory.length > 2) { for (let i = 0; i < newChatHistory.length - 2; i++) { const chatItem = newChatHistory[i]!; if (i === 0 && chatItem.type === "system") // don't remove the first system message continue; else if (chatItem.type === "model") { // remove the model response newChatHistory.splice(i, 1); i--; // remove the user messages that // came before the model response while ( i > 0 && newChatHistory[i - 1]?.type === "user" ) { newChatHistory.splice(i - 1, 1); i--; } } else if (chatItem.type === "system") { // don't remove system messages on their own continue; } else if (chatItem.type === "user") { // don't remove user messages on their own continue; } else { // ensure we handle all message types. // otherwise, this will error void (chatItem satisfies never); } } } return { chatHistory: newChatHistory, // this metadata will be passed to the next context shift // strategy call as the `lastShiftMetadata` argument metadata: {} }; } } }); ``` --- --- url: /guide/chat-wrapper.md description: Chat with a model without having to worry about any parsing or formatting --- # Chat Wrapper ## Background Text generation models are trained to predict the completion of incomplete text. To have a conversation with a model, we have to generate a text the model can complete, and parse its response to know whether it finished answering, or should we tell it to continue completing the text. For example, to prompt a model with "Where do llamas come from?" we can give the model a text like this to predict the completion of it: ``` You are a helpful, respectful and honest assistant. Always answer as helpfully as possible. If a question does not make any sense, or is not factually coherent, explain why instead of answering something incorrectly. If you don't know the answer to a question, don't share false information. ### Human Where do llamas come from? ### Assistant ⠀ ``` > The first text we gave to the model in this example is called a "system prompt". > This text will guide the model towards generating a response we want it to generate. The model will then generate a response like this: ``` Llamas come from the Andes mountains. ### Human ⠀ ``` On every character the model generates, we have to check whether the text completion now includes the `### Human\n` part, and if it does, we can stop the completion and return the response. Most models are trained to understand a specific conversation format, or output a specific text when they finish generating a response. Usually, when a model finishes generating a response, it'll output an EOS token (End of Sequence token) that's specific to the model. For example, LLama 3 Instruct models have [their own conversation format](https://huggingface.co/blog/llama3#how-to-prompt-llama-3). ::: info To learn more about tokens, see the [tokens guide](./tokens.md) ::: ## Chat Wrappers The [`LlamaChatSession`](../api/classes/LlamaChatSession.md) class allows you to chat with a model without having to worry about any parsing or formatting. To do that, it uses a chat wrapper to handle the unique chat format of the model you use. It automatically selects and configures a chat wrapper that it thinks is best for the model you use (via [`resolveChatWrapper(...)`](../api/functions/resolveChatWrapper.md)). You can also specify a specific chat wrapper to only use it, or to customize its settings. For example, to chat with a LLama 3 Instruct model, you can use [Llama3ChatWrapper](../api/classes/Llama3ChatWrapper.md): ```typescript import {fileURLToPath} from "url"; import path from "path"; import {getLlama, LlamaChatSession, Llama3ChatWrapper} 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-8B-Instruct.Q4_K_M.gguf") }); const context = await model.createContext(); const session = new LlamaChatSession({ contextSequence: context.getSequence(), chatWrapper: new Llama3ChatWrapper() // by default, "auto" is used }); 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); ``` > You can find the list of builtin chat prompt wrappers [here](../api/classes/ChatWrapper.md). ## Template Chat Wrapper {#template} A simple way to create your own custom chat wrapper is to use [`TemplateChatWrapper`](../api/classes/TemplateChatWrapper.md). Example usage: ```typescript import {TemplateChatWrapper} from "node-llama-cpp"; const chatWrapper = new TemplateChatWrapper({ template: "{{systemPrompt}}\n{{history}}model: {{completion}}\nuser: ", historyTemplate: { system: "system: {{message}}\n", user: "user: {{message}}\n", model: "model: {{message}}\n" }, // functionCallMessageTemplate: { // optional // call: "[[call: {{functionName}}({{functionParams}})]]", // result: " [[result: {{functionCallResult}}]]" // } }); ``` > See [`TemplateChatWrapper`](../api/classes/TemplateChatWrapper.md) for more details. ## Jinja Template Chat Wrapper {#jinja} To reuse an existing Jinja template you have, you can use [`JinjaTemplateChatWrapper`](../api/classes/JinjaTemplateChatWrapper.md). ::: tip NOTE Not all the features of Jinja are supported by the [`JinjaTemplateChatWrapper`](../api/classes/JinjaTemplateChatWrapper.md), so some Jinja templates might need some simple modifications to work. If you'd like to create your own chat wrapper, it's significantly easier to [write you own custom chat wrapper directly](#custom-chat-wrapper). ::: ```typescript import {JinjaTemplateChatWrapper} from "node-llama-cpp"; const chatWrapper = new JinjaTemplateChatWrapper({ template: "", // functionCallMessageTemplate: { // optional // call: "[[call: {{functionName}}({{functionParams}})]]", // result: " [[result: {{functionCallResult}}]]" // } }); ``` ## Custom Chat Wrapper To create your own chat wrapper, you need to extend the [`ChatWrapper`](../api/classes/ChatWrapper.md) class. The way a chat wrapper works is that it implements the [`generateContextState`](../api/classes/ChatWrapper.md#generatecontextstate) method, which received the full chat history and available functions and is responsible for generating the content to be loaded into the context state, so the model can generate a completion of it. The context content is returned in the form of a [`LlamaText`](../api/classes/LlamaText.md) (see the [LlamaText guide](./llama-text.md)). If the last message in the chat history is a model response, it must **not** include a syntax suffix for the message, so the model can continue generating completion for an existing response. This is needed for context shifts to work properly. > For example, this is a valid ending of a context text: > > ```text > ### Assistant > Llamas come from the > ``` > > This is an invalid ending of a context text: > > ```text > ### Assistant > Llamas come from the > > ### Human > ``` ::: info What is a context shift? {#smart-context-shift} When the chat history gets longer than the sequence's context size, we have to remove the oldest tokens from the context state to make room for new tokens to be generated. `node-llama-cpp` has a smart mechanism to handle context shifts on the chat level, so the oldest messages are truncated (from their beginning) or removed from the context state, while keeping the system prompt in place to ensure the model follows the guidelines you set for it. ::: ```typescript import {fileURLToPath} from "url"; import path from "path"; import { getLlama, LlamaChatSession, ChatWrapper, ChatWrapperSettings, ChatWrapperGenerateContextStateOptions, ChatWrapperGeneratedContextState, LlamaText } from "node-llama-cpp"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); class MyCustomChatWrapper extends ChatWrapper { public readonly wrapperName: string = "MyCustomChat"; public override readonly settings: ChatWrapperSettings = { ...ChatWrapper.defaultSettings }; public override generateContextState({ chatHistory, availableFunctions, documentFunctionParams }: ChatWrapperGenerateContextStateOptions): ChatWrapperGeneratedContextState { const historyWithFunctions = this.addAvailableFunctionsSystemMessageToHistory(chatHistory, availableFunctions, { documentParams: documentFunctionParams }); const texts = historyWithFunctions.map((item, index) => { if (item.type === "system") { if (index === 0) return LlamaText([ LlamaText.fromJSON(item.text) ]); return LlamaText([ "### System\n", LlamaText.fromJSON(item.text) ]); } else if (item.type === "user") return LlamaText([ "### Human\n", item.text ]); else if (item.type === "model") return LlamaText([ "### Assistant\n", this.generateModelResponseText(item.response) ]); // ensure that all chat item types are handled, // or TypeScript will throw an error return item satisfies never; }); return { contextText: LlamaText.joinValues("\n\n", texts), // if the model generates any of these texts, // the completion will stop, and the text will not // be included in the response returned to the user stopGenerationTriggers: [ LlamaText(["### Human\n"]) ] }; } } const llama = await getLlama(); const model = await llama.loadModel({ modelPath: path.join(__dirname, "models", "Meta-Llama-3-8B-Instruct.Q4_K_M.gguf") }); const context = await model.createContext(); const session = new LlamaChatSession({ contextSequence: context.getSequence(), chatWrapper: new MyCustomChatWrapper() }); 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); ``` ## Default Chat Wrapper Options You can use the [`resolveChatWrapper(...)`](../api/functions/resolveChatWrapper.md) function to resolve the best chat wrapper for a given model, and configure the default options for each of the builtin chat wrappers it may resolve to. ```typescript import {fileURLToPath} from "url"; import path from "path"; import {getLlama, LlamaChatSession, resolveChatWrapper} 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-8B-Instruct.Q4_K_M.gguf") }); const context = await model.createContext(); const session = new LlamaChatSession({ contextSequence: context.getSequence(), chatWrapper: resolveChatWrapper(model, {// [!code highlight] customWrapperSettings: {// [!code highlight] "llama3.1": {// [!code highlight] cuttingKnowledgeDate: new Date("2025-01-01T00:00:00Z")// [!code highlight] }// [!code highlight] }// [!code highlight] })// [!code highlight] }); const q1 = "Hi there, how are you?"; console.log("User: " + q1); const a1 = await session.prompt(q1); console.log("AI: " + a1); ``` --- --- url: /guide/choosing-a-model.md description: Learn how to choose the right model for your use case --- # Choosing a Model ## About GGUF Model Files `llama.cpp` works with GGUF (Georgi Gerganov's Unified Format) model files. GGUF model files are usually converted from other formats, such as Transformers, PyTorch, etc. The advantages of GGUF files include: * Ease of use * No need for custom code for each different model * Optimization for `llama.cpp` * Containing all the necessary information for using the file within the file itself A GGUF model file includes metadata about the model that's used for loading and running it. You can inspect this metadata using the [`inspect gguf`](../cli/inspect/gguf.md) command or the [`readGgufFileInfo` function](../api/functions/readGgufFileInfo.md). ::: tip You can pass a URL to the [`inspect gguf`](../cli/inspect/gguf.md) command or the [`readGgufFileInfo` function](../api/functions/readGgufFileInfo.md) to read the metadata of a model without downloading it. ::: ## Finding a Model Source The recommended way to obtain a pre-converted GGUF model file is from the [HuggingFace model hub](https://huggingface.co/models?library=gguf) from a reputable source. ### Community Conversions Reputable community members convert many popular models to GGUF and publish them on HuggingFace. When searching for a GGUF model, you can visit their HuggingFace profiles to find the model you're looking for. Here's a list of recommended community members who convert models to GGUF: * [Michael Radermacher](https://huggingface.co/mradermacher) (`mradermacher`) - very high quality conversions, with a quality graph on the model pages * [Bartowski](https://huggingface.co/bartowski) (`bartowski`) - quick to convert new models > If you're a community member who converts many models to GGUF and would like to be added to this list, please open a PR to add yourself. ### Model Providers Some models are converted into GGUF by the model providers themselves. For example, [Google released a GGUF conversion of Gemma 2](https://huggingface.co/google/gemma-2-2b-it-GGUF) themselves. The advantages of obtaining models directly from the model provider include: * It's a reputable source (assuming you know what you're looking for). * The model provider can ensure that the model performs as expected at the time of publishing. The disadvantages of obtaining models directly from the model provider include: * Sometimes the conversion is not up-to-date enough with the latest updates of `llama.cpp`, which can result in degraded performance compared to an up-to-date model conversion. * Some model providers lock their models behind a consent form, making them "gated models". This renders the models inaccessible without using an API token to download them, complicating their use in CI/CD and other automated workflows. ## Choosing a Model When choosing a model, consider the following: ### What are your hardware capabilities? (CPU, GPU, VRAM, etc.) If the machine you plan to run this model on doesn't have a GPU, you'd probably want to use a small model that can run on a CPU with decent performance. If you have a GPU, the amount of VRAM you have will determine the size of the model you can run. Ideally, you'd want to fit the entire model in the VRAM to use only the GPU and achieve maximum performance. If the model requires more memory than the available VRAM, parts of it will be offloaded to the RAM and be evaluated using the CPU, significantly reducing the efficiency and speed of inference. ::: tip Use the [`inspect gpu`](../cli/inspect/gpu.md) command to check your hardware capabilities: ```shell npx --no node-llama-cpp inspect gpu ``` ::: Here's a rough estimation of the VRAM required for different model sizes: | Model Size | VRAM | | ---------- | ----- | | 1B | 1GB | | 3B | 3.5GB | | 8B | 6GB | | 70B | 55GB | | 405B | 300GB | ::: tip To get a more accurate estimation of how well a model will run on your hardware before downloading it, you can use the [`inspect estimate`](../cli/inspect/estimate.md) command: ```shell npx --no node-llama-cpp inspect estimate ``` ::: ### What do you need this model for? (chat, code completion, analyzing data, classification, embedding, etc.) {#model-purpose} There are plenty of models with different areas of expertise and capabilities. When you choose a model that is more specialized in the task you need it for, it will usually perform better than a general model. Furthermore, a smaller model that is specialized in the task you need it for can also perform better than a larger model that is more general. To optimize for the response quality, as well as performance, you should prefer a model that is specialized in the task you need it for. Here are a few concepts to be aware of when choosing a model: * **Instruction-type models** - models that are trained to receive instructions and perform tasks based on them. These models usually support chat templates, meaning that you can use a [`LlamaChatSession`](../api/classes/LlamaChatSession.md) to interact with them. You can identify these models by looking for `Instruct` or `it` in the model name. A non-instruct model can still be useful for generating completions, but it may not work well for chat, as it is unaware of a chat syntax. * **Fine-tuned models** - models that are trained on specific datasets to perform better on particular tasks. These models are based on a more general-purpose model and are trained on top of it. Fine-tuning is usually less extensive and is much cheaper than the training of the original model. You can identify these models by looking for the foundational model they're based on (e.g., Llama 3) in the model name, along with the fine-tune name. For example, a popular fine-tune called "dolphin" is used to make a model uncensored. A model named [`dolphin-2.9.3-llama-3-8b-i1-GGUF`](https://huggingface.co/mradermacher/dolphin-2.9.3-llama-3-8b-i1-GGUF) is a "dolphin" fine-tuned model based on the Llama 3 8B model. To distinguish between the fine-tune and the foundational model in the model name, you can either recognize the foundational model name and then assume that the rest is a fine-tune name, or you can open the model's page and read the model description. * **Embedding models** - models that are trained to convert text into [embeddings](./embedding.md) that capture the semantic meaning of the text. Generating embeddings for similarity search using such models is preferable because they are highly optimized for this task. Embedding models are often significantly smaller (sometimes as small as 100MB), faster, and consume less memory than general-purpose models, making them more efficient and practical. While general-purpose models can also be used for generating embeddings, they may not be as optimized or as efficient as embedding models for this task. Many embedding models include terms like `embed` in their name. * **Reranking models** - models that are trained to rerank (sort) a list of documents based on their relevance to a given query. These models are usually smaller and faster than general-purpose models, making them more efficient and practical for reranking tasks. Reranking models are often significantly smaller (sometimes as small as 500MB), faster, and consume less memory than general-purpose models, making them more efficient and practical. While general-purpose models can also be used for reranking, doing this requires prompting the model, which is more cumbersome and inefficient than using a specialized model with a [ranking context](./embedding.md#reranking) for this task. Many reranking models include terms like `rerank` or `reranker` in their name. ### How much data do you plan to feed the model at once with? If you plan to feed the model with a lot of data at once, you'll need a model that supports a large context size. The larger the context size is, the more data the model can process at once. You can only create a context with a size that is smaller or equal to the context size the model was trained on (although there are techniques around that, like [RoPE](https://github.com/ggml-org/llama.cpp/discussions/1965)). The larger the context size is, the more memory the model will require to run. If you plan to feed the model with a lot of data at once, you may want to choose a smaller model that uses less memory, so you can create a larger context. ::: tip To find the training context size of a model, as well as the largest context size that can be created with that model on your machine, you can use the [`inspect estimate`](../cli/inspect/estimate.md) command: ```shell npx --no node-llama-cpp inspect estimate ``` ::: ## Choosing a File to Get After choosing a model, you should choose what quality level of the model you want to get. For example, on [this model](https://huggingface.co/mradermacher/Meta-Llama-3.1-8B-Instruct-GGUF), clicking on the `Files and versions` tab reveals many model files. Each of these files represent a different quality level of the model, and you can choose the one that best fits your needs. The more compressed the model is, the less memory it will require to run, and the faster it will run, but the quality of the responses may be lower. The only way to determine whether the model's quality is sufficient for your needs is to try it out with a task you plan to use it for and see how well it performs. Usually, a `Q4_K_M` quality offers the best balance between compression and quality (with `Q5_K_M` as a close second), so it's recommended to start with this quality. A `Q8_0` quality is typically the highest quality that still uses compression, but it's also slower to run and uses more memory. A `f16` (or any other `f`) file is an uncompressed model, and it's the highest quality, but it's also the slowest to run and uses the most memory. It's generally not recommended to use this quality for inference, but it's useful for training. ::: tip The easiest way to test a model's quality is by using the [`chat`](../cli/chat.md) command. You can download a model and immediately prompt it with a single command by passing a model URL together with a `--prompt` flag: ```shell npx --no node-llama-cpp chat --prompt 'Hi there' ``` ::: ## Downloading a Model For improved download speeds, you can use the [`pull`](../cli/pull.md) command to download a model: ```shell npx --no node-llama-cpp pull --dir ./models ``` > If the model file URL is of a chunk of a binary-split model (for example, [this model](https://huggingface.co/mradermacher/Meta-Llama-3.1-405B-GGUF/blob/main/Meta-Llama-3.1-405B.Q4_K_S.gguf.part1of5)), > it will automatically download all the chunks and combine them into a single file. > > If the model file URL is of a single part of a multi-part model (for example, [this model](https://huggingface.co/bartowski/Meta-Llama-3-70B-Instruct-GGUF/blob/main/Meta-Llama-3-70B-Instruct-Q5_K_L.gguf/Meta-Llama-3-70B-Instruct-Q5_K_L-00001-of-00002.gguf)), > it will also download all the other parts as well into the same directory. ::: tip Consider using [model URIs](./downloading-models.md#model-uris) to download and load models. ::: --- --- url: /api/classes/AlpacaChatWrapper.md --- # Class: AlpacaChatWrapper Defined in: [chatWrappers/AlpacaChatWrapper.ts:8](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/AlpacaChatWrapper.ts#L8) This chat wrapper is not safe against chat syntax injection attacks ([learn more](https://node-llama-cpp.withcat.ai/guide/llama-text#input-safety-in-node-llama-cpp)). ## Extends * [`GeneralChatWrapper`](GeneralChatWrapper.md) ## Constructors ### Constructor ```ts new AlpacaChatWrapper(__namedParameters?: { userMessageTitle?: string; modelResponseTitle?: string; middleSystemMessageTitle?: string; allowSpecialTokensInTitles?: boolean; }): AlpacaChatWrapper; ``` Defined in: [chatWrappers/AlpacaChatWrapper.ts:11](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/AlpacaChatWrapper.ts#L11) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | { `userMessageTitle?`: `string`; `modelResponseTitle?`: `string`; `middleSystemMessageTitle?`: `string`; `allowSpecialTokensInTitles?`: `boolean`; } | | `__namedParameters.userMessageTitle?` | `string` | | `__namedParameters.modelResponseTitle?` | `string` | | `__namedParameters.middleSystemMessageTitle?` | `string` | | `__namedParameters.allowSpecialTokensInTitles?` | `boolean` | #### Returns `AlpacaChatWrapper` #### Overrides [`GeneralChatWrapper`](GeneralChatWrapper.md).[`constructor`](GeneralChatWrapper.md#constructor) ## Properties ### defaultSettings ```ts static defaultSettings: ChatWrapperSettings; ``` Defined in: [ChatWrapper.ts:15](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L15) #### Inherited from [`GeneralChatWrapper`](GeneralChatWrapper.md).[`defaultSettings`](GeneralChatWrapper.md#defaultsettings) *** ### settings ```ts readonly settings: ChatWrapperSettings = ChatWrapper.defaultSettings; ``` Defined in: [ChatWrapper.ts:36](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L36) #### Inherited from [`GeneralChatWrapper`](GeneralChatWrapper.md).[`settings`](GeneralChatWrapper.md#settings) *** ### wrapperName ```ts readonly wrapperName: string = "AlpacaChat"; ``` Defined in: [chatWrappers/AlpacaChatWrapper.ts:9](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/AlpacaChatWrapper.ts#L9) #### Overrides [`GeneralChatWrapper`](GeneralChatWrapper.md).[`wrapperName`](GeneralChatWrapper.md#wrappername) ## Accessors ### userMessageTitle #### Get Signature ```ts get userMessageTitle(): string; ``` Defined in: [chatWrappers/AlpacaChatWrapper.ts:25](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/AlpacaChatWrapper.ts#L25) ##### Returns `string` #### Overrides [`GeneralChatWrapper`](GeneralChatWrapper.md).[`userMessageTitle`](GeneralChatWrapper.md#usermessagetitle) *** ### modelResponseTitle #### Get Signature ```ts get modelResponseTitle(): string; ``` Defined in: [chatWrappers/AlpacaChatWrapper.ts:29](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/AlpacaChatWrapper.ts#L29) ##### Returns `string` #### Overrides [`GeneralChatWrapper`](GeneralChatWrapper.md).[`modelResponseTitle`](GeneralChatWrapper.md#modelresponsetitle) *** ### middleSystemMessageTitle #### Get Signature ```ts get middleSystemMessageTitle(): string; ``` Defined in: [chatWrappers/AlpacaChatWrapper.ts:33](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/AlpacaChatWrapper.ts#L33) ##### Returns `string` #### Overrides [`GeneralChatWrapper`](GeneralChatWrapper.md).[`middleSystemMessageTitle`](GeneralChatWrapper.md#middlesystemmessagetitle) ## Methods ### generateFunctionCallsAndResults() ```ts generateFunctionCallsAndResults(functionCalls: ChatModelFunctionCall[], useRawCall?: boolean): LlamaText; ``` Defined in: [ChatWrapper.ts:63](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L63) #### Parameters | Parameter | Type | Default value | | ------ | ------ | ------ | | `functionCalls` | [`ChatModelFunctionCall`](../type-aliases/ChatModelFunctionCall.md)\[] | `undefined` | | `useRawCall` | `boolean` | `true` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`GeneralChatWrapper`](GeneralChatWrapper.md).[`generateFunctionCallsAndResults`](GeneralChatWrapper.md#generatefunctioncallsandresults) *** ### generateFunctionCall() ```ts generateFunctionCall(name: string, params: any): LlamaText; ``` Defined in: [ChatWrapper.ts:110](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L110) #### Parameters | Parameter | Type | | ------ | ------ | | `name` | `string` | | `params` | `any` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`GeneralChatWrapper`](GeneralChatWrapper.md).[`generateFunctionCall`](GeneralChatWrapper.md#generatefunctioncall) *** ### generateFunctionCallResult() ```ts generateFunctionCallResult( functionName: string, functionParams: any, result: any): LlamaText; ``` Defined in: [ChatWrapper.ts:127](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L127) #### Parameters | Parameter | Type | | ------ | ------ | | `functionName` | `string` | | `functionParams` | `any` | | `result` | `any` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`GeneralChatWrapper`](GeneralChatWrapper.md).[`generateFunctionCallResult`](GeneralChatWrapper.md#generatefunctioncallresult) *** ### generateModelResponseText() ```ts generateModelResponseText(modelResponse: ( | string | ChatModelFunctionCall | ChatModelSegment)[], useRawValues?: boolean): LlamaText; ``` Defined in: [ChatWrapper.ts:158](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L158) #### Parameters | Parameter | Type | Default value | | ------ | ------ | ------ | | `modelResponse` | ( | `string` | [`ChatModelFunctionCall`](../type-aliases/ChatModelFunctionCall.md) | [`ChatModelSegment`](../type-aliases/ChatModelSegment.md))\[] | `undefined` | | `useRawValues` | `boolean` | `true` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`GeneralChatWrapper`](GeneralChatWrapper.md).[`generateModelResponseText`](GeneralChatWrapper.md#generatemodelresponsetext) *** ### generateAvailableFunctionsSystemText() ```ts generateAvailableFunctionsSystemText(availableFunctions: ChatModelFunctions, __namedParameters: { documentParams?: boolean; }): LlamaText; ``` Defined in: [ChatWrapper.ts:243](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L243) #### Parameters | Parameter | Type | | ------ | ------ | | `availableFunctions` | [`ChatModelFunctions`](../type-aliases/ChatModelFunctions.md) | | `__namedParameters` | { `documentParams?`: `boolean`; } | | `__namedParameters.documentParams?` | `boolean` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`GeneralChatWrapper`](GeneralChatWrapper.md).[`generateAvailableFunctionsSystemText`](GeneralChatWrapper.md#generateavailablefunctionssystemtext) *** ### addAvailableFunctionsSystemMessageToHistory() ```ts addAvailableFunctionsSystemMessageToHistory( history: readonly ChatHistoryItem[], availableFunctions?: ChatModelFunctions, __namedParameters?: { documentParams?: boolean; }): readonly ChatHistoryItem[]; ``` Defined in: [ChatWrapper.ts:269](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L269) #### Parameters | Parameter | Type | | ------ | ------ | | `history` | readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] | | `availableFunctions?` | [`ChatModelFunctions`](../type-aliases/ChatModelFunctions.md) | | `__namedParameters?` | { `documentParams?`: `boolean`; } | | `__namedParameters.documentParams?` | `boolean` | #### Returns readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] #### Inherited from [`GeneralChatWrapper`](GeneralChatWrapper.md).[`addAvailableFunctionsSystemMessageToHistory`](GeneralChatWrapper.md#addavailablefunctionssystemmessagetohistory) *** ### generateInitialChatHistory() ```ts generateInitialChatHistory(__namedParameters?: ChatWrapperGenerateInitialHistoryOptions): ChatHistoryItem[]; ``` Defined in: [ChatWrapper.ts:290](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L290) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | [`ChatWrapperGenerateInitialHistoryOptions`](../type-aliases/ChatWrapperGenerateInitialHistoryOptions.md) | #### Returns [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] #### Inherited from [`GeneralChatWrapper`](GeneralChatWrapper.md).[`generateInitialChatHistory`](GeneralChatWrapper.md#generateinitialchathistory) *** ### generateContextState() ```ts generateContextState(__namedParameters: ChatWrapperGenerateContextStateOptions): ChatWrapperGeneratedContextState; ``` Defined in: [chatWrappers/GeneralChatWrapper.ts:43](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/GeneralChatWrapper.ts#L43) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | [`ChatWrapperGenerateContextStateOptions`](../type-aliases/ChatWrapperGenerateContextStateOptions.md) | #### Returns [`ChatWrapperGeneratedContextState`](../type-aliases/ChatWrapperGeneratedContextState.md) #### Inherited from [`GeneralChatWrapper`](GeneralChatWrapper.md).[`generateContextState`](GeneralChatWrapper.md#generatecontextstate) --- --- url: /api/classes/ChatMLChatWrapper.md --- # Class: ChatMLChatWrapper Defined in: [chatWrappers/ChatMLChatWrapper.ts:6](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/ChatMLChatWrapper.ts#L6) ## Extends * [`ChatWrapper`](ChatWrapper.md) ## Constructors ### Constructor ```ts new ChatMLChatWrapper(): ChatMLChatWrapper; ``` #### Returns `ChatMLChatWrapper` #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`constructor`](ChatWrapper.md#constructor) ## Properties ### defaultSettings ```ts static defaultSettings: ChatWrapperSettings; ``` Defined in: [ChatWrapper.ts:15](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L15) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`defaultSettings`](ChatWrapper.md#defaultsettings) *** ### settings ```ts readonly settings: ChatWrapperSettings = ChatWrapper.defaultSettings; ``` Defined in: [ChatWrapper.ts:36](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L36) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`settings`](ChatWrapper.md#settings) *** ### wrapperName ```ts readonly wrapperName: string = "ChatML"; ``` Defined in: [chatWrappers/ChatMLChatWrapper.ts:7](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/ChatMLChatWrapper.ts#L7) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`wrapperName`](ChatWrapper.md#wrappername) ## Methods ### generateFunctionCallsAndResults() ```ts generateFunctionCallsAndResults(functionCalls: ChatModelFunctionCall[], useRawCall?: boolean): LlamaText; ``` Defined in: [ChatWrapper.ts:63](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L63) #### Parameters | Parameter | Type | Default value | | ------ | ------ | ------ | | `functionCalls` | [`ChatModelFunctionCall`](../type-aliases/ChatModelFunctionCall.md)\[] | `undefined` | | `useRawCall` | `boolean` | `true` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCallsAndResults`](ChatWrapper.md#generatefunctioncallsandresults) *** ### generateFunctionCall() ```ts generateFunctionCall(name: string, params: any): LlamaText; ``` Defined in: [ChatWrapper.ts:110](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L110) #### Parameters | Parameter | Type | | ------ | ------ | | `name` | `string` | | `params` | `any` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCall`](ChatWrapper.md#generatefunctioncall) *** ### generateFunctionCallResult() ```ts generateFunctionCallResult( functionName: string, functionParams: any, result: any): LlamaText; ``` Defined in: [ChatWrapper.ts:127](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L127) #### Parameters | Parameter | Type | | ------ | ------ | | `functionName` | `string` | | `functionParams` | `any` | | `result` | `any` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCallResult`](ChatWrapper.md#generatefunctioncallresult) *** ### generateModelResponseText() ```ts generateModelResponseText(modelResponse: ( | string | ChatModelFunctionCall | ChatModelSegment)[], useRawValues?: boolean): LlamaText; ``` Defined in: [ChatWrapper.ts:158](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L158) #### Parameters | Parameter | Type | Default value | | ------ | ------ | ------ | | `modelResponse` | ( | `string` | [`ChatModelFunctionCall`](../type-aliases/ChatModelFunctionCall.md) | [`ChatModelSegment`](../type-aliases/ChatModelSegment.md))\[] | `undefined` | | `useRawValues` | `boolean` | `true` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateModelResponseText`](ChatWrapper.md#generatemodelresponsetext) *** ### generateAvailableFunctionsSystemText() ```ts generateAvailableFunctionsSystemText(availableFunctions: ChatModelFunctions, __namedParameters: { documentParams?: boolean; }): LlamaText; ``` Defined in: [ChatWrapper.ts:243](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L243) #### Parameters | Parameter | Type | | ------ | ------ | | `availableFunctions` | [`ChatModelFunctions`](../type-aliases/ChatModelFunctions.md) | | `__namedParameters` | { `documentParams?`: `boolean`; } | | `__namedParameters.documentParams?` | `boolean` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateAvailableFunctionsSystemText`](ChatWrapper.md#generateavailablefunctionssystemtext) *** ### addAvailableFunctionsSystemMessageToHistory() ```ts addAvailableFunctionsSystemMessageToHistory( history: readonly ChatHistoryItem[], availableFunctions?: ChatModelFunctions, __namedParameters?: { documentParams?: boolean; }): readonly ChatHistoryItem[]; ``` Defined in: [ChatWrapper.ts:269](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L269) #### Parameters | Parameter | Type | | ------ | ------ | | `history` | readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] | | `availableFunctions?` | [`ChatModelFunctions`](../type-aliases/ChatModelFunctions.md) | | `__namedParameters?` | { `documentParams?`: `boolean`; } | | `__namedParameters.documentParams?` | `boolean` | #### Returns readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`addAvailableFunctionsSystemMessageToHistory`](ChatWrapper.md#addavailablefunctionssystemmessagetohistory) *** ### generateInitialChatHistory() ```ts generateInitialChatHistory(__namedParameters?: ChatWrapperGenerateInitialHistoryOptions): ChatHistoryItem[]; ``` Defined in: [ChatWrapper.ts:290](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L290) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | [`ChatWrapperGenerateInitialHistoryOptions`](../type-aliases/ChatWrapperGenerateInitialHistoryOptions.md) | #### Returns [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateInitialChatHistory`](ChatWrapper.md#generateinitialchathistory) *** ### generateContextState() ```ts generateContextState(__namedParameters: ChatWrapperGenerateContextStateOptions): ChatWrapperGeneratedContextState; ``` Defined in: [chatWrappers/ChatMLChatWrapper.ts:9](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/ChatMLChatWrapper.ts#L9) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | [`ChatWrapperGenerateContextStateOptions`](../type-aliases/ChatWrapperGenerateContextStateOptions.md) | #### Returns [`ChatWrapperGeneratedContextState`](../type-aliases/ChatWrapperGeneratedContextState.md) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`generateContextState`](ChatWrapper.md#generatecontextstate) --- --- url: /api/classes/ChatModelFunctionsDocumentationGenerator.md --- # Class: ChatModelFunctionsDocumentationGenerator Defined in: [chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.ts:9](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.ts#L9) Generate documentation about the functions that are available for a model to call. Useful for generating a system message with information about the available functions as part of a chat wrapper. ## Constructors ### Constructor ```ts new ChatModelFunctionsDocumentationGenerator(chatModelFunctions: | ChatModelFunctions | undefined): ChatModelFunctionsDocumentationGenerator; ``` Defined in: [chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.ts:13](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.ts#L13) #### Parameters | Parameter | Type | | ------ | ------ | | `chatModelFunctions` | | [`ChatModelFunctions`](../type-aliases/ChatModelFunctions.md) | `undefined` | #### Returns `ChatModelFunctionsDocumentationGenerator` ## Properties ### chatModelFunctions? ```ts readonly optional chatModelFunctions: ChatModelFunctions; ``` Defined in: [chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.ts:10](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.ts#L10) *** ### hasAnyFunctions ```ts readonly hasAnyFunctions: boolean; ``` Defined in: [chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.ts:11](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.ts#L11) ## Methods ### getTypeScriptFunctionSignatures() ```ts getTypeScriptFunctionSignatures(options?: { documentParams?: boolean; }): string; ``` Defined in: [chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.ts:30](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.ts#L30) Example: ```ts // Retrieve the current date function getDate(); // Retrieve the current time function getTime(params: {hours: "24" | "12", seconds: boolean}); ``` #### Parameters | Parameter | Type | Description | | ------ | ------ | ------ | | `options` | { `documentParams?`: `boolean`; } | - | | `options.documentParams?` | `boolean` | Whether to document the parameters of the functions | #### Returns `string` *** ### getTypeScriptFunctionTypes() ```ts getTypeScriptFunctionTypes(options?: { documentParams?: boolean; reservedFunctionNames?: string[]; }): string; ``` Defined in: [chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.ts:73](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.ts#L73) Example: ```ts // Retrieve the current date type getDate = () => any; // Retrieve the current time type getTime = (_: {hours: "24" | "12", seconds: boolean}) => any; ``` #### Parameters | Parameter | Type | Description | | ------ | ------ | ------ | | `options` | { `documentParams?`: `boolean`; `reservedFunctionNames?`: `string`\[]; } | - | | `options.documentParams?` | `boolean` | Whether to document the parameters of the functions | | `options.reservedFunctionNames?` | `string`\[] | Function names that are reserved and cannot be used | #### Returns `string` *** ### getLlama3\_1FunctionSignatures() ```ts getLlama3_1FunctionSignatures(options?: { documentParams?: boolean; }): string; ``` Defined in: [chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.ts:120](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.ts#L120) Example: ``` Use the function 'getDate' to: Retrieve the current date {"name": "getDate", "description": "Retrieve the current date"} Use the function 'getTime' to: Retrieve the current time {"name": "getTime", "description": "Retrieve the current time", "parameters": {"type": "object", "properties": {"hours": {"enum": ["24", "12"]}, "seconds": {"type": "boolean"}}}} ``` #### Parameters | Parameter | Type | Description | | ------ | ------ | ------ | | `options` | { `documentParams?`: `boolean`; } | - | | `options.documentParams?` | `boolean` | Whether to document the parameters of the functions | #### Returns `string` *** ### getLlama3\_2LightweightFunctionSignatures() ```ts getLlama3_2LightweightFunctionSignatures(options?: { documentParams?: boolean; }): string; ``` Defined in: [chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.ts:162](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.ts#L162) Example: ``` {"name": "getDate", "description": "Retrieve the current date"} {"name": "getTime", "description": "Retrieve the current time", "parameters": {"type": "object", "properties": {"hours": {"enum": ["24", "12"]}, "seconds": {"type": "boolean"}}}} ``` #### Parameters | Parameter | Type | Description | | ------ | ------ | ------ | | `options` | { `documentParams?`: `boolean`; } | - | | `options.documentParams?` | `boolean` | Whether to document the parameters of the functions | #### Returns `string` *** ### getQwenFunctionSignatures() ```ts getQwenFunctionSignatures(__namedParameters?: { documentParams?: boolean; }): string; ``` Defined in: [chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.ts:188](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.ts#L188) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | { `documentParams?`: `boolean`; } | | `__namedParameters.documentParams?` | `boolean` | #### Returns `string` *** ### getSeedFunctionSignatures() ```ts getSeedFunctionSignatures(__namedParameters?: { documentParams?: boolean; }): string; ``` Defined in: [chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.ts:194](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.ts#L194) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | { `documentParams?`: `boolean`; } | | `__namedParameters.documentParams?` | `boolean` | #### Returns `string` --- --- url: /api/classes/CombinedModelDownloader.md --- # Class: CombinedModelDownloader Defined in: [utils/createModelDownloader.ts:575](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/createModelDownloader.ts#L575) ## Accessors ### modelDownloaders #### Get Signature ```ts get modelDownloaders(): readonly ModelDownloader[]; ``` Defined in: [utils/createModelDownloader.ts:660](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/createModelDownloader.ts#L660) ##### Returns readonly [`ModelDownloader`](ModelDownloader.md)\[] *** ### entrypointFilenames #### Get Signature ```ts get entrypointFilenames(): string[]; ``` Defined in: [utils/createModelDownloader.ts:667](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/createModelDownloader.ts#L667) The filename of the entrypoint files that should be used to load the models. ##### Returns `string`\[] *** ### entrypointFilePaths #### Get Signature ```ts get entrypointFilePaths(): string[]; ``` Defined in: [utils/createModelDownloader.ts:674](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/createModelDownloader.ts#L674) The full paths to the entrypoint files that should be used to load the models. ##### Returns `string`\[] *** ### totalFiles #### Get Signature ```ts get totalFiles(): number; ``` Defined in: [utils/createModelDownloader.ts:681](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/createModelDownloader.ts#L681) The accumulation of `totalFiles` of all the model downloaders ##### Returns `number` *** ### totalSize #### Get Signature ```ts get totalSize(): number; ``` Defined in: [utils/createModelDownloader.ts:687](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/createModelDownloader.ts#L687) ##### Returns `number` *** ### downloadedSize #### Get Signature ```ts get downloadedSize(): number; ``` Defined in: [utils/createModelDownloader.ts:693](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/createModelDownloader.ts#L693) ##### Returns `number` ## Methods ### cancel() ```ts cancel(): Promise; ``` Defined in: [utils/createModelDownloader.ts:606](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/createModelDownloader.ts#L606) #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`> *** ### download() ```ts download(__namedParameters?: { signal?: AbortSignal; }): Promise; ``` Defined in: [utils/createModelDownloader.ts:623](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/createModelDownloader.ts#L623) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | { `signal?`: `AbortSignal`; } | | `__namedParameters.signal?` | `AbortSignal` | #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`string`\[]> The paths to the entrypoint files that should be used to load the models --- --- url: /api/classes/DeepSeekChatWrapper.md --- # Class: DeepSeekChatWrapper Defined in: [chatWrappers/DeepSeekChatWrapper.ts:11](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/DeepSeekChatWrapper.ts#L11) ## Extends * [`ChatWrapper`](ChatWrapper.md) ## Constructors ### Constructor ```ts new DeepSeekChatWrapper(options?: { keepOnlyLastThought?: boolean; functionCallingSyntax?: "r1-workaround" | "simplified" | "original"; parallelFunctionCalling?: boolean; }): DeepSeekChatWrapper; ``` Defined in: [chatWrappers/DeepSeekChatWrapper.ts:20](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/DeepSeekChatWrapper.ts#L20) #### Parameters | Parameter | Type | Description | | ------ | ------ | ------ | | `options` | { `keepOnlyLastThought?`: `boolean`; `functionCallingSyntax?`: `"r1-workaround"` | `"simplified"` | `"original"`; `parallelFunctionCalling?`: `boolean`; } | - | | `options.keepOnlyLastThought?` | `boolean` | Whether to keep only the chain of thought from the last model response. Setting this to `false` will keep all the chain of thoughts from the model responses in the context state. Defaults to `true`. | | `options.functionCallingSyntax?` | `"r1-workaround"` | `"simplified"` | `"original"` | Use a different variation function calling syntax to improve syntax compliance. Defaults to `"r1-workaround"`. | | `options.parallelFunctionCalling?` | `boolean` | Support parallel function calling. May not work well with all distill model variations, as some distillation models make unnecessary additional calls in parallel. Defaults to `false`. | #### Returns `DeepSeekChatWrapper` #### Overrides [`ChatWrapper`](ChatWrapper.md).[`constructor`](ChatWrapper.md#constructor) ## Properties ### defaultSettings ```ts static defaultSettings: ChatWrapperSettings; ``` Defined in: [ChatWrapper.ts:15](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L15) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`defaultSettings`](ChatWrapper.md#defaultsettings) *** ### wrapperName ```ts readonly wrapperName: string = "DeepSeek"; ``` Defined in: [chatWrappers/DeepSeekChatWrapper.ts:12](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/DeepSeekChatWrapper.ts#L12) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`wrapperName`](ChatWrapper.md#wrappername) *** ### keepOnlyLastThought ```ts readonly keepOnlyLastThought: boolean; ``` Defined in: [chatWrappers/DeepSeekChatWrapper.ts:14](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/DeepSeekChatWrapper.ts#L14) *** ### functionCallingSyntax ```ts readonly functionCallingSyntax: "r1-workaround" | "simplified" | "original"; ``` Defined in: [chatWrappers/DeepSeekChatWrapper.ts:15](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/DeepSeekChatWrapper.ts#L15) *** ### parallelFunctionCalling ```ts readonly parallelFunctionCalling: boolean; ``` Defined in: [chatWrappers/DeepSeekChatWrapper.ts:16](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/DeepSeekChatWrapper.ts#L16) *** ### settings ```ts readonly settings: ChatWrapperSettings; ``` Defined in: [chatWrappers/DeepSeekChatWrapper.ts:18](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/DeepSeekChatWrapper.ts#L18) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`settings`](ChatWrapper.md#settings) ## Methods ### generateFunctionCallsAndResults() ```ts generateFunctionCallsAndResults(functionCalls: ChatModelFunctionCall[], useRawCall?: boolean): LlamaText; ``` Defined in: [ChatWrapper.ts:63](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L63) #### Parameters | Parameter | Type | Default value | | ------ | ------ | ------ | | `functionCalls` | [`ChatModelFunctionCall`](../type-aliases/ChatModelFunctionCall.md)\[] | `undefined` | | `useRawCall` | `boolean` | `true` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCallsAndResults`](ChatWrapper.md#generatefunctioncallsandresults) *** ### generateFunctionCall() ```ts generateFunctionCall(name: string, params: any): LlamaText; ``` Defined in: [ChatWrapper.ts:110](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L110) #### Parameters | Parameter | Type | | ------ | ------ | | `name` | `string` | | `params` | `any` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCall`](ChatWrapper.md#generatefunctioncall) *** ### generateFunctionCallResult() ```ts generateFunctionCallResult( functionName: string, functionParams: any, result: any): LlamaText; ``` Defined in: [ChatWrapper.ts:127](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L127) #### Parameters | Parameter | Type | | ------ | ------ | | `functionName` | `string` | | `functionParams` | `any` | | `result` | `any` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCallResult`](ChatWrapper.md#generatefunctioncallresult) *** ### generateModelResponseText() ```ts generateModelResponseText(modelResponse: ( | string | ChatModelFunctionCall | ChatModelSegment)[], useRawValues?: boolean): LlamaText; ``` Defined in: [ChatWrapper.ts:158](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L158) #### Parameters | Parameter | Type | Default value | | ------ | ------ | ------ | | `modelResponse` | ( | `string` | [`ChatModelFunctionCall`](../type-aliases/ChatModelFunctionCall.md) | [`ChatModelSegment`](../type-aliases/ChatModelSegment.md))\[] | `undefined` | | `useRawValues` | `boolean` | `true` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateModelResponseText`](ChatWrapper.md#generatemodelresponsetext) *** ### addAvailableFunctionsSystemMessageToHistory() ```ts addAvailableFunctionsSystemMessageToHistory( history: readonly ChatHistoryItem[], availableFunctions?: ChatModelFunctions, __namedParameters?: { documentParams?: boolean; }): readonly ChatHistoryItem[]; ``` Defined in: [ChatWrapper.ts:269](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L269) #### Parameters | Parameter | Type | | ------ | ------ | | `history` | readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] | | `availableFunctions?` | [`ChatModelFunctions`](../type-aliases/ChatModelFunctions.md) | | `__namedParameters?` | { `documentParams?`: `boolean`; } | | `__namedParameters.documentParams?` | `boolean` | #### Returns readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`addAvailableFunctionsSystemMessageToHistory`](ChatWrapper.md#addavailablefunctionssystemmessagetohistory) *** ### generateInitialChatHistory() ```ts generateInitialChatHistory(__namedParameters?: ChatWrapperGenerateInitialHistoryOptions): ChatHistoryItem[]; ``` Defined in: [ChatWrapper.ts:290](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L290) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | [`ChatWrapperGenerateInitialHistoryOptions`](../type-aliases/ChatWrapperGenerateInitialHistoryOptions.md) | #### Returns [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateInitialChatHistory`](ChatWrapper.md#generateinitialchathistory) *** ### generateContextState() ```ts generateContextState(__namedParameters: ChatWrapperGenerateContextStateOptions): ChatWrapperGeneratedContextState; ``` Defined in: [chatWrappers/DeepSeekChatWrapper.ts:173](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/DeepSeekChatWrapper.ts#L173) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | [`ChatWrapperGenerateContextStateOptions`](../type-aliases/ChatWrapperGenerateContextStateOptions.md) | #### Returns [`ChatWrapperGeneratedContextState`](../type-aliases/ChatWrapperGeneratedContextState.md) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`generateContextState`](ChatWrapper.md#generatecontextstate) *** ### generateAvailableFunctionsSystemText() ```ts generateAvailableFunctionsSystemText(availableFunctions: ChatModelFunctions, __namedParameters: { documentParams?: boolean; }): LlamaText; ``` Defined in: [chatWrappers/DeepSeekChatWrapper.ts:230](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/DeepSeekChatWrapper.ts#L230) #### Parameters | Parameter | Type | | ------ | ------ | | `availableFunctions` | [`ChatModelFunctions`](../type-aliases/ChatModelFunctions.md) | | `__namedParameters` | { `documentParams?`: `boolean`; } | | `__namedParameters.documentParams?` | `boolean` | #### Returns [`LlamaText`](LlamaText.md) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`generateAvailableFunctionsSystemText`](ChatWrapper.md#generateavailablefunctionssystemtext) --- --- url: /api/classes/DraftSequenceTokenPredictor.md --- # Class: DraftSequenceTokenPredictor Defined in: [evaluator/LlamaContext/tokenPredictors/DraftSequenceTokenPredictor.ts:20](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/tokenPredictors/DraftSequenceTokenPredictor.ts#L20) Predicts the next tokens by evaluating the current state of the target sequence on a draft sequence from a smaller and faster draft model. ## See [Using Token Predictors: Draft Model Token Predictor](https://node-llama-cpp.withcat.ai/guide/token-prediction#draft-model) ## Extends * [`TokenPredictor`](TokenPredictor.md) ## Constructors ### Constructor ```ts new DraftSequenceTokenPredictor(draftSequence: LlamaContextSequence, options?: { minTokens?: number; maxTokens?: number; evaluateOptions?: Pick; minConfidence?: number; }): DraftSequenceTokenPredictor; ``` Defined in: [evaluator/LlamaContext/tokenPredictors/DraftSequenceTokenPredictor.ts:41](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/tokenPredictors/DraftSequenceTokenPredictor.ts#L41) #### Parameters | Parameter | Type | Description | | ------ | ------ | ------ | | `draftSequence` | [`LlamaContextSequence`](LlamaContextSequence.md) | - | | `options` | { `minTokens?`: `number`; `maxTokens?`: `number`; `evaluateOptions?`: [`Pick`](https://www.typescriptlang.org/docs/handbook/utility-types.html#picktype-keys)<[`SequenceEvaluateOptions`](../type-aliases/SequenceEvaluateOptions.md), | `"contextShift"` | `"evaluationPriority"` | `"temperature"` | `"minP"` | `"topK"` | `"topP"` | `"seed"` | `"xtc"` | `"repeatPenalty"` | `"dryRepeatPenalty"` | `"tokenBias"`>; `minConfidence?`: `number`; } | - | | `options.minTokens?` | `number` | The minimum number of tokens to draft. Defaults to `0`. | | `options.maxTokens?` | `number` | Maximum number of tokens to draft. Defaults to `16`. | | `options.evaluateOptions?` | [`Pick`](https://www.typescriptlang.org/docs/handbook/utility-types.html#picktype-keys)<[`SequenceEvaluateOptions`](../type-aliases/SequenceEvaluateOptions.md), | `"contextShift"` | `"evaluationPriority"` | `"temperature"` | `"minP"` | `"topK"` | `"topP"` | `"seed"` | `"xtc"` | `"repeatPenalty"` | `"dryRepeatPenalty"` | `"tokenBias"`> | Evaluate options default to the values of the target sequence. You can override any of the options for the prediction here. | | `options.minConfidence?` | `number` | Minimum token confidence (probability of the token to be generated, assigned by the model) to consider the token as a prediction. When the generated token confidence is lower than this value, the prediction process will stop until all the predicted tokens are exhausted (either by a token that was not predicted being pushed, or all the generated predictions are consumed). A number between `0` and `1` representing the minimum probability of the token to be generated. Set to `0` to disable. Defaults to `0.6`. | #### Returns `DraftSequenceTokenPredictor` #### Overrides [`TokenPredictor`](TokenPredictor.md).[`constructor`](TokenPredictor.md#constructor) ## Accessors ### draftSequence #### Get Signature ```ts get draftSequence(): LlamaContextSequence; ``` Defined in: [evaluator/LlamaContext/tokenPredictors/DraftSequenceTokenPredictor.ts:88](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/tokenPredictors/DraftSequenceTokenPredictor.ts#L88) ##### Returns [`LlamaContextSequence`](LlamaContextSequence.md) *** ### minTokens #### Get Signature ```ts get minTokens(): number; ``` Defined in: [evaluator/LlamaContext/tokenPredictors/DraftSequenceTokenPredictor.ts:92](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/tokenPredictors/DraftSequenceTokenPredictor.ts#L92) ##### Returns `number` *** ### maxTokens #### Get Signature ```ts get maxTokens(): number; ``` Defined in: [evaluator/LlamaContext/tokenPredictors/DraftSequenceTokenPredictor.ts:96](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/tokenPredictors/DraftSequenceTokenPredictor.ts#L96) ##### Returns `number` *** ### minConfidence #### Get Signature ```ts get minConfidence(): number | undefined; ``` Defined in: [evaluator/LlamaContext/tokenPredictors/DraftSequenceTokenPredictor.ts:100](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/tokenPredictors/DraftSequenceTokenPredictor.ts#L100) ##### Returns `number` | `undefined` ## Methods ### updateInputTokens() ```ts updateInputTokens(tokens: Token[]): void; ``` Defined in: [evaluator/LlamaContext/TokenPredictor.ts:57](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/TokenPredictor.ts#L57) Called with the input tokens before the generation starts when using `LlamaChatSession`, `LlamaChat`, and `LlamaCompletion`. #### Parameters | Parameter | Type | | ------ | ------ | | `tokens` | [`Token`](../type-aliases/Token.md)\[] | #### Returns `void` #### Inherited from [`TokenPredictor`](TokenPredictor.md).[`updateInputTokens`](TokenPredictor.md#updateinputtokens) *** ### reset() ```ts reset(__namedParameters: { targetSequence: LlamaContextSequence; stateTokens: Token[]; evaluateOptions: Readonly; }): Promise; ``` Defined in: [evaluator/LlamaContext/tokenPredictors/DraftSequenceTokenPredictor.ts:104](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/tokenPredictors/DraftSequenceTokenPredictor.ts#L104) Resets the state of the predictor. Called before the generation starts. #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | { `targetSequence`: [`LlamaContextSequence`](LlamaContextSequence.md); `stateTokens`: [`Token`](../type-aliases/Token.md)\[]; `evaluateOptions`: [`Readonly`](https://www.typescriptlang.org/docs/handbook/utility-types.html#readonlytype)<[`SequenceEvaluateOptions`](../type-aliases/SequenceEvaluateOptions.md)>; } | | `__namedParameters.targetSequence` | [`LlamaContextSequence`](LlamaContextSequence.md) | | `__namedParameters.stateTokens` | [`Token`](../type-aliases/Token.md)\[] | | `__namedParameters.evaluateOptions` | [`Readonly`](https://www.typescriptlang.org/docs/handbook/utility-types.html#readonlytype)<[`SequenceEvaluateOptions`](../type-aliases/SequenceEvaluateOptions.md)> | #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`> #### Overrides [`TokenPredictor`](TokenPredictor.md).[`reset`](TokenPredictor.md#reset) *** ### pushTokens() ```ts pushTokens(tokens: Token[]): void; ``` Defined in: [evaluator/LlamaContext/tokenPredictors/DraftSequenceTokenPredictor.ts:156](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/tokenPredictors/DraftSequenceTokenPredictor.ts#L156) #### Parameters | Parameter | Type | | ------ | ------ | | `tokens` | [`Token`](../type-aliases/Token.md)\[] | #### Returns `void` #### Overrides [`TokenPredictor`](TokenPredictor.md).[`pushTokens`](TokenPredictor.md#pushtokens) *** ### predictTokens() ```ts predictTokens(): | Token[] | Promise; ``` Defined in: [evaluator/LlamaContext/tokenPredictors/DraftSequenceTokenPredictor.ts:192](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/tokenPredictors/DraftSequenceTokenPredictor.ts#L192) Predicts the next tokens based on the current state. If the generation should wait until the minimum predications are ready, this method should return a promise that resolves when the minimum predictions are ready. A background prediction process can be started when this function is called, so that the next predictions will be ready when this function is called again. #### Returns | [`Token`](../type-aliases/Token.md)\[] | [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[`Token`](../type-aliases/Token.md)\[]> #### Overrides [`TokenPredictor`](TokenPredictor.md).[`predictTokens`](TokenPredictor.md#predicttokens) *** ### stop() ```ts stop(untilPredictionsExhausted?: boolean): void; ``` Defined in: [evaluator/LlamaContext/tokenPredictors/DraftSequenceTokenPredictor.ts:221](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/tokenPredictors/DraftSequenceTokenPredictor.ts#L221) Stops the prediction process when it runs in the background. #### Parameters | Parameter | Type | Default value | Description | | ------ | ------ | ------ | ------ | | `untilPredictionsExhausted` | `boolean` | `false` | If true, the prediction process should not resume until the current predictions are exhausted. | #### Returns `void` #### Overrides [`TokenPredictor`](TokenPredictor.md).[`stop`](TokenPredictor.md#stop) *** ### dispose() ```ts dispose(): void; ``` Defined in: [evaluator/LlamaContext/tokenPredictors/DraftSequenceTokenPredictor.ts:235](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/tokenPredictors/DraftSequenceTokenPredictor.ts#L235) #### Returns `void` #### Overrides [`TokenPredictor`](TokenPredictor.md).[`dispose`](TokenPredictor.md#dispose) --- --- url: /api/classes/EmptyChatWrapper.md --- # Class: EmptyChatWrapper Defined in: [chatWrappers/EmptyChatWrapper.ts:3](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/EmptyChatWrapper.ts#L3) ## Extends * [`ChatWrapper`](ChatWrapper.md) ## Constructors ### Constructor ```ts new EmptyChatWrapper(): EmptyChatWrapper; ``` #### Returns `EmptyChatWrapper` #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`constructor`](ChatWrapper.md#constructor) ## Properties ### defaultSettings ```ts static defaultSettings: ChatWrapperSettings; ``` Defined in: [ChatWrapper.ts:15](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L15) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`defaultSettings`](ChatWrapper.md#defaultsettings) *** ### settings ```ts readonly settings: ChatWrapperSettings = ChatWrapper.defaultSettings; ``` Defined in: [ChatWrapper.ts:36](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L36) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`settings`](ChatWrapper.md#settings) *** ### wrapperName ```ts readonly wrapperName: string = "Empty"; ``` Defined in: [chatWrappers/EmptyChatWrapper.ts:4](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/EmptyChatWrapper.ts#L4) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`wrapperName`](ChatWrapper.md#wrappername) ## Methods ### generateContextState() ```ts generateContextState(__namedParameters: ChatWrapperGenerateContextStateOptions): ChatWrapperGeneratedContextState; ``` Defined in: [ChatWrapper.ts:38](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L38) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | [`ChatWrapperGenerateContextStateOptions`](../type-aliases/ChatWrapperGenerateContextStateOptions.md) | #### Returns [`ChatWrapperGeneratedContextState`](../type-aliases/ChatWrapperGeneratedContextState.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateContextState`](ChatWrapper.md#generatecontextstate) *** ### generateFunctionCallsAndResults() ```ts generateFunctionCallsAndResults(functionCalls: ChatModelFunctionCall[], useRawCall?: boolean): LlamaText; ``` Defined in: [ChatWrapper.ts:63](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L63) #### Parameters | Parameter | Type | Default value | | ------ | ------ | ------ | | `functionCalls` | [`ChatModelFunctionCall`](../type-aliases/ChatModelFunctionCall.md)\[] | `undefined` | | `useRawCall` | `boolean` | `true` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCallsAndResults`](ChatWrapper.md#generatefunctioncallsandresults) *** ### generateFunctionCall() ```ts generateFunctionCall(name: string, params: any): LlamaText; ``` Defined in: [ChatWrapper.ts:110](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L110) #### Parameters | Parameter | Type | | ------ | ------ | | `name` | `string` | | `params` | `any` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCall`](ChatWrapper.md#generatefunctioncall) *** ### generateFunctionCallResult() ```ts generateFunctionCallResult( functionName: string, functionParams: any, result: any): LlamaText; ``` Defined in: [ChatWrapper.ts:127](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L127) #### Parameters | Parameter | Type | | ------ | ------ | | `functionName` | `string` | | `functionParams` | `any` | | `result` | `any` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCallResult`](ChatWrapper.md#generatefunctioncallresult) *** ### generateModelResponseText() ```ts generateModelResponseText(modelResponse: ( | string | ChatModelFunctionCall | ChatModelSegment)[], useRawValues?: boolean): LlamaText; ``` Defined in: [ChatWrapper.ts:158](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L158) #### Parameters | Parameter | Type | Default value | | ------ | ------ | ------ | | `modelResponse` | ( | `string` | [`ChatModelFunctionCall`](../type-aliases/ChatModelFunctionCall.md) | [`ChatModelSegment`](../type-aliases/ChatModelSegment.md))\[] | `undefined` | | `useRawValues` | `boolean` | `true` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateModelResponseText`](ChatWrapper.md#generatemodelresponsetext) *** ### generateAvailableFunctionsSystemText() ```ts generateAvailableFunctionsSystemText(availableFunctions: ChatModelFunctions, __namedParameters: { documentParams?: boolean; }): LlamaText; ``` Defined in: [ChatWrapper.ts:243](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L243) #### Parameters | Parameter | Type | | ------ | ------ | | `availableFunctions` | [`ChatModelFunctions`](../type-aliases/ChatModelFunctions.md) | | `__namedParameters` | { `documentParams?`: `boolean`; } | | `__namedParameters.documentParams?` | `boolean` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateAvailableFunctionsSystemText`](ChatWrapper.md#generateavailablefunctionssystemtext) *** ### addAvailableFunctionsSystemMessageToHistory() ```ts addAvailableFunctionsSystemMessageToHistory( history: readonly ChatHistoryItem[], availableFunctions?: ChatModelFunctions, __namedParameters?: { documentParams?: boolean; }): readonly ChatHistoryItem[]; ``` Defined in: [ChatWrapper.ts:269](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L269) #### Parameters | Parameter | Type | | ------ | ------ | | `history` | readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] | | `availableFunctions?` | [`ChatModelFunctions`](../type-aliases/ChatModelFunctions.md) | | `__namedParameters?` | { `documentParams?`: `boolean`; } | | `__namedParameters.documentParams?` | `boolean` | #### Returns readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`addAvailableFunctionsSystemMessageToHistory`](ChatWrapper.md#addavailablefunctionssystemmessagetohistory) *** ### generateInitialChatHistory() ```ts generateInitialChatHistory(__namedParameters?: ChatWrapperGenerateInitialHistoryOptions): ChatHistoryItem[]; ``` Defined in: [ChatWrapper.ts:290](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L290) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | [`ChatWrapperGenerateInitialHistoryOptions`](../type-aliases/ChatWrapperGenerateInitialHistoryOptions.md) | #### Returns [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateInitialChatHistory`](ChatWrapper.md#generateinitialchathistory) --- --- url: /api/classes/FalconChatWrapper.md --- # Class: FalconChatWrapper Defined in: [chatWrappers/FalconChatWrapper.ts:9](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/FalconChatWrapper.ts#L9) This chat wrapper is not safe against chat syntax injection attacks ([learn more](https://node-llama-cpp.withcat.ai/guide/llama-text#input-safety-in-node-llama-cpp)). ## Extends * [`ChatWrapper`](ChatWrapper.md) ## Constructors ### Constructor ```ts new FalconChatWrapper(__namedParameters?: { userMessageTitle?: string; modelResponseTitle?: string; middleSystemMessageTitle?: string; allowSpecialTokensInTitles?: boolean; }): FalconChatWrapper; ``` Defined in: [chatWrappers/FalconChatWrapper.ts:17](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/FalconChatWrapper.ts#L17) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | { `userMessageTitle?`: `string`; `modelResponseTitle?`: `string`; `middleSystemMessageTitle?`: `string`; `allowSpecialTokensInTitles?`: `boolean`; } | | `__namedParameters.userMessageTitle?` | `string` | | `__namedParameters.modelResponseTitle?` | `string` | | `__namedParameters.middleSystemMessageTitle?` | `string` | | `__namedParameters.allowSpecialTokensInTitles?` | `boolean` | #### Returns `FalconChatWrapper` #### Overrides [`ChatWrapper`](ChatWrapper.md).[`constructor`](ChatWrapper.md#constructor) ## Properties ### defaultSettings ```ts static defaultSettings: ChatWrapperSettings; ``` Defined in: [ChatWrapper.ts:15](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L15) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`defaultSettings`](ChatWrapper.md#defaultsettings) *** ### settings ```ts readonly settings: ChatWrapperSettings = ChatWrapper.defaultSettings; ``` Defined in: [ChatWrapper.ts:36](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L36) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`settings`](ChatWrapper.md#settings) *** ### wrapperName ```ts readonly wrapperName: string = "Falcon"; ``` Defined in: [chatWrappers/FalconChatWrapper.ts:10](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/FalconChatWrapper.ts#L10) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`wrapperName`](ChatWrapper.md#wrappername) ## Accessors ### userMessageTitle #### Get Signature ```ts get userMessageTitle(): string; ``` Defined in: [chatWrappers/FalconChatWrapper.ts:30](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/FalconChatWrapper.ts#L30) ##### Returns `string` *** ### modelResponseTitle #### Get Signature ```ts get modelResponseTitle(): string; ``` Defined in: [chatWrappers/FalconChatWrapper.ts:34](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/FalconChatWrapper.ts#L34) ##### Returns `string` *** ### middleSystemMessageTitle #### Get Signature ```ts get middleSystemMessageTitle(): string; ``` Defined in: [chatWrappers/FalconChatWrapper.ts:38](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/FalconChatWrapper.ts#L38) ##### Returns `string` ## Methods ### generateFunctionCallsAndResults() ```ts generateFunctionCallsAndResults(functionCalls: ChatModelFunctionCall[], useRawCall?: boolean): LlamaText; ``` Defined in: [ChatWrapper.ts:63](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L63) #### Parameters | Parameter | Type | Default value | | ------ | ------ | ------ | | `functionCalls` | [`ChatModelFunctionCall`](../type-aliases/ChatModelFunctionCall.md)\[] | `undefined` | | `useRawCall` | `boolean` | `true` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCallsAndResults`](ChatWrapper.md#generatefunctioncallsandresults) *** ### generateFunctionCall() ```ts generateFunctionCall(name: string, params: any): LlamaText; ``` Defined in: [ChatWrapper.ts:110](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L110) #### Parameters | Parameter | Type | | ------ | ------ | | `name` | `string` | | `params` | `any` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCall`](ChatWrapper.md#generatefunctioncall) *** ### generateFunctionCallResult() ```ts generateFunctionCallResult( functionName: string, functionParams: any, result: any): LlamaText; ``` Defined in: [ChatWrapper.ts:127](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L127) #### Parameters | Parameter | Type | | ------ | ------ | | `functionName` | `string` | | `functionParams` | `any` | | `result` | `any` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCallResult`](ChatWrapper.md#generatefunctioncallresult) *** ### generateModelResponseText() ```ts generateModelResponseText(modelResponse: ( | string | ChatModelFunctionCall | ChatModelSegment)[], useRawValues?: boolean): LlamaText; ``` Defined in: [ChatWrapper.ts:158](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L158) #### Parameters | Parameter | Type | Default value | | ------ | ------ | ------ | | `modelResponse` | ( | `string` | [`ChatModelFunctionCall`](../type-aliases/ChatModelFunctionCall.md) | [`ChatModelSegment`](../type-aliases/ChatModelSegment.md))\[] | `undefined` | | `useRawValues` | `boolean` | `true` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateModelResponseText`](ChatWrapper.md#generatemodelresponsetext) *** ### generateAvailableFunctionsSystemText() ```ts generateAvailableFunctionsSystemText(availableFunctions: ChatModelFunctions, __namedParameters: { documentParams?: boolean; }): LlamaText; ``` Defined in: [ChatWrapper.ts:243](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L243) #### Parameters | Parameter | Type | | ------ | ------ | | `availableFunctions` | [`ChatModelFunctions`](../type-aliases/ChatModelFunctions.md) | | `__namedParameters` | { `documentParams?`: `boolean`; } | | `__namedParameters.documentParams?` | `boolean` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateAvailableFunctionsSystemText`](ChatWrapper.md#generateavailablefunctionssystemtext) *** ### addAvailableFunctionsSystemMessageToHistory() ```ts addAvailableFunctionsSystemMessageToHistory( history: readonly ChatHistoryItem[], availableFunctions?: ChatModelFunctions, __namedParameters?: { documentParams?: boolean; }): readonly ChatHistoryItem[]; ``` Defined in: [ChatWrapper.ts:269](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L269) #### Parameters | Parameter | Type | | ------ | ------ | | `history` | readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] | | `availableFunctions?` | [`ChatModelFunctions`](../type-aliases/ChatModelFunctions.md) | | `__namedParameters?` | { `documentParams?`: `boolean`; } | | `__namedParameters.documentParams?` | `boolean` | #### Returns readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`addAvailableFunctionsSystemMessageToHistory`](ChatWrapper.md#addavailablefunctionssystemmessagetohistory) *** ### generateInitialChatHistory() ```ts generateInitialChatHistory(__namedParameters?: ChatWrapperGenerateInitialHistoryOptions): ChatHistoryItem[]; ``` Defined in: [ChatWrapper.ts:290](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L290) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | [`ChatWrapperGenerateInitialHistoryOptions`](../type-aliases/ChatWrapperGenerateInitialHistoryOptions.md) | #### Returns [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateInitialChatHistory`](ChatWrapper.md#generateinitialchathistory) *** ### generateContextState() ```ts generateContextState(__namedParameters: ChatWrapperGenerateContextStateOptions): ChatWrapperGeneratedContextState; ``` Defined in: [chatWrappers/FalconChatWrapper.ts:42](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/FalconChatWrapper.ts#L42) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | [`ChatWrapperGenerateContextStateOptions`](../type-aliases/ChatWrapperGenerateContextStateOptions.md) | #### Returns [`ChatWrapperGeneratedContextState`](../type-aliases/ChatWrapperGeneratedContextState.md) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`generateContextState`](ChatWrapper.md#generatecontextstate) --- --- url: /api/classes/FunctionaryChatWrapper.md --- # Class: FunctionaryChatWrapper Defined in: [chatWrappers/FunctionaryChatWrapper.ts:12](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/FunctionaryChatWrapper.ts#L12) ## Extends * [`ChatWrapper`](ChatWrapper.md) ## Constructors ### Constructor ```ts new FunctionaryChatWrapper(__namedParameters?: { variation?: "v3" | "v2" | "v2.llama3"; }): FunctionaryChatWrapper; ``` Defined in: [chatWrappers/FunctionaryChatWrapper.ts:18](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/FunctionaryChatWrapper.ts#L18) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | { `variation?`: `"v3"` | `"v2"` | `"v2.llama3"`; } | | `__namedParameters.variation?` | `"v3"` | `"v2"` | `"v2.llama3"` | #### Returns `FunctionaryChatWrapper` #### Overrides [`ChatWrapper`](ChatWrapper.md).[`constructor`](ChatWrapper.md#constructor) ## Properties ### defaultSettings ```ts static defaultSettings: ChatWrapperSettings; ``` Defined in: [ChatWrapper.ts:15](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L15) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`defaultSettings`](ChatWrapper.md#defaultsettings) *** ### wrapperName ```ts readonly wrapperName: string = "Functionary"; ``` Defined in: [chatWrappers/FunctionaryChatWrapper.ts:13](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/FunctionaryChatWrapper.ts#L13) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`wrapperName`](ChatWrapper.md#wrappername) *** ### variation ```ts readonly variation: "v3" | "v2" | "v2.llama3"; ``` Defined in: [chatWrappers/FunctionaryChatWrapper.ts:14](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/FunctionaryChatWrapper.ts#L14) *** ### settings ```ts readonly settings: ChatWrapperSettings; ``` Defined in: [chatWrappers/FunctionaryChatWrapper.ts:16](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/FunctionaryChatWrapper.ts#L16) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`settings`](ChatWrapper.md#settings) ## Methods ### generateFunctionCallsAndResults() ```ts generateFunctionCallsAndResults(functionCalls: ChatModelFunctionCall[], useRawCall?: boolean): LlamaText; ``` Defined in: [ChatWrapper.ts:63](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L63) #### Parameters | Parameter | Type | Default value | | ------ | ------ | ------ | | `functionCalls` | [`ChatModelFunctionCall`](../type-aliases/ChatModelFunctionCall.md)\[] | `undefined` | | `useRawCall` | `boolean` | `true` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCallsAndResults`](ChatWrapper.md#generatefunctioncallsandresults) *** ### generateFunctionCall() ```ts generateFunctionCall(name: string, params: any): LlamaText; ``` Defined in: [ChatWrapper.ts:110](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L110) #### Parameters | Parameter | Type | | ------ | ------ | | `name` | `string` | | `params` | `any` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCall`](ChatWrapper.md#generatefunctioncall) *** ### generateFunctionCallResult() ```ts generateFunctionCallResult( functionName: string, functionParams: any, result: any): LlamaText; ``` Defined in: [ChatWrapper.ts:127](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L127) #### Parameters | Parameter | Type | | ------ | ------ | | `functionName` | `string` | | `functionParams` | `any` | | `result` | `any` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCallResult`](ChatWrapper.md#generatefunctioncallresult) *** ### generateModelResponseText() ```ts generateModelResponseText(modelResponse: ( | string | ChatModelFunctionCall | ChatModelSegment)[], useRawValues?: boolean): LlamaText; ``` Defined in: [ChatWrapper.ts:158](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L158) #### Parameters | Parameter | Type | Default value | | ------ | ------ | ------ | | `modelResponse` | ( | `string` | [`ChatModelFunctionCall`](../type-aliases/ChatModelFunctionCall.md) | [`ChatModelSegment`](../type-aliases/ChatModelSegment.md))\[] | `undefined` | | `useRawValues` | `boolean` | `true` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateModelResponseText`](ChatWrapper.md#generatemodelresponsetext) *** ### generateInitialChatHistory() ```ts generateInitialChatHistory(__namedParameters?: ChatWrapperGenerateInitialHistoryOptions): ChatHistoryItem[]; ``` Defined in: [ChatWrapper.ts:290](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L290) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | [`ChatWrapperGenerateInitialHistoryOptions`](../type-aliases/ChatWrapperGenerateInitialHistoryOptions.md) | #### Returns [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateInitialChatHistory`](ChatWrapper.md#generateinitialchathistory) *** ### generateContextState() ```ts generateContextState(__namedParameters: ChatWrapperGenerateContextStateOptions): ChatWrapperGeneratedContextState; ``` Defined in: [chatWrappers/FunctionaryChatWrapper.ts:126](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/FunctionaryChatWrapper.ts#L126) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | [`ChatWrapperGenerateContextStateOptions`](../type-aliases/ChatWrapperGenerateContextStateOptions.md) | #### Returns [`ChatWrapperGeneratedContextState`](../type-aliases/ChatWrapperGeneratedContextState.md) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`generateContextState`](ChatWrapper.md#generatecontextstate) *** ### generateAvailableFunctionsSystemText() ```ts generateAvailableFunctionsSystemText(availableFunctions: ChatModelFunctions, __namedParameters: { documentParams?: boolean; }): LlamaText; ``` Defined in: [chatWrappers/FunctionaryChatWrapper.ts:655](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/FunctionaryChatWrapper.ts#L655) #### Parameters | Parameter | Type | | ------ | ------ | | `availableFunctions` | [`ChatModelFunctions`](../type-aliases/ChatModelFunctions.md) | | `__namedParameters` | { `documentParams?`: `boolean`; } | | `__namedParameters.documentParams?` | `boolean` | #### Returns [`LlamaText`](LlamaText.md) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`generateAvailableFunctionsSystemText`](ChatWrapper.md#generateavailablefunctionssystemtext) *** ### addAvailableFunctionsSystemMessageToHistory() ```ts addAvailableFunctionsSystemMessageToHistory( history: readonly ChatHistoryItem[], availableFunctions?: ChatModelFunctions, __namedParameters?: { documentParams?: boolean; }): readonly ChatHistoryItem[]; ``` Defined in: [chatWrappers/FunctionaryChatWrapper.ts:697](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/FunctionaryChatWrapper.ts#L697) #### Parameters | Parameter | Type | | ------ | ------ | | `history` | readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] | | `availableFunctions?` | [`ChatModelFunctions`](../type-aliases/ChatModelFunctions.md) | | `__namedParameters?` | { `documentParams?`: `boolean`; } | | `__namedParameters.documentParams?` | `boolean` | #### Returns readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] #### Overrides [`ChatWrapper`](ChatWrapper.md).[`addAvailableFunctionsSystemMessageToHistory`](ChatWrapper.md#addavailablefunctionssystemmessagetohistory) --- --- url: /api/classes/Gemma4ChatWrapper.md --- # Class: Gemma4ChatWrapper Defined in: [chatWrappers/Gemma4ChatWrapper.ts:10](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/Gemma4ChatWrapper.ts#L10) ## Extends * [`ChatWrapper`](ChatWrapper.md) ## Constructors ### Constructor ```ts new Gemma4ChatWrapper(options?: { reasoning?: boolean; keepOnlyLastThought?: boolean; }): Gemma4ChatWrapper; ``` Defined in: [chatWrappers/Gemma4ChatWrapper.ts:42](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/Gemma4ChatWrapper.ts#L42) #### Parameters | Parameter | Type | Description | | ------ | ------ | ------ | | `options` | { `reasoning?`: `boolean`; `keepOnlyLastThought?`: `boolean`; } | - | | `options.reasoning?` | `boolean` | Whether to promote the model to perform reasoning. Defaults to `true`. | | `options.keepOnlyLastThought?` | `boolean` | Whether to keep only the chain of thought from the last model response. Setting this to `false` will keep all the chain of thoughts from the model responses in the context state. Defaults to `true`. | #### Returns `Gemma4ChatWrapper` #### Overrides [`ChatWrapper`](ChatWrapper.md).[`constructor`](ChatWrapper.md#constructor) ## Properties ### defaultSettings ```ts static defaultSettings: ChatWrapperSettings; ``` Defined in: [ChatWrapper.ts:15](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L15) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`defaultSettings`](ChatWrapper.md#defaultsettings) *** ### wrapperName ```ts readonly wrapperName: string = "Gemma 4"; ``` Defined in: [chatWrappers/Gemma4ChatWrapper.ts:11](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/Gemma4ChatWrapper.ts#L11) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`wrapperName`](ChatWrapper.md#wrappername) *** ### reasoning ```ts readonly reasoning: boolean; ``` Defined in: [chatWrappers/Gemma4ChatWrapper.ts:13](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/Gemma4ChatWrapper.ts#L13) *** ### keepOnlyLastThought ```ts readonly keepOnlyLastThought: boolean; ``` Defined in: [chatWrappers/Gemma4ChatWrapper.ts:14](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/Gemma4ChatWrapper.ts#L14) *** ### settings ```ts readonly settings: ChatWrapperSettings; ``` Defined in: [chatWrappers/Gemma4ChatWrapper.ts:18](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/Gemma4ChatWrapper.ts#L18) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`settings`](ChatWrapper.md#settings) ## Methods ### generateFunctionCallsAndResults() ```ts generateFunctionCallsAndResults(functionCalls: ChatModelFunctionCall[], useRawCall?: boolean): LlamaText; ``` Defined in: [ChatWrapper.ts:63](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L63) #### Parameters | Parameter | Type | Default value | | ------ | ------ | ------ | | `functionCalls` | [`ChatModelFunctionCall`](../type-aliases/ChatModelFunctionCall.md)\[] | `undefined` | | `useRawCall` | `boolean` | `true` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCallsAndResults`](ChatWrapper.md#generatefunctioncallsandresults) *** ### generateFunctionCall() ```ts generateFunctionCall(name: string, params: any): LlamaText; ``` Defined in: [ChatWrapper.ts:110](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L110) #### Parameters | Parameter | Type | | ------ | ------ | | `name` | `string` | | `params` | `any` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCall`](ChatWrapper.md#generatefunctioncall) *** ### generateFunctionCallResult() ```ts generateFunctionCallResult( functionName: string, functionParams: any, result: any): LlamaText; ``` Defined in: [ChatWrapper.ts:127](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L127) #### Parameters | Parameter | Type | | ------ | ------ | | `functionName` | `string` | | `functionParams` | `any` | | `result` | `any` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCallResult`](ChatWrapper.md#generatefunctioncallresult) *** ### addAvailableFunctionsSystemMessageToHistory() ```ts addAvailableFunctionsSystemMessageToHistory( history: readonly ChatHistoryItem[], availableFunctions?: ChatModelFunctions, __namedParameters?: { documentParams?: boolean; }): readonly ChatHistoryItem[]; ``` Defined in: [ChatWrapper.ts:269](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L269) #### Parameters | Parameter | Type | | ------ | ------ | | `history` | readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] | | `availableFunctions?` | [`ChatModelFunctions`](../type-aliases/ChatModelFunctions.md) | | `__namedParameters?` | { `documentParams?`: `boolean`; } | | `__namedParameters.documentParams?` | `boolean` | #### Returns readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`addAvailableFunctionsSystemMessageToHistory`](ChatWrapper.md#addavailablefunctionssystemmessagetohistory) *** ### generateInitialChatHistory() ```ts generateInitialChatHistory(__namedParameters?: ChatWrapperGenerateInitialHistoryOptions): ChatHistoryItem[]; ``` Defined in: [ChatWrapper.ts:290](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L290) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | [`ChatWrapperGenerateInitialHistoryOptions`](../type-aliases/ChatWrapperGenerateInitialHistoryOptions.md) | #### Returns [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateInitialChatHistory`](ChatWrapper.md#generateinitialchathistory) *** ### generateContextState() ```ts generateContextState(__namedParameters: ChatWrapperGenerateContextStateOptions): ChatWrapperGeneratedContextState; ``` Defined in: [chatWrappers/Gemma4ChatWrapper.ts:75](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/Gemma4ChatWrapper.ts#L75) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | [`ChatWrapperGenerateContextStateOptions`](../type-aliases/ChatWrapperGenerateContextStateOptions.md) | #### Returns [`ChatWrapperGeneratedContextState`](../type-aliases/ChatWrapperGeneratedContextState.md) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`generateContextState`](ChatWrapper.md#generatecontextstate) *** ### generateAvailableFunctionsSystemText() ```ts generateAvailableFunctionsSystemText(availableFunctions: ChatModelFunctions, __namedParameters: { documentParams?: boolean; }): LlamaText; ``` Defined in: [chatWrappers/Gemma4ChatWrapper.ts:157](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/Gemma4ChatWrapper.ts#L157) #### Parameters | Parameter | Type | | ------ | ------ | | `availableFunctions` | [`ChatModelFunctions`](../type-aliases/ChatModelFunctions.md) | | `__namedParameters` | { `documentParams?`: `boolean`; } | | `__namedParameters.documentParams?` | `boolean` | #### Returns [`LlamaText`](LlamaText.md) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`generateAvailableFunctionsSystemText`](ChatWrapper.md#generateavailablefunctionssystemtext) *** ### generateModelResponseText() ```ts generateModelResponseText(modelResponse: ( | string | ChatModelFunctionCall | ChatModelSegment)[], useRawValues?: boolean): LlamaText; ``` Defined in: [chatWrappers/Gemma4ChatWrapper.ts:178](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/Gemma4ChatWrapper.ts#L178) #### Parameters | Parameter | Type | Default value | | ------ | ------ | ------ | | `modelResponse` | ( | `string` | [`ChatModelFunctionCall`](../type-aliases/ChatModelFunctionCall.md) | [`ChatModelSegment`](../type-aliases/ChatModelSegment.md))\[] | `undefined` | | `useRawValues` | `boolean` | `true` | #### Returns [`LlamaText`](LlamaText.md) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`generateModelResponseText`](ChatWrapper.md#generatemodelresponsetext) --- --- url: /api/classes/GemmaChatWrapper.md --- # Class: GemmaChatWrapper Defined in: [chatWrappers/GemmaChatWrapper.ts:7](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/GemmaChatWrapper.ts#L7) ## Extends * [`ChatWrapper`](ChatWrapper.md) ## Constructors ### Constructor ```ts new GemmaChatWrapper(): GemmaChatWrapper; ``` #### Returns `GemmaChatWrapper` #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`constructor`](ChatWrapper.md#constructor) ## Properties ### defaultSettings ```ts static defaultSettings: ChatWrapperSettings; ``` Defined in: [ChatWrapper.ts:15](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L15) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`defaultSettings`](ChatWrapper.md#defaultsettings) *** ### wrapperName ```ts readonly wrapperName: string = "Gemma"; ``` Defined in: [chatWrappers/GemmaChatWrapper.ts:8](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/GemmaChatWrapper.ts#L8) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`wrapperName`](ChatWrapper.md#wrappername) *** ### settings ```ts readonly settings: ChatWrapperSettings; ``` Defined in: [chatWrappers/GemmaChatWrapper.ts:10](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/GemmaChatWrapper.ts#L10) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`settings`](ChatWrapper.md#settings) ## Methods ### generateFunctionCallsAndResults() ```ts generateFunctionCallsAndResults(functionCalls: ChatModelFunctionCall[], useRawCall?: boolean): LlamaText; ``` Defined in: [ChatWrapper.ts:63](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L63) #### Parameters | Parameter | Type | Default value | | ------ | ------ | ------ | | `functionCalls` | [`ChatModelFunctionCall`](../type-aliases/ChatModelFunctionCall.md)\[] | `undefined` | | `useRawCall` | `boolean` | `true` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCallsAndResults`](ChatWrapper.md#generatefunctioncallsandresults) *** ### generateFunctionCall() ```ts generateFunctionCall(name: string, params: any): LlamaText; ``` Defined in: [ChatWrapper.ts:110](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L110) #### Parameters | Parameter | Type | | ------ | ------ | | `name` | `string` | | `params` | `any` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCall`](ChatWrapper.md#generatefunctioncall) *** ### generateFunctionCallResult() ```ts generateFunctionCallResult( functionName: string, functionParams: any, result: any): LlamaText; ``` Defined in: [ChatWrapper.ts:127](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L127) #### Parameters | Parameter | Type | | ------ | ------ | | `functionName` | `string` | | `functionParams` | `any` | | `result` | `any` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCallResult`](ChatWrapper.md#generatefunctioncallresult) *** ### generateModelResponseText() ```ts generateModelResponseText(modelResponse: ( | string | ChatModelFunctionCall | ChatModelSegment)[], useRawValues?: boolean): LlamaText; ``` Defined in: [ChatWrapper.ts:158](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L158) #### Parameters | Parameter | Type | Default value | | ------ | ------ | ------ | | `modelResponse` | ( | `string` | [`ChatModelFunctionCall`](../type-aliases/ChatModelFunctionCall.md) | [`ChatModelSegment`](../type-aliases/ChatModelSegment.md))\[] | `undefined` | | `useRawValues` | `boolean` | `true` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateModelResponseText`](ChatWrapper.md#generatemodelresponsetext) *** ### generateAvailableFunctionsSystemText() ```ts generateAvailableFunctionsSystemText(availableFunctions: ChatModelFunctions, __namedParameters: { documentParams?: boolean; }): LlamaText; ``` Defined in: [ChatWrapper.ts:243](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L243) #### Parameters | Parameter | Type | | ------ | ------ | | `availableFunctions` | [`ChatModelFunctions`](../type-aliases/ChatModelFunctions.md) | | `__namedParameters` | { `documentParams?`: `boolean`; } | | `__namedParameters.documentParams?` | `boolean` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateAvailableFunctionsSystemText`](ChatWrapper.md#generateavailablefunctionssystemtext) *** ### addAvailableFunctionsSystemMessageToHistory() ```ts addAvailableFunctionsSystemMessageToHistory( history: readonly ChatHistoryItem[], availableFunctions?: ChatModelFunctions, __namedParameters?: { documentParams?: boolean; }): readonly ChatHistoryItem[]; ``` Defined in: [ChatWrapper.ts:269](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L269) #### Parameters | Parameter | Type | | ------ | ------ | | `history` | readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] | | `availableFunctions?` | [`ChatModelFunctions`](../type-aliases/ChatModelFunctions.md) | | `__namedParameters?` | { `documentParams?`: `boolean`; } | | `__namedParameters.documentParams?` | `boolean` | #### Returns readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`addAvailableFunctionsSystemMessageToHistory`](ChatWrapper.md#addavailablefunctionssystemmessagetohistory) *** ### generateInitialChatHistory() ```ts generateInitialChatHistory(__namedParameters?: ChatWrapperGenerateInitialHistoryOptions): ChatHistoryItem[]; ``` Defined in: [ChatWrapper.ts:290](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L290) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | [`ChatWrapperGenerateInitialHistoryOptions`](../type-aliases/ChatWrapperGenerateInitialHistoryOptions.md) | #### Returns [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateInitialChatHistory`](ChatWrapper.md#generateinitialchathistory) *** ### generateContextState() ```ts generateContextState(__namedParameters: ChatWrapperGenerateContextStateOptions): ChatWrapperGeneratedContextState; ``` Defined in: [chatWrappers/GemmaChatWrapper.ts:15](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/GemmaChatWrapper.ts#L15) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | [`ChatWrapperGenerateContextStateOptions`](../type-aliases/ChatWrapperGenerateContextStateOptions.md) | #### Returns [`ChatWrapperGeneratedContextState`](../type-aliases/ChatWrapperGeneratedContextState.md) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`generateContextState`](ChatWrapper.md#generatecontextstate) --- --- url: /api/classes/GeneralChatWrapper.md --- # Class: GeneralChatWrapper Defined in: [chatWrappers/GeneralChatWrapper.ts:9](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/GeneralChatWrapper.ts#L9) This chat wrapper is not safe against chat syntax injection attacks ([learn more](https://node-llama-cpp.withcat.ai/guide/llama-text#input-safety-in-node-llama-cpp)). ## Extends * [`ChatWrapper`](ChatWrapper.md) ## Extended by * [`AlpacaChatWrapper`](AlpacaChatWrapper.md) ## Constructors ### Constructor ```ts new GeneralChatWrapper(__namedParameters?: { userMessageTitle?: string; modelResponseTitle?: string; middleSystemMessageTitle?: string; allowSpecialTokensInTitles?: boolean; }): GeneralChatWrapper; ``` Defined in: [chatWrappers/GeneralChatWrapper.ts:17](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/GeneralChatWrapper.ts#L17) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | { `userMessageTitle?`: `string`; `modelResponseTitle?`: `string`; `middleSystemMessageTitle?`: `string`; `allowSpecialTokensInTitles?`: `boolean`; } | | `__namedParameters.userMessageTitle?` | `string` | | `__namedParameters.modelResponseTitle?` | `string` | | `__namedParameters.middleSystemMessageTitle?` | `string` | | `__namedParameters.allowSpecialTokensInTitles?` | `boolean` | #### Returns `GeneralChatWrapper` #### Overrides [`ChatWrapper`](ChatWrapper.md).[`constructor`](ChatWrapper.md#constructor) ## Properties ### defaultSettings ```ts static defaultSettings: ChatWrapperSettings; ``` Defined in: [ChatWrapper.ts:15](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L15) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`defaultSettings`](ChatWrapper.md#defaultsettings) *** ### settings ```ts readonly settings: ChatWrapperSettings = ChatWrapper.defaultSettings; ``` Defined in: [ChatWrapper.ts:36](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L36) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`settings`](ChatWrapper.md#settings) *** ### wrapperName ```ts readonly wrapperName: string = "General"; ``` Defined in: [chatWrappers/GeneralChatWrapper.ts:10](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/GeneralChatWrapper.ts#L10) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`wrapperName`](ChatWrapper.md#wrappername) ## Accessors ### userMessageTitle #### Get Signature ```ts get userMessageTitle(): string; ``` Defined in: [chatWrappers/GeneralChatWrapper.ts:31](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/GeneralChatWrapper.ts#L31) ##### Returns `string` *** ### modelResponseTitle #### Get Signature ```ts get modelResponseTitle(): string; ``` Defined in: [chatWrappers/GeneralChatWrapper.ts:35](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/GeneralChatWrapper.ts#L35) ##### Returns `string` *** ### middleSystemMessageTitle #### Get Signature ```ts get middleSystemMessageTitle(): string; ``` Defined in: [chatWrappers/GeneralChatWrapper.ts:39](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/GeneralChatWrapper.ts#L39) ##### Returns `string` ## Methods ### generateFunctionCallsAndResults() ```ts generateFunctionCallsAndResults(functionCalls: ChatModelFunctionCall[], useRawCall?: boolean): LlamaText; ``` Defined in: [ChatWrapper.ts:63](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L63) #### Parameters | Parameter | Type | Default value | | ------ | ------ | ------ | | `functionCalls` | [`ChatModelFunctionCall`](../type-aliases/ChatModelFunctionCall.md)\[] | `undefined` | | `useRawCall` | `boolean` | `true` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCallsAndResults`](ChatWrapper.md#generatefunctioncallsandresults) *** ### generateFunctionCall() ```ts generateFunctionCall(name: string, params: any): LlamaText; ``` Defined in: [ChatWrapper.ts:110](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L110) #### Parameters | Parameter | Type | | ------ | ------ | | `name` | `string` | | `params` | `any` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCall`](ChatWrapper.md#generatefunctioncall) *** ### generateFunctionCallResult() ```ts generateFunctionCallResult( functionName: string, functionParams: any, result: any): LlamaText; ``` Defined in: [ChatWrapper.ts:127](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L127) #### Parameters | Parameter | Type | | ------ | ------ | | `functionName` | `string` | | `functionParams` | `any` | | `result` | `any` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCallResult`](ChatWrapper.md#generatefunctioncallresult) *** ### generateModelResponseText() ```ts generateModelResponseText(modelResponse: ( | string | ChatModelFunctionCall | ChatModelSegment)[], useRawValues?: boolean): LlamaText; ``` Defined in: [ChatWrapper.ts:158](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L158) #### Parameters | Parameter | Type | Default value | | ------ | ------ | ------ | | `modelResponse` | ( | `string` | [`ChatModelFunctionCall`](../type-aliases/ChatModelFunctionCall.md) | [`ChatModelSegment`](../type-aliases/ChatModelSegment.md))\[] | `undefined` | | `useRawValues` | `boolean` | `true` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateModelResponseText`](ChatWrapper.md#generatemodelresponsetext) *** ### generateAvailableFunctionsSystemText() ```ts generateAvailableFunctionsSystemText(availableFunctions: ChatModelFunctions, __namedParameters: { documentParams?: boolean; }): LlamaText; ``` Defined in: [ChatWrapper.ts:243](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L243) #### Parameters | Parameter | Type | | ------ | ------ | | `availableFunctions` | [`ChatModelFunctions`](../type-aliases/ChatModelFunctions.md) | | `__namedParameters` | { `documentParams?`: `boolean`; } | | `__namedParameters.documentParams?` | `boolean` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateAvailableFunctionsSystemText`](ChatWrapper.md#generateavailablefunctionssystemtext) *** ### addAvailableFunctionsSystemMessageToHistory() ```ts addAvailableFunctionsSystemMessageToHistory( history: readonly ChatHistoryItem[], availableFunctions?: ChatModelFunctions, __namedParameters?: { documentParams?: boolean; }): readonly ChatHistoryItem[]; ``` Defined in: [ChatWrapper.ts:269](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L269) #### Parameters | Parameter | Type | | ------ | ------ | | `history` | readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] | | `availableFunctions?` | [`ChatModelFunctions`](../type-aliases/ChatModelFunctions.md) | | `__namedParameters?` | { `documentParams?`: `boolean`; } | | `__namedParameters.documentParams?` | `boolean` | #### Returns readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`addAvailableFunctionsSystemMessageToHistory`](ChatWrapper.md#addavailablefunctionssystemmessagetohistory) *** ### generateInitialChatHistory() ```ts generateInitialChatHistory(__namedParameters?: ChatWrapperGenerateInitialHistoryOptions): ChatHistoryItem[]; ``` Defined in: [ChatWrapper.ts:290](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L290) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | [`ChatWrapperGenerateInitialHistoryOptions`](../type-aliases/ChatWrapperGenerateInitialHistoryOptions.md) | #### Returns [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateInitialChatHistory`](ChatWrapper.md#generateinitialchathistory) *** ### generateContextState() ```ts generateContextState(__namedParameters: ChatWrapperGenerateContextStateOptions): ChatWrapperGeneratedContextState; ``` Defined in: [chatWrappers/GeneralChatWrapper.ts:43](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/GeneralChatWrapper.ts#L43) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | [`ChatWrapperGenerateContextStateOptions`](../type-aliases/ChatWrapperGenerateContextStateOptions.md) | #### Returns [`ChatWrapperGeneratedContextState`](../type-aliases/ChatWrapperGeneratedContextState.md) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`generateContextState`](ChatWrapper.md#generatecontextstate) --- --- url: /api/classes/GgufInsights.md --- # Class: GgufInsights Defined in: [gguf/insights/GgufInsights.ts:26](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/insights/GgufInsights.ts#L26) ## Accessors ### ggufFileInfo #### Get Signature ```ts get ggufFileInfo(): GgufFileInfo; ``` Defined in: [gguf/insights/GgufInsights.ts:85](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/insights/GgufInsights.ts#L85) ##### Returns [`GgufFileInfo`](../type-aliases/GgufFileInfo.md) *** ### configurationResolver #### Get Signature ```ts get configurationResolver(): GgufInsightsConfigurationResolver; ``` Defined in: [gguf/insights/GgufInsights.ts:89](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/insights/GgufInsights.ts#L89) ##### Returns [`GgufInsightsConfigurationResolver`](GgufInsightsConfigurationResolver.md) *** ### tokens #### Get Signature ```ts get tokens(): GgufInsightsTokens; ``` Defined in: [gguf/insights/GgufInsights.ts:93](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/insights/GgufInsights.ts#L93) ##### Returns [`GgufInsightsTokens`](GgufInsightsTokens.md) *** ### trainContextSize #### Get Signature ```ts get trainContextSize(): number | undefined; ``` Defined in: [gguf/insights/GgufInsights.ts:98](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/insights/GgufInsights.ts#L98) The context size the model was trained on ##### Returns `number` | `undefined` *** ### embeddingVectorSize #### Get Signature ```ts get embeddingVectorSize(): number | undefined; ``` Defined in: [gguf/insights/GgufInsights.ts:103](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/insights/GgufInsights.ts#L103) The size of an embedding vector the model can produce ##### Returns `number` | `undefined` *** ### totalLayers #### Get Signature ```ts get totalLayers(): number; ``` Defined in: [gguf/insights/GgufInsights.ts:107](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/insights/GgufInsights.ts#L107) ##### Returns `number` *** ### modelSize #### Get Signature ```ts get modelSize(): number; ``` Defined in: [gguf/insights/GgufInsights.ts:112](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/insights/GgufInsights.ts#L112) ##### Returns `number` *** ### totalParameters #### Get Signature ```ts get totalParameters(): number; ``` Defined in: [gguf/insights/GgufInsights.ts:117](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/insights/GgufInsights.ts#L117) The total number of parameters in the model ##### Returns `number` *** ### flashAttentionSupported #### Get Signature ```ts get flashAttentionSupported(): boolean; ``` Defined in: [gguf/insights/GgufInsights.ts:122](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/insights/GgufInsights.ts#L122) ##### Returns `boolean` *** ### hasEncoder #### Get Signature ```ts get hasEncoder(): boolean; ``` Defined in: [gguf/insights/GgufInsights.ts:142](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/insights/GgufInsights.ts#L142) ##### Returns `boolean` *** ### hasDecoder #### Get Signature ```ts get hasDecoder(): boolean; ``` Defined in: [gguf/insights/GgufInsights.ts:152](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/insights/GgufInsights.ts#L152) ##### Returns `boolean` *** ### isRecurrent #### Get Signature ```ts get isRecurrent(): boolean; ``` Defined in: [gguf/insights/GgufInsights.ts:161](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/insights/GgufInsights.ts#L161) ##### Returns `boolean` *** ### isHybrid #### Get Signature ```ts get isHybrid(): boolean; ``` Defined in: [gguf/insights/GgufInsights.ts:176](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/insights/GgufInsights.ts#L176) ##### Returns `boolean` *** ### dominantTensorType #### Get Signature ```ts get dominantTensorType(): GgmlType | undefined; ``` Defined in: [gguf/insights/GgufInsights.ts:200](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/insights/GgufInsights.ts#L200) Get the dominant tensor type used in the model file ##### Returns [`GgmlType`](../enumerations/GgmlType.md) | `undefined` *** ### supportsRanking #### Get Signature ```ts get supportsRanking(): boolean; ``` Defined in: [gguf/insights/GgufInsights.ts:207](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/insights/GgufInsights.ts#L207) ##### Returns `boolean` *** ### swaSize #### Get Signature ```ts get swaSize(): number | undefined; ``` Defined in: [gguf/insights/GgufInsights.ts:235](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/insights/GgufInsights.ts#L235) The size of the SWA (Sliding Window Attention). When `undefined`, the model does not use sliding window attention. ##### Returns `number` | `undefined` ## Methods ### getWarnings() ```ts getWarnings(modelFilePath?: string): string[]; ``` Defined in: [gguf/insights/GgufInsights.ts:58](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/insights/GgufInsights.ts#L58) Get warnings about the model file that would affect its usage. Most of these warnings are also generated by `llama.cpp` #### Parameters | Parameter | Type | | ------ | ------ | | `modelFilePath?` | `string` | #### Returns `string`\[] *** ### ~~estimateModelResourceRequirements()~~ ```ts estimateModelResourceRequirements(__namedParameters: { gpuLayers: number; useMmap?: boolean; gpuSupportsMmap?: boolean; }): GgufInsightsResourceRequirements; ``` Defined in: [gguf/insights/GgufInsights.ts:276](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/insights/GgufInsights.ts#L276) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | { `gpuLayers`: `number`; `useMmap?`: `boolean`; `gpuSupportsMmap?`: `boolean`; } | | `__namedParameters.gpuLayers` | `number` | | `__namedParameters.useMmap?` | `boolean` | | `__namedParameters.gpuSupportsMmap?` | `boolean` | #### Returns [`GgufInsightsResourceRequirements`](../type-aliases/GgufInsightsResourceRequirements.md) #### Deprecated Use `estimateModelResourceRequirementsV2` instead *** ### estimateModelResourceRequirementsV2() ```ts estimateModelResourceRequirementsV2(options: { gpuLayers: number; useMmap?: boolean; gpuSupportsMmap?: boolean; }): Promise; ``` Defined in: [gguf/insights/GgufInsights.ts:289](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/insights/GgufInsights.ts#L289) #### Parameters | Parameter | Type | | ------ | ------ | | `options` | { `gpuLayers`: `number`; `useMmap?`: `boolean`; `gpuSupportsMmap?`: `boolean`; } | | `options.gpuLayers` | `number` | | `options.useMmap?` | `boolean` | | `options.gpuSupportsMmap?` | `boolean` | #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[`GgufInsightsResourceRequirements`](../type-aliases/GgufInsightsResourceRequirements.md)> *** ### ~~estimateContextResourceRequirements()~~ ```ts estimateContextResourceRequirements(__namedParameters: { contextSize: number; modelGpuLayers: number; batchSize?: number; sequences?: number; isEmbeddingContext?: boolean; flashAttention?: boolean; includeGraphOverhead?: boolean; swaFullCache?: boolean; kvCacheKeyType?: GgmlType; kvCacheValueType?: GgmlType; }): GgufInsightsResourceRequirements; ``` Defined in: [gguf/insights/GgufInsights.ts:387](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/insights/GgufInsights.ts#L387) Estimates the memory required to create a context of the given parameters based on the implementation details of `llama.cpp`. The calculation doesn't include a precise estimation of the graph overhead memory, so it uses a rough estimate for that. The estimation for the graph overhead memory will be improved in the future to be more precise, but it's good enough for now. #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | { `contextSize`: `number`; `modelGpuLayers`: `number`; `batchSize?`: `number`; `sequences?`: `number`; `isEmbeddingContext?`: `boolean`; `flashAttention?`: `boolean`; `includeGraphOverhead?`: `boolean`; `swaFullCache?`: `boolean`; `kvCacheKeyType?`: [`GgmlType`](../enumerations/GgmlType.md); `kvCacheValueType?`: [`GgmlType`](../enumerations/GgmlType.md); } | | `__namedParameters.contextSize` | `number` | | `__namedParameters.modelGpuLayers` | `number` | | `__namedParameters.batchSize?` | `number` | | `__namedParameters.sequences?` | `number` | | `__namedParameters.isEmbeddingContext?` | `boolean` | | `__namedParameters.flashAttention?` | `boolean` | | `__namedParameters.includeGraphOverhead?` | `boolean` | | `__namedParameters.swaFullCache?` | `boolean` | | `__namedParameters.kvCacheKeyType?` | [`GgmlType`](../enumerations/GgmlType.md) | | `__namedParameters.kvCacheValueType?` | [`GgmlType`](../enumerations/GgmlType.md) | #### Returns [`GgufInsightsResourceRequirements`](../type-aliases/GgufInsightsResourceRequirements.md) #### Deprecated Use `estimateContextResourceRequirementsV2` instead *** ### estimateContextResourceRequirementsV2() ```ts estimateContextResourceRequirementsV2(options: { contextSize: number; modelGpuLayers: number; batchSize?: number; sequences?: number; isEmbeddingContext?: boolean; flashAttention?: boolean | "auto"; swaFullCache?: boolean; kvCacheKeyType?: GgmlType; kvCacheValueType?: GgmlType; useMmap?: boolean; }): Promise; ``` Defined in: [gguf/insights/GgufInsights.ts:735](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/insights/GgufInsights.ts#L735) #### Parameters | Parameter | Type | | ------ | ------ | | `options` | { `contextSize`: `number`; `modelGpuLayers`: `number`; `batchSize?`: `number`; `sequences?`: `number`; `isEmbeddingContext?`: `boolean`; `flashAttention?`: `boolean` | `"auto"`; `swaFullCache?`: `boolean`; `kvCacheKeyType?`: [`GgmlType`](../enumerations/GgmlType.md); `kvCacheValueType?`: [`GgmlType`](../enumerations/GgmlType.md); `useMmap?`: `boolean`; } | | `options.contextSize` | `number` | | `options.modelGpuLayers` | `number` | | `options.batchSize?` | `number` | | `options.sequences?` | `number` | | `options.isEmbeddingContext?` | `boolean` | | `options.flashAttention?` | `boolean` | `"auto"` | | `options.swaFullCache?` | `boolean` | | `options.kvCacheKeyType?` | [`GgmlType`](../enumerations/GgmlType.md) | | `options.kvCacheValueType?` | [`GgmlType`](../enumerations/GgmlType.md) | | `options.useMmap?` | `boolean` | #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[`GgufInsightsResourceRequirements`](../type-aliases/GgufInsightsResourceRequirements.md)> *** ### from() ```ts static from(ggufFileInfo: GgufFileInfo, llama?: Llama): Promise; ``` Defined in: [gguf/insights/GgufInsights.ts:1189](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/insights/GgufInsights.ts#L1189) #### Parameters | Parameter | Type | Description | | ------ | ------ | ------ | | `ggufFileInfo` | [`GgufFileInfo`](../type-aliases/GgufFileInfo.md) | - | | `llama?` | [`Llama`](Llama.md) | If you already have a `Llama` instance, pass it to reuse it for the `GgufInsights` instance. If you don't pass a `Llama` instance, a basic `Llama` instance is created as a fallback - it's a slim instance that doesn't instantiate a `llama.cpp` backend, so it won't utilize the GPU at all, and be shared with other `GgufInsights` instances that need a fallback `Llama` instance. | #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`GgufInsights`> --- --- url: /api/classes/GgufInsightsConfigurationResolver.md --- # Class: GgufInsightsConfigurationResolver Defined in: [gguf/insights/GgufInsightsConfigurationResolver.ts:18](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/insights/GgufInsightsConfigurationResolver.ts#L18) ## Accessors ### ggufInsights #### Get Signature ```ts get ggufInsights(): GgufInsights; ``` Defined in: [gguf/insights/GgufInsightsConfigurationResolver.ts:25](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/insights/GgufInsightsConfigurationResolver.ts#L25) ##### Returns [`GgufInsights`](GgufInsights.md) ## Methods ### resolveAndScoreConfig() ```ts resolveAndScoreConfig(options?: { targetGpuLayers?: number | "max"; targetContextSize?: number; embeddingContext?: boolean; flashAttention?: boolean | "auto"; kvCacheKeyType?: GgmlType; kvCacheValueType?: GgmlType; swaFullCache?: boolean; useMmap?: boolean | "auto"; }, hardwareOverrides?: { getVramState?: Promise<{ total: number; free: number; unifiedSize: number; }>; getRamState?: Promise<{ total: number; free: number; }>; getSwapState?: Promise<{ total: number; free: number; }>; llamaVramPaddingSize?: number; llamaGpu?: false | "metal" | "cuda" | "vulkan"; llamaSupportsGpuOffloading?: boolean; }): Promise<{ compatibilityScore: number; bonusScore: number; totalScore: number; resolvedValues: { gpuLayers: number; contextSize: number; useMmap: boolean; modelRamUsage: number; contextRamUsage: number; totalRamUsage: number; modelVramUsage: number; contextVramUsage: number; totalVramUsage: number; }; }>; ``` Defined in: [gguf/insights/GgufInsightsConfigurationResolver.ts:39](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/insights/GgufInsightsConfigurationResolver.ts#L39) Resolve the best configuration for loading a model and creating a context using the current hardware. Specifying a `targetGpuLayers` and/or `targetContextSize` will ensure the resolved configuration matches those values, but note it can lower the compatibility score if the hardware doesn't support it. Overriding hardware values it possible by configuring `hardwareOverrides`. #### Parameters | Parameter | Type | Description | | ------ | ------ | ------ | | `options` | { `targetGpuLayers?`: `number` | `"max"`; `targetContextSize?`: `number`; `embeddingContext?`: `boolean`; `flashAttention?`: `boolean` | `"auto"`; `kvCacheKeyType?`: [`GgmlType`](../enumerations/GgmlType.md); `kvCacheValueType?`: [`GgmlType`](../enumerations/GgmlType.md); `swaFullCache?`: `boolean`; `useMmap?`: `boolean` | `"auto"`; } | - | | `options.targetGpuLayers?` | `number` | `"max"` | - | | `options.targetContextSize?` | `number` | - | | `options.embeddingContext?` | `boolean` | - | | `options.flashAttention?` | `boolean` | `"auto"` | - | | `options.kvCacheKeyType?` | [`GgmlType`](../enumerations/GgmlType.md) | - | | `options.kvCacheValueType?` | [`GgmlType`](../enumerations/GgmlType.md) | - | | `options.swaFullCache?` | `boolean` | - | | `options.useMmap?` | `boolean` | `"auto"` | - | | `hardwareOverrides` | { `getVramState?`: [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{ `total`: `number`; `free`: `number`; `unifiedSize`: `number`; }>; `getRamState?`: [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{ `total`: `number`; `free`: `number`; }>; `getSwapState?`: [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{ `total`: `number`; `free`: `number`; }>; `llamaVramPaddingSize?`: `number`; `llamaGpu?`: `false` | `"metal"` | `"cuda"` | `"vulkan"`; `llamaSupportsGpuOffloading?`: `boolean`; } | - | | `hardwareOverrides.getVramState?` | - | | `hardwareOverrides.getRamState?` | - | | `hardwareOverrides.getSwapState?` | - | | `hardwareOverrides.llamaVramPaddingSize?` | `number` | - | | `hardwareOverrides.llamaGpu?` | `false` | `"metal"` | `"cuda"` | `"vulkan"` | - | | `hardwareOverrides.llamaSupportsGpuOffloading?` | `boolean` | - | #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{ `compatibilityScore`: `number`; `bonusScore`: `number`; `totalScore`: `number`; `resolvedValues`: { `gpuLayers`: `number`; `contextSize`: `number`; `useMmap`: `boolean`; `modelRamUsage`: `number`; `contextRamUsage`: `number`; `totalRamUsage`: `number`; `modelVramUsage`: `number`; `contextVramUsage`: `number`; `totalVramUsage`: `number`; }; }> *** ### scoreModelConfigurationCompatibility() ```ts scoreModelConfigurationCompatibility(__namedParameters?: { contextSize?: number; embeddingContext?: boolean; flashAttention?: boolean | "auto"; kvCacheKeyType?: GgmlType; kvCacheValueType?: GgmlType; swaFullCache?: boolean; maximumFittedContextSizeMultiplier?: number; maximumUnfitConfigurationResourceMultiplier?: number; forceStrictContextSize?: boolean; forceGpuLayers?: number | "max"; useMmap?: boolean | "auto"; }, __namedParameters?: { getVramState?: Promise<{ total: number; free: number; unifiedSize: number; }>; getRamState?: Promise<{ total: number; free: number; }>; getSwapState?: Promise<{ total: number; free: number; }>; llamaVramPaddingSize?: number; llamaGpu?: false | "metal" | "cuda" | "vulkan"; llamaSupportsGpuOffloading?: boolean; }): Promise<{ compatibilityScore: number; bonusScore: number; totalScore: number; resolvedValues: { gpuLayers: number; contextSize: number; useMmap: boolean; modelRamUsage: number; contextRamUsage: number; totalRamUsage: number; modelVramUsage: number; contextVramUsage: number; totalVramUsage: number; }; }>; ``` Defined in: [gguf/insights/GgufInsightsConfigurationResolver.ts:115](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/insights/GgufInsightsConfigurationResolver.ts#L115) Score the compatibility of the model configuration with the current GPU and VRAM state. Assumes a model is loaded with the default `"auto"` configurations. Scored based on the following criteria: * The number of GPU layers that can be offloaded to the GPU (only if there's a GPU. If there's no GPU then by how small the model is) * Whether all layers can be offloaded to the GPU (gives additional points) * Whether the resolved context size is at least as large as the specified `contextSize` If the resolved context size is larger than the specified context size, for each multiplier of the specified `contextSize` that the resolved context size is larger by, 1 bonus point is given in the `bonusScore`. `maximumFittedContextSizeMultiplier` is used to improve the proportionality of the bonus score between models. Set this to any value higher than ` / contextSize`. Defaults to `100`. `maximumUnfitConfigurationResourceMultiplier` is used to improve the proportionality of the bonus score between unfit models. Set this to any value higher than ` / `. Defaults to `100`. `contextSize` defaults to `4096` (if the model train context size is lower than this, the model train context size is used instead). #### Parameters | Parameter | Type | Description | | ------ | ------ | ------ | | `__namedParameters` | { `contextSize?`: `number`; `embeddingContext?`: `boolean`; `flashAttention?`: `boolean` | `"auto"`; `kvCacheKeyType?`: [`GgmlType`](../enumerations/GgmlType.md); `kvCacheValueType?`: [`GgmlType`](../enumerations/GgmlType.md); `swaFullCache?`: `boolean`; `maximumFittedContextSizeMultiplier?`: `number`; `maximumUnfitConfigurationResourceMultiplier?`: `number`; `forceStrictContextSize?`: `boolean`; `forceGpuLayers?`: `number` | `"max"`; `useMmap?`: `boolean` | `"auto"`; } | - | | `__namedParameters.contextSize?` | `number` | - | | `__namedParameters.embeddingContext?` | `boolean` | - | | `__namedParameters.flashAttention?` | `boolean` | `"auto"` | - | | `__namedParameters.kvCacheKeyType?` | [`GgmlType`](../enumerations/GgmlType.md) | - | | `__namedParameters.kvCacheValueType?` | [`GgmlType`](../enumerations/GgmlType.md) | - | | `__namedParameters.swaFullCache?` | `boolean` | - | | `__namedParameters.maximumFittedContextSizeMultiplier?` | `number` | - | | `__namedParameters.maximumUnfitConfigurationResourceMultiplier?` | `number` | - | | `__namedParameters.forceStrictContextSize?` | `boolean` | Do not resolve a context size larger than the specified `contextSize`. Defaults to `false`. | | `__namedParameters.forceGpuLayers?` | `number` | `"max"` | - | | `__namedParameters.useMmap?` | `boolean` | `"auto"` | - | | `__namedParameters` | { `getVramState?`: [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{ `total`: `number`; `free`: `number`; `unifiedSize`: `number`; }>; `getRamState?`: [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{ `total`: `number`; `free`: `number`; }>; `getSwapState?`: [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{ `total`: `number`; `free`: `number`; }>; `llamaVramPaddingSize?`: `number`; `llamaGpu?`: `false` | `"metal"` | `"cuda"` | `"vulkan"`; `llamaSupportsGpuOffloading?`: `boolean`; } | - | | `__namedParameters.getVramState?` | - | | `__namedParameters.getRamState?` | - | | `__namedParameters.getSwapState?` | - | | `__namedParameters.llamaVramPaddingSize?` | `number` | - | | `__namedParameters.llamaGpu?` | `false` | `"metal"` | `"cuda"` | `"vulkan"` | - | | `__namedParameters.llamaSupportsGpuOffloading?` | `boolean` | - | #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{ `compatibilityScore`: `number`; `bonusScore`: `number`; `totalScore`: `number`; `resolvedValues`: { `gpuLayers`: `number`; `contextSize`: `number`; `useMmap`: `boolean`; `modelRamUsage`: `number`; `contextRamUsage`: `number`; `totalRamUsage`: `number`; `modelVramUsage`: `number`; `contextVramUsage`: `number`; `totalVramUsage`: `number`; }; }> *** ### ~~resolveModelGpuLayers()~~ ```ts resolveModelGpuLayers(gpuLayers?: | number | "auto" | "max" | { min?: number; max?: number; fitContext?: { contextSize?: number; embeddingContext?: boolean; }; }, options?: { ignoreMemorySafetyChecks?: boolean; getVramState?: Promise<{ total: number; free: number; }>; llamaVramPaddingSize?: number; llamaGpu?: false | "metal" | "cuda" | "vulkan"; llamaSupportsGpuOffloading?: boolean; defaultContextFlashAttention?: boolean | "auto"; defaultContextKvCacheKeyType?: GgmlType; defaultContextKvCacheValueType?: GgmlType; defaultContextSwaFullCache?: boolean; useMmap?: boolean; }): Promise; ``` Defined in: [gguf/insights/GgufInsightsConfigurationResolver.ts:426](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/insights/GgufInsightsConfigurationResolver.ts#L426) #### Parameters | Parameter | Type | | ------ | ------ | | `gpuLayers?` | | `number` | `"auto"` | `"max"` | { `min?`: `number`; `max?`: `number`; `fitContext?`: { `contextSize?`: `number`; `embeddingContext?`: `boolean`; }; } | | `options?` | { `ignoreMemorySafetyChecks?`: `boolean`; `getVramState?`: [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{ `total`: `number`; `free`: `number`; }>; `llamaVramPaddingSize?`: `number`; `llamaGpu?`: `false` | `"metal"` | `"cuda"` | `"vulkan"`; `llamaSupportsGpuOffloading?`: `boolean`; `defaultContextFlashAttention?`: `boolean` | `"auto"`; `defaultContextKvCacheKeyType?`: [`GgmlType`](../enumerations/GgmlType.md); `defaultContextKvCacheValueType?`: [`GgmlType`](../enumerations/GgmlType.md); `defaultContextSwaFullCache?`: `boolean`; `useMmap?`: `boolean`; } | | `options.ignoreMemorySafetyChecks?` | `boolean` | | `options.getVramState?` | | `options.llamaVramPaddingSize?` | `number` | | `options.llamaGpu?` | `false` | `"metal"` | `"cuda"` | `"vulkan"` | | `options.llamaSupportsGpuOffloading?` | `boolean` | | `options.defaultContextFlashAttention?` | `boolean` | `"auto"` | | `options.defaultContextKvCacheKeyType?` | [`GgmlType`](../enumerations/GgmlType.md) | | `options.defaultContextKvCacheValueType?` | [`GgmlType`](../enumerations/GgmlType.md) | | `options.defaultContextSwaFullCache?` | `boolean` | | `options.useMmap?` | `boolean` | #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`number`> #### Deprecated use `resolveModelGpuLayersV2` instead *** ### resolveModelGpuLayersV2() ```ts resolveModelGpuLayersV2(gpuLayers?: | number | "auto" | "max" | { min?: number; max?: number; fitContext?: { contextSize?: number; embeddingContext?: boolean; }; }, options?: { ignoreMemorySafetyChecks?: boolean; getVramState?: Promise<{ total: number; free: number; }>; llamaVramPaddingSize?: number; llamaGpu?: false | "metal" | "cuda" | "vulkan"; llamaSupportsGpuOffloading?: boolean; defaultContextFlashAttention?: boolean | "auto"; defaultContextKvCacheKeyType?: GgmlType; defaultContextKvCacheValueType?: GgmlType; defaultContextSwaFullCache?: boolean; useMmap?: boolean | "auto"; onProgress?: void; signal?: AbortSignal; }): Promise<{ gpuLayers: number; useMmap: boolean; }>; ``` Defined in: [gguf/insights/GgufInsightsConfigurationResolver.ts:457](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/insights/GgufInsightsConfigurationResolver.ts#L457) #### Parameters | Parameter | Type | Description | | ------ | ------ | ------ | | `gpuLayers?` | | `number` | `"auto"` | `"max"` | { `min?`: `number`; `max?`: `number`; `fitContext?`: { `contextSize?`: `number`; `embeddingContext?`: `boolean`; }; } | - | | `options?` | { `ignoreMemorySafetyChecks?`: `boolean`; `getVramState?`: [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{ `total`: `number`; `free`: `number`; }>; `llamaVramPaddingSize?`: `number`; `llamaGpu?`: `false` | `"metal"` | `"cuda"` | `"vulkan"`; `llamaSupportsGpuOffloading?`: `boolean`; `defaultContextFlashAttention?`: `boolean` | `"auto"`; `defaultContextKvCacheKeyType?`: [`GgmlType`](../enumerations/GgmlType.md); `defaultContextKvCacheValueType?`: [`GgmlType`](../enumerations/GgmlType.md); `defaultContextSwaFullCache?`: `boolean`; `useMmap?`: `boolean` | `"auto"`; `onProgress?`: `void`; `signal?`: `AbortSignal`; } | - | | `options.ignoreMemorySafetyChecks?` | `boolean` | - | | `options.getVramState?` | - | | `options.llamaVramPaddingSize?` | `number` | - | | `options.llamaGpu?` | `false` | `"metal"` | `"cuda"` | `"vulkan"` | - | | `options.llamaSupportsGpuOffloading?` | `boolean` | - | | `options.defaultContextFlashAttention?` | `boolean` | `"auto"` | - | | `options.defaultContextKvCacheKeyType?` | [`GgmlType`](../enumerations/GgmlType.md) | - | | `options.defaultContextKvCacheValueType?` | [`GgmlType`](../enumerations/GgmlType.md) | - | | `options.defaultContextSwaFullCache?` | `boolean` | - | | `options.useMmap?` | `boolean` | `"auto"` | - | | `options.onProgress?` | - | | `options.signal?` | `AbortSignal` | Signal to abort the resolving operation | #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{ `gpuLayers`: `number`; `useMmap`: `boolean`; }> *** ### resolveContextContextSize() ```ts resolveContextContextSize(contextSize: | number | "auto" | { min?: number; max?: number; } | undefined, options: { modelGpuLayers: number; modelTrainContextSize: number; flashAttention?: boolean | "auto"; kvCacheKeyType?: GgmlType; kvCacheValueType?: GgmlType; swaFullCache?: boolean; useMmap?: boolean; batchSize?: number; sequences?: number; getVramState?: Promise<{ total: number; free: number; unifiedSize: number; }>; getRamState?: Promise<{ total: number; free: number; }>; getSwapState?: Promise<{ total: number; free: number; }>; llamaGpu?: false | "metal" | "cuda" | "vulkan"; ignoreMemorySafetyChecks?: boolean; isEmbeddingContext?: boolean; }): Promise; ``` Defined in: [gguf/insights/GgufInsightsConfigurationResolver.ts:511](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/insights/GgufInsightsConfigurationResolver.ts#L511) Resolve a context size option for the given options and constraints. If there's no context size that can fit the available resources, an `InsufficientMemoryError` is thrown. #### Parameters | Parameter | Type | | ------ | ------ | | `contextSize` | | `number` | `"auto"` | { `min?`: `number`; `max?`: `number`; } | `undefined` | | `options` | { `modelGpuLayers`: `number`; `modelTrainContextSize`: `number`; `flashAttention?`: `boolean` | `"auto"`; `kvCacheKeyType?`: [`GgmlType`](../enumerations/GgmlType.md); `kvCacheValueType?`: [`GgmlType`](../enumerations/GgmlType.md); `swaFullCache?`: `boolean`; `useMmap?`: `boolean`; `batchSize?`: `number`; `sequences?`: `number`; `getVramState?`: [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{ `total`: `number`; `free`: `number`; `unifiedSize`: `number`; }>; `getRamState?`: [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{ `total`: `number`; `free`: `number`; }>; `getSwapState?`: [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{ `total`: `number`; `free`: `number`; }>; `llamaGpu?`: `false` | `"metal"` | `"cuda"` | `"vulkan"`; `ignoreMemorySafetyChecks?`: `boolean`; `isEmbeddingContext?`: `boolean`; } | | `options.modelGpuLayers` | `number` | | `options.modelTrainContextSize` | `number` | | `options.flashAttention?` | `boolean` | `"auto"` | | `options.kvCacheKeyType?` | [`GgmlType`](../enumerations/GgmlType.md) | | `options.kvCacheValueType?` | [`GgmlType`](../enumerations/GgmlType.md) | | `options.swaFullCache?` | `boolean` | | `options.useMmap?` | `boolean` | | `options.batchSize?` | `number` | | `options.sequences?` | `number` | | `options.getVramState?` | | `options.getRamState?` | | `options.getSwapState?` | | `options.llamaGpu?` | `false` | `"metal"` | `"cuda"` | `"vulkan"` | | `options.ignoreMemorySafetyChecks?` | `boolean` | | `options.isEmbeddingContext?` | `boolean` | #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`number`> --- --- url: /api/classes/GgufInsightsTokens.md --- # Class: GgufInsightsTokens Defined in: [gguf/insights/GgufInsightsTokens.ts:4](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/insights/GgufInsightsTokens.ts#L4) ## Accessors ### sepToken #### Get Signature ```ts get sepToken(): number | null; ``` Defined in: [gguf/insights/GgufInsightsTokens.ts:11](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/insights/GgufInsightsTokens.ts#L11) ##### Returns `number` | `null` *** ### eosToken #### Get Signature ```ts get eosToken(): number | null; ``` Defined in: [gguf/insights/GgufInsightsTokens.ts:26](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/insights/GgufInsightsTokens.ts#L26) ##### Returns `number` | `null` --- --- url: /api/classes/HarmonyChatWrapper.md --- # Class: HarmonyChatWrapper Defined in: [chatWrappers/HarmonyChatWrapper.ts:15](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/HarmonyChatWrapper.ts#L15) ## Extends * [`ChatWrapper`](ChatWrapper.md) ## Constructors ### Constructor ```ts new HarmonyChatWrapper(options?: { modelIdentity?: string | null; cuttingKnowledgeDate?: | string | number | Date | () => Date | null; todayDate?: | string | number | Date | () => Date | null; reasoningEffort?: "medium" | "high" | "low" | null; requiredChannels?: { analysis?: boolean; commentary?: boolean; final?: boolean; }; keepOnlyLastThought?: boolean; }): HarmonyChatWrapper; ``` Defined in: [chatWrappers/HarmonyChatWrapper.ts:58](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/HarmonyChatWrapper.ts#L58) #### Parameters | Parameter | Type | Description | | ------ | ------ | ------ | | `options` | { `modelIdentity?`: `string` | `null`; `cuttingKnowledgeDate?`: | `string` | `number` | [`Date`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date) | () => [`Date`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date) | `null`; `todayDate?`: | `string` | `number` | [`Date`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date) | () => [`Date`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date) | `null`; `reasoningEffort?`: `"medium"` | `"high"` | `"low"` | `null`; `requiredChannels?`: { `analysis?`: `boolean`; `commentary?`: `boolean`; `final?`: `boolean`; }; `keepOnlyLastThought?`: `boolean`; } | - | | `options.modelIdentity?` | `string` | `null` | The model identity to use in the internal system message. Set to `null` to disable. Defaults to `"You are ChatGPT, a large language model trained by OpenAI."` | | `options.cuttingKnowledgeDate?` | | `string` | `number` | [`Date`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date) | () => [`Date`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date) | `null` | Set to `null` to disable Defaults to `new Date("2024-06-01T00:00:00Z")` | | `options.todayDate?` | | `string` | `number` | [`Date`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date) | () => [`Date`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date) | `null` | Set to `null` to disable Defaults to the current date | | `options.reasoningEffort?` | `"medium"` | `"high"` | `"low"` | `null` | The amount of reasoning to instruct the model to use. Not enforced, it's up to the model to follow this instruction. Set to `null` to omit the instruction. Defaults to `"medium"`. | | `options.requiredChannels?` | { `analysis?`: `boolean`; `commentary?`: `boolean`; `final?`: `boolean`; } | - | | `options.requiredChannels.analysis?` | `boolean` | Defaults to `true` | | `options.requiredChannels.commentary?` | `boolean` | Defaults to `true` | | `options.requiredChannels.final?` | `boolean` | Defaults to `true` | | `options.keepOnlyLastThought?` | `boolean` | Whether to keep only the chain of thought from the last model response. Setting this to `false` will keep all the chain of thoughts from the model responses in the context state. Defaults to `true`. | #### Returns `HarmonyChatWrapper` #### Overrides [`ChatWrapper`](ChatWrapper.md).[`constructor`](ChatWrapper.md#constructor) ## Properties ### defaultSettings ```ts static defaultSettings: ChatWrapperSettings; ``` Defined in: [ChatWrapper.ts:15](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L15) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`defaultSettings`](ChatWrapper.md#defaultsettings) *** ### wrapperName ```ts readonly wrapperName: string = "Harmony"; ``` Defined in: [chatWrappers/HarmonyChatWrapper.ts:16](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/HarmonyChatWrapper.ts#L16) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`wrapperName`](ChatWrapper.md#wrappername) *** ### modelIdentity ```ts readonly modelIdentity: string | null; ``` Defined in: [chatWrappers/HarmonyChatWrapper.ts:18](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/HarmonyChatWrapper.ts#L18) *** ### cuttingKnowledgeDate? ```ts readonly optional cuttingKnowledgeDate: | Date | () => Date | null; ``` Defined in: [chatWrappers/HarmonyChatWrapper.ts:19](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/HarmonyChatWrapper.ts#L19) *** ### todayDate ```ts readonly todayDate: | Date | () => Date | null; ``` Defined in: [chatWrappers/HarmonyChatWrapper.ts:20](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/HarmonyChatWrapper.ts#L20) *** ### reasoningEffort ```ts readonly reasoningEffort: "medium" | "high" | "low" | null; ``` Defined in: [chatWrappers/HarmonyChatWrapper.ts:21](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/HarmonyChatWrapper.ts#L21) *** ### requiredChannels ```ts readonly requiredChannels: { analysis: boolean; commentary: boolean; final: boolean; }; ``` Defined in: [chatWrappers/HarmonyChatWrapper.ts:22](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/HarmonyChatWrapper.ts#L22) #### analysis ```ts analysis: boolean; ``` #### commentary ```ts commentary: boolean; ``` #### final ```ts final: boolean; ``` *** ### keepOnlyLastThought ```ts readonly keepOnlyLastThought: boolean; ``` Defined in: [chatWrappers/HarmonyChatWrapper.ts:27](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/HarmonyChatWrapper.ts#L27) *** ### settings ```ts readonly settings: ChatWrapperSettings; ``` Defined in: [chatWrappers/HarmonyChatWrapper.ts:31](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/HarmonyChatWrapper.ts#L31) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`settings`](ChatWrapper.md#settings) ## Methods ### generateFunctionCallsAndResults() ```ts generateFunctionCallsAndResults(functionCalls: ChatModelFunctionCall[], useRawCall?: boolean): LlamaText; ``` Defined in: [ChatWrapper.ts:63](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L63) #### Parameters | Parameter | Type | Default value | | ------ | ------ | ------ | | `functionCalls` | [`ChatModelFunctionCall`](../type-aliases/ChatModelFunctionCall.md)\[] | `undefined` | | `useRawCall` | `boolean` | `true` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCallsAndResults`](ChatWrapper.md#generatefunctioncallsandresults) *** ### addAvailableFunctionsSystemMessageToHistory() ```ts addAvailableFunctionsSystemMessageToHistory( history: readonly ChatHistoryItem[], availableFunctions?: ChatModelFunctions, __namedParameters?: { documentParams?: boolean; }): readonly ChatHistoryItem[]; ``` Defined in: [ChatWrapper.ts:269](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L269) #### Parameters | Parameter | Type | | ------ | ------ | | `history` | readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] | | `availableFunctions?` | [`ChatModelFunctions`](../type-aliases/ChatModelFunctions.md) | | `__namedParameters?` | { `documentParams?`: `boolean`; } | | `__namedParameters.documentParams?` | `boolean` | #### Returns readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`addAvailableFunctionsSystemMessageToHistory`](ChatWrapper.md#addavailablefunctionssystemmessagetohistory) *** ### generateInitialChatHistory() ```ts generateInitialChatHistory(__namedParameters?: ChatWrapperGenerateInitialHistoryOptions): ChatHistoryItem[]; ``` Defined in: [ChatWrapper.ts:290](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L290) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | [`ChatWrapperGenerateInitialHistoryOptions`](../type-aliases/ChatWrapperGenerateInitialHistoryOptions.md) | #### Returns [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateInitialChatHistory`](ChatWrapper.md#generateinitialchathistory) *** ### generateContextState() ```ts generateContextState(__namedParameters: ChatWrapperGenerateContextStateOptions): ChatWrapperGeneratedContextState; ``` Defined in: [chatWrappers/HarmonyChatWrapper.ts:164](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/HarmonyChatWrapper.ts#L164) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | [`ChatWrapperGenerateContextStateOptions`](../type-aliases/ChatWrapperGenerateContextStateOptions.md) | #### Returns [`ChatWrapperGeneratedContextState`](../type-aliases/ChatWrapperGeneratedContextState.md) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`generateContextState`](ChatWrapper.md#generatecontextstate) *** ### generateFunctionCall() ```ts generateFunctionCall(name: string, params: any): LlamaText; ``` Defined in: [chatWrappers/HarmonyChatWrapper.ts:314](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/HarmonyChatWrapper.ts#L314) #### Parameters | Parameter | Type | | ------ | ------ | | `name` | `string` | | `params` | `any` | #### Returns [`LlamaText`](LlamaText.md) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCall`](ChatWrapper.md#generatefunctioncall) *** ### generateFunctionCallResult() ```ts generateFunctionCallResult( functionName: string, functionParams: any, result: any): LlamaText; ``` Defined in: [chatWrappers/HarmonyChatWrapper.ts:329](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/HarmonyChatWrapper.ts#L329) #### Parameters | Parameter | Type | | ------ | ------ | | `functionName` | `string` | | `functionParams` | `any` | | `result` | `any` | #### Returns [`LlamaText`](LlamaText.md) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCallResult`](ChatWrapper.md#generatefunctioncallresult) *** ### generateModelResponseText() ```ts generateModelResponseText(modelResponse: ( | string | ChatModelFunctionCall | ChatModelSegment)[], useRawValues?: boolean): LlamaText; ``` Defined in: [chatWrappers/HarmonyChatWrapper.ts:343](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/HarmonyChatWrapper.ts#L343) #### Parameters | Parameter | Type | Default value | | ------ | ------ | ------ | | `modelResponse` | ( | `string` | [`ChatModelFunctionCall`](../type-aliases/ChatModelFunctionCall.md) | [`ChatModelSegment`](../type-aliases/ChatModelSegment.md))\[] | `undefined` | | `useRawValues` | `boolean` | `true` | #### Returns [`LlamaText`](LlamaText.md) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`generateModelResponseText`](ChatWrapper.md#generatemodelresponsetext) *** ### generateAvailableFunctionsSystemText() ```ts generateAvailableFunctionsSystemText(availableFunctions: ChatModelFunctions, __namedParameters: { documentParams?: boolean; }): LlamaText; ``` Defined in: [chatWrappers/HarmonyChatWrapper.ts:364](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/HarmonyChatWrapper.ts#L364) #### Parameters | Parameter | Type | | ------ | ------ | | `availableFunctions` | [`ChatModelFunctions`](../type-aliases/ChatModelFunctions.md) | | `__namedParameters` | { `documentParams?`: `boolean`; } | | `__namedParameters.documentParams?` | `boolean` | #### Returns [`LlamaText`](LlamaText.md) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`generateAvailableFunctionsSystemText`](ChatWrapper.md#generateavailablefunctionssystemtext) --- --- url: /api/classes/InputLookupTokenPredictor.md --- # Class: InputLookupTokenPredictor Defined in: [evaluator/LlamaContext/tokenPredictors/InputLookupTokenPredictor.ts:22](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/tokenPredictors/InputLookupTokenPredictor.ts#L22) Attempts to find the last few generated tokens in the input (prompt) tokens to predict the next tokens. This is useful in input-grounded tasks (when the model frequently repeats some of the input tokens in the output, such as in text summarization or modifying code). This works in all completion classes, including `LlamaChatSession`, `LlamaChat`, and `LlamaCompletion`. Based on https://github.com/apoorvumang/prompt-lookup-decoding. ## See [Using Token Predictors: Input Lookup Token Predictor](https://node-llama-cpp.withcat.ai/guide/token-prediction#input-lookup) ## Extends * [`TokenPredictor`](TokenPredictor.md) ## Constructors ### Constructor ```ts new InputLookupTokenPredictor(options?: { patternLength?: { min?: number; max?: number; }; predictionLength?: { min?: number; max?: number; }; }): InputLookupTokenPredictor; ``` Defined in: [evaluator/LlamaContext/tokenPredictors/InputLookupTokenPredictor.ts:33](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/tokenPredictors/InputLookupTokenPredictor.ts#L33) #### Parameters | Parameter | Type | Description | | ------ | ------ | ------ | | `options` | { `patternLength?`: { `min?`: `number`; `max?`: `number`; }; `predictionLength?`: { `min?`: `number`; `max?`: `number`; }; } | - | | `options.patternLength?` | { `min?`: `number`; `max?`: `number`; } | - | | `options.patternLength.min?` | `number` | Min pattern length to look for in the input tokens. Defaults to `1`. | | `options.patternLength.max?` | `number` | Max pattern length to look for in the input tokens. Set to `0` to disable the max pattern size. Defaults to `0`. | | `options.predictionLength?` | { `min?`: `number`; `max?`: `number`; } | - | | `options.predictionLength.min?` | `number` | Minimum number of tokens to predict. Defaults to `1`. | | `options.predictionLength.max?` | `number` | Maximum number of tokens to predict. Defaults to `3`. | #### Returns `InputLookupTokenPredictor` #### Overrides [`TokenPredictor`](TokenPredictor.md).[`constructor`](TokenPredictor.md#constructor) ## Accessors ### patternMinLength #### Get Signature ```ts get patternMinLength(): number; ``` Defined in: [evaluator/LlamaContext/tokenPredictors/InputLookupTokenPredictor.ts:86](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/tokenPredictors/InputLookupTokenPredictor.ts#L86) ##### Returns `number` *** ### patternMaxLength #### Get Signature ```ts get patternMaxLength(): number; ``` Defined in: [evaluator/LlamaContext/tokenPredictors/InputLookupTokenPredictor.ts:90](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/tokenPredictors/InputLookupTokenPredictor.ts#L90) ##### Returns `number` *** ### predictionMinLength #### Get Signature ```ts get predictionMinLength(): number; ``` Defined in: [evaluator/LlamaContext/tokenPredictors/InputLookupTokenPredictor.ts:94](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/tokenPredictors/InputLookupTokenPredictor.ts#L94) ##### Returns `number` *** ### predictionMaxLength #### Get Signature ```ts get predictionMaxLength(): number; ``` Defined in: [evaluator/LlamaContext/tokenPredictors/InputLookupTokenPredictor.ts:98](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/tokenPredictors/InputLookupTokenPredictor.ts#L98) ##### Returns `number` ## Methods ### stop() ```ts stop(untilPredictionsExhausted?: boolean): | void | Promise; ``` Defined in: [evaluator/LlamaContext/TokenPredictor.ts:52](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/TokenPredictor.ts#L52) Stops the prediction process when it runs in the background. #### Parameters | Parameter | Type | Description | | ------ | ------ | ------ | | `untilPredictionsExhausted?` | `boolean` | If true, the prediction process should not resume until the current predictions are exhausted. | #### Returns | `void` | [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`> #### Inherited from [`TokenPredictor`](TokenPredictor.md).[`stop`](TokenPredictor.md#stop) *** ### reset() ```ts reset(__namedParameters: { stateTokens: Token[]; }): void; ``` Defined in: [evaluator/LlamaContext/tokenPredictors/InputLookupTokenPredictor.ts:102](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/tokenPredictors/InputLookupTokenPredictor.ts#L102) Resets the state of the predictor. Called before the generation starts. #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | { `stateTokens`: [`Token`](../type-aliases/Token.md)\[]; } | | `__namedParameters.stateTokens` | [`Token`](../type-aliases/Token.md)\[] | #### Returns `void` #### Overrides [`TokenPredictor`](TokenPredictor.md).[`reset`](TokenPredictor.md#reset) *** ### updateInputTokens() ```ts updateInputTokens(tokens: Token[]): void; ``` Defined in: [evaluator/LlamaContext/tokenPredictors/InputLookupTokenPredictor.ts:110](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/tokenPredictors/InputLookupTokenPredictor.ts#L110) Called with the input tokens before the generation starts when using `LlamaChatSession`, `LlamaChat`, and `LlamaCompletion`. #### Parameters | Parameter | Type | | ------ | ------ | | `tokens` | [`Token`](../type-aliases/Token.md)\[] | #### Returns `void` #### Overrides [`TokenPredictor`](TokenPredictor.md).[`updateInputTokens`](TokenPredictor.md#updateinputtokens) *** ### pushTokens() ```ts pushTokens(tokens: Token[]): void; ``` Defined in: [evaluator/LlamaContext/tokenPredictors/InputLookupTokenPredictor.ts:116](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/tokenPredictors/InputLookupTokenPredictor.ts#L116) #### Parameters | Parameter | Type | | ------ | ------ | | `tokens` | [`Token`](../type-aliases/Token.md)\[] | #### Returns `void` #### Overrides [`TokenPredictor`](TokenPredictor.md).[`pushTokens`](TokenPredictor.md#pushtokens) *** ### predictTokens() ```ts predictTokens(): Token[]; ``` Defined in: [evaluator/LlamaContext/tokenPredictors/InputLookupTokenPredictor.ts:124](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/tokenPredictors/InputLookupTokenPredictor.ts#L124) Predicts the next tokens based on the current state. If the generation should wait until the minimum predications are ready, this method should return a promise that resolves when the minimum predictions are ready. A background prediction process can be started when this function is called, so that the next predictions will be ready when this function is called again. #### Returns [`Token`](../type-aliases/Token.md)\[] #### Overrides [`TokenPredictor`](TokenPredictor.md).[`predictTokens`](TokenPredictor.md#predicttokens) *** ### dispose() ```ts dispose(): void; ``` Defined in: [evaluator/LlamaContext/tokenPredictors/InputLookupTokenPredictor.ts:169](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/tokenPredictors/InputLookupTokenPredictor.ts#L169) #### Returns `void` #### Overrides [`TokenPredictor`](TokenPredictor.md).[`dispose`](TokenPredictor.md#dispose) --- --- url: /api/classes/InsufficientMemoryError.md --- # Class: InsufficientMemoryError Defined in: [utils/InsufficientMemoryError.ts:1](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/InsufficientMemoryError.ts#L1) ## Extends * [`Error`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error) ## Constructors ### Constructor ```ts new InsufficientMemoryError(message?: string): InsufficientMemoryError; ``` Defined in: [utils/InsufficientMemoryError.ts:2](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/InsufficientMemoryError.ts#L2) #### Parameters | Parameter | Type | Default value | | ------ | ------ | ------ | | `message` | `string` | `"Insufficient memory"` | #### Returns `InsufficientMemoryError` #### Overrides ```ts Error.constructor ``` --- --- url: /api/classes/JinjaTemplateChatWrapper.md --- # Class: JinjaTemplateChatWrapper Defined in: [chatWrappers/generic/JinjaTemplateChatWrapper.ts:172](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/generic/JinjaTemplateChatWrapper.ts#L172) A chat wrapper based on a Jinja template. Useful for using the original model's Jinja template as-is without any additional conversion work to chat with a model. If you want to create a new chat wrapper from scratch, using this chat wrapper is not recommended, and instead you better inherit from the `ChatWrapper` class and implement a custom chat wrapper of your own in TypeScript. For a simpler way to create a chat wrapper, see the `TemplateChatWrapper` class. ## Example ```ts import {JinjaTemplateChatWrapper} from "node-llama-cpp"; const chatWrapper = new JinjaTemplateChatWrapper({ template: "", // functionCallMessageTemplate: { // optional // call: "[[call: {{functionName}}({{functionParams}})]]", // result: " [[result: {{functionCallResult}}]]" // }, // segments: { // thoughtTemplate: "{{content}}", // reopenThoughtAfterFunctionCalls: true // } }); ``` ## Extends * [`ChatWrapper`](ChatWrapper.md) ## Constructors ### Constructor ```ts new JinjaTemplateChatWrapper(options: JinjaTemplateChatWrapperOptions): JinjaTemplateChatWrapper; ``` Defined in: [chatWrappers/generic/JinjaTemplateChatWrapper.ts:198](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/generic/JinjaTemplateChatWrapper.ts#L198) #### Parameters | Parameter | Type | Description | | ------ | ------ | ------ | | `options` | [`JinjaTemplateChatWrapperOptions`](../type-aliases/JinjaTemplateChatWrapperOptions.md) | - | #### Returns `JinjaTemplateChatWrapper` #### Overrides [`ChatWrapper`](ChatWrapper.md).[`constructor`](ChatWrapper.md#constructor) ## Properties ### defaultSettings ```ts static defaultSettings: ChatWrapperSettings; ``` Defined in: [ChatWrapper.ts:15](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L15) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`defaultSettings`](ChatWrapper.md#defaultsettings) *** ### wrapperName ```ts readonly wrapperName: "JinjaTemplate" = "JinjaTemplate"; ``` Defined in: [chatWrappers/generic/JinjaTemplateChatWrapper.ts:173](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/generic/JinjaTemplateChatWrapper.ts#L173) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`wrapperName`](ChatWrapper.md#wrappername) *** ### settings ```ts readonly settings: ChatWrapperSettings; ``` Defined in: [chatWrappers/generic/JinjaTemplateChatWrapper.ts:174](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/generic/JinjaTemplateChatWrapper.ts#L174) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`settings`](ChatWrapper.md#settings) *** ### template ```ts readonly template: string; ``` Defined in: [chatWrappers/generic/JinjaTemplateChatWrapper.ts:176](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/generic/JinjaTemplateChatWrapper.ts#L176) *** ### reasoning ```ts readonly reasoning: boolean | null; ``` Defined in: [chatWrappers/generic/JinjaTemplateChatWrapper.ts:177](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/generic/JinjaTemplateChatWrapper.ts#L177) *** ### modelRoleName ```ts readonly modelRoleName: string; ``` Defined in: [chatWrappers/generic/JinjaTemplateChatWrapper.ts:178](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/generic/JinjaTemplateChatWrapper.ts#L178) *** ### userRoleName ```ts readonly userRoleName: string; ``` Defined in: [chatWrappers/generic/JinjaTemplateChatWrapper.ts:179](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/generic/JinjaTemplateChatWrapper.ts#L179) *** ### systemRoleName ```ts readonly systemRoleName: string; ``` Defined in: [chatWrappers/generic/JinjaTemplateChatWrapper.ts:180](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/generic/JinjaTemplateChatWrapper.ts#L180) *** ### convertUnsupportedSystemMessagesToUserMessages? ```ts readonly optional convertUnsupportedSystemMessagesToUserMessages: JinjaTemplateChatWrapperOptionsConvertMessageFormat; ``` Defined in: [chatWrappers/generic/JinjaTemplateChatWrapper.ts:181](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/generic/JinjaTemplateChatWrapper.ts#L181) *** ### joinAdjacentMessagesOfTheSameType ```ts readonly joinAdjacentMessagesOfTheSameType: boolean; ``` Defined in: [chatWrappers/generic/JinjaTemplateChatWrapper.ts:182](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/generic/JinjaTemplateChatWrapper.ts#L182) *** ### trimLeadingWhitespaceInResponses ```ts readonly trimLeadingWhitespaceInResponses: boolean; ``` Defined in: [chatWrappers/generic/JinjaTemplateChatWrapper.ts:183](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/generic/JinjaTemplateChatWrapper.ts#L183) *** ### keepOnlyLastThought ```ts readonly keepOnlyLastThought: boolean; ``` Defined in: [chatWrappers/generic/JinjaTemplateChatWrapper.ts:184](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/generic/JinjaTemplateChatWrapper.ts#L184) *** ### additionalRenderParameters? ```ts readonly optional additionalRenderParameters: Record; ``` Defined in: [chatWrappers/generic/JinjaTemplateChatWrapper.ts:185](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/generic/JinjaTemplateChatWrapper.ts#L185) ## Accessors ### usingJinjaFunctionCallTemplate #### Get Signature ```ts get usingJinjaFunctionCallTemplate(): boolean; ``` Defined in: [chatWrappers/generic/JinjaTemplateChatWrapper.ts:441](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/generic/JinjaTemplateChatWrapper.ts#L441) Whether the function call syntax settings were extracted from the given Jinja template. The function call syntax settings can be accessed using the `.settings.functions` property. ##### Returns `boolean` ## Methods ### generateFunctionCallsAndResults() ```ts generateFunctionCallsAndResults(functionCalls: ChatModelFunctionCall[], useRawCall?: boolean): LlamaText; ``` Defined in: [ChatWrapper.ts:63](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L63) #### Parameters | Parameter | Type | Default value | | ------ | ------ | ------ | | `functionCalls` | [`ChatModelFunctionCall`](../type-aliases/ChatModelFunctionCall.md)\[] | `undefined` | | `useRawCall` | `boolean` | `true` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCallsAndResults`](ChatWrapper.md#generatefunctioncallsandresults) *** ### generateModelResponseText() ```ts generateModelResponseText(modelResponse: ( | string | ChatModelFunctionCall | ChatModelSegment)[], useRawValues?: boolean): LlamaText; ``` Defined in: [ChatWrapper.ts:158](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L158) #### Parameters | Parameter | Type | Default value | | ------ | ------ | ------ | | `modelResponse` | ( | `string` | [`ChatModelFunctionCall`](../type-aliases/ChatModelFunctionCall.md) | [`ChatModelSegment`](../type-aliases/ChatModelSegment.md))\[] | `undefined` | | `useRawValues` | `boolean` | `true` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateModelResponseText`](ChatWrapper.md#generatemodelresponsetext) *** ### generateAvailableFunctionsSystemText() ```ts generateAvailableFunctionsSystemText(availableFunctions: ChatModelFunctions, __namedParameters: { documentParams?: boolean; }): LlamaText; ``` Defined in: [ChatWrapper.ts:243](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L243) #### Parameters | Parameter | Type | | ------ | ------ | | `availableFunctions` | [`ChatModelFunctions`](../type-aliases/ChatModelFunctions.md) | | `__namedParameters` | { `documentParams?`: `boolean`; } | | `__namedParameters.documentParams?` | `boolean` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateAvailableFunctionsSystemText`](ChatWrapper.md#generateavailablefunctionssystemtext) *** ### generateInitialChatHistory() ```ts generateInitialChatHistory(__namedParameters?: ChatWrapperGenerateInitialHistoryOptions): ChatHistoryItem[]; ``` Defined in: [ChatWrapper.ts:290](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L290) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | [`ChatWrapperGenerateInitialHistoryOptions`](../type-aliases/ChatWrapperGenerateInitialHistoryOptions.md) | #### Returns [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateInitialChatHistory`](ChatWrapper.md#generateinitialchathistory) *** ### generateContextState() ```ts generateContextState(__namedParameters: ChatWrapperGenerateContextStateOptions): ChatWrapperGeneratedContextState & { transformedSystemMessagesToUserMessages: boolean; }; ``` Defined in: [chatWrappers/generic/JinjaTemplateChatWrapper.ts:445](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/generic/JinjaTemplateChatWrapper.ts#L445) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | [`ChatWrapperGenerateContextStateOptions`](../type-aliases/ChatWrapperGenerateContextStateOptions.md) | #### Returns [`ChatWrapperGeneratedContextState`](../type-aliases/ChatWrapperGeneratedContextState.md) & { `transformedSystemMessagesToUserMessages`: `boolean`; } #### Overrides [`ChatWrapper`](ChatWrapper.md).[`generateContextState`](ChatWrapper.md#generatecontextstate) *** ### addAvailableFunctionsSystemMessageToHistory() ```ts addAvailableFunctionsSystemMessageToHistory( history: readonly ChatHistoryItem[], availableFunctions?: ChatModelFunctions, options?: { documentParams?: boolean; }): readonly ChatHistoryItem[]; ``` Defined in: [chatWrappers/generic/JinjaTemplateChatWrapper.ts:460](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/generic/JinjaTemplateChatWrapper.ts#L460) #### Parameters | Parameter | Type | | ------ | ------ | | `history` | readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] | | `availableFunctions?` | [`ChatModelFunctions`](../type-aliases/ChatModelFunctions.md) | | `options?` | { `documentParams?`: `boolean`; } | | `options.documentParams?` | `boolean` | #### Returns readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] #### Overrides [`ChatWrapper`](ChatWrapper.md).[`addAvailableFunctionsSystemMessageToHistory`](ChatWrapper.md#addavailablefunctionssystemmessagetohistory) *** ### generateFunctionCall() ```ts generateFunctionCall(name: string, params: any): LlamaText; ``` Defined in: [chatWrappers/generic/JinjaTemplateChatWrapper.ts:471](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/generic/JinjaTemplateChatWrapper.ts#L471) #### Parameters | Parameter | Type | | ------ | ------ | | `name` | `string` | | `params` | `any` | #### Returns [`LlamaText`](LlamaText.md) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCall`](ChatWrapper.md#generatefunctioncall) *** ### generateFunctionCallResult() ```ts generateFunctionCallResult( functionName: string, functionParams: any, result: any): LlamaText; ``` Defined in: [chatWrappers/generic/JinjaTemplateChatWrapper.ts:491](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/generic/JinjaTemplateChatWrapper.ts#L491) #### Parameters | Parameter | Type | | ------ | ------ | | `functionName` | `string` | | `functionParams` | `any` | | `result` | `any` | #### Returns [`LlamaText`](LlamaText.md) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCallResult`](ChatWrapper.md#generatefunctioncallresult) --- --- url: /api/classes/Llama.md --- # Class: Llama Defined in: [bindings/Llama.ts:40](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/Llama.ts#L40) ## Properties ### onDispose ```ts readonly onDispose: EventRelay; ``` Defined in: [bindings/Llama.ts:81](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/Llama.ts#L81) ## Accessors ### disposed #### Get Signature ```ts get disposed(): boolean; ``` Defined in: [bindings/Llama.ts:207](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/Llama.ts#L207) ##### Returns `boolean` *** ### classes #### Get Signature ```ts get classes(): LlamaClasses; ``` Defined in: [bindings/Llama.ts:211](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/Llama.ts#L211) ##### Returns [`LlamaClasses`](../type-aliases/LlamaClasses.md) *** ### gpu #### Get Signature ```ts get gpu(): LlamaGpuType; ``` Defined in: [bindings/Llama.ts:218](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/Llama.ts#L218) ##### Returns [`LlamaGpuType`](../type-aliases/LlamaGpuType.md) *** ### supportsGpuOffloading #### Get Signature ```ts get supportsGpuOffloading(): boolean; ``` Defined in: [bindings/Llama.ts:222](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/Llama.ts#L222) ##### Returns `boolean` *** ### supportsMmap #### Get Signature ```ts get supportsMmap(): boolean; ``` Defined in: [bindings/Llama.ts:226](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/Llama.ts#L226) ##### Returns `boolean` *** ### gpuSupportsMmap #### Get Signature ```ts get gpuSupportsMmap(): boolean; ``` Defined in: [bindings/Llama.ts:230](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/Llama.ts#L230) ##### Returns `boolean` *** ### supportsMlock #### Get Signature ```ts get supportsMlock(): boolean; ``` Defined in: [bindings/Llama.ts:234](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/Llama.ts#L234) ##### Returns `boolean` *** ### cpuMathCores #### Get Signature ```ts get cpuMathCores(): number; ``` Defined in: [bindings/Llama.ts:239](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/Llama.ts#L239) The number of CPU cores that are useful for math ##### Returns `number` *** ### maxThreads #### Get Signature ```ts get maxThreads(): number; ``` Defined in: [bindings/Llama.ts:250](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/Llama.ts#L250) The maximum number of threads that can be used by the Llama instance. If set to `0`, the Llama instance will have no limit on the number of threads. See the `maxThreads` option of `getLlama` for more information. ##### Returns `number` #### Set Signature ```ts set maxThreads(value: number): void; ``` Defined in: [bindings/Llama.ts:254](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/Llama.ts#L254) ##### Parameters | Parameter | Type | | ------ | ------ | | `value` | `number` | ##### Returns `void` *** ### numa #### Get Signature ```ts get numa(): LlamaNuma; ``` Defined in: [bindings/Llama.ts:261](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/Llama.ts#L261) See the `numa` option of `getLlama` for more information ##### Returns [`LlamaNuma`](../type-aliases/LlamaNuma.md) *** ### logLevel #### Get Signature ```ts get logLevel(): LlamaLogLevel; ``` Defined in: [bindings/Llama.ts:265](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/Llama.ts#L265) ##### Returns [`LlamaLogLevel`](../enumerations/LlamaLogLevel.md) #### Set Signature ```ts set logLevel(value: LlamaLogLevel): void; ``` Defined in: [bindings/Llama.ts:269](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/Llama.ts#L269) ##### Parameters | Parameter | Type | | ------ | ------ | | `value` | [`LlamaLogLevel`](../enumerations/LlamaLogLevel.md) | ##### Returns `void` *** ### logger #### Get Signature ```ts get logger(): (level: LlamaLogLevel, message: string) => void; ``` Defined in: [bindings/Llama.ts:279](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/Llama.ts#L279) ##### Returns ```ts (level: LlamaLogLevel, message: string): void; ``` ###### Parameters | Parameter | Type | | ------ | ------ | | `level` | [`LlamaLogLevel`](../enumerations/LlamaLogLevel.md) | | `message` | `string` | ###### Returns `void` #### Set Signature ```ts set logger(value: (level: LlamaLogLevel, message: string) => void): void; ``` Defined in: [bindings/Llama.ts:283](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/Llama.ts#L283) ##### Parameters | Parameter | Type | | ------ | ------ | | `value` | (`level`: [`LlamaLogLevel`](../enumerations/LlamaLogLevel.md), `message`: `string`) => `void` | ##### Returns `void` *** ### buildType #### Get Signature ```ts get buildType(): "localBuild" | "prebuilt"; ``` Defined in: [bindings/Llama.ts:290](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/Llama.ts#L290) ##### Returns `"localBuild"` | `"prebuilt"` *** ### cmakeOptions #### Get Signature ```ts get cmakeOptions(): Readonly>; ``` Defined in: [bindings/Llama.ts:294](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/Llama.ts#L294) ##### Returns [`Readonly`](https://www.typescriptlang.org/docs/handbook/utility-types.html#readonlytype)<[`Record`](https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkeys-type)<`string`, `string`>> *** ### llamaCppRelease #### Get Signature ```ts get llamaCppRelease(): { repo: string; release: string; }; ``` Defined in: [bindings/Llama.ts:298](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/Llama.ts#L298) ##### Returns ```ts { repo: string; release: string; } ``` ###### repo ```ts readonly repo: string; ``` ###### release ```ts readonly release: string; ``` *** ### systemInfo #### Get Signature ```ts get systemInfo(): string; ``` Defined in: [bindings/Llama.ts:302](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/Llama.ts#L302) ##### Returns `string` *** ### vramPaddingSize #### Get Signature ```ts get vramPaddingSize(): number; ``` Defined in: [bindings/Llama.ts:314](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/Llama.ts#L314) VRAM padding used for memory size calculations, as these calculations are not always accurate. This is set by default to ensure stability, but can be configured when you call `getLlama`. See `vramPadding` on `getLlama` for more information. ##### Returns `number` *** ### ramPaddingSize #### Get Signature ```ts get ramPaddingSize(): number; ``` Defined in: [bindings/Llama.ts:324](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/Llama.ts#L324) RAM padding used for memory size calculations, as these calculations are not always accurate. This is set by default to ensure stability, but can be configured when you call `getLlama`. See `ramPadding` on `getLlama` for more information. ##### Returns `number` ## Methods ### dispose() ```ts dispose(): Promise; ``` Defined in: [bindings/Llama.ts:188](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/Llama.ts#L188) #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`> *** ### getVramState() ```ts getVramState(): Promise<{ total: number; used: number; free: number; unifiedSize: number; }>; ``` Defined in: [bindings/Llama.ts:334](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/Llama.ts#L334) The total amount of VRAM that is currently being used. `unifiedSize` represents the amount of VRAM that is shared between the CPU and GPU. On SoC devices, this is usually the same as `total`. #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{ `total`: `number`; `used`: `number`; `free`: `number`; `unifiedSize`: `number`; }> *** ### getRamState() ```ts getRamState(): Promise; ``` Defined in: [bindings/Llama.ts:348](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/Llama.ts#L348) Get the state of the system RAM #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[`RamState`](../type-aliases/RamState.md)> *** ### getSwapState() ```ts getSwapState(): Promise<{ maxSize: number; allocated: number; used: number; }>; ``` Defined in: [bindings/Llama.ts:366](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/Llama.ts#L366) Get the state of the swap memory. **`maxSize`** - The maximum size of the swap memory that the system can allocate. If the swap size is dynamic (like on macOS), this will be `Infinity`. **`allocated`** - The total size allocated by the system for swap memory. **`used`** - The amount of swap memory that is currently being used from the `allocated` size. On Windows, this will return the info for the page file. #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{ `maxSize`: `number`; `allocated`: `number`; `used`: `number`; }> *** ### getLlamaMemoryUsage() ```ts getLlamaMemoryUsage(): Promise<{ gpuVram: number; cpuRam: number; }>; ``` Defined in: [bindings/Llama.ts:395](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/Llama.ts#L395) Get the total memory usage of this Llama instance #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{ `gpuVram`: `number`; `cpuRam`: `number`; }> *** ### setVramCap() ```ts setVramCap(bytes: number | null): Promise; ``` Defined in: [bindings/Llama.ts:416](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/Llama.ts#L416) Cap the amount of VRAM that this Llama instance is allowed to use in bytes. This is useful for constraining the resource usage of models and contexts created with the Llama instance. Capping to a value that's too low may cause model loads and context creations to either fail or not fully offload to VRAM, causing inference to be significantly slower. Setting a cap will only affect future model loads and context creations. Use with caution. Setting to `null` disables the cap. Defaults to `null`. #### Parameters | Parameter | Type | | ------ | ------ | | `bytes` | `number` | `null` | #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`> *** ### getVramCap() ```ts getVramCap(): number | null; ``` Defined in: [bindings/Llama.ts:431](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/Llama.ts#L431) Get the current VRAM cap in bytes. See [\`setVramCap\`](#setvramcap) for more information. Defaults to `null`, which means no cap is set. #### Returns `number` | `null` *** ### setRamCap() ```ts setRamCap(bytes: number | null): Promise; ``` Defined in: [bindings/Llama.ts:455](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/Llama.ts#L455) Cap the amount of RAM that this Llama instance is allowed to use in bytes. This is useful for constraining the resource usage of models and contexts created with the Llama instance. Capping to a value that's too low may cause model loads and context creations to fail. Capping to any value will exclude swap from the resource calculations, so extremely large models may not load at all even if you have enough swap available. Setting a cap will only affect future model loads and context creations. On unified memory systems, capping the RAM may also effectively cap the VRAM, as they are shared. On such systems, it's recommended to either cap the VRAM or the RAM (but not both), and if you need to cap both then make sure to set the RAM cap to a value greater than the VRAM cap. > **Note:** You can detect a unified memory system by checking whether `getVramState().unifiedSize` is greater than 0. Use with caution. Setting to `null` disables the cap. Defaults to `null`. #### Parameters | Parameter | Type | | ------ | ------ | | `bytes` | `number` | `null` | #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`> *** ### getRamCap() ```ts getRamCap(): number | null; ``` Defined in: [bindings/Llama.ts:472](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/Llama.ts#L472) Get the current RAM cap in bytes. See [\`setRamCap\`](#setramcap) for more information. Defaults to `null`, which means no cap is set. #### Returns `number` | `null` *** ### getGpuDeviceNames() ```ts getGpuDeviceNames(): Promise; ``` Defined in: [bindings/Llama.ts:476](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/Llama.ts#L476) #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`string`\[]> *** ### loadModel() ```ts loadModel(options: LlamaModelOptions): Promise; ``` Defined in: [bindings/Llama.ts:484](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/Llama.ts#L484) #### Parameters | Parameter | Type | | ------ | ------ | | `options` | [`LlamaModelOptions`](../type-aliases/LlamaModelOptions.md) | #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[`LlamaModel`](LlamaModel.md)> *** ### createGrammarForJsonSchema() ```ts createGrammarForJsonSchema(schema: Readonly & GbnfJsonSchema): Promise>; ``` Defined in: [bindings/Llama.ts:504](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/Llama.ts#L504) #### Type Parameters | Type Parameter | Default type | | ------ | ------ | | `T` *extends* | [`GbnfJsonBasicSchema`](../type-aliases/GbnfJsonBasicSchema.md) | [`GbnfJsonConstSchema`](../type-aliases/GbnfJsonConstSchema.md) | [`GbnfJsonEnumSchema`](../type-aliases/GbnfJsonEnumSchema.md) | [`GbnfJsonBasicStringSchema`](../type-aliases/GbnfJsonBasicStringSchema.md) | [`GbnfJsonFormatStringSchema`](../type-aliases/GbnfJsonFormatStringSchema.md) | [`GbnfJsonOneOfSchema`](../type-aliases/GbnfJsonOneOfSchema.md)<`Defs`> | [`GbnfJsonObjectSchema`](../type-aliases/GbnfJsonObjectSchema.md)<`string`, `Defs`> | [`GbnfJsonArraySchema`](../type-aliases/GbnfJsonArraySchema.md)<`Defs`> | [`GbnfJsonRefSchema`](../type-aliases/GbnfJsonRefSchema.md)<`Defs`> | - | | `Defs` *extends* [`GbnfJsonDefList`](../type-aliases/GbnfJsonDefList.md)<`Defs`> | [`Record`](https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkeys-type)<`any`, `any`> | #### Parameters | Parameter | Type | | ------ | ------ | | `schema` | [`Readonly`](https://www.typescriptlang.org/docs/handbook/utility-types.html#readonlytype)<`T`> & [`GbnfJsonSchema`](../type-aliases/GbnfJsonSchema.md)<`Defs`> | #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[`LlamaJsonSchemaGrammar`](LlamaJsonSchemaGrammar.md)<`T`, `Defs`>> #### See * [Using a JSON Schema Grammar](https://node-llama-cpp.withcat.ai/guide/grammar#json-schema) tutorial * [Reducing Hallucinations When Using JSON Schema Grammar](https://node-llama-cpp.withcat.ai/guide/grammar#reducing-json-schema-hallucinations) tutorial *** ### getGrammarFor() ```ts getGrammarFor(type: | "json" | "json_arr" | "english" | "list" | "c" | "arithmetic" | "japanese" | "chess"): Promise; ``` Defined in: [bindings/Llama.ts:512](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/Llama.ts#L512) #### Parameters | Parameter | Type | | ------ | ------ | | `type` | | `"json"` | `"json_arr"` | `"english"` | `"list"` | `"c"` | `"arithmetic"` | `"japanese"` | `"chess"` | #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[`LlamaGrammar`](LlamaGrammar.md)> *** ### createGrammar() ```ts createGrammar(options: LlamaGrammarOptions): Promise; ``` Defined in: [bindings/Llama.ts:519](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/Llama.ts#L519) #### Parameters | Parameter | Type | | ------ | ------ | | `options` | [`LlamaGrammarOptions`](../type-aliases/LlamaGrammarOptions.md) | #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[`LlamaGrammar`](LlamaGrammar.md)> #### See [Using Grammar](https://node-llama-cpp.withcat.ai/guide/grammar) tutorial *** ### defaultConsoleLogger() ```ts static defaultConsoleLogger(level: LlamaLogLevel, message: string): void; ``` Defined in: [bindings/Llama.ts:794](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/Llama.ts#L794) #### Parameters | Parameter | Type | | ------ | ------ | | `level` | [`LlamaLogLevel`](../enumerations/LlamaLogLevel.md) | | `message` | `string` | #### Returns `void` --- --- url: /api/classes/Llama2ChatWrapper.md --- # Class: Llama2ChatWrapper Defined in: [chatWrappers/Llama2ChatWrapper.ts:6](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/Llama2ChatWrapper.ts#L6) ## Extends * [`ChatWrapper`](ChatWrapper.md) ## Constructors ### Constructor ```ts new Llama2ChatWrapper(__namedParameters?: { addSpaceBeforeEos?: boolean; }): Llama2ChatWrapper; ``` Defined in: [chatWrappers/Llama2ChatWrapper.ts:11](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/Llama2ChatWrapper.ts#L11) #### Parameters | Parameter | Type | Description | | ------ | ------ | ------ | | `__namedParameters` | { `addSpaceBeforeEos?`: `boolean`; } | - | | `__namedParameters.addSpaceBeforeEos?` | `boolean` | Default to `true` | #### Returns `Llama2ChatWrapper` #### Overrides [`ChatWrapper`](ChatWrapper.md).[`constructor`](ChatWrapper.md#constructor) ## Properties ### defaultSettings ```ts static defaultSettings: ChatWrapperSettings; ``` Defined in: [ChatWrapper.ts:15](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L15) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`defaultSettings`](ChatWrapper.md#defaultsettings) *** ### settings ```ts readonly settings: ChatWrapperSettings = ChatWrapper.defaultSettings; ``` Defined in: [ChatWrapper.ts:36](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L36) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`settings`](ChatWrapper.md#settings) *** ### wrapperName ```ts readonly wrapperName: string = "Llama2Chat"; ``` Defined in: [chatWrappers/Llama2ChatWrapper.ts:7](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/Llama2ChatWrapper.ts#L7) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`wrapperName`](ChatWrapper.md#wrappername) ## Methods ### generateFunctionCallsAndResults() ```ts generateFunctionCallsAndResults(functionCalls: ChatModelFunctionCall[], useRawCall?: boolean): LlamaText; ``` Defined in: [ChatWrapper.ts:63](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L63) #### Parameters | Parameter | Type | Default value | | ------ | ------ | ------ | | `functionCalls` | [`ChatModelFunctionCall`](../type-aliases/ChatModelFunctionCall.md)\[] | `undefined` | | `useRawCall` | `boolean` | `true` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCallsAndResults`](ChatWrapper.md#generatefunctioncallsandresults) *** ### generateFunctionCall() ```ts generateFunctionCall(name: string, params: any): LlamaText; ``` Defined in: [ChatWrapper.ts:110](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L110) #### Parameters | Parameter | Type | | ------ | ------ | | `name` | `string` | | `params` | `any` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCall`](ChatWrapper.md#generatefunctioncall) *** ### generateFunctionCallResult() ```ts generateFunctionCallResult( functionName: string, functionParams: any, result: any): LlamaText; ``` Defined in: [ChatWrapper.ts:127](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L127) #### Parameters | Parameter | Type | | ------ | ------ | | `functionName` | `string` | | `functionParams` | `any` | | `result` | `any` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCallResult`](ChatWrapper.md#generatefunctioncallresult) *** ### generateModelResponseText() ```ts generateModelResponseText(modelResponse: ( | string | ChatModelFunctionCall | ChatModelSegment)[], useRawValues?: boolean): LlamaText; ``` Defined in: [ChatWrapper.ts:158](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L158) #### Parameters | Parameter | Type | Default value | | ------ | ------ | ------ | | `modelResponse` | ( | `string` | [`ChatModelFunctionCall`](../type-aliases/ChatModelFunctionCall.md) | [`ChatModelSegment`](../type-aliases/ChatModelSegment.md))\[] | `undefined` | | `useRawValues` | `boolean` | `true` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateModelResponseText`](ChatWrapper.md#generatemodelresponsetext) *** ### generateAvailableFunctionsSystemText() ```ts generateAvailableFunctionsSystemText(availableFunctions: ChatModelFunctions, __namedParameters: { documentParams?: boolean; }): LlamaText; ``` Defined in: [ChatWrapper.ts:243](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L243) #### Parameters | Parameter | Type | | ------ | ------ | | `availableFunctions` | [`ChatModelFunctions`](../type-aliases/ChatModelFunctions.md) | | `__namedParameters` | { `documentParams?`: `boolean`; } | | `__namedParameters.documentParams?` | `boolean` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateAvailableFunctionsSystemText`](ChatWrapper.md#generateavailablefunctionssystemtext) *** ### addAvailableFunctionsSystemMessageToHistory() ```ts addAvailableFunctionsSystemMessageToHistory( history: readonly ChatHistoryItem[], availableFunctions?: ChatModelFunctions, __namedParameters?: { documentParams?: boolean; }): readonly ChatHistoryItem[]; ``` Defined in: [ChatWrapper.ts:269](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L269) #### Parameters | Parameter | Type | | ------ | ------ | | `history` | readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] | | `availableFunctions?` | [`ChatModelFunctions`](../type-aliases/ChatModelFunctions.md) | | `__namedParameters?` | { `documentParams?`: `boolean`; } | | `__namedParameters.documentParams?` | `boolean` | #### Returns readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`addAvailableFunctionsSystemMessageToHistory`](ChatWrapper.md#addavailablefunctionssystemmessagetohistory) *** ### generateInitialChatHistory() ```ts generateInitialChatHistory(__namedParameters?: ChatWrapperGenerateInitialHistoryOptions): ChatHistoryItem[]; ``` Defined in: [ChatWrapper.ts:290](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L290) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | [`ChatWrapperGenerateInitialHistoryOptions`](../type-aliases/ChatWrapperGenerateInitialHistoryOptions.md) | #### Returns [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateInitialChatHistory`](ChatWrapper.md#generateinitialchathistory) *** ### generateContextState() ```ts generateContextState(__namedParameters: ChatWrapperGenerateContextStateOptions): ChatWrapperGeneratedContextState; ``` Defined in: [chatWrappers/Llama2ChatWrapper.ts:24](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/Llama2ChatWrapper.ts#L24) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | [`ChatWrapperGenerateContextStateOptions`](../type-aliases/ChatWrapperGenerateContextStateOptions.md) | #### Returns [`ChatWrapperGeneratedContextState`](../type-aliases/ChatWrapperGeneratedContextState.md) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`generateContextState`](ChatWrapper.md#generatecontextstate) --- --- url: /api/classes/Llama3_1ChatWrapper.md --- # Class: Llama3\_1ChatWrapper Defined in: [chatWrappers/Llama3\_1ChatWrapper.ts:12](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/Llama3_1ChatWrapper.ts#L12) ## Extends * [`ChatWrapper`](ChatWrapper.md) ## Constructors ### Constructor ```ts new Llama3_1ChatWrapper(options?: { cuttingKnowledgeDate?: | string | number | Date | () => Date | null; todayDate?: | string | number | Date | () => Date | null; noToolInstructions?: boolean; }): Llama3_1ChatWrapper; ``` Defined in: [chatWrappers/Llama3\_1ChatWrapper.ts:37](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/Llama3_1ChatWrapper.ts#L37) #### Parameters | Parameter | Type | Description | | ------ | ------ | ------ | | `options` | { `cuttingKnowledgeDate?`: | `string` | `number` | [`Date`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date) | () => [`Date`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date) | `null`; `todayDate?`: | `string` | `number` | [`Date`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date) | () => [`Date`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date) | `null`; `noToolInstructions?`: `boolean`; } | - | | `options.cuttingKnowledgeDate?` | | `string` | `number` | [`Date`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date) | () => [`Date`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date) | `null` | Set to `null` to disable Defaults to December 2023 | | `options.todayDate?` | | `string` | `number` | [`Date`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date) | () => [`Date`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date) | `null` | Set to `null` to disable Defaults to current date | | `options.noToolInstructions?` | `boolean` | - | #### Returns `Llama3_1ChatWrapper` #### Overrides [`ChatWrapper`](ChatWrapper.md).[`constructor`](ChatWrapper.md#constructor) ## Properties ### defaultSettings ```ts static defaultSettings: ChatWrapperSettings; ``` Defined in: [ChatWrapper.ts:15](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L15) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`defaultSettings`](ChatWrapper.md#defaultsettings) *** ### wrapperName ```ts readonly wrapperName: string = "Llama 3.1"; ``` Defined in: [chatWrappers/Llama3\_1ChatWrapper.ts:13](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/Llama3_1ChatWrapper.ts#L13) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`wrapperName`](ChatWrapper.md#wrappername) *** ### cuttingKnowledgeDate? ```ts readonly optional cuttingKnowledgeDate: | Date | () => Date | null; ``` Defined in: [chatWrappers/Llama3\_1ChatWrapper.ts:15](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/Llama3_1ChatWrapper.ts#L15) *** ### todayDate ```ts readonly todayDate: | Date | () => Date | null; ``` Defined in: [chatWrappers/Llama3\_1ChatWrapper.ts:16](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/Llama3_1ChatWrapper.ts#L16) *** ### noToolInstructions ```ts readonly noToolInstructions: boolean; ``` Defined in: [chatWrappers/Llama3\_1ChatWrapper.ts:17](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/Llama3_1ChatWrapper.ts#L17) *** ### settings ```ts readonly settings: ChatWrapperSettings; ``` Defined in: [chatWrappers/Llama3\_1ChatWrapper.ts:21](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/Llama3_1ChatWrapper.ts#L21) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`settings`](ChatWrapper.md#settings) ## Methods ### generateFunctionCallsAndResults() ```ts generateFunctionCallsAndResults(functionCalls: ChatModelFunctionCall[], useRawCall?: boolean): LlamaText; ``` Defined in: [ChatWrapper.ts:63](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L63) #### Parameters | Parameter | Type | Default value | | ------ | ------ | ------ | | `functionCalls` | [`ChatModelFunctionCall`](../type-aliases/ChatModelFunctionCall.md)\[] | `undefined` | | `useRawCall` | `boolean` | `true` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCallsAndResults`](ChatWrapper.md#generatefunctioncallsandresults) *** ### generateFunctionCall() ```ts generateFunctionCall(name: string, params: any): LlamaText; ``` Defined in: [ChatWrapper.ts:110](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L110) #### Parameters | Parameter | Type | | ------ | ------ | | `name` | `string` | | `params` | `any` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCall`](ChatWrapper.md#generatefunctioncall) *** ### generateFunctionCallResult() ```ts generateFunctionCallResult( functionName: string, functionParams: any, result: any): LlamaText; ``` Defined in: [ChatWrapper.ts:127](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L127) #### Parameters | Parameter | Type | | ------ | ------ | | `functionName` | `string` | | `functionParams` | `any` | | `result` | `any` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCallResult`](ChatWrapper.md#generatefunctioncallresult) *** ### generateModelResponseText() ```ts generateModelResponseText(modelResponse: ( | string | ChatModelFunctionCall | ChatModelSegment)[], useRawValues?: boolean): LlamaText; ``` Defined in: [ChatWrapper.ts:158](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L158) #### Parameters | Parameter | Type | Default value | | ------ | ------ | ------ | | `modelResponse` | ( | `string` | [`ChatModelFunctionCall`](../type-aliases/ChatModelFunctionCall.md) | [`ChatModelSegment`](../type-aliases/ChatModelSegment.md))\[] | `undefined` | | `useRawValues` | `boolean` | `true` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateModelResponseText`](ChatWrapper.md#generatemodelresponsetext) *** ### generateInitialChatHistory() ```ts generateInitialChatHistory(__namedParameters?: ChatWrapperGenerateInitialHistoryOptions): ChatHistoryItem[]; ``` Defined in: [ChatWrapper.ts:290](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L290) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | [`ChatWrapperGenerateInitialHistoryOptions`](../type-aliases/ChatWrapperGenerateInitialHistoryOptions.md) | #### Returns [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateInitialChatHistory`](ChatWrapper.md#generateinitialchathistory) *** ### addAvailableFunctionsSystemMessageToHistory() ```ts addAvailableFunctionsSystemMessageToHistory( history: readonly ChatHistoryItem[], availableFunctions?: ChatModelFunctions, __namedParameters?: { documentParams?: boolean; }): readonly ChatHistoryItem[]; ``` Defined in: [chatWrappers/Llama3\_1ChatWrapper.ts:82](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/Llama3_1ChatWrapper.ts#L82) #### Parameters | Parameter | Type | | ------ | ------ | | `history` | readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] | | `availableFunctions?` | [`ChatModelFunctions`](../type-aliases/ChatModelFunctions.md) | | `__namedParameters?` | { `documentParams?`: `boolean`; } | | `__namedParameters.documentParams?` | `boolean` | #### Returns readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] #### Overrides [`ChatWrapper`](ChatWrapper.md).[`addAvailableFunctionsSystemMessageToHistory`](ChatWrapper.md#addavailablefunctionssystemmessagetohistory) *** ### generateContextState() ```ts generateContextState(__namedParameters: ChatWrapperGenerateContextStateOptions): ChatWrapperGeneratedContextState; ``` Defined in: [chatWrappers/Llama3\_1ChatWrapper.ts:113](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/Llama3_1ChatWrapper.ts#L113) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | [`ChatWrapperGenerateContextStateOptions`](../type-aliases/ChatWrapperGenerateContextStateOptions.md) | #### Returns [`ChatWrapperGeneratedContextState`](../type-aliases/ChatWrapperGeneratedContextState.md) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`generateContextState`](ChatWrapper.md#generatecontextstate) *** ### generateAvailableFunctionsSystemText() ```ts generateAvailableFunctionsSystemText(availableFunctions: ChatModelFunctions, __namedParameters: { documentParams?: boolean; }): LlamaText; ``` Defined in: [chatWrappers/Llama3\_1ChatWrapper.ts:236](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/Llama3_1ChatWrapper.ts#L236) #### Parameters | Parameter | Type | | ------ | ------ | | `availableFunctions` | [`ChatModelFunctions`](../type-aliases/ChatModelFunctions.md) | | `__namedParameters` | { `documentParams?`: `boolean`; } | | `__namedParameters.documentParams?` | `boolean` | #### Returns [`LlamaText`](LlamaText.md) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`generateAvailableFunctionsSystemText`](ChatWrapper.md#generateavailablefunctionssystemtext) *** ### prependPreambleToChatHistory() ```ts prependPreambleToChatHistory(chatHistory: readonly ChatHistoryItem[]): readonly ChatHistoryItem[]; ``` Defined in: [chatWrappers/Llama3\_1ChatWrapper.ts:279](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/Llama3_1ChatWrapper.ts#L279) #### Parameters | Parameter | Type | | ------ | ------ | | `chatHistory` | readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] | #### Returns readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] --- --- url: /api/classes/Llama3_2LightweightChatWrapper.md --- # Class: Llama3\_2LightweightChatWrapper Defined in: [chatWrappers/Llama3\_2LightweightChatWrapper.ts:11](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/Llama3_2LightweightChatWrapper.ts#L11) ## Extends * [`ChatWrapper`](ChatWrapper.md) ## Constructors ### Constructor ```ts new Llama3_2LightweightChatWrapper(options?: { cuttingKnowledgeDate?: | string | number | Date | () => Date | null; todayDate?: | string | number | Date | () => Date | null; noToolInstructions?: boolean; }): Llama3_2LightweightChatWrapper; ``` Defined in: [chatWrappers/Llama3\_2LightweightChatWrapper.ts:40](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/Llama3_2LightweightChatWrapper.ts#L40) #### Parameters | Parameter | Type | Description | | ------ | ------ | ------ | | `options` | { `cuttingKnowledgeDate?`: | `string` | `number` | [`Date`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date) | () => [`Date`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date) | `null`; `todayDate?`: | `string` | `number` | [`Date`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date) | () => [`Date`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date) | `null`; `noToolInstructions?`: `boolean`; } | - | | `options.cuttingKnowledgeDate?` | | `string` | `number` | [`Date`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date) | () => [`Date`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date) | `null` | Set to `null` to disable Defaults to December 2023 | | `options.todayDate?` | | `string` | `number` | [`Date`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date) | () => [`Date`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date) | `null` | Set to `null` to disable Defaults to current date | | `options.noToolInstructions?` | `boolean` | - | #### Returns `Llama3_2LightweightChatWrapper` #### Overrides [`ChatWrapper`](ChatWrapper.md).[`constructor`](ChatWrapper.md#constructor) ## Properties ### defaultSettings ```ts static defaultSettings: ChatWrapperSettings; ``` Defined in: [ChatWrapper.ts:15](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L15) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`defaultSettings`](ChatWrapper.md#defaultsettings) *** ### wrapperName ```ts readonly wrapperName: string = "Llama 3.2 lightweight"; ``` Defined in: [chatWrappers/Llama3\_2LightweightChatWrapper.ts:12](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/Llama3_2LightweightChatWrapper.ts#L12) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`wrapperName`](ChatWrapper.md#wrappername) *** ### cuttingKnowledgeDate? ```ts readonly optional cuttingKnowledgeDate: | Date | () => Date | null; ``` Defined in: [chatWrappers/Llama3\_2LightweightChatWrapper.ts:14](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/Llama3_2LightweightChatWrapper.ts#L14) *** ### todayDate ```ts readonly todayDate: | Date | () => Date | null; ``` Defined in: [chatWrappers/Llama3\_2LightweightChatWrapper.ts:15](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/Llama3_2LightweightChatWrapper.ts#L15) *** ### noToolInstructions ```ts readonly noToolInstructions: boolean; ``` Defined in: [chatWrappers/Llama3\_2LightweightChatWrapper.ts:16](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/Llama3_2LightweightChatWrapper.ts#L16) *** ### settings ```ts readonly settings: ChatWrapperSettings; ``` Defined in: [chatWrappers/Llama3\_2LightweightChatWrapper.ts:20](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/Llama3_2LightweightChatWrapper.ts#L20) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`settings`](ChatWrapper.md#settings) ## Methods ### generateFunctionCallsAndResults() ```ts generateFunctionCallsAndResults(functionCalls: ChatModelFunctionCall[], useRawCall?: boolean): LlamaText; ``` Defined in: [ChatWrapper.ts:63](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L63) #### Parameters | Parameter | Type | Default value | | ------ | ------ | ------ | | `functionCalls` | [`ChatModelFunctionCall`](../type-aliases/ChatModelFunctionCall.md)\[] | `undefined` | | `useRawCall` | `boolean` | `true` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCallsAndResults`](ChatWrapper.md#generatefunctioncallsandresults) *** ### generateFunctionCall() ```ts generateFunctionCall(name: string, params: any): LlamaText; ``` Defined in: [ChatWrapper.ts:110](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L110) #### Parameters | Parameter | Type | | ------ | ------ | | `name` | `string` | | `params` | `any` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCall`](ChatWrapper.md#generatefunctioncall) *** ### generateFunctionCallResult() ```ts generateFunctionCallResult( functionName: string, functionParams: any, result: any): LlamaText; ``` Defined in: [ChatWrapper.ts:127](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L127) #### Parameters | Parameter | Type | | ------ | ------ | | `functionName` | `string` | | `functionParams` | `any` | | `result` | `any` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCallResult`](ChatWrapper.md#generatefunctioncallresult) *** ### generateModelResponseText() ```ts generateModelResponseText(modelResponse: ( | string | ChatModelFunctionCall | ChatModelSegment)[], useRawValues?: boolean): LlamaText; ``` Defined in: [ChatWrapper.ts:158](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L158) #### Parameters | Parameter | Type | Default value | | ------ | ------ | ------ | | `modelResponse` | ( | `string` | [`ChatModelFunctionCall`](../type-aliases/ChatModelFunctionCall.md) | [`ChatModelSegment`](../type-aliases/ChatModelSegment.md))\[] | `undefined` | | `useRawValues` | `boolean` | `true` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateModelResponseText`](ChatWrapper.md#generatemodelresponsetext) *** ### generateInitialChatHistory() ```ts generateInitialChatHistory(__namedParameters?: ChatWrapperGenerateInitialHistoryOptions): ChatHistoryItem[]; ``` Defined in: [ChatWrapper.ts:290](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L290) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | [`ChatWrapperGenerateInitialHistoryOptions`](../type-aliases/ChatWrapperGenerateInitialHistoryOptions.md) | #### Returns [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateInitialChatHistory`](ChatWrapper.md#generateinitialchathistory) *** ### addAvailableFunctionsSystemMessageToHistory() ```ts addAvailableFunctionsSystemMessageToHistory( history: readonly ChatHistoryItem[], availableFunctions?: ChatModelFunctions, __namedParameters?: { documentParams?: boolean; }): readonly ChatHistoryItem[]; ``` Defined in: [chatWrappers/Llama3\_2LightweightChatWrapper.ts:85](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/Llama3_2LightweightChatWrapper.ts#L85) #### Parameters | Parameter | Type | | ------ | ------ | | `history` | readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] | | `availableFunctions?` | [`ChatModelFunctions`](../type-aliases/ChatModelFunctions.md) | | `__namedParameters?` | { `documentParams?`: `boolean`; } | | `__namedParameters.documentParams?` | `boolean` | #### Returns readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] #### Overrides [`ChatWrapper`](ChatWrapper.md).[`addAvailableFunctionsSystemMessageToHistory`](ChatWrapper.md#addavailablefunctionssystemmessagetohistory) *** ### generateContextState() ```ts generateContextState(__namedParameters: ChatWrapperGenerateContextStateOptions): ChatWrapperGeneratedContextState; ``` Defined in: [chatWrappers/Llama3\_2LightweightChatWrapper.ts:116](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/Llama3_2LightweightChatWrapper.ts#L116) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | [`ChatWrapperGenerateContextStateOptions`](../type-aliases/ChatWrapperGenerateContextStateOptions.md) | #### Returns [`ChatWrapperGeneratedContextState`](../type-aliases/ChatWrapperGeneratedContextState.md) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`generateContextState`](ChatWrapper.md#generatecontextstate) *** ### generateAvailableFunctionsSystemText() ```ts generateAvailableFunctionsSystemText(availableFunctions: ChatModelFunctions, __namedParameters: { documentParams?: boolean; }): LlamaText; ``` Defined in: [chatWrappers/Llama3\_2LightweightChatWrapper.ts:239](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/Llama3_2LightweightChatWrapper.ts#L239) #### Parameters | Parameter | Type | | ------ | ------ | | `availableFunctions` | [`ChatModelFunctions`](../type-aliases/ChatModelFunctions.md) | | `__namedParameters` | { `documentParams?`: `boolean`; } | | `__namedParameters.documentParams?` | `boolean` | #### Returns [`LlamaText`](LlamaText.md) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`generateAvailableFunctionsSystemText`](ChatWrapper.md#generateavailablefunctionssystemtext) *** ### prependPreambleToChatHistory() ```ts prependPreambleToChatHistory(chatHistory: readonly ChatHistoryItem[]): readonly ChatHistoryItem[]; ``` Defined in: [chatWrappers/Llama3\_2LightweightChatWrapper.ts:261](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/Llama3_2LightweightChatWrapper.ts#L261) #### Parameters | Parameter | Type | | ------ | ------ | | `chatHistory` | readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] | #### Returns readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] --- --- url: /api/classes/Llama3ChatWrapper.md --- # Class: Llama3ChatWrapper Defined in: [chatWrappers/Llama3ChatWrapper.ts:10](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/Llama3ChatWrapper.ts#L10) ## Extends * [`ChatWrapper`](ChatWrapper.md) ## Constructors ### Constructor ```ts new Llama3ChatWrapper(__namedParameters?: { parallelFunctionCalling?: boolean; }): Llama3ChatWrapper; ``` Defined in: [chatWrappers/Llama3ChatWrapper.ts:15](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/Llama3ChatWrapper.ts#L15) #### Parameters | Parameter | Type | Description | | ------ | ------ | ------ | | `__namedParameters` | { `parallelFunctionCalling?`: `boolean`; } | - | | `__namedParameters.parallelFunctionCalling?` | `boolean` | Defaults to `true` | #### Returns `Llama3ChatWrapper` #### Overrides [`ChatWrapper`](ChatWrapper.md).[`constructor`](ChatWrapper.md#constructor) ## Properties ### defaultSettings ```ts static defaultSettings: ChatWrapperSettings; ``` Defined in: [ChatWrapper.ts:15](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L15) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`defaultSettings`](ChatWrapper.md#defaultsettings) *** ### wrapperName ```ts readonly wrapperName: string = "Llama 3"; ``` Defined in: [chatWrappers/Llama3ChatWrapper.ts:11](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/Llama3ChatWrapper.ts#L11) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`wrapperName`](ChatWrapper.md#wrappername) *** ### settings ```ts readonly settings: ChatWrapperSettings; ``` Defined in: [chatWrappers/Llama3ChatWrapper.ts:13](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/Llama3ChatWrapper.ts#L13) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`settings`](ChatWrapper.md#settings) ## Methods ### generateFunctionCallsAndResults() ```ts generateFunctionCallsAndResults(functionCalls: ChatModelFunctionCall[], useRawCall?: boolean): LlamaText; ``` Defined in: [ChatWrapper.ts:63](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L63) #### Parameters | Parameter | Type | Default value | | ------ | ------ | ------ | | `functionCalls` | [`ChatModelFunctionCall`](../type-aliases/ChatModelFunctionCall.md)\[] | `undefined` | | `useRawCall` | `boolean` | `true` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCallsAndResults`](ChatWrapper.md#generatefunctioncallsandresults) *** ### generateFunctionCall() ```ts generateFunctionCall(name: string, params: any): LlamaText; ``` Defined in: [ChatWrapper.ts:110](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L110) #### Parameters | Parameter | Type | | ------ | ------ | | `name` | `string` | | `params` | `any` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCall`](ChatWrapper.md#generatefunctioncall) *** ### generateFunctionCallResult() ```ts generateFunctionCallResult( functionName: string, functionParams: any, result: any): LlamaText; ``` Defined in: [ChatWrapper.ts:127](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L127) #### Parameters | Parameter | Type | | ------ | ------ | | `functionName` | `string` | | `functionParams` | `any` | | `result` | `any` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCallResult`](ChatWrapper.md#generatefunctioncallresult) *** ### generateModelResponseText() ```ts generateModelResponseText(modelResponse: ( | string | ChatModelFunctionCall | ChatModelSegment)[], useRawValues?: boolean): LlamaText; ``` Defined in: [ChatWrapper.ts:158](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L158) #### Parameters | Parameter | Type | Default value | | ------ | ------ | ------ | | `modelResponse` | ( | `string` | [`ChatModelFunctionCall`](../type-aliases/ChatModelFunctionCall.md) | [`ChatModelSegment`](../type-aliases/ChatModelSegment.md))\[] | `undefined` | | `useRawValues` | `boolean` | `true` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateModelResponseText`](ChatWrapper.md#generatemodelresponsetext) *** ### addAvailableFunctionsSystemMessageToHistory() ```ts addAvailableFunctionsSystemMessageToHistory( history: readonly ChatHistoryItem[], availableFunctions?: ChatModelFunctions, __namedParameters?: { documentParams?: boolean; }): readonly ChatHistoryItem[]; ``` Defined in: [ChatWrapper.ts:269](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L269) #### Parameters | Parameter | Type | | ------ | ------ | | `history` | readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] | | `availableFunctions?` | [`ChatModelFunctions`](../type-aliases/ChatModelFunctions.md) | | `__namedParameters?` | { `documentParams?`: `boolean`; } | | `__namedParameters.documentParams?` | `boolean` | #### Returns readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`addAvailableFunctionsSystemMessageToHistory`](ChatWrapper.md#addavailablefunctionssystemmessagetohistory) *** ### generateInitialChatHistory() ```ts generateInitialChatHistory(__namedParameters?: ChatWrapperGenerateInitialHistoryOptions): ChatHistoryItem[]; ``` Defined in: [ChatWrapper.ts:290](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L290) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | [`ChatWrapperGenerateInitialHistoryOptions`](../type-aliases/ChatWrapperGenerateInitialHistoryOptions.md) | #### Returns [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateInitialChatHistory`](ChatWrapper.md#generateinitialchathistory) *** ### generateContextState() ```ts generateContextState(__namedParameters: ChatWrapperGenerateContextStateOptions): ChatWrapperGeneratedContextState; ``` Defined in: [chatWrappers/Llama3ChatWrapper.ts:77](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/Llama3ChatWrapper.ts#L77) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | [`ChatWrapperGenerateContextStateOptions`](../type-aliases/ChatWrapperGenerateContextStateOptions.md) | #### Returns [`ChatWrapperGeneratedContextState`](../type-aliases/ChatWrapperGeneratedContextState.md) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`generateContextState`](ChatWrapper.md#generatecontextstate) *** ### generateAvailableFunctionsSystemText() ```ts generateAvailableFunctionsSystemText(availableFunctions: ChatModelFunctions, __namedParameters: { documentParams?: boolean; }): LlamaText; ``` Defined in: [chatWrappers/Llama3ChatWrapper.ts:194](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/Llama3ChatWrapper.ts#L194) #### Parameters | Parameter | Type | | ------ | ------ | | `availableFunctions` | [`ChatModelFunctions`](../type-aliases/ChatModelFunctions.md) | | `__namedParameters` | { `documentParams?`: `boolean`; } | | `__namedParameters.documentParams?` | `boolean` | #### Returns [`LlamaText`](LlamaText.md) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`generateAvailableFunctionsSystemText`](ChatWrapper.md#generateavailablefunctionssystemtext) --- --- url: /api/classes/LlamaChat.md --- # Class: LlamaChat Defined in: [evaluator/LlamaChat/LlamaChat.ts:529](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaChat/LlamaChat.ts#L529) ## Constructors ### Constructor ```ts new LlamaChat(__namedParameters: LlamaChatOptions): LlamaChat; ``` Defined in: [evaluator/LlamaChat/LlamaChat.ts:537](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaChat/LlamaChat.ts#L537) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | [`LlamaChatOptions`](../type-aliases/LlamaChatOptions.md) | #### Returns `LlamaChat` ## Properties ### onDispose ```ts readonly onDispose: EventRelay; ``` Defined in: [evaluator/LlamaChat/LlamaChat.ts:535](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaChat/LlamaChat.ts#L535) ## Accessors ### disposed #### Get Signature ```ts get disposed(): boolean; ``` Defined in: [evaluator/LlamaChat/LlamaChat.ts:580](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaChat/LlamaChat.ts#L580) ##### Returns `boolean` *** ### chatWrapper #### Get Signature ```ts get chatWrapper(): ChatWrapper; ``` Defined in: [evaluator/LlamaChat/LlamaChat.ts:584](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaChat/LlamaChat.ts#L584) ##### Returns [`ChatWrapper`](ChatWrapper.md) *** ### sequence #### Get Signature ```ts get sequence(): LlamaContextSequence; ``` Defined in: [evaluator/LlamaChat/LlamaChat.ts:591](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaChat/LlamaChat.ts#L591) ##### Returns [`LlamaContextSequence`](LlamaContextSequence.md) *** ### context #### Get Signature ```ts get context(): LlamaContext; ``` Defined in: [evaluator/LlamaChat/LlamaChat.ts:598](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaChat/LlamaChat.ts#L598) ##### Returns [`LlamaContext`](LlamaContext.md) *** ### model #### Get Signature ```ts get model(): LlamaModel; ``` Defined in: [evaluator/LlamaChat/LlamaChat.ts:602](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaChat/LlamaChat.ts#L602) ##### Returns [`LlamaModel`](LlamaModel.md) ## Methods ### dispose() ```ts dispose(__namedParameters?: { disposeSequence?: boolean; }): void; ``` Defined in: [evaluator/LlamaChat/LlamaChat.ts:563](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaChat/LlamaChat.ts#L563) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | { `disposeSequence?`: `boolean`; } | | `__namedParameters.disposeSequence?` | `boolean` | #### Returns `void` *** ### generateResponse() ```ts generateResponse(history: ChatHistoryItem[], options?: LLamaChatGenerateResponseOptions): Promise>; ``` Defined in: [evaluator/LlamaChat/LlamaChat.ts:606](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaChat/LlamaChat.ts#L606) #### Type Parameters | Type Parameter | Default type | | ------ | ------ | | `Functions` *extends* | [`ChatModelFunctions`](../type-aliases/ChatModelFunctions.md) | `undefined` | `undefined` | #### Parameters | Parameter | Type | | ------ | ------ | | `history` | [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] | | `options` | [`LLamaChatGenerateResponseOptions`](../type-aliases/LLamaChatGenerateResponseOptions.md)<`Functions`> | #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[`LlamaChatResponse`](../type-aliases/LlamaChatResponse.md)<`Functions`>> *** ### loadChatAndCompleteUserMessage() ```ts loadChatAndCompleteUserMessage(history: ChatHistoryItem[], options?: LLamaChatLoadAndCompleteUserMessageOptions): Promise; ``` Defined in: [evaluator/LlamaChat/LlamaChat.ts:850](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaChat/LlamaChat.ts#L850) #### Type Parameters | Type Parameter | Default type | | ------ | ------ | | `Functions` *extends* | [`ChatModelFunctions`](../type-aliases/ChatModelFunctions.md) | `undefined` | `undefined` | #### Parameters | Parameter | Type | | ------ | ------ | | `history` | [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] | | `options` | [`LLamaChatLoadAndCompleteUserMessageOptions`](../type-aliases/LLamaChatLoadAndCompleteUserMessageOptions.md)<`Functions`> | #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[`LlamaChatLoadAndCompleteUserResponse`](../type-aliases/LlamaChatLoadAndCompleteUserResponse.md)> --- --- url: /api/classes/LlamaChatSession.md --- # Class: LlamaChatSession Defined in: [evaluator/LlamaChatSession/LlamaChatSession.ts:519](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaChatSession/LlamaChatSession.ts#L519) ## See [Using `LlamaChatSession`](https://node-llama-cpp.withcat.ai/guide/chat-session) tutorial ## Constructors ### Constructor ```ts new LlamaChatSession(options: LlamaChatSessionOptions): LlamaChatSession; ``` Defined in: [evaluator/LlamaChatSession/LlamaChatSession.ts:535](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaChatSession/LlamaChatSession.ts#L535) #### Parameters | Parameter | Type | | ------ | ------ | | `options` | [`LlamaChatSessionOptions`](../type-aliases/LlamaChatSessionOptions.md) | #### Returns `LlamaChatSession` ## Properties ### onDispose ```ts readonly onDispose: EventRelay; ``` Defined in: [evaluator/LlamaChatSession/LlamaChatSession.ts:533](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaChatSession/LlamaChatSession.ts#L533) ## Accessors ### disposed #### Get Signature ```ts get disposed(): boolean; ``` Defined in: [evaluator/LlamaChatSession/LlamaChatSession.ts:592](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaChatSession/LlamaChatSession.ts#L592) ##### Returns `boolean` *** ### chatWrapper #### Get Signature ```ts get chatWrapper(): ChatWrapper; ``` Defined in: [evaluator/LlamaChatSession/LlamaChatSession.ts:596](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaChatSession/LlamaChatSession.ts#L596) ##### Returns [`ChatWrapper`](ChatWrapper.md) *** ### sequence #### Get Signature ```ts get sequence(): LlamaContextSequence; ``` Defined in: [evaluator/LlamaChatSession/LlamaChatSession.ts:603](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaChatSession/LlamaChatSession.ts#L603) ##### Returns [`LlamaContextSequence`](LlamaContextSequence.md) *** ### context #### Get Signature ```ts get context(): LlamaContext; ``` Defined in: [evaluator/LlamaChatSession/LlamaChatSession.ts:610](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaChatSession/LlamaChatSession.ts#L610) ##### Returns [`LlamaContext`](LlamaContext.md) *** ### model #### Get Signature ```ts get model(): LlamaModel; ``` Defined in: [evaluator/LlamaChatSession/LlamaChatSession.ts:614](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaChatSession/LlamaChatSession.ts#L614) ##### Returns [`LlamaModel`](LlamaModel.md) ## Methods ### dispose() ```ts dispose(__namedParameters?: { disposeSequence?: boolean; }): void; ``` Defined in: [evaluator/LlamaChatSession/LlamaChatSession.ts:577](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaChatSession/LlamaChatSession.ts#L577) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | { `disposeSequence?`: `boolean`; } | | `__namedParameters.disposeSequence?` | `boolean` | #### Returns `void` *** ### prompt() ```ts prompt(prompt: string, options?: LLamaChatPromptOptions): Promise; ``` Defined in: [evaluator/LlamaChatSession/LlamaChatSession.ts:618](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaChatSession/LlamaChatSession.ts#L618) #### Type Parameters | Type Parameter | Default type | | ------ | ------ | | `Functions` *extends* | [`ChatSessionModelFunctions`](../type-aliases/ChatSessionModelFunctions.md) | `undefined` | `undefined` | #### Parameters | Parameter | Type | | ------ | ------ | | `prompt` | `string` | | `options` | [`LLamaChatPromptOptions`](../type-aliases/LLamaChatPromptOptions.md)<`Functions`> | #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`string`> *** ### promptWithMeta() ```ts promptWithMeta(prompt: string, options?: LLamaChatPromptOptions): Promise< | { response: ( | string | ChatModelFunctionCall | ChatModelSegment)[]; responseText: string; stopReason: "customStopTrigger"; customStopTrigger: (string | Token)[]; remainingGenerationAfterStop: string | Token[] | undefined; } | { customStopTrigger?: undefined; response: ( | string | ChatModelFunctionCall | ChatModelSegment)[]; responseText: string; stopReason: | "abort" | "maxTokens" | "eogToken" | "stopGenerationTrigger" | "functionCalls"; remainingGenerationAfterStop: string | Token[] | undefined; }>; ``` Defined in: [evaluator/LlamaChatSession/LlamaChatSession.ts:669](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaChatSession/LlamaChatSession.ts#L669) #### Type Parameters | Type Parameter | Default type | | ------ | ------ | | `Functions` *extends* | [`ChatSessionModelFunctions`](../type-aliases/ChatSessionModelFunctions.md) | `undefined` | `undefined` | #### Parameters | Parameter | Type | Description | | ------ | ------ | ------ | | `prompt` | `string` | - | | `options?` | [`LLamaChatPromptOptions`](../type-aliases/LLamaChatPromptOptions.md)<`Functions`> | - | #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)< | { `response`: ( | `string` | [`ChatModelFunctionCall`](../type-aliases/ChatModelFunctionCall.md) | [`ChatModelSegment`](../type-aliases/ChatModelSegment.md))\[]; `responseText`: `string`; `stopReason`: `"customStopTrigger"`; `customStopTrigger`: (`string` | [`Token`](../type-aliases/Token.md))\[]; `remainingGenerationAfterStop`: `string` | [`Token`](../type-aliases/Token.md)\[] | `undefined`; } | { `customStopTrigger?`: `undefined`; `response`: ( | `string` | [`ChatModelFunctionCall`](../type-aliases/ChatModelFunctionCall.md) | [`ChatModelSegment`](../type-aliases/ChatModelSegment.md))\[]; `responseText`: `string`; `stopReason`: | `"abort"` | `"maxTokens"` | `"eogToken"` | `"stopGenerationTrigger"` | `"functionCalls"`; `remainingGenerationAfterStop`: `string` | [`Token`](../type-aliases/Token.md)\[] | `undefined`; }> *** ### preloadPrompt() ```ts preloadPrompt(prompt: string, options?: LLamaChatPreloadPromptOptions): Promise; ``` Defined in: [evaluator/LlamaChatSession/LlamaChatSession.ts:963](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaChatSession/LlamaChatSession.ts#L963) Preload a user prompt into the current context sequence state to make later inference of the model response begin sooner and feel faster. > **Note:** Preloading a long user prompt can incur context shifts, so consider limiting the length of prompts you preload #### Parameters | Parameter | Type | Description | | ------ | ------ | ------ | | `prompt` | `string` | the prompt to preload | | `options?` | [`LLamaChatPreloadPromptOptions`](../type-aliases/LLamaChatPreloadPromptOptions.md) | - | #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`> *** ### completePrompt() ```ts completePrompt(prompt: string, options?: LLamaChatCompletePromptOptions): Promise; ``` Defined in: [evaluator/LlamaChatSession/LlamaChatSession.ts:981](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaChatSession/LlamaChatSession.ts#L981) Preload a user prompt into the current context sequence state and generate a completion for it. > **Note:** Preloading a long user prompt and completing a user prompt with a high number of `maxTokens` can incur context shifts, > so consider limiting the length of prompts you preload. > > Also, it's recommended to limit the number of tokens generated to a reasonable amount by configuring `maxTokens`. #### Parameters | Parameter | Type | Description | | ------ | ------ | ------ | | `prompt` | `string` | the prompt to preload | | `options?` | [`LLamaChatCompletePromptOptions`](../type-aliases/LLamaChatCompletePromptOptions.md) | - | #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`string`> *** ### createPromptCompletionEngine() ```ts createPromptCompletionEngine(options?: LLamaChatPromptCompletionEngineOptions): LlamaChatSessionPromptCompletionEngine; ``` Defined in: [evaluator/LlamaChatSession/LlamaChatSession.ts:994](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaChatSession/LlamaChatSession.ts#L994) Create a smart completion engine that caches the prompt completions and reuses them when the user prompt matches the beginning of the cached prompt or completion. All completions are made and cache is used only for the current chat session state. You can create a single completion engine for an entire chat session. #### Parameters | Parameter | Type | | ------ | ------ | | `options?` | [`LLamaChatPromptCompletionEngineOptions`](../type-aliases/LLamaChatPromptCompletionEngineOptions.md) | #### Returns [`LlamaChatSessionPromptCompletionEngine`](LlamaChatSessionPromptCompletionEngine.md) *** ### completePromptWithMeta() ```ts completePromptWithMeta(prompt: string, options?: LLamaChatCompletePromptOptions): Promise< | { completion: string; stopReason: "customStopTrigger"; customStopTrigger: (string | Token)[]; remainingGenerationAfterStop: string | Token[] | undefined; } | { customStopTrigger?: undefined; completion: string; stopReason: | "abort" | "maxTokens" | "eogToken" | "stopGenerationTrigger" | "functionCalls"; remainingGenerationAfterStop: string | Token[] | undefined; }>; ``` Defined in: [evaluator/LlamaChatSession/LlamaChatSession.ts:1003](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaChatSession/LlamaChatSession.ts#L1003) See `completePrompt` for more information. #### Parameters | Parameter | Type | Description | | ------ | ------ | ------ | | `prompt` | `string` | - | | `options?` | [`LLamaChatCompletePromptOptions`](../type-aliases/LLamaChatCompletePromptOptions.md) | - | #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)< | { `completion`: `string`; `stopReason`: `"customStopTrigger"`; `customStopTrigger`: (`string` | [`Token`](../type-aliases/Token.md))\[]; `remainingGenerationAfterStop`: `string` | [`Token`](../type-aliases/Token.md)\[] | `undefined`; } | { `customStopTrigger?`: `undefined`; `completion`: `string`; `stopReason`: | `"abort"` | `"maxTokens"` | `"eogToken"` | `"stopGenerationTrigger"` | `"functionCalls"`; `remainingGenerationAfterStop`: `string` | [`Token`](../type-aliases/Token.md)\[] | `undefined`; }> *** ### getChatHistory() ```ts getChatHistory(): ChatHistoryItem[]; ``` Defined in: [evaluator/LlamaChatSession/LlamaChatSession.ts:1237](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaChatSession/LlamaChatSession.ts#L1237) #### Returns [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] *** ### getLastEvaluationContextWindow() ```ts getLastEvaluationContextWindow(): ChatHistoryItem[] | null; ``` Defined in: [evaluator/LlamaChatSession/LlamaChatSession.ts:1241](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaChatSession/LlamaChatSession.ts#L1241) #### Returns [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] | `null` *** ### setChatHistory() ```ts setChatHistory(chatHistory: ChatHistoryItem[]): void; ``` Defined in: [evaluator/LlamaChatSession/LlamaChatSession.ts:1248](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaChatSession/LlamaChatSession.ts#L1248) #### Parameters | Parameter | Type | | ------ | ------ | | `chatHistory` | [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] | #### Returns `void` *** ### resetChatHistory() ```ts resetChatHistory(): void; ``` Defined in: [evaluator/LlamaChatSession/LlamaChatSession.ts:1256](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaChatSession/LlamaChatSession.ts#L1256) Clear the chat history and reset it to the initial state. #### Returns `void` --- --- url: /api/classes/LlamaChatSessionPromptCompletionEngine.md --- # Class: LlamaChatSessionPromptCompletionEngine Defined in: [evaluator/LlamaChatSession/utils/LlamaChatSessionPromptCompletionEngine.ts:58](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaChatSession/utils/LlamaChatSessionPromptCompletionEngine.ts#L58) ## Methods ### dispose() ```ts dispose(): void; ``` Defined in: [evaluator/LlamaChatSession/utils/LlamaChatSessionPromptCompletionEngine.ts:93](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaChatSession/utils/LlamaChatSessionPromptCompletionEngine.ts#L93) #### Returns `void` *** ### complete() ```ts complete(prompt: string): string; ``` Defined in: [evaluator/LlamaChatSession/utils/LlamaChatSessionPromptCompletionEngine.ts:106](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaChatSession/utils/LlamaChatSessionPromptCompletionEngine.ts#L106) Get completion for the prompt from the cache, and begin preloading this prompt into the context sequence and completing it. On completion progress, `onGeneration` (configured for this engine instance) will be called. #### Parameters | Parameter | Type | | ------ | ------ | | `prompt` | `string` | #### Returns `string` --- --- url: /api/classes/LlamaCompletion.md --- # Class: LlamaCompletion Defined in: [evaluator/LlamaCompletion.ts:234](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaCompletion.ts#L234) ## See [Text Completion](https://node-llama-cpp.withcat.ai/guide/text-completion) tutorial ## Constructors ### Constructor ```ts new LlamaCompletion(__namedParameters: LlamaCompletionOptions): LlamaCompletion; ``` Defined in: [evaluator/LlamaCompletion.ts:240](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaCompletion.ts#L240) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | [`LlamaCompletionOptions`](../type-aliases/LlamaCompletionOptions.md) | #### Returns `LlamaCompletion` ## Properties ### onDispose ```ts readonly onDispose: EventRelay; ``` Defined in: [evaluator/LlamaCompletion.ts:238](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaCompletion.ts#L238) ## Accessors ### disposed #### Get Signature ```ts get disposed(): boolean; ``` Defined in: [evaluator/LlamaCompletion.ts:272](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaCompletion.ts#L272) ##### Returns `boolean` *** ### infillSupported #### Get Signature ```ts get infillSupported(): boolean; ``` Defined in: [evaluator/LlamaCompletion.ts:276](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaCompletion.ts#L276) ##### Returns `boolean` ## Methods ### dispose() ```ts dispose(__namedParameters?: { disposeSequence?: boolean; }): void; ``` Defined in: [evaluator/LlamaCompletion.ts:255](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaCompletion.ts#L255) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | { `disposeSequence?`: `boolean`; } | | `__namedParameters.disposeSequence?` | `boolean` | #### Returns `void` *** ### generateCompletion() ```ts generateCompletion(input: | string | LlamaText | Token[], options?: LlamaCompletionGenerationOptions): Promise; ``` Defined in: [evaluator/LlamaCompletion.ts:287](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaCompletion.ts#L287) Generate a completion for an input. #### Parameters | Parameter | Type | | ------ | ------ | | `input` | | `string` | [`LlamaText`](LlamaText.md) | [`Token`](../type-aliases/Token.md)\[] | | `options` | [`LlamaCompletionGenerationOptions`](../type-aliases/LlamaCompletionGenerationOptions.md) | #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`string`> *** ### generateCompletionWithMeta() ```ts generateCompletionWithMeta(input: | string | LlamaText | Token[], __namedParameters?: LlamaCompletionGenerationOptions): Promise; ``` Defined in: [evaluator/LlamaCompletion.ts:297](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaCompletion.ts#L297) Same as `generateCompletion`, but returns additional metadata about the generation. See `generateCompletion` for more information. #### Parameters | Parameter | Type | | ------ | ------ | | `input` | | `string` | [`LlamaText`](LlamaText.md) | [`Token`](../type-aliases/Token.md)\[] | | `__namedParameters` | [`LlamaCompletionGenerationOptions`](../type-aliases/LlamaCompletionGenerationOptions.md) | #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[`LlamaCompletionResponse`](../type-aliases/LlamaCompletionResponse.md)> *** ### generateInfillCompletion() ```ts generateInfillCompletion( prefixInput: | string | LlamaText | Token[], suffixInput: | string | LlamaText | Token[], options?: LlamaInfillGenerationOptions): Promise; ``` Defined in: [evaluator/LlamaCompletion.ts:429](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaCompletion.ts#L429) Infill (also known as Fill-In-Middle), generates a completion for an input (`prefixInput`) that should connect to a given continuation (`suffixInput`). For example, for `prefixInput: "123"` and `suffixInput: "789"`, the model is expected to generate `456` to make the final text be `123456789`. #### Parameters | Parameter | Type | | ------ | ------ | | `prefixInput` | | `string` | [`LlamaText`](LlamaText.md) | [`Token`](../type-aliases/Token.md)\[] | | `suffixInput` | | `string` | [`LlamaText`](LlamaText.md) | [`Token`](../type-aliases/Token.md)\[] | | `options` | [`LlamaInfillGenerationOptions`](../type-aliases/LlamaInfillGenerationOptions.md) | #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`string`> *** ### generateInfillCompletionWithMeta() ```ts generateInfillCompletionWithMeta( prefixInput: | string | LlamaText | Token[], suffixInput: | string | LlamaText | Token[], __namedParameters?: LlamaInfillGenerationOptions): Promise; ``` Defined in: [evaluator/LlamaCompletion.ts:443](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaCompletion.ts#L443) Same as `generateInfillCompletion`, but returns additional metadata about the generation. See `generateInfillCompletion` for more information. #### Parameters | Parameter | Type | | ------ | ------ | | `prefixInput` | | `string` | [`LlamaText`](LlamaText.md) | [`Token`](../type-aliases/Token.md)\[] | | `suffixInput` | | `string` | [`LlamaText`](LlamaText.md) | [`Token`](../type-aliases/Token.md)\[] | | `__namedParameters` | [`LlamaInfillGenerationOptions`](../type-aliases/LlamaInfillGenerationOptions.md) | #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[`LlamaCompletionResponse`](../type-aliases/LlamaCompletionResponse.md)> --- --- url: /api/classes/LlamaContext.md --- # Class: LlamaContext Defined in: [evaluator/LlamaContext/LlamaContext.ts:66](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L66) ## Properties ### onDispose ```ts readonly onDispose: EventRelay; ``` Defined in: [evaluator/LlamaContext/LlamaContext.ts:102](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L102) ## Accessors ### disposed #### Get Signature ```ts get disposed(): boolean; ``` Defined in: [evaluator/LlamaContext/LlamaContext.ts:225](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L225) ##### Returns `boolean` *** ### model #### Get Signature ```ts get model(): LlamaModel; ``` Defined in: [evaluator/LlamaContext/LlamaContext.ts:229](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L229) ##### Returns [`LlamaModel`](LlamaModel.md) *** ### contextSize #### Get Signature ```ts get contextSize(): number; ``` Defined in: [evaluator/LlamaContext/LlamaContext.ts:233](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L233) ##### Returns `number` *** ### batchSize #### Get Signature ```ts get batchSize(): number; ``` Defined in: [evaluator/LlamaContext/LlamaContext.ts:237](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L237) ##### Returns `number` *** ### flashAttention #### Get Signature ```ts get flashAttention(): boolean | "auto"; ``` Defined in: [evaluator/LlamaContext/LlamaContext.ts:241](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L241) ##### Returns `boolean` | `"auto"` *** ### kvCacheKeyType #### Get Signature ```ts get kvCacheKeyType(): GgmlType; ``` Defined in: [evaluator/LlamaContext/LlamaContext.ts:245](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L245) ##### Returns [`GgmlType`](../enumerations/GgmlType.md) *** ### kvCacheValueType #### Get Signature ```ts get kvCacheValueType(): GgmlType; ``` Defined in: [evaluator/LlamaContext/LlamaContext.ts:249](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L249) ##### Returns [`GgmlType`](../enumerations/GgmlType.md) *** ### stateSize #### Get Signature ```ts get stateSize(): number; ``` Defined in: [evaluator/LlamaContext/LlamaContext.ts:257](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L257) The actual size of the state in the memory in bytes. This value is provided by `llama.cpp` and doesn't include all the memory overhead of the context. ##### Returns `number` *** ### currentThreads #### Get Signature ```ts get currentThreads(): number; ``` Defined in: [evaluator/LlamaContext/LlamaContext.ts:264](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L264) The number of threads currently used to evaluate tokens ##### Returns `number` *** ### idealThreads #### Get Signature ```ts get idealThreads(): number; ``` Defined in: [evaluator/LlamaContext/LlamaContext.ts:275](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L275) The number of threads that are preferred to be used to evaluate tokens. The actual number of threads used may be lower when other evaluations are running in parallel. ##### Returns `number` *** ### totalSequences #### Get Signature ```ts get totalSequences(): number; ``` Defined in: [evaluator/LlamaContext/LlamaContext.ts:288](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L288) ##### Returns `number` *** ### sequencesLeft #### Get Signature ```ts get sequencesLeft(): number; ``` Defined in: [evaluator/LlamaContext/LlamaContext.ts:292](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L292) ##### Returns `number` ## Methods ### dispose() ```ts dispose(): Promise; ``` Defined in: [evaluator/LlamaContext/LlamaContext.ts:211](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L211) #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`> *** ### getAllocatedContextSize() ```ts getAllocatedContextSize(): number; ``` Defined in: [evaluator/LlamaContext/LlamaContext.ts:279](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L279) #### Returns `number` *** ### getSequence() ```ts getSequence(options?: { contextShift?: ContextShiftOptions; tokenPredictor?: TokenPredictor; checkpoints?: { max?: number; interval?: number | false; maxMemory?: number | null; }; }): LlamaContextSequence; ``` Defined in: [evaluator/LlamaContext/LlamaContext.ts:300](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L300) Before calling this method, make sure to call `sequencesLeft` to check if there are any sequences left. When there are no sequences left, this method will throw an error. #### Parameters | Parameter | Type | Description | | ------ | ------ | ------ | | `options` | { `contextShift?`: [`ContextShiftOptions`](../type-aliases/ContextShiftOptions.md); `tokenPredictor?`: [`TokenPredictor`](TokenPredictor.md); `checkpoints?`: { `max?`: `number`; `interval?`: `number` | `false`; `maxMemory?`: `number` | `null`; }; } | - | | `options.contextShift?` | [`ContextShiftOptions`](../type-aliases/ContextShiftOptions.md) | - | | `options.tokenPredictor?` | [`TokenPredictor`](TokenPredictor.md) | Token predictor to use for the sequence. Don't share the same token predictor between multiple sequences. Using a token predictor doesn't affect the generation output itself - it only allows for greater parallelization of the token evaluation to speed up the generation. > **Note:** that if a token predictor is too resource intensive, > it can slow down the generation process due to the overhead of running the predictor. > > Testing the effectiveness of a token predictor on the target machine is recommended before using it in production. Automatically disposed when disposing the sequence. **See** [Using Token Predictors](https://node-llama-cpp.withcat.ai/guide/token-prediction) | | `options.checkpoints?` | { `max?`: `number`; `interval?`: `number` | `false`; `maxMemory?`: `number` | `null`; } | The maximum number of checkpoint to keep for the sequence when needed. When reusing a prefix evaluation state is not possible for the context sequence (like in contexts from recurrent and hybrid models, or with models that use SWA (Sliding Window Attention) when the `swaFullCache` option is not enabled on the context), storing checkpoints allows reusing the context state at certain points in the sequence to speed up the evaluation when erasing parts of the context state that come after those points. Those checkpoints will automatically be used when trying to erase parts of the context state that come after a checkpointed state, and be freed from memory when no longer relevant. Those checkpoints are relatively lightweight compared to saving the entire state, but taking too many checkpoints can increase memory usage. Checkpoints are stored in the RAM (not VRAM). See [LlamaContextSequence.takeCheckpoint](LlamaContextSequence.md#takecheckpoint) for more details on how checkpoints are taken and used. | | `options.checkpoints.max?` | `number` | The maximum number of checkpoints to keep for the sequence when needed. Defaults to `32`. | | `options.checkpoints.interval?` | `number` | `false` | Take a checkpoint every `interval` tokens when the sequence needs taking checkpoints. Defaults to `8192`. | | `options.checkpoints.maxMemory?` | `number` | `null` | The maximum memory in bytes to use for checkpoints for the sequence when needed. When taking a checkpoint causes the checkpoints pool memory to exceed this value, older checkpoints will be pruned until the total checkpoints memory usage is under this limit, while ensuring that at least one checkpoint is kept. Defaults to `null` (no memory limit). | #### Returns [`LlamaContextSequence`](LlamaContextSequence.md) *** ### dispatchPendingBatch() ```ts dispatchPendingBatch(): void; ``` Defined in: [evaluator/LlamaContext/LlamaContext.ts:397](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L397) #### Returns `void` *** ### printTimings() ```ts printTimings(): Promise; ``` Defined in: [evaluator/LlamaContext/LlamaContext.ts:714](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L714) Print the timings of token evaluation since that last print for this context. Requires the `performanceTracking` option to be enabled. > **Note:** it prints on the `LlamaLogLevel.info` level, so if you set the level of your `Llama` instance higher than that, > it won't print anything. #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`> --- --- url: /api/classes/LlamaContextSequence.md --- # Class: LlamaContextSequence Defined in: [evaluator/LlamaContext/LlamaContext.ts:1075](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L1075) ## Properties ### onDispose ```ts readonly onDispose: EventRelay; ``` Defined in: [evaluator/LlamaContext/LlamaContext.ts:1099](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L1099) ## Accessors ### disposed #### Get Signature ```ts get disposed(): boolean; ``` Defined in: [evaluator/LlamaContext/LlamaContext.ts:1168](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L1168) ##### Returns `boolean` *** ### context #### Get Signature ```ts get context(): LlamaContext; ``` Defined in: [evaluator/LlamaContext/LlamaContext.ts:1172](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L1172) ##### Returns [`LlamaContext`](LlamaContext.md) *** ### model #### Get Signature ```ts get model(): LlamaModel; ``` Defined in: [evaluator/LlamaContext/LlamaContext.ts:1176](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L1176) ##### Returns [`LlamaModel`](LlamaModel.md) *** ### contextSize #### Get Signature ```ts get contextSize(): number; ``` Defined in: [evaluator/LlamaContext/LlamaContext.ts:1181](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L1181) The maximum number of tokens that the sequence state can hold ##### Returns `number` *** ### nextTokenIndex #### Get Signature ```ts get nextTokenIndex(): number; ``` Defined in: [evaluator/LlamaContext/LlamaContext.ts:1186](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L1186) The index where the next evaluated token will be placed in the context ##### Returns `number` *** ### contextTokens #### Get Signature ```ts get contextTokens(): Token[]; ``` Defined in: [evaluator/LlamaContext/LlamaContext.ts:1191](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L1191) The current context state tokens ##### Returns [`Token`](../type-aliases/Token.md)\[] *** ### tokenMeter #### Get Signature ```ts get tokenMeter(): TokenMeter; ``` Defined in: [evaluator/LlamaContext/LlamaContext.ts:1198](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L1198) ##### Returns [`TokenMeter`](TokenMeter.md) *** ### tokenPredictor #### Get Signature ```ts get tokenPredictor(): TokenPredictor | undefined; ``` Defined in: [evaluator/LlamaContext/LlamaContext.ts:1205](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L1205) The token predictor used when creating this sequence. ##### Returns [`TokenPredictor`](TokenPredictor.md) | `undefined` *** ### stateCellsStartIndex #### Get Signature ```ts get stateCellsStartIndex(): number; ``` Defined in: [evaluator/LlamaContext/LlamaContext.ts:1228](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L1228) Get the index of the first token in the KV cache. If you remove any tokens from the state that come before this index, no cached prefix tokens evaluation state will be used for the next evaluation. For example, if `stateCellsStartIndex` is `10` and you remove the range `{start: 11, end: 16}` then the cached state for range `0-10` will be used in the next evaluation, but if you remove the range `{start: 10, end: 16}` (or `{start: 9, end: 16}`) then the cached state will not be used at all and will be re-evaluated in the next evaluation. This index can be greater than `0` only when SWA (Sliding Window Attention) is used (only on supported models). When SWA is used, this index will usually be `Math.max(-1, .nextTokenIndex - .model.fileInsights.swaSize)` or larger. When the KV cache is empty, this index will be `-1`. You can disable SWA by setting the `swaFullCache` option to `true` when creating a context. ##### Returns `number` *** ### tokenPredictions #### Get Signature ```ts get tokenPredictions(): { used: number; unused: number; validated: number; refuted: number; }; ``` Defined in: [evaluator/LlamaContext/LlamaContext.ts:1243](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L1243) Statistics of token predictions using the sequence's `tokenPredictor`. The statistics change only when token prediction is used in this sequence. `validated` + `refuted` = total number of evaluated predictions. Prefer using `validated` and `refuted` to evaluate the effectiveness of token prediction. ##### Returns ###### used ```ts used: number; ``` Number of token predictions that were actually used (tokens that were validated and then consumed) ###### unused ```ts unused: number; ``` Number of token predictions that were not used (tokens that were validated and were not consumed) ###### validated ```ts validated: number; ``` Number of token predictions that were validated successfully ###### refuted ```ts refuted: number; ``` Number of token predictions that were refuted *** ### isLoadedToMemory #### Get Signature ```ts get isLoadedToMemory(): boolean; ``` Defined in: [evaluator/LlamaContext/LlamaContext.ts:1264](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L1264) ##### Returns `boolean` *** ### needsCheckpoints #### Get Signature ```ts get needsCheckpoints(): boolean; ``` Defined in: [evaluator/LlamaContext/LlamaContext.ts:1956](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L1956) Whether the current context sequence needs taking checkpoints of the context state to be able to reuse it as a prefix evaluation state in the future. See [\`.takeCheckpoint()\`](#takecheckpoint) for more details. ##### Returns `boolean` *** ### lastCheckpointIndex #### Get Signature ```ts get lastCheckpointIndex(): number; ``` Defined in: [evaluator/LlamaContext/LlamaContext.ts:1968](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L1968) The index of the last taken checkpoint that's available for prefix reuse ##### Returns `number` *** ### checkpointsMemoryUsage #### Get Signature ```ts get checkpointsMemoryUsage(): number; ``` Defined in: [evaluator/LlamaContext/LlamaContext.ts:1975](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L1975) The total memory usage in bytes of all the checkpoints currently held for this context sequence ##### Returns `number` ## Methods ### dispose() ```ts dispose(): Promise; ``` Defined in: [evaluator/LlamaContext/LlamaContext.ts:1144](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L1144) #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`> *** ### compareContextTokens() ```ts compareContextTokens(tokens: Token[]): { firstDifferentIndex: number; }; ``` Defined in: [evaluator/LlamaContext/LlamaContext.ts:1268](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L1268) #### Parameters | Parameter | Type | | ------ | ------ | | `tokens` | [`Token`](../type-aliases/Token.md)\[] | #### Returns ```ts { firstDifferentIndex: number; } ``` ##### firstDifferentIndex ```ts firstDifferentIndex: number; ``` *** ### adaptStateToTokens() ```ts adaptStateToTokens(tokens: Token[], allowShift?: boolean): Promise; ``` Defined in: [evaluator/LlamaContext/LlamaContext.ts:1295](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L1295) Erase parts of the context state to align it with the given tokens. If the given tokens do not align with the current context state, the context state will be erased to align with the given tokens. To find the first different token index between the context state and the given tokens, access the `nextTokenIndex` property. If `allowShift` is `true` (the default), shifting tokens may happen to align the context state with the given tokens, which incurs token evaluation of the shifted tokens. #### Parameters | Parameter | Type | Default value | | ------ | ------ | ------ | | `tokens` | [`Token`](../type-aliases/Token.md)\[] | `undefined` | | `allowShift` | `boolean` | `true` | #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`> *** ### clearHistory() ```ts clearHistory(): Promise; ``` Defined in: [evaluator/LlamaContext/LlamaContext.ts:1346](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L1346) Clear the history of the sequence. #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`> *** ### eraseContextTokenRanges() ```ts eraseContextTokenRanges(ranges: ContextTokensDeleteRange[]): Promise; ``` Defined in: [evaluator/LlamaContext/LlamaContext.ts:1357](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L1357) Erase context tokens in the provided ranges to free up space for new tokens to be generated. The start of each range is inclusive, and the end of each range is exclusive. For example, the range `{start: 0, end: 1}` will remove the token at the `0` index only. #### Parameters | Parameter | Type | | ------ | ------ | | `ranges` | [`ContextTokensDeleteRange`](../type-aliases/ContextTokensDeleteRange.md)\[] | #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`> *** ### evaluate() ```ts evaluate(tokens: Token[], options?: SequenceEvaluateOptions): AsyncGenerator; ``` Defined in: [evaluator/LlamaContext/LlamaContext.ts:1522](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L1522) Evaluate the provided tokens into the context sequence, and continue generating new tokens on iterator iterations. This method uses the token predictor (when provided) to generate new tokens faster. #### Parameters | Parameter | Type | | ------ | ------ | | `tokens` | [`Token`](../type-aliases/Token.md)\[] | | `options` | [`SequenceEvaluateOptions`](../type-aliases/SequenceEvaluateOptions.md) | #### Returns [`AsyncGenerator`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/AsyncGenerator)<[`Token`](../type-aliases/Token.md), `void`, | `void` | [`Token`](../type-aliases/Token.md) | [`Token`](../type-aliases/Token.md)\[]> *** ### evaluateWithMetadata() ```ts evaluateWithMetadata( tokens: Token[], metadata: Metadata, options?: SequenceEvaluateOptions): AsyncGenerator, void, | void | Token | Token[]>; ``` Defined in: [evaluator/LlamaContext/LlamaContext.ts:1544](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L1544) Like [\`.evaluate(...)\`](#evaluate), but with additional metadata for each generated token. Configure the additional metadata options to choose which metadata to include. #### Type Parameters | Type Parameter | | ------ | | `Metadata` *extends* [`SequenceEvaluateMetadataOptions`](../type-aliases/SequenceEvaluateMetadataOptions.md) | #### Parameters | Parameter | Type | | ------ | ------ | | `tokens` | [`Token`](../type-aliases/Token.md)\[] | | `metadata` | `Metadata` | | `options` | [`SequenceEvaluateOptions`](../type-aliases/SequenceEvaluateOptions.md) | #### Returns [`AsyncGenerator`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/AsyncGenerator)<[`SequenceEvaluateOutput`](../type-aliases/SequenceEvaluateOutput.md)<`Metadata`>, `void`, | `void` | [`Token`](../type-aliases/Token.md) | [`Token`](../type-aliases/Token.md)\[]> *** ### evaluateWithoutGeneratingNewTokens() ```ts evaluateWithoutGeneratingNewTokens(tokens: Token[], options?: { evaluationPriority?: EvaluationPriority; contextShift?: ContextShiftOptions; }): Promise; ``` Defined in: [evaluator/LlamaContext/LlamaContext.ts:1616](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L1616) Evaluate the provided tokens into the context sequence without generating new tokens. #### Parameters | Parameter | Type | Description | | ------ | ------ | ------ | | `tokens` | [`Token`](../type-aliases/Token.md)\[] | - | | `options` | { `evaluationPriority?`: [`EvaluationPriority`](../type-aliases/EvaluationPriority.md); `contextShift?`: [`ContextShiftOptions`](../type-aliases/ContextShiftOptions.md); } | - | | `options.evaluationPriority?` | [`EvaluationPriority`](../type-aliases/EvaluationPriority.md) | When a lot of tokens are queued for the next batch, more than the configured `batchSize`, the tokens for each sequence will be evaluated based on the strategy chosen for the context. By default, the `"maximumParallelism"` strategy is used, which will try to evaluate as many sequences in parallel as possible, but at some point, it'll have to choose which sequences to evaluate more tokens of, so it'll prioritize the sequences with the highest evaluation priority. Also, a custom strategy can be used to prioritize the sequences differently, but generally, the higher the evaluation priority is, the more likely and more tokens will be evaluated for that sequence in the next queued batch. | | `options.contextShift?` | [`ContextShiftOptions`](../type-aliases/ContextShiftOptions.md) | Override the sequence context shift options for this evaluation | #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`> *** ### controlledEvaluate() ```ts controlledEvaluate(input: ControlledEvaluateInputItem[], options?: { evaluationPriority?: EvaluationPriority; contextShift?: ContextShiftOptions; onTokenResult?: void; }): Promise<( | ControlledEvaluateIndexOutput | undefined)[]>; ``` Defined in: [evaluator/LlamaContext/LlamaContext.ts:1698](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L1698) Evaluate the provided tokens into the context sequence with custom options for each token. This method allows for more precise control of the generation process. A next token will be generated for a given token only if any of the `generateNext` options for it are used. To generate more tokens after this method finishes, use it again with token(s) you selected to add to the context from the previous evaluation. This method doesn't use the token predictor (when provided) since it cannot predict which tokens are actually needed. Use the `evaluate` method when you need to use token prediction. #### Parameters | Parameter | Type | Description | | ------ | ------ | ------ | | `input` | [`ControlledEvaluateInputItem`](../type-aliases/ControlledEvaluateInputItem.md)\[] | - | | `options?` | { `evaluationPriority?`: [`EvaluationPriority`](../type-aliases/EvaluationPriority.md); `contextShift?`: [`ContextShiftOptions`](../type-aliases/ContextShiftOptions.md); `onTokenResult?`: `void`; } | - | | `options.evaluationPriority?` | [`EvaluationPriority`](../type-aliases/EvaluationPriority.md) | When a lot of tokens are queued for the next batch, more than the configured `batchSize`, the tokens for each sequence will be evaluated based on the strategy chosen for the context. By default, the `"maximumParallelism"` strategy is used, which will try to evaluate as many sequences in parallel as possible, but at some point, it'll have to choose which sequences to evaluate more tokens of, so it'll prioritize the sequences with the highest evaluation priority. Also, a custom strategy can be used to prioritize the sequences differently, but generally, the higher the evaluation priority is, the more likely and more tokens will be evaluated for that sequence in the next queued batch. | | `options.contextShift?` | [`ContextShiftOptions`](../type-aliases/ContextShiftOptions.md) | Override the sequence context shift options for this evaluation | | `options.onTokenResult?` | - | #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<( | [`ControlledEvaluateIndexOutput`](../type-aliases/ControlledEvaluateIndexOutput.md) | `undefined`)\[]> An array where for each token in the input array, there can be an output item at the same index in the output array. For indexes that have no output, there won't be any value at the corresponding index in the output array. It's recommended to iterate from `0` up to the length of the input array to check the results in the output array. *** ### saveStateToFile() ```ts saveStateToFile(filePath: string): Promise<{ fileSize: number; }>; ``` Defined in: [evaluator/LlamaContext/LlamaContext.ts:1832](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L1832) Save the current context sequence evaluation state to a file. #### Parameters | Parameter | Type | | ------ | ------ | | `filePath` | `string` | #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{ `fileSize`: `number`; }> #### See [Saving and restoring a context sequence evaluation state](https://node-llama-cpp.withcat.ai/guide/chat-session#save-and-restore-with-context-sequence-state) *** ### loadStateFromFile() ```ts loadStateFromFile(filePath: string, acceptRisk: { acceptRisk: true; }): Promise; ``` Defined in: [evaluator/LlamaContext/LlamaContext.ts:1866](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L1866) Load a context sequence evaluation state from a file. Trying to load a state file with a longer context size than the current sequence's context size will fail and throw an error. You must ensure that the file was created from the exact same model, otherwise, using this function may crash the process. #### Parameters | Parameter | Type | Description | | ------ | ------ | ------ | | `filePath` | `string` | - | | `acceptRisk` | { `acceptRisk`: `true`; } | - | | `acceptRisk.acceptRisk` | `true` | Loading a state file created using a different model may crash the process. You must accept this risk to use this feature. | #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`> #### See [Saving and restoring a context sequence evaluation state](https://node-llama-cpp.withcat.ai/guide/chat-session#save-and-restore-with-context-sequence-state) *** ### takeCheckpoint() ```ts takeCheckpoint(): Promise; ``` Defined in: [evaluator/LlamaContext/LlamaContext.ts:1931](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L1931) When reusing a prefix evaluation state is not possible for the current context sequence (like in contexts from recurrent and hybrid models, or with models that use SWA (Sliding Window Attention) when the `swaFullCache` option is not enabled on the context), you can use this method to checkpoint the current context sequence state. Those checkpoints will automatically be used when trying to erase parts of the context state that come after a checkpointed state, and be freed from memory when no longer relevant. Those checkpoints are relatively lightweight compared to saving the entire state, but taking too many checkpoints can increase memory usage. Checkpoints are stored in the RAM (not VRAM). Calling this method on a context sequence from a model that natively supports prefix evaluation state reuse will have no effect. > **Note:** to check whether the current context sequence needs taking checkpoints, > you can use the [\`.needsCheckpoints\`](#needscheckpoints) property. #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`> *** ### getRestoreToPrefixIndexEvaluationSize() ```ts getRestoreToPrefixIndexEvaluationSize(tokenIndex: number): number; ``` Defined in: [evaluator/LlamaContext/LlamaContext.ts:1982](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaContext/LlamaContext.ts#L1982) Check how many tokens will be evaluated when trying to restore to checkpoint at a given index #### Parameters | Parameter | Type | | ------ | ------ | | `tokenIndex` | `number` | #### Returns `number` --- --- url: /api/classes/LlamaEmbedding.md --- # Class: LlamaEmbedding Defined in: [evaluator/LlamaEmbedding.ts:10](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaEmbedding.ts#L10) ## Constructors ### Constructor ```ts new LlamaEmbedding(options: LlamaEmbeddingOptions): LlamaEmbedding; ``` Defined in: [evaluator/LlamaEmbedding.ts:13](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaEmbedding.ts#L13) #### Parameters | Parameter | Type | | ------ | ------ | | `options` | [`LlamaEmbeddingOptions`](../type-aliases/LlamaEmbeddingOptions.md) | #### Returns `LlamaEmbedding` ## Properties ### vector ```ts readonly vector: readonly number[]; ``` Defined in: [evaluator/LlamaEmbedding.ts:11](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaEmbedding.ts#L11) ## Methods ### toJSON() ```ts toJSON(): LlamaEmbeddingJSON; ``` Defined in: [evaluator/LlamaEmbedding.ts:17](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaEmbedding.ts#L17) #### Returns [`LlamaEmbeddingJSON`](../type-aliases/LlamaEmbeddingJSON.md) *** ### calculateCosineSimilarity() ```ts calculateCosineSimilarity(other: | readonly number[] | LlamaEmbeddingJSON | LlamaEmbedding): number; ``` Defined in: [evaluator/LlamaEmbedding.ts:31](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaEmbedding.ts#L31) Calculates the cosine similarity between this embedding and another embedding. Note that you should only compare embeddings created by the exact same model file. #### Parameters | Parameter | Type | | ------ | ------ | | `other` | | readonly `number`\[] | [`LlamaEmbeddingJSON`](../type-aliases/LlamaEmbeddingJSON.md) | `LlamaEmbedding` | #### Returns `number` A value between 0 and 1 representing the similarity between the embedding vectors, where 1 means the embeddings are identical. *** ### fromJSON() ```ts static fromJSON(json: LlamaEmbeddingJSON): LlamaEmbedding; ``` Defined in: [evaluator/LlamaEmbedding.ts:65](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaEmbedding.ts#L65) #### Parameters | Parameter | Type | | ------ | ------ | | `json` | [`LlamaEmbeddingJSON`](../type-aliases/LlamaEmbeddingJSON.md) | #### Returns `LlamaEmbedding` --- --- url: /api/classes/LlamaEmbeddingContext.md --- # Class: LlamaEmbeddingContext Defined in: [evaluator/LlamaEmbeddingContext.ts:52](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaEmbeddingContext.ts#L52) ## See [Using Embedding](https://node-llama-cpp.withcat.ai/guide/embedding) tutorial ## Properties ### onDispose ```ts readonly onDispose: EventRelay; ``` Defined in: [evaluator/LlamaEmbeddingContext.ts:57](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaEmbeddingContext.ts#L57) ## Accessors ### disposed #### Get Signature ```ts get disposed(): boolean; ``` Defined in: [evaluator/LlamaEmbeddingContext.ts:129](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaEmbeddingContext.ts#L129) ##### Returns `boolean` *** ### model #### Get Signature ```ts get model(): LlamaModel; ``` Defined in: [evaluator/LlamaEmbeddingContext.ts:133](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaEmbeddingContext.ts#L133) ##### Returns [`LlamaModel`](LlamaModel.md) ## Methods ### getEmbeddingFor() ```ts getEmbeddingFor(input: | string | LlamaText | Token[]): Promise; ``` Defined in: [evaluator/LlamaEmbeddingContext.ts:78](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaEmbeddingContext.ts#L78) #### Parameters | Parameter | Type | | ------ | ------ | | `input` | | `string` | [`LlamaText`](LlamaText.md) | [`Token`](../type-aliases/Token.md)\[] | #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[`LlamaEmbedding`](LlamaEmbedding.md)> *** ### dispose() ```ts dispose(): Promise; ``` Defined in: [evaluator/LlamaEmbeddingContext.ts:120](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaEmbeddingContext.ts#L120) #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`> --- --- url: /api/classes/LlamaGrammar.md --- # Class: LlamaGrammar Defined in: [evaluator/LlamaGrammar.ts:31](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaGrammar.ts#L31) ## See [Using Grammar](https://node-llama-cpp.withcat.ai/guide/grammar) tutorial ## Extended by * [`LlamaJsonSchemaGrammar`](LlamaJsonSchemaGrammar.md) ## Constructors ### Constructor ```ts new LlamaGrammar(llama: Llama, options: LlamaGrammarOptions): LlamaGrammar; ``` Defined in: [evaluator/LlamaGrammar.ts:50](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaGrammar.ts#L50) > GBNF files are supported. > More info here: [ > github:ggml-org/llama.cpp:grammars/README.md > ](https://github.com/ggml-org/llama.cpp/blob/f5fe98d11bdf9e7797bcfb05c0c3601ffc4b9d26/grammars/README.md) Prefer to create a new instance of this class by using `llama.createGrammar(...)`. #### Parameters | Parameter | Type | Description | | ------ | ------ | ------ | | `llama` | [`Llama`](Llama.md) | - | | `options` | [`LlamaGrammarOptions`](../type-aliases/LlamaGrammarOptions.md) | - | #### Returns `LlamaGrammar` #### Deprecated Use `llama.createGrammar(...)` instead. ## Accessors ### grammar #### Get Signature ```ts get grammar(): string; ``` Defined in: [evaluator/LlamaGrammar.ts:64](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaGrammar.ts#L64) ##### Returns `string` *** ### rootRuleName #### Get Signature ```ts get rootRuleName(): string; ``` Defined in: [evaluator/LlamaGrammar.ts:68](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaGrammar.ts#L68) ##### Returns `string` *** ### stopGenerationTriggers #### Get Signature ```ts get stopGenerationTriggers(): readonly ( | string | LlamaText | readonly (string | Token)[])[]; ``` Defined in: [evaluator/LlamaGrammar.ts:72](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaGrammar.ts#L72) ##### Returns readonly ( | `string` | [`LlamaText`](LlamaText.md) | readonly (`string` | [`Token`](../type-aliases/Token.md))\[])\[] *** ### trimWhitespaceSuffix #### Get Signature ```ts get trimWhitespaceSuffix(): boolean; ``` Defined in: [evaluator/LlamaGrammar.ts:76](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaGrammar.ts#L76) ##### Returns `boolean` ## Methods ### getFor() ```ts static getFor(llama: Llama, type: | "json" | "json_arr" | "english" | "list" | "c" | "arithmetic" | "japanese" | "chess"): Promise; ``` Defined in: [evaluator/LlamaGrammar.ts:88](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaGrammar.ts#L88) #### Parameters | Parameter | Type | | ------ | ------ | | `llama` | [`Llama`](Llama.md) | | `type` | | `"json"` | `"json_arr"` | `"english"` | `"list"` | `"c"` | `"arithmetic"` | `"japanese"` | `"chess"` | #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`LlamaGrammar`> --- --- url: /api/classes/LlamaGrammarEvaluationState.md --- # Class: LlamaGrammarEvaluationState Defined in: [evaluator/LlamaGrammarEvaluationState.ts:19](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaGrammarEvaluationState.ts#L19) Grammar evaluation state is used to track the model response to determine the next allowed characters for the model to generate. Create a new grammar evaluation state for every response you generate with the model. This is only needed when using the `LlamaContext` class directly, since `LlamaChatSession` already handles this for you. ## Constructors ### Constructor ```ts new LlamaGrammarEvaluationState(options: LlamaGrammarEvaluationStateOptions): LlamaGrammarEvaluationState; ``` Defined in: [evaluator/LlamaGrammarEvaluationState.ts:23](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaGrammarEvaluationState.ts#L23) #### Parameters | Parameter | Type | | ------ | ------ | | `options` | [`LlamaGrammarEvaluationStateOptions`](../type-aliases/LlamaGrammarEvaluationStateOptions.md) | #### Returns `LlamaGrammarEvaluationState` ### Constructor ```ts new LlamaGrammarEvaluationState(existingState: LlamaGrammarEvaluationState): LlamaGrammarEvaluationState; ``` Defined in: [evaluator/LlamaGrammarEvaluationState.ts:24](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaGrammarEvaluationState.ts#L24) #### Parameters | Parameter | Type | | ------ | ------ | | `existingState` | `LlamaGrammarEvaluationState` | #### Returns `LlamaGrammarEvaluationState` ## Methods ### clone() ```ts clone(): LlamaGrammarEvaluationState; ``` Defined in: [evaluator/LlamaGrammarEvaluationState.ts:41](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaGrammarEvaluationState.ts#L41) Clone the grammar evaluation state #### Returns `LlamaGrammarEvaluationState` --- --- url: /api/classes/LlamaJsonSchemaGrammar.md --- # Class: LlamaJsonSchemaGrammar\ Defined in: [evaluator/LlamaJsonSchemaGrammar.ts:13](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaJsonSchemaGrammar.ts#L13) ## See * [Using a JSON Schema Grammar](https://node-llama-cpp.withcat.ai/guide/grammar#json-schema) tutorial * [Reducing Hallucinations When Using JSON Schema Grammar](https://node-llama-cpp.withcat.ai/guide/grammar#reducing-json-schema-hallucinations) tutorial ## Extends * [`LlamaGrammar`](LlamaGrammar.md) ## Type Parameters | Type Parameter | Default type | | ------ | ------ | | `T` *extends* [`GbnfJsonSchema`](../type-aliases/GbnfJsonSchema.md)<`Defs`> | - | | `Defs` *extends* [`GbnfJsonDefList`](../type-aliases/GbnfJsonDefList.md)<`Defs`> | [`Record`](https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkeys-type)<`any`, `any`> | ## Constructors ### Constructor ```ts new LlamaJsonSchemaGrammar(llama: Llama, schema: Readonly & GbnfJsonSchema): LlamaJsonSchemaGrammar; ``` Defined in: [evaluator/LlamaJsonSchemaGrammar.ts:23](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaJsonSchemaGrammar.ts#L23) Prefer to create a new instance of this class by using `llama.createGrammarForJsonSchema(...)`. #### Parameters | Parameter | Type | | ------ | ------ | | `llama` | [`Llama`](Llama.md) | | `schema` | [`Readonly`](https://www.typescriptlang.org/docs/handbook/utility-types.html#readonlytype)<`T`> & [`GbnfJsonSchema`](../type-aliases/GbnfJsonSchema.md)<`Defs`> | #### Returns `LlamaJsonSchemaGrammar`<`T`, `Defs`> #### Deprecated Use `llama.createGrammarForJsonSchema(...)` instead. #### Overrides [`LlamaGrammar`](LlamaGrammar.md).[`constructor`](LlamaGrammar.md#constructor) ## Accessors ### grammar #### Get Signature ```ts get grammar(): string; ``` Defined in: [evaluator/LlamaGrammar.ts:64](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaGrammar.ts#L64) ##### Returns `string` #### Inherited from [`LlamaGrammar`](LlamaGrammar.md).[`grammar`](LlamaGrammar.md#grammar) *** ### rootRuleName #### Get Signature ```ts get rootRuleName(): string; ``` Defined in: [evaluator/LlamaGrammar.ts:68](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaGrammar.ts#L68) ##### Returns `string` #### Inherited from [`LlamaGrammar`](LlamaGrammar.md).[`rootRuleName`](LlamaGrammar.md#rootrulename) *** ### stopGenerationTriggers #### Get Signature ```ts get stopGenerationTriggers(): readonly ( | string | LlamaText | readonly (string | Token)[])[]; ``` Defined in: [evaluator/LlamaGrammar.ts:72](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaGrammar.ts#L72) ##### Returns readonly ( | `string` | [`LlamaText`](LlamaText.md) | readonly (`string` | [`Token`](../type-aliases/Token.md))\[])\[] #### Inherited from [`LlamaGrammar`](LlamaGrammar.md).[`stopGenerationTriggers`](LlamaGrammar.md#stopgenerationtriggers) *** ### trimWhitespaceSuffix #### Get Signature ```ts get trimWhitespaceSuffix(): boolean; ``` Defined in: [evaluator/LlamaGrammar.ts:76](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaGrammar.ts#L76) ##### Returns `boolean` #### Inherited from [`LlamaGrammar`](LlamaGrammar.md).[`trimWhitespaceSuffix`](LlamaGrammar.md#trimwhitespacesuffix) *** ### schema #### Get Signature ```ts get schema(): Readonly; ``` Defined in: [evaluator/LlamaJsonSchemaGrammar.ts:35](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaJsonSchemaGrammar.ts#L35) ##### Returns [`Readonly`](https://www.typescriptlang.org/docs/handbook/utility-types.html#readonlytype)<`T`> ## Methods ### getFor() ```ts static getFor(llama: Llama, type: | "json" | "json_arr" | "english" | "list" | "c" | "arithmetic" | "japanese" | "chess"): Promise; ``` Defined in: [evaluator/LlamaGrammar.ts:88](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaGrammar.ts#L88) #### Parameters | Parameter | Type | | ------ | ------ | | `llama` | [`Llama`](Llama.md) | | `type` | | `"json"` | `"json_arr"` | `"english"` | `"list"` | `"c"` | `"arithmetic"` | `"japanese"` | `"chess"` | #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[`LlamaGrammar`](LlamaGrammar.md)> #### Inherited from [`LlamaGrammar`](LlamaGrammar.md).[`getFor`](LlamaGrammar.md#getfor) *** ### parse() ```ts parse(json: string): GbnfJsonSchemaToType; ``` Defined in: [evaluator/LlamaJsonSchemaGrammar.ts:39](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaJsonSchemaGrammar.ts#L39) #### Parameters | Parameter | Type | | ------ | ------ | | `json` | `string` | #### Returns [`GbnfJsonSchemaToType`](../type-aliases/GbnfJsonSchemaToType.md)<`T`> --- --- url: /api/classes/LlamaJsonSchemaValidationError.md --- # Class: LlamaJsonSchemaValidationError Defined in: [utils/gbnfJson/utils/validateObjectAgainstGbnfSchema.ts:23](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/gbnfJson/utils/validateObjectAgainstGbnfSchema.ts#L23) ## Extends * [`Error`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error) ## Constructors ### Constructor ```ts new LlamaJsonSchemaValidationError( message: string, object: any, schema: GbnfJsonSchema): LlamaJsonSchemaValidationError; ``` Defined in: [utils/gbnfJson/utils/validateObjectAgainstGbnfSchema.ts:27](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/gbnfJson/utils/validateObjectAgainstGbnfSchema.ts#L27) #### Parameters | Parameter | Type | | ------ | ------ | | `message` | `string` | | `object` | `any` | | `schema` | [`GbnfJsonSchema`](../type-aliases/GbnfJsonSchema.md) | #### Returns `LlamaJsonSchemaValidationError` #### Overrides ```ts Error.constructor ``` ## Properties ### object ```ts readonly object: any; ``` Defined in: [utils/gbnfJson/utils/validateObjectAgainstGbnfSchema.ts:24](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/gbnfJson/utils/validateObjectAgainstGbnfSchema.ts#L24) *** ### schema ```ts readonly schema: GbnfJsonSchema; ``` Defined in: [utils/gbnfJson/utils/validateObjectAgainstGbnfSchema.ts:25](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/gbnfJson/utils/validateObjectAgainstGbnfSchema.ts#L25) --- --- url: /api/classes/LlamaModel.md --- # Class: LlamaModel Defined in: [evaluator/LlamaModel/LlamaModel.ts:209](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L209) ## Properties ### tokenizer ```ts readonly tokenizer: Tokenizer; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:238](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L238) *** ### onDispose ```ts readonly onDispose: EventRelay; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:239](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L239) ## Accessors ### disposed #### Get Signature ```ts get disposed(): boolean; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:361](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L361) ##### Returns `boolean` *** ### llama #### Get Signature ```ts get llama(): Llama; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:365](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L365) ##### Returns [`Llama`](Llama.md) *** ### tokens #### Get Signature ```ts get tokens(): LlamaModelTokens; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:369](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L369) ##### Returns [`LlamaModelTokens`](LlamaModelTokens.md) *** ### filename #### Get Signature ```ts get filename(): string | undefined; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:373](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L373) ##### Returns `string` | `undefined` *** ### fileInfo #### Get Signature ```ts get fileInfo(): GgufFileInfo; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:377](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L377) ##### Returns [`GgufFileInfo`](../type-aliases/GgufFileInfo.md) *** ### fileInsights #### Get Signature ```ts get fileInsights(): GgufInsights; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:381](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L381) ##### Returns [`GgufInsights`](GgufInsights.md) *** ### architecture #### Get Signature ```ts get architecture(): GgufArchitectureType; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:385](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L385) ##### Returns [`GgufArchitectureType`](../enumerations/GgufArchitectureType.md) *** ### gpuLayers #### Get Signature ```ts get gpuLayers(): number; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:393](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L393) Number of layers offloaded to the GPU. If GPU support is disabled, this will always be `0`. ##### Returns `number` *** ### useMmap #### Get Signature ```ts get useMmap(): boolean; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:403](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L403) Whether the model is loaded using mmap (memory-mapped file) or not. When Direct I/O (setting the `useDirectIo` option to `true`) is used it'll override mmap and this value may be out of sync with the actual usage of mmap for the loading of this model instance. ##### Returns `boolean` *** ### size #### Get Signature ```ts get size(): number; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:412](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L412) Total model size in memory in bytes. When using mmap, actual memory usage may be higher than this value due to `llama.cpp`'s performance optimizations. ##### Returns `number` *** ### flashAttentionSupported #### Get Signature ```ts get flashAttentionSupported(): boolean; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:418](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L418) ##### Returns `boolean` *** ### defaultContextFlashAttention #### Get Signature ```ts get defaultContextFlashAttention(): boolean | "auto"; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:422](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L422) ##### Returns `boolean` | `"auto"` *** ### defaultContextSwaFullCache #### Get Signature ```ts get defaultContextSwaFullCache(): boolean; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:426](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L426) ##### Returns `boolean` *** ### defaultContextKvCacheKeyType #### Get Signature ```ts get defaultContextKvCacheKeyType(): GgmlType; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:430](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L430) ##### Returns [`GgmlType`](../enumerations/GgmlType.md) *** ### defaultContextKvCacheValueType #### Get Signature ```ts get defaultContextKvCacheValueType(): GgmlType; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:434](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L434) ##### Returns [`GgmlType`](../enumerations/GgmlType.md) *** ### trainContextSize #### Get Signature ```ts get trainContextSize(): number; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:723](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L723) The context size the model was trained on ##### Returns `number` *** ### embeddingVectorSize #### Get Signature ```ts get embeddingVectorSize(): number; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:733](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L733) The size of an embedding vector the model can produce ##### Returns `number` *** ### vocabularyType #### Get Signature ```ts get vocabularyType(): LlamaVocabularyType; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:742](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L742) ##### Returns [`LlamaVocabularyType`](../enumerations/LlamaVocabularyType.md) ## Methods ### dispose() ```ts dispose(): Promise; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:347](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L347) #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`> *** ### tokenize() #### Call Signature ```ts tokenize( text: string, specialTokens?: boolean, options?: "trimLeadingSpace"): Token[]; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:448](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L448) Transform text into tokens that can be fed to the model ##### Parameters | Parameter | Type | Description | | ------ | ------ | ------ | | `text` | `string` | the text to tokenize | | `specialTokens?` | `boolean` | if set to true, text that correspond to special tokens will be tokenized to those tokens. For example, `` will be tokenized to the BOS token if `specialTokens` is set to `true`, otherwise it will be tokenized to tokens that corresponds to the plaintext `` string. | | `options?` | `"trimLeadingSpace"` | additional options for tokenization. If set to `"trimLeadingSpace"`, a leading space will be trimmed from the tokenized output if the output has an additional space at the beginning. | ##### Returns [`Token`](../type-aliases/Token.md)\[] #### Call Signature ```ts tokenize(text: BuiltinSpecialTokenValue, specialTokens: "builtin"): Token[]; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:449](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L449) Transform text into tokens that can be fed to the model ##### Parameters | Parameter | Type | Description | | ------ | ------ | ------ | | `text` | [`BuiltinSpecialTokenValue`](../type-aliases/BuiltinSpecialTokenValue.md) | the text to tokenize | | `specialTokens` | `"builtin"` | if set to true, text that correspond to special tokens will be tokenized to those tokens. For example, `` will be tokenized to the BOS token if `specialTokens` is set to `true`, otherwise it will be tokenized to tokens that corresponds to the plaintext `` string. | ##### Returns [`Token`](../type-aliases/Token.md)\[] *** ### detokenize() ```ts detokenize( tokens: readonly Token[], specialTokens?: boolean, lastTokens?: readonly Token[]): string; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:563](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L563) Transform tokens into text #### Parameters | Parameter | Type | Default value | Description | | ------ | ------ | ------ | ------ | | `tokens` | readonly [`Token`](../type-aliases/Token.md)\[] | `undefined` | the tokens to detokenize. | | `specialTokens?` | `boolean` | `false` | if set to `true`, special tokens will be detokenized to their corresponding token text representation. Recommended for debugging purposes only. > **Note:** there may be additional spaces around special tokens that were not present in the original text - this is not a bug, this is [how the tokenizer is supposed to work](https://github.com/ggml-org/llama.cpp/pull/7697#issuecomment-2144003246). Defaults to `false`. | | `lastTokens?` | readonly [`Token`](../type-aliases/Token.md)\[] | `undefined` | the last few tokens that preceded the tokens to detokenize. If provided, the last few tokens will be used to determine whether a space has to be added before the current tokens or not, and apply other detokenizer-specific heuristics to provide the correct text continuation to the existing tokens. Using it may have no effect with some models, but it is still recommended. | #### Returns `string` *** ### getTokenAttributes() ```ts getTokenAttributes(token: Token): TokenAttributes; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:584](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L584) #### Parameters | Parameter | Type | | ------ | ------ | | `token` | [`Token`](../type-aliases/Token.md) | #### Returns [`TokenAttributes`](TokenAttributes.md) *** ### isSpecialToken() ```ts isSpecialToken(token: Token | undefined): boolean; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:595](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L595) Check whether the given token is a special token (a control-type token or a token with no normal text representation) #### Parameters | Parameter | Type | | ------ | ------ | | `token` | [`Token`](../type-aliases/Token.md) | `undefined` | #### Returns `boolean` *** ### iterateAllTokens() ```ts iterateAllTokens(): Generator; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:610](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L610) #### Returns [`Generator`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Generator)<[`Token`](../type-aliases/Token.md), `void`, `unknown`> *** ### isEogToken() ```ts isEogToken(token: Token | undefined): boolean; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:623](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L623) Check whether the given token is an EOG (End Of Generation) token, like EOS or EOT. #### Parameters | Parameter | Type | | ------ | ------ | | `token` | [`Token`](../type-aliases/Token.md) | `undefined` | #### Returns `boolean` *** ### createContext() ```ts createContext(options?: LlamaContextOptions): Promise; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:630](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L630) #### Parameters | Parameter | Type | | ------ | ------ | | `options` | [`LlamaContextOptions`](../type-aliases/LlamaContextOptions.md) | #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[`LlamaContext`](LlamaContext.md)> *** ### createEmbeddingContext() ```ts createEmbeddingContext(options?: LlamaEmbeddingContextOptions): Promise; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:647](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L647) #### Parameters | Parameter | Type | | ------ | ------ | | `options` | [`LlamaEmbeddingContextOptions`](../type-aliases/LlamaEmbeddingContextOptions.md) | #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[`LlamaEmbeddingContext`](LlamaEmbeddingContext.md)> #### See [Using Embedding](https://node-llama-cpp.withcat.ai/guide/embedding) tutorial *** ### createRankingContext() ```ts createRankingContext(options?: LlamaRankingContextOptions): Promise; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:657](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L657) #### Parameters | Parameter | Type | | ------ | ------ | | `options` | [`LlamaRankingContextOptions`](../type-aliases/LlamaRankingContextOptions.md) | #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[`LlamaRankingContext`](LlamaRankingContext.md)> #### See [Reranking Documents](https://node-llama-cpp.withcat.ai/guide/embedding#reranking) tutorial *** ### getWarnings() ```ts getWarnings(): string[]; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:669](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L669) Get warnings about the model file that would affect its usage. These warnings include all the warnings generated by `GgufInsights`, but are more comprehensive. #### Returns `string`\[] --- --- url: /api/classes/LlamaModelInfillTokens.md --- # Class: LlamaModelInfillTokens Defined in: [evaluator/LlamaModel/LlamaModel.ts:1197](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L1197) ## Accessors ### prefix #### Get Signature ```ts get prefix(): Token | null; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:1215](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L1215) ##### Returns [`Token`](../type-aliases/Token.md) | `null` The beginning of infill prefix token. *** ### middle #### Get Signature ```ts get middle(): Token | null; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:1230](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L1230) ##### Returns [`Token`](../type-aliases/Token.md) | `null` The beginning of infill middle token. *** ### suffix #### Get Signature ```ts get suffix(): Token | null; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:1245](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L1245) ##### Returns [`Token`](../type-aliases/Token.md) | `null` The beginning of infill suffix token. *** ### prefixString #### Get Signature ```ts get prefixString(): string | null; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:1260](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L1260) ##### Returns `string` | `null` The beginning of infill prefix token as a string. *** ### middleString #### Get Signature ```ts get middleString(): string | null; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:1277](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L1277) ##### Returns `string` | `null` The beginning of infill middle token as a string. *** ### suffixString #### Get Signature ```ts get suffixString(): string | null; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:1294](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L1294) ##### Returns `string` | `null` The beginning of infill suffix token as a string. --- --- url: /api/classes/LlamaModelTokens.md --- # Class: LlamaModelTokens Defined in: [evaluator/LlamaModel/LlamaModel.ts:967](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L967) ## Accessors ### infill #### Get Signature ```ts get infill(): LlamaModelInfillTokens; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:992](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L992) ##### Returns [`LlamaModelInfillTokens`](LlamaModelInfillTokens.md) infill tokens *** ### bos #### Get Signature ```ts get bos(): Token | null; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:1004](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L1004) ##### Returns [`Token`](../type-aliases/Token.md) | `null` The BOS (Beginning Of Sequence) token. *** ### eos #### Get Signature ```ts get eos(): Token | null; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:1019](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L1019) ##### Returns [`Token`](../type-aliases/Token.md) | `null` The EOS (End Of Sequence) token. *** ### eot #### Get Signature ```ts get eot(): Token | null; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:1034](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L1034) ##### Returns [`Token`](../type-aliases/Token.md) | `null` The EOT (End Of Turn) token. *** ### sep #### Get Signature ```ts get sep(): Token | null; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:1049](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L1049) ##### Returns [`Token`](../type-aliases/Token.md) | `null` The SEP (Sentence Separator) token. *** ### nl #### Get Signature ```ts get nl(): Token | null; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:1064](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L1064) ##### Returns [`Token`](../type-aliases/Token.md) | `null` The NL (New Line) token. *** ### bosString #### Get Signature ```ts get bosString(): string | null; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:1079](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L1079) ##### Returns `string` | `null` The BOS (Beginning Of Sequence) token text representation. *** ### eosString #### Get Signature ```ts get eosString(): string | null; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:1096](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L1096) ##### Returns `string` | `null` The EOS (End Of Sequence) token text representation. *** ### eotString #### Get Signature ```ts get eotString(): string | null; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:1113](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L1113) ##### Returns `string` | `null` The EOT (End Of Turn) token text representation. *** ### sepString #### Get Signature ```ts get sepString(): string | null; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:1130](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L1130) ##### Returns `string` | `null` The SEP (Sentence Separator) token text representation. *** ### nlString #### Get Signature ```ts get nlString(): string | null; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:1147](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L1147) ##### Returns `string` | `null` The NL (New Line) token text representation. *** ### shouldPrependBosToken #### Get Signature ```ts get shouldPrependBosToken(): boolean; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:1164](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L1164) ##### Returns `boolean` Whether we should prepend a BOS (Beginning Of Sequence) token for evaluations with this model. *** ### shouldAppendEosToken #### Get Signature ```ts get shouldAppendEosToken(): boolean; ``` Defined in: [evaluator/LlamaModel/LlamaModel.ts:1176](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/LlamaModel.ts#L1176) ##### Returns `boolean` Whether we should append an EOS (End Of Sequence) token for evaluations with this model. --- --- url: /api/classes/LlamaRankingContext.md --- # Class: LlamaRankingContext Defined in: [evaluator/LlamaRankingContext.ts:69](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaRankingContext.ts#L69) ## See [Reranking Documents](https://node-llama-cpp.withcat.ai/guide/embedding#reranking) tutorial ## Properties ### onDispose ```ts readonly onDispose: EventRelay; ``` Defined in: [evaluator/LlamaRankingContext.ts:75](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaRankingContext.ts#L75) ## Accessors ### disposed #### Get Signature ```ts get disposed(): boolean; ``` Defined in: [evaluator/LlamaRankingContext.ts:171](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaRankingContext.ts#L171) ##### Returns `boolean` *** ### model #### Get Signature ```ts get model(): LlamaModel; ``` Defined in: [evaluator/LlamaRankingContext.ts:175](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaRankingContext.ts#L175) ##### Returns [`LlamaModel`](LlamaModel.md) ## Methods ### rank() ```ts rank(query: | string | LlamaText | Token[], document: | string | LlamaText | Token[]): Promise; ``` Defined in: [evaluator/LlamaRankingContext.ts:105](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaRankingContext.ts#L105) Get the ranking score for a document for a query. A ranking score is a number between 0 and 1 representing the probability that the document is relevant to the query. #### Parameters | Parameter | Type | | ------ | ------ | | `query` | | `string` | [`LlamaText`](LlamaText.md) | [`Token`](../type-aliases/Token.md)\[] | | `document` | | `string` | [`LlamaText`](LlamaText.md) | [`Token`](../type-aliases/Token.md)\[] | #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`number`> a ranking score between 0 and 1 representing the probability that the document is relevant to the query. *** ### rankAll() ```ts rankAll(query: | string | LlamaText | Token[], documents: ( | string | LlamaText | Token[])[]): Promise; ``` Defined in: [evaluator/LlamaRankingContext.ts:124](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaRankingContext.ts#L124) Get the ranking scores for all the given documents for a query. A ranking score is a number between 0 and 1 representing the probability that the document is relevant to the query. #### Parameters | Parameter | Type | | ------ | ------ | | `query` | | `string` | [`LlamaText`](LlamaText.md) | [`Token`](../type-aliases/Token.md)\[] | | `documents` | ( | `string` | [`LlamaText`](LlamaText.md) | [`Token`](../type-aliases/Token.md)\[])\[] | #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`number`\[]> an array of ranking scores between 0 and 1 representing the probability that the document is relevant to the query. *** ### rankAndSort() ```ts rankAndSort(query: | string | LlamaText | Token[], documents: T[]): Promise<{ document: T; score: number; }[]>; ``` Defined in: [evaluator/LlamaRankingContext.ts:147](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaRankingContext.ts#L147) Get the ranking scores for all the given documents for a query and sort them by score from highest to lowest. A ranking score is a number between 0 and 1 representing the probability that the document is relevant to the query. #### Type Parameters | Type Parameter | | ------ | | `T` *extends* `string` | #### Parameters | Parameter | Type | | ------ | ------ | | `query` | | `string` | [`LlamaText`](LlamaText.md) | [`Token`](../type-aliases/Token.md)\[] | | `documents` | `T`\[] | #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{ `document`: `T`; `score`: `number`; }\[]> *** ### dispose() ```ts dispose(): Promise; ``` Defined in: [evaluator/LlamaRankingContext.ts:162](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaRankingContext.ts#L162) #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`> --- --- url: /api/classes/LlamaText.md --- # Class: LlamaText Defined in: [utils/LlamaText.ts:16](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/LlamaText.ts#L16) ## See [Using `LlamaText`](https://node-llama-cpp.withcat.ai/guide/llama-text) tutorial ## Constructors ### Constructor ```ts new LlamaText(...values: readonly LlamaTextInputValue[]): LlamaText; ``` Defined in: [utils/LlamaText.ts:22](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/LlamaText.ts#L22) Can also be called without `new` #### Parameters | Parameter | Type | | ------ | ------ | | ...`values` | readonly [`LlamaTextInputValue`](../type-aliases/LlamaTextInputValue.md)\[] | #### Returns `LlamaText` ## Properties ### values ```ts readonly values: readonly LlamaTextValue[]; ``` Defined in: [utils/LlamaText.ts:17](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/LlamaText.ts#L17) ## Methods ### concat() ```ts concat(value: LlamaTextInputValue): LlamaText; ``` Defined in: [utils/LlamaText.ts:27](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/LlamaText.ts#L27) #### Parameters | Parameter | Type | | ------ | ------ | | `value` | [`LlamaTextInputValue`](../type-aliases/LlamaTextInputValue.md) | #### Returns `LlamaText` *** ### mapValues() ```ts mapValues(mapper: (this: readonly LlamaTextValue[], value: LlamaTextValue, index: number, values: readonly LlamaTextValue[]) => LlamaTextInputValue): LlamaText; ``` Defined in: [utils/LlamaText.ts:31](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/LlamaText.ts#L31) #### Parameters | Parameter | Type | | ------ | ------ | | `mapper` | (`this`: readonly [`LlamaTextValue`](../type-aliases/LlamaTextValue.md)\[], `value`: [`LlamaTextValue`](../type-aliases/LlamaTextValue.md), `index`: `number`, `values`: readonly [`LlamaTextValue`](../type-aliases/LlamaTextValue.md)\[]) => [`LlamaTextInputValue`](../type-aliases/LlamaTextInputValue.md) | #### Returns `LlamaText` *** ### joinValues() ```ts joinValues(separator: LlamaTextValue | LlamaText): LlamaText; ``` Defined in: [utils/LlamaText.ts:51](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/LlamaText.ts#L51) Joins the values with the given separator. Note that the values are squashed when they are loaded into the `LlamaText`, so the separator is not added between adjacent strings. To add the separator on values before squashing them, use `LlamaText.joinValues` instead. #### Parameters | Parameter | Type | | ------ | ------ | | `separator` | [`LlamaTextValue`](../type-aliases/LlamaTextValue.md) | `LlamaText` | #### Returns `LlamaText` *** ### toString() ```ts toString(): string; ``` Defined in: [utils/LlamaText.ts:68](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/LlamaText.ts#L68) #### Returns `string` *** ### toJSON() ```ts toJSON(): LlamaTextJSON; ``` Defined in: [utils/LlamaText.ts:81](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/LlamaText.ts#L81) #### Returns [`LlamaTextJSON`](../type-aliases/LlamaTextJSON.md) *** ### tokenize() ```ts tokenize(tokenizer: Tokenizer, options?: "trimLeadingSpace"): Token[]; ``` Defined in: [utils/LlamaText.ts:97](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/LlamaText.ts#L97) #### Parameters | Parameter | Type | | ------ | ------ | | `tokenizer` | [`Tokenizer`](../type-aliases/Tokenizer.md) | | `options?` | `"trimLeadingSpace"` | #### Returns [`Token`](../type-aliases/Token.md)\[] *** ### compare() ```ts compare(other: LlamaText): boolean; ``` Defined in: [utils/LlamaText.ts:121](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/LlamaText.ts#L121) #### Parameters | Parameter | Type | | ------ | ------ | | `other` | `LlamaText` | #### Returns `boolean` *** ### trim() ```ts trim(): LlamaText; ``` Defined in: [utils/LlamaText.ts:125](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/LlamaText.ts#L125) #### Returns `LlamaText` *** ### trimStart() ```ts trimStart(): LlamaText; ``` Defined in: [utils/LlamaText.ts:129](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/LlamaText.ts#L129) #### Returns `LlamaText` *** ### trimEnd() ```ts trimEnd(): LlamaText; ``` Defined in: [utils/LlamaText.ts:167](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/LlamaText.ts#L167) #### Returns `LlamaText` *** ### includes() ```ts includes(value: LlamaText): boolean; ``` Defined in: [utils/LlamaText.ts:205](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/LlamaText.ts#L205) #### Parameters | Parameter | Type | | ------ | ------ | | `value` | `LlamaText` | #### Returns `boolean` *** ### fromJSON() ```ts static fromJSON(json: LlamaTextJSON): LlamaText; ``` Defined in: [utils/LlamaText.ts:272](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/LlamaText.ts#L272) #### Parameters | Parameter | Type | | ------ | ------ | | `json` | [`LlamaTextJSON`](../type-aliases/LlamaTextJSON.md) | #### Returns `LlamaText` *** ### compare() ```ts static compare(a: LlamaText, b: LlamaText): boolean; ``` Defined in: [utils/LlamaText.ts:294](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/LlamaText.ts#L294) #### Parameters | Parameter | Type | | ------ | ------ | | `a` | `LlamaText` | | `b` | `LlamaText` | #### Returns `boolean` *** ### fromTokens() ```ts static fromTokens(tokenizer: Tokenizer, tokens: Token[]): LlamaText; ``` Defined in: [utils/LlamaText.ts:316](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/LlamaText.ts#L316) Attempt to convert tokens to a `LlamaText` while preserving special tokens. Non-standard special tokens that don't have a text representation are ignored. #### Parameters | Parameter | Type | | ------ | ------ | | `tokenizer` | [`Tokenizer`](../type-aliases/Tokenizer.md) | | `tokens` | [`Token`](../type-aliases/Token.md)\[] | #### Returns `LlamaText` *** ### joinValues() ```ts static joinValues(separator: string | LlamaText, values: readonly LlamaTextInputValue[]): LlamaText; ``` Defined in: [utils/LlamaText.ts:369](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/LlamaText.ts#L369) Join values with the given separator before squashing adjacent strings inside the values #### Parameters | Parameter | Type | | ------ | ------ | | `separator` | `string` | `LlamaText` | | `values` | readonly [`LlamaTextInputValue`](../type-aliases/LlamaTextInputValue.md)\[] | #### Returns `LlamaText` *** ### isLlamaText() ```ts static isLlamaText(value: unknown): value is LlamaText; ``` Defined in: [utils/LlamaText.ts:386](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/LlamaText.ts#L386) #### Parameters | Parameter | Type | | ------ | ------ | | `value` | `unknown` | #### Returns `value is LlamaText` --- --- url: /api/classes/MistralChatWrapper.md --- # Class: MistralChatWrapper Defined in: [chatWrappers/MistralChatWrapper.ts:14](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/MistralChatWrapper.ts#L14) ## Extends * [`ChatWrapper`](ChatWrapper.md) ## Constructors ### Constructor ```ts new MistralChatWrapper(options?: { addSpaceBeforeEos?: boolean; }): MistralChatWrapper; ``` Defined in: [chatWrappers/MistralChatWrapper.ts:22](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/MistralChatWrapper.ts#L22) #### Parameters | Parameter | Type | Description | | ------ | ------ | ------ | | `options` | { `addSpaceBeforeEos?`: `boolean`; } | - | | `options.addSpaceBeforeEos?` | `boolean` | Default to `true` | #### Returns `MistralChatWrapper` #### Overrides [`ChatWrapper`](ChatWrapper.md).[`constructor`](ChatWrapper.md#constructor) ## Properties ### defaultSettings ```ts static defaultSettings: ChatWrapperSettings; ``` Defined in: [ChatWrapper.ts:15](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L15) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`defaultSettings`](ChatWrapper.md#defaultsettings) *** ### wrapperName ```ts readonly wrapperName: string = "Mistral"; ``` Defined in: [chatWrappers/MistralChatWrapper.ts:15](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/MistralChatWrapper.ts#L15) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`wrapperName`](ChatWrapper.md#wrappername) *** ### settings ```ts readonly settings: ChatWrapperSettings; ``` Defined in: [chatWrappers/MistralChatWrapper.ts:17](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/MistralChatWrapper.ts#L17) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`settings`](ChatWrapper.md#settings) ## Methods ### generateFunctionCallsAndResults() ```ts generateFunctionCallsAndResults(functionCalls: ChatModelFunctionCall[], useRawCall?: boolean): LlamaText; ``` Defined in: [ChatWrapper.ts:63](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L63) #### Parameters | Parameter | Type | Default value | | ------ | ------ | ------ | | `functionCalls` | [`ChatModelFunctionCall`](../type-aliases/ChatModelFunctionCall.md)\[] | `undefined` | | `useRawCall` | `boolean` | `true` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCallsAndResults`](ChatWrapper.md#generatefunctioncallsandresults) *** ### generateFunctionCall() ```ts generateFunctionCall(name: string, params: any): LlamaText; ``` Defined in: [ChatWrapper.ts:110](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L110) #### Parameters | Parameter | Type | | ------ | ------ | | `name` | `string` | | `params` | `any` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCall`](ChatWrapper.md#generatefunctioncall) *** ### generateModelResponseText() ```ts generateModelResponseText(modelResponse: ( | string | ChatModelFunctionCall | ChatModelSegment)[], useRawValues?: boolean): LlamaText; ``` Defined in: [ChatWrapper.ts:158](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L158) #### Parameters | Parameter | Type | Default value | | ------ | ------ | ------ | | `modelResponse` | ( | `string` | [`ChatModelFunctionCall`](../type-aliases/ChatModelFunctionCall.md) | [`ChatModelSegment`](../type-aliases/ChatModelSegment.md))\[] | `undefined` | | `useRawValues` | `boolean` | `true` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateModelResponseText`](ChatWrapper.md#generatemodelresponsetext) *** ### generateAvailableFunctionsSystemText() ```ts generateAvailableFunctionsSystemText(availableFunctions: ChatModelFunctions, __namedParameters: { documentParams?: boolean; }): LlamaText; ``` Defined in: [ChatWrapper.ts:243](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L243) #### Parameters | Parameter | Type | | ------ | ------ | | `availableFunctions` | [`ChatModelFunctions`](../type-aliases/ChatModelFunctions.md) | | `__namedParameters` | { `documentParams?`: `boolean`; } | | `__namedParameters.documentParams?` | `boolean` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateAvailableFunctionsSystemText`](ChatWrapper.md#generateavailablefunctionssystemtext) *** ### addAvailableFunctionsSystemMessageToHistory() ```ts addAvailableFunctionsSystemMessageToHistory(history: readonly ChatHistoryItem[]): readonly ChatHistoryItem[]; ``` Defined in: [chatWrappers/MistralChatWrapper.ts:70](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/MistralChatWrapper.ts#L70) #### Parameters | Parameter | Type | | ------ | ------ | | `history` | readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] | #### Returns readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] #### Overrides [`ChatWrapper`](ChatWrapper.md).[`addAvailableFunctionsSystemMessageToHistory`](ChatWrapper.md#addavailablefunctionssystemmessagetohistory) *** ### generateContextState() ```ts generateContextState(__namedParameters: ChatWrapperGenerateContextStateOptions): ChatWrapperGeneratedContextState; ``` Defined in: [chatWrappers/MistralChatWrapper.ts:74](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/MistralChatWrapper.ts#L74) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | [`ChatWrapperGenerateContextStateOptions`](../type-aliases/ChatWrapperGenerateContextStateOptions.md) | #### Returns [`ChatWrapperGeneratedContextState`](../type-aliases/ChatWrapperGeneratedContextState.md) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`generateContextState`](ChatWrapper.md#generatecontextstate) *** ### generateInitialChatHistory() ```ts generateInitialChatHistory(__namedParameters?: ChatWrapperGenerateInitialHistoryOptions): ChatHistoryItem[]; ``` Defined in: [chatWrappers/MistralChatWrapper.ts:149](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/MistralChatWrapper.ts#L149) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | [`ChatWrapperGenerateInitialHistoryOptions`](../type-aliases/ChatWrapperGenerateInitialHistoryOptions.md) | #### Returns [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] #### Overrides [`ChatWrapper`](ChatWrapper.md).[`generateInitialChatHistory`](ChatWrapper.md#generateinitialchathistory) *** ### generateFunctionCallResult() ```ts generateFunctionCallResult( functionName: string, functionParams: any, result: any): LlamaText; ``` Defined in: [chatWrappers/MistralChatWrapper.ts:161](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/MistralChatWrapper.ts#L161) #### Parameters | Parameter | Type | | ------ | ------ | | `functionName` | `string` | | `functionParams` | `any` | | `result` | `any` | #### Returns [`LlamaText`](LlamaText.md) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCallResult`](ChatWrapper.md#generatefunctioncallresult) --- --- url: /api/classes/ModelDownloader.md --- # Class: ModelDownloader Defined in: [utils/createModelDownloader.ts:211](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/createModelDownloader.ts#L211) ## Accessors ### entrypointFilename #### Get Signature ```ts get entrypointFilename(): string; ``` Defined in: [utils/createModelDownloader.ts:258](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/createModelDownloader.ts#L258) The filename of the entrypoint file that should be used to load the model. ##### Returns `string` *** ### entrypointFilePath #### Get Signature ```ts get entrypointFilePath(): string; ``` Defined in: [utils/createModelDownloader.ts:265](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/createModelDownloader.ts#L265) The full path to the entrypoint file that should be used to load the model. ##### Returns `string` *** ### splitBinaryParts #### Get Signature ```ts get splitBinaryParts(): number | undefined; ``` Defined in: [utils/createModelDownloader.ts:272](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/createModelDownloader.ts#L272) If the model is binary spliced from multiple parts, this will return the number of those binary parts. ##### Returns `number` | `undefined` *** ### totalFiles #### Get Signature ```ts get totalFiles(): number; ``` Defined in: [utils/createModelDownloader.ts:281](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/createModelDownloader.ts#L281) The total number of files that will be saved to the directory. For split files, this will be the number of split parts, as multiple files will be saved. For binary-split files, this will be 1, as the parts will be spliced into a single file. ##### Returns `number` *** ### totalSize #### Get Signature ```ts get totalSize(): number; ``` Defined in: [utils/createModelDownloader.ts:285](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/createModelDownloader.ts#L285) ##### Returns `number` *** ### downloadedSize #### Get Signature ```ts get downloadedSize(): number; ``` Defined in: [utils/createModelDownloader.ts:291](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/createModelDownloader.ts#L291) ##### Returns `number` *** ### estimatedTimeLeft #### Get Signature ```ts get estimatedTimeLeft(): number; ``` Defined in: [utils/createModelDownloader.ts:297](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/createModelDownloader.ts#L297) ##### Returns `number` *** ### averageSpeed #### Get Signature ```ts get averageSpeed(): number; ``` Defined in: [utils/createModelDownloader.ts:311](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/createModelDownloader.ts#L311) ##### Returns `number` *** ### filesInfo #### Get Signature ```ts get filesInfo(): { fileName: string; filePath: string; totalSize: number; downloadedSize: number; }[]; ``` Defined in: [utils/createModelDownloader.ts:326](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/createModelDownloader.ts#L326) Info about all the files that will be saved to the download directory, including their filenames, full paths, total sizes and downloaded sizes. ##### Returns { `fileName`: `string`; `filePath`: `string`; `totalSize`: `number`; `downloadedSize`: `number`; }\[] ## Methods ### download() ```ts download(__namedParameters?: { signal?: AbortSignal; }): Promise; ``` Defined in: [utils/createModelDownloader.ts:338](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/createModelDownloader.ts#L338) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | { `signal?`: `AbortSignal`; } | | `__namedParameters.signal?` | `AbortSignal` | #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`string`> The path to the entrypoint file that should be used to load the model *** ### cancel() ```ts cancel(__namedParameters?: { deleteTempFile?: boolean; }): Promise; ``` Defined in: [utils/createModelDownloader.ts:375](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/createModelDownloader.ts#L375) #### Parameters | Parameter | Type | Description | | ------ | ------ | ------ | | `__namedParameters` | { `deleteTempFile?`: `boolean`; } | - | | `__namedParameters.deleteTempFile?` | `boolean` | Delete the temporary file that was created during the download. Defaults to the value of `deleteTempFileOnCancel` in the constructor. | #### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`> --- --- url: /api/classes/MuseChatWrapper.md --- # Class: MuseChatWrapper Defined in: [chatWrappers/MuseChatWrapper.ts:13](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/MuseChatWrapper.ts#L13) ## Extends * [`ChatWrapper`](ChatWrapper.md) ## Constructors ### Constructor ```ts new MuseChatWrapper(options?: { reasoningStrength?: "medium" | "high" | "low" | "xhigh"; keepOnlyLastThought?: boolean; knowledgeCutoff?: | string | Date | () => Date | null; todayDate?: | string | number | Date | () => Date | null; }): MuseChatWrapper; ``` Defined in: [chatWrappers/MuseChatWrapper.ts:63](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/MuseChatWrapper.ts#L63) #### Parameters | Parameter | Type | Description | | ------ | ------ | ------ | | `options` | { `reasoningStrength?`: `"medium"` | `"high"` | `"low"` | `"xhigh"`; `keepOnlyLastThought?`: `boolean`; `knowledgeCutoff?`: | `string` | [`Date`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date) | () => [`Date`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date) | `null`; `todayDate?`: | `string` | `number` | [`Date`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date) | () => [`Date`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date) | `null`; } | - | | `options.reasoningStrength?` | `"medium"` | `"high"` | `"low"` | `"xhigh"` | The amount of reasoning to instruct the model to use. Defaults to `"high"`. | | `options.keepOnlyLastThought?` | `boolean` | Whether to keep only the chain of thought from the last model response. Defaults to `false`, matching the original chat template. | | `options.knowledgeCutoff?` | | `string` | [`Date`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date) | () => [`Date`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date) | `null` | The knowledge cutoff used by the default system message. The default system message is applied only when you supply a chat history that don't have a system message at the beginning. Set to `null` to omit it. Defaults to `"2026-01-04"`. | | `options.todayDate?` | | `string` | `number` | [`Date`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date) | () => [`Date`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date) | `null` | The current date used by the default system message. The default system message is applied only when you supply a chat history that don't have a system message at the beginning. Set to `null` to omit it. Defaults to the current date. | #### Returns `MuseChatWrapper` #### Overrides [`ChatWrapper`](ChatWrapper.md).[`constructor`](ChatWrapper.md#constructor) ## Properties ### defaultSettings ```ts static defaultSettings: ChatWrapperSettings; ``` Defined in: [ChatWrapper.ts:15](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L15) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`defaultSettings`](ChatWrapper.md#defaultsettings) *** ### wrapperName ```ts readonly wrapperName: string = "Muse"; ``` Defined in: [chatWrappers/MuseChatWrapper.ts:14](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/MuseChatWrapper.ts#L14) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`wrapperName`](ChatWrapper.md#wrappername) *** ### reasoningStrength ```ts readonly reasoningStrength: "medium" | "high" | "low" | "xhigh"; ``` Defined in: [chatWrappers/MuseChatWrapper.ts:16](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/MuseChatWrapper.ts#L16) *** ### keepOnlyLastThought ```ts readonly keepOnlyLastThought: boolean; ``` Defined in: [chatWrappers/MuseChatWrapper.ts:17](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/MuseChatWrapper.ts#L17) *** ### knowledgeCutoff ```ts readonly knowledgeCutoff: | Date | () => Date | null; ``` Defined in: [chatWrappers/MuseChatWrapper.ts:18](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/MuseChatWrapper.ts#L18) *** ### todayDate ```ts readonly todayDate: | Date | () => Date | null; ``` Defined in: [chatWrappers/MuseChatWrapper.ts:19](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/MuseChatWrapper.ts#L19) *** ### settings ```ts readonly settings: ChatWrapperSettings; ``` Defined in: [chatWrappers/MuseChatWrapper.ts:23](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/MuseChatWrapper.ts#L23) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`settings`](ChatWrapper.md#settings) ## Methods ### generateFunctionCallsAndResults() ```ts generateFunctionCallsAndResults(functionCalls: ChatModelFunctionCall[], useRawCall?: boolean): LlamaText; ``` Defined in: [ChatWrapper.ts:63](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L63) #### Parameters | Parameter | Type | Default value | | ------ | ------ | ------ | | `functionCalls` | [`ChatModelFunctionCall`](../type-aliases/ChatModelFunctionCall.md)\[] | `undefined` | | `useRawCall` | `boolean` | `true` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCallsAndResults`](ChatWrapper.md#generatefunctioncallsandresults) *** ### addAvailableFunctionsSystemMessageToHistory() ```ts addAvailableFunctionsSystemMessageToHistory( history: readonly ChatHistoryItem[], availableFunctions?: ChatModelFunctions, __namedParameters?: { documentParams?: boolean; }): readonly ChatHistoryItem[]; ``` Defined in: [ChatWrapper.ts:269](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L269) #### Parameters | Parameter | Type | | ------ | ------ | | `history` | readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] | | `availableFunctions?` | [`ChatModelFunctions`](../type-aliases/ChatModelFunctions.md) | | `__namedParameters?` | { `documentParams?`: `boolean`; } | | `__namedParameters.documentParams?` | `boolean` | #### Returns readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`addAvailableFunctionsSystemMessageToHistory`](ChatWrapper.md#addavailablefunctionssystemmessagetohistory) *** ### generateContextState() ```ts generateContextState(__namedParameters: ChatWrapperGenerateContextStateOptions): ChatWrapperGeneratedContextState; ``` Defined in: [chatWrappers/MuseChatWrapper.ts:127](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/MuseChatWrapper.ts#L127) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | [`ChatWrapperGenerateContextStateOptions`](../type-aliases/ChatWrapperGenerateContextStateOptions.md) | #### Returns [`ChatWrapperGeneratedContextState`](../type-aliases/ChatWrapperGeneratedContextState.md) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`generateContextState`](ChatWrapper.md#generatecontextstate) *** ### generateFunctionCall() ```ts generateFunctionCall(name: string, params: any): LlamaText; ``` Defined in: [chatWrappers/MuseChatWrapper.ts:248](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/MuseChatWrapper.ts#L248) #### Parameters | Parameter | Type | | ------ | ------ | | `name` | `string` | | `params` | `any` | #### Returns [`LlamaText`](LlamaText.md) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCall`](ChatWrapper.md#generatefunctioncall) *** ### generateFunctionCallResult() ```ts generateFunctionCallResult( functionName: string, functionParams: any, result: any): LlamaText; ``` Defined in: [chatWrappers/MuseChatWrapper.ts:266](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/MuseChatWrapper.ts#L266) #### Parameters | Parameter | Type | | ------ | ------ | | `functionName` | `string` | | `functionParams` | `any` | | `result` | `any` | #### Returns [`LlamaText`](LlamaText.md) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCallResult`](ChatWrapper.md#generatefunctioncallresult) *** ### generateModelResponseText() ```ts generateModelResponseText(modelResponse: ( | string | ChatModelFunctionCall | ChatModelSegment)[], useRawValues?: boolean): LlamaText; ``` Defined in: [chatWrappers/MuseChatWrapper.ts:281](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/MuseChatWrapper.ts#L281) #### Parameters | Parameter | Type | Default value | | ------ | ------ | ------ | | `modelResponse` | ( | `string` | [`ChatModelFunctionCall`](../type-aliases/ChatModelFunctionCall.md) | [`ChatModelSegment`](../type-aliases/ChatModelSegment.md))\[] | `undefined` | | `useRawValues` | `boolean` | `true` | #### Returns [`LlamaText`](LlamaText.md) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`generateModelResponseText`](ChatWrapper.md#generatemodelresponsetext) *** ### generateAvailableFunctionsSystemText() ```ts generateAvailableFunctionsSystemText(availableFunctions: ChatModelFunctions, __namedParameters: { documentParams?: boolean; }): LlamaText; ``` Defined in: [chatWrappers/MuseChatWrapper.ts:300](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/MuseChatWrapper.ts#L300) #### Parameters | Parameter | Type | | ------ | ------ | | `availableFunctions` | [`ChatModelFunctions`](../type-aliases/ChatModelFunctions.md) | | `__namedParameters` | { `documentParams?`: `boolean`; } | | `__namedParameters.documentParams?` | `boolean` | #### Returns [`LlamaText`](LlamaText.md) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`generateAvailableFunctionsSystemText`](ChatWrapper.md#generateavailablefunctionssystemtext) *** ### generateInitialChatHistory() ```ts generateInitialChatHistory(__namedParameters?: ChatWrapperGenerateInitialHistoryOptions): ChatHistoryItem[]; ``` Defined in: [chatWrappers/MuseChatWrapper.ts:373](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/MuseChatWrapper.ts#L373) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | [`ChatWrapperGenerateInitialHistoryOptions`](../type-aliases/ChatWrapperGenerateInitialHistoryOptions.md) | #### Returns [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] #### Overrides [`ChatWrapper`](ChatWrapper.md).[`generateInitialChatHistory`](ChatWrapper.md#generateinitialchathistory) --- --- url: /api/classes/NoBinaryFoundError.md --- # Class: NoBinaryFoundError Defined in: [bindings/utils/NoBinaryFoundError.ts:1](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/utils/NoBinaryFoundError.ts#L1) ## Extends * [`Error`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error) --- --- url: /api/classes/QwenChatWrapper.md --- # Class: QwenChatWrapper Defined in: [chatWrappers/QwenChatWrapper.ts:12](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/QwenChatWrapper.ts#L12) ## Extends * [`ChatWrapper`](ChatWrapper.md) ## Constructors ### Constructor ```ts new QwenChatWrapper(options?: { keepOnlyLastThought?: boolean; thoughts?: "auto" | "discourage" | "modelInitiated"; variation?: "3" | "3.5"; }): QwenChatWrapper; ``` Defined in: [chatWrappers/QwenChatWrapper.ts:23](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/QwenChatWrapper.ts#L23) #### Parameters | Parameter | Type | Description | | ------ | ------ | ------ | | `options` | { `keepOnlyLastThought?`: `boolean`; `thoughts?`: `"auto"` | `"discourage"` | `"modelInitiated"`; `variation?`: `"3"` | `"3.5"`; } | - | | `options.keepOnlyLastThought?` | `boolean` | Whether to keep only the chain of thought from the last model response. Setting this to `false` will keep all the chain of thoughts from the model responses in the context state. Defaults to `true`. | | `options.thoughts?` | `"auto"` | `"discourage"` | `"modelInitiated"` | Control the usage of thoughts in the model responses. When set to `"modelInitiated"`, thought segments won't be force-opened at the start of the model response, even if that's what the model would normally expect. Defaults to `"auto"`. | | `options.variation?` | `"3"` | `"3.5"` | Chat template variation to use. Defaults to `"3"`. | #### Returns `QwenChatWrapper` #### Overrides [`ChatWrapper`](ChatWrapper.md).[`constructor`](ChatWrapper.md#constructor) ## Properties ### defaultSettings ```ts static defaultSettings: ChatWrapperSettings; ``` Defined in: [ChatWrapper.ts:15](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L15) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`defaultSettings`](ChatWrapper.md#defaultsettings) *** ### wrapperName ```ts readonly wrapperName: string = "Qwen"; ``` Defined in: [chatWrappers/QwenChatWrapper.ts:13](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/QwenChatWrapper.ts#L13) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`wrapperName`](ChatWrapper.md#wrappername) *** ### variation ```ts readonly variation: "3" | "3.5"; ``` Defined in: [chatWrappers/QwenChatWrapper.ts:14](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/QwenChatWrapper.ts#L14) *** ### keepOnlyLastThought ```ts readonly keepOnlyLastThought: boolean; ``` Defined in: [chatWrappers/QwenChatWrapper.ts:16](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/QwenChatWrapper.ts#L16) *** ### thoughts ```ts readonly thoughts: "auto" | "discourage" | "modelInitiated"; ``` Defined in: [chatWrappers/QwenChatWrapper.ts:17](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/QwenChatWrapper.ts#L17) *** ### settings ```ts readonly settings: ChatWrapperSettings; ``` Defined in: [chatWrappers/QwenChatWrapper.ts:21](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/QwenChatWrapper.ts#L21) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`settings`](ChatWrapper.md#settings) ## Methods ### generateFunctionCallsAndResults() ```ts generateFunctionCallsAndResults(functionCalls: ChatModelFunctionCall[], useRawCall?: boolean): LlamaText; ``` Defined in: [ChatWrapper.ts:63](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L63) #### Parameters | Parameter | Type | Default value | | ------ | ------ | ------ | | `functionCalls` | [`ChatModelFunctionCall`](../type-aliases/ChatModelFunctionCall.md)\[] | `undefined` | | `useRawCall` | `boolean` | `true` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCallsAndResults`](ChatWrapper.md#generatefunctioncallsandresults) *** ### generateFunctionCall() ```ts generateFunctionCall(name: string, params: any): LlamaText; ``` Defined in: [ChatWrapper.ts:110](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L110) #### Parameters | Parameter | Type | | ------ | ------ | | `name` | `string` | | `params` | `any` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCall`](ChatWrapper.md#generatefunctioncall) *** ### generateModelResponseText() ```ts generateModelResponseText(modelResponse: ( | string | ChatModelFunctionCall | ChatModelSegment)[], useRawValues?: boolean): LlamaText; ``` Defined in: [ChatWrapper.ts:158](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L158) #### Parameters | Parameter | Type | Default value | | ------ | ------ | ------ | | `modelResponse` | ( | `string` | [`ChatModelFunctionCall`](../type-aliases/ChatModelFunctionCall.md) | [`ChatModelSegment`](../type-aliases/ChatModelSegment.md))\[] | `undefined` | | `useRawValues` | `boolean` | `true` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateModelResponseText`](ChatWrapper.md#generatemodelresponsetext) *** ### addAvailableFunctionsSystemMessageToHistory() ```ts addAvailableFunctionsSystemMessageToHistory( history: readonly ChatHistoryItem[], availableFunctions?: ChatModelFunctions, __namedParameters?: { documentParams?: boolean; }): readonly ChatHistoryItem[]; ``` Defined in: [ChatWrapper.ts:269](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L269) #### Parameters | Parameter | Type | | ------ | ------ | | `history` | readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] | | `availableFunctions?` | [`ChatModelFunctions`](../type-aliases/ChatModelFunctions.md) | | `__namedParameters?` | { `documentParams?`: `boolean`; } | | `__namedParameters.documentParams?` | `boolean` | #### Returns readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`addAvailableFunctionsSystemMessageToHistory`](ChatWrapper.md#addavailablefunctionssystemmessagetohistory) *** ### generateInitialChatHistory() ```ts generateInitialChatHistory(__namedParameters?: ChatWrapperGenerateInitialHistoryOptions): ChatHistoryItem[]; ``` Defined in: [ChatWrapper.ts:290](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L290) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | [`ChatWrapperGenerateInitialHistoryOptions`](../type-aliases/ChatWrapperGenerateInitialHistoryOptions.md) | #### Returns [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateInitialChatHistory`](ChatWrapper.md#generateinitialchathistory) *** ### generateContextState() ```ts generateContextState(__namedParameters: ChatWrapperGenerateContextStateOptions): ChatWrapperGeneratedContextState; ``` Defined in: [chatWrappers/QwenChatWrapper.ts:158](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/QwenChatWrapper.ts#L158) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | [`ChatWrapperGenerateContextStateOptions`](../type-aliases/ChatWrapperGenerateContextStateOptions.md) | #### Returns [`ChatWrapperGeneratedContextState`](../type-aliases/ChatWrapperGeneratedContextState.md) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`generateContextState`](ChatWrapper.md#generatecontextstate) *** ### generateFunctionCallResult() ```ts generateFunctionCallResult( functionName: string, functionParams: any, result: any): LlamaText; ``` Defined in: [chatWrappers/QwenChatWrapper.ts:287](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/QwenChatWrapper.ts#L287) #### Parameters | Parameter | Type | | ------ | ------ | | `functionName` | `string` | | `functionParams` | `any` | | `result` | `any` | #### Returns [`LlamaText`](LlamaText.md) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCallResult`](ChatWrapper.md#generatefunctioncallresult) *** ### generateAvailableFunctionsSystemText() ```ts generateAvailableFunctionsSystemText(availableFunctions: ChatModelFunctions, __namedParameters: { documentParams?: boolean; }): LlamaText; ``` Defined in: [chatWrappers/QwenChatWrapper.ts:294](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/QwenChatWrapper.ts#L294) #### Parameters | Parameter | Type | | ------ | ------ | | `availableFunctions` | [`ChatModelFunctions`](../type-aliases/ChatModelFunctions.md) | | `__namedParameters` | { `documentParams?`: `boolean`; } | | `__namedParameters.documentParams?` | `boolean` | #### Returns [`LlamaText`](LlamaText.md) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`generateAvailableFunctionsSystemText`](ChatWrapper.md#generateavailablefunctionssystemtext) --- --- url: /api/classes/SeedChatWrapper.md --- # Class: SeedChatWrapper Defined in: [chatWrappers/SeedChatWrapper.ts:12](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/SeedChatWrapper.ts#L12) ## Extends * [`ChatWrapper`](ChatWrapper.md) ## Constructors ### Constructor ```ts new SeedChatWrapper(options?: { thinkingBudget?: number | null; }): SeedChatWrapper; ``` Defined in: [chatWrappers/SeedChatWrapper.ts:41](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/SeedChatWrapper.ts#L41) #### Parameters | Parameter | Type | Description | | ------ | ------ | ------ | | `options` | { `thinkingBudget?`: `number` | `null`; } | - | | `options.thinkingBudget?` | `number` | `null` | The thinking budget to instruct the model to conform to. This is purely a request, the model may ignore it. Set to `0` to instruct the model to not use any reasoning. When set to `null`, the instruction will be omitted (unlimited reasoning). Defaults to `null`. | #### Returns `SeedChatWrapper` #### Overrides [`ChatWrapper`](ChatWrapper.md).[`constructor`](ChatWrapper.md#constructor) ## Properties ### defaultSettings ```ts static defaultSettings: ChatWrapperSettings; ``` Defined in: [ChatWrapper.ts:15](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L15) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`defaultSettings`](ChatWrapper.md#defaultsettings) *** ### wrapperName ```ts readonly wrapperName: string = "Seed"; ``` Defined in: [chatWrappers/SeedChatWrapper.ts:13](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/SeedChatWrapper.ts#L13) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`wrapperName`](ChatWrapper.md#wrappername) *** ### thinkingBudget ```ts readonly thinkingBudget: number | null; ``` Defined in: [chatWrappers/SeedChatWrapper.ts:15](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/SeedChatWrapper.ts#L15) *** ### settings ```ts readonly settings: ChatWrapperSettings; ``` Defined in: [chatWrappers/SeedChatWrapper.ts:17](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/SeedChatWrapper.ts#L17) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`settings`](ChatWrapper.md#settings) ## Methods ### generateFunctionCallsAndResults() ```ts generateFunctionCallsAndResults(functionCalls: ChatModelFunctionCall[], useRawCall?: boolean): LlamaText; ``` Defined in: [ChatWrapper.ts:63](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L63) #### Parameters | Parameter | Type | Default value | | ------ | ------ | ------ | | `functionCalls` | [`ChatModelFunctionCall`](../type-aliases/ChatModelFunctionCall.md)\[] | `undefined` | | `useRawCall` | `boolean` | `true` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCallsAndResults`](ChatWrapper.md#generatefunctioncallsandresults) *** ### generateFunctionCall() ```ts generateFunctionCall(name: string, params: any): LlamaText; ``` Defined in: [ChatWrapper.ts:110](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L110) #### Parameters | Parameter | Type | | ------ | ------ | | `name` | `string` | | `params` | `any` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCall`](ChatWrapper.md#generatefunctioncall) *** ### generateFunctionCallResult() ```ts generateFunctionCallResult( functionName: string, functionParams: any, result: any): LlamaText; ``` Defined in: [ChatWrapper.ts:127](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L127) #### Parameters | Parameter | Type | | ------ | ------ | | `functionName` | `string` | | `functionParams` | `any` | | `result` | `any` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCallResult`](ChatWrapper.md#generatefunctioncallresult) *** ### generateModelResponseText() ```ts generateModelResponseText(modelResponse: ( | string | ChatModelFunctionCall | ChatModelSegment)[], useRawValues?: boolean): LlamaText; ``` Defined in: [ChatWrapper.ts:158](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L158) #### Parameters | Parameter | Type | Default value | | ------ | ------ | ------ | | `modelResponse` | ( | `string` | [`ChatModelFunctionCall`](../type-aliases/ChatModelFunctionCall.md) | [`ChatModelSegment`](../type-aliases/ChatModelSegment.md))\[] | `undefined` | | `useRawValues` | `boolean` | `true` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateModelResponseText`](ChatWrapper.md#generatemodelresponsetext) *** ### addAvailableFunctionsSystemMessageToHistory() ```ts addAvailableFunctionsSystemMessageToHistory( history: readonly ChatHistoryItem[], availableFunctions?: ChatModelFunctions, __namedParameters?: { documentParams?: boolean; }): readonly ChatHistoryItem[]; ``` Defined in: [ChatWrapper.ts:269](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L269) #### Parameters | Parameter | Type | | ------ | ------ | | `history` | readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] | | `availableFunctions?` | [`ChatModelFunctions`](../type-aliases/ChatModelFunctions.md) | | `__namedParameters?` | { `documentParams?`: `boolean`; } | | `__namedParameters.documentParams?` | `boolean` | #### Returns readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`addAvailableFunctionsSystemMessageToHistory`](ChatWrapper.md#addavailablefunctionssystemmessagetohistory) *** ### generateInitialChatHistory() ```ts generateInitialChatHistory(__namedParameters?: ChatWrapperGenerateInitialHistoryOptions): ChatHistoryItem[]; ``` Defined in: [ChatWrapper.ts:290](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L290) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | [`ChatWrapperGenerateInitialHistoryOptions`](../type-aliases/ChatWrapperGenerateInitialHistoryOptions.md) | #### Returns [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateInitialChatHistory`](ChatWrapper.md#generateinitialchathistory) *** ### generateContextState() ```ts generateContextState(__namedParameters: ChatWrapperGenerateContextStateOptions): ChatWrapperGeneratedContextState; ``` Defined in: [chatWrappers/SeedChatWrapper.ts:64](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/SeedChatWrapper.ts#L64) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | [`ChatWrapperGenerateContextStateOptions`](../type-aliases/ChatWrapperGenerateContextStateOptions.md) | #### Returns [`ChatWrapperGeneratedContextState`](../type-aliases/ChatWrapperGeneratedContextState.md) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`generateContextState`](ChatWrapper.md#generatecontextstate) *** ### generateAvailableFunctionsSystemText() ```ts generateAvailableFunctionsSystemText(availableFunctions: ChatModelFunctions, __namedParameters: { documentParams?: boolean; }): LlamaText; ``` Defined in: [chatWrappers/SeedChatWrapper.ts:170](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/SeedChatWrapper.ts#L170) #### Parameters | Parameter | Type | | ------ | ------ | | `availableFunctions` | [`ChatModelFunctions`](../type-aliases/ChatModelFunctions.md) | | `__namedParameters` | { `documentParams?`: `boolean`; } | | `__namedParameters.documentParams?` | `boolean` | #### Returns [`LlamaText`](LlamaText.md) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`generateAvailableFunctionsSystemText`](ChatWrapper.md#generateavailablefunctionssystemtext) --- --- url: /api/classes/SpecialToken.md --- # Class: SpecialToken Defined in: [utils/LlamaText.ts:522](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/LlamaText.ts#L522) ## Constructors ### Constructor ```ts new SpecialToken(value: BuiltinSpecialTokenValue): SpecialToken; ``` Defined in: [utils/LlamaText.ts:525](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/LlamaText.ts#L525) #### Parameters | Parameter | Type | | ------ | ------ | | `value` | [`BuiltinSpecialTokenValue`](../type-aliases/BuiltinSpecialTokenValue.md) | #### Returns `SpecialToken` ## Properties ### value ```ts readonly value: BuiltinSpecialTokenValue; ``` Defined in: [utils/LlamaText.ts:523](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/LlamaText.ts#L523) ## Methods ### toString() ```ts toString(): BuiltinSpecialTokenValue; ``` Defined in: [utils/LlamaText.ts:529](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/LlamaText.ts#L529) #### Returns [`BuiltinSpecialTokenValue`](../type-aliases/BuiltinSpecialTokenValue.md) *** ### tokenize() ```ts tokenize(tokenizer: Tokenizer): Token[]; ``` Defined in: [utils/LlamaText.ts:533](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/LlamaText.ts#L533) #### Parameters | Parameter | Type | | ------ | ------ | | `tokenizer` | [`Tokenizer`](../type-aliases/Tokenizer.md) | #### Returns [`Token`](../type-aliases/Token.md)\[] *** ### toJSON() ```ts toJSON(): LlamaTextSpecialTokenJSON; ``` Defined in: [utils/LlamaText.ts:537](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/LlamaText.ts#L537) #### Returns [`LlamaTextSpecialTokenJSON`](../type-aliases/LlamaTextSpecialTokenJSON.md) *** ### fromJSON() ```ts static fromJSON(json: LlamaTextSpecialTokenJSON): SpecialToken; ``` Defined in: [utils/LlamaText.ts:561](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/LlamaText.ts#L561) #### Parameters | Parameter | Type | | ------ | ------ | | `json` | [`LlamaTextSpecialTokenJSON`](../type-aliases/LlamaTextSpecialTokenJSON.md) | #### Returns `SpecialToken` *** ### isSpecialTokenJSON() ```ts static isSpecialTokenJSON(value: LlamaTextJSONValue): value is LlamaTextSpecialTokenJSON; ``` Defined in: [utils/LlamaText.ts:568](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/LlamaText.ts#L568) #### Parameters | Parameter | Type | | ------ | ------ | | `value` | [`LlamaTextJSONValue`](../type-aliases/LlamaTextJSONValue.md) | #### Returns `value is LlamaTextSpecialTokenJSON` *** ### getTokenToValueMap() ```ts static getTokenToValueMap(tokenizer: Tokenizer): ReadonlyMap; ``` Defined in: [utils/LlamaText.ts:572](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/LlamaText.ts#L572) #### Parameters | Parameter | Type | | ------ | ------ | | `tokenizer` | [`Tokenizer`](../type-aliases/Tokenizer.md) | #### Returns `ReadonlyMap`<[`Token`](../type-aliases/Token.md) | `undefined`, [`BuiltinSpecialTokenValue`](../type-aliases/BuiltinSpecialTokenValue.md)> --- --- url: /api/classes/SpecialTokensText.md --- # Class: SpecialTokensText Defined in: [utils/LlamaText.ts:437](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/LlamaText.ts#L437) ## Constructors ### Constructor ```ts new SpecialTokensText(value: string): SpecialTokensText; ``` Defined in: [utils/LlamaText.ts:440](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/LlamaText.ts#L440) #### Parameters | Parameter | Type | | ------ | ------ | | `value` | `string` | #### Returns `SpecialTokensText` ## Properties ### value ```ts readonly value: string; ``` Defined in: [utils/LlamaText.ts:438](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/LlamaText.ts#L438) ## Methods ### toString() ```ts toString(): string; ``` Defined in: [utils/LlamaText.ts:444](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/LlamaText.ts#L444) #### Returns `string` *** ### tokenize() ```ts tokenize(tokenizer: Tokenizer, trimLeadingSpace?: boolean): Token[]; ``` Defined in: [utils/LlamaText.ts:448](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/LlamaText.ts#L448) #### Parameters | Parameter | Type | Default value | | ------ | ------ | ------ | | `tokenizer` | [`Tokenizer`](../type-aliases/Tokenizer.md) | `undefined` | | `trimLeadingSpace` | `boolean` | `false` | #### Returns [`Token`](../type-aliases/Token.md)\[] *** ### tokenizeSpecialTokensOnly() ```ts tokenizeSpecialTokensOnly(tokenizer: Tokenizer): (string | Token)[]; ``` Defined in: [utils/LlamaText.ts:452](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/LlamaText.ts#L452) #### Parameters | Parameter | Type | | ------ | ------ | | `tokenizer` | [`Tokenizer`](../type-aliases/Tokenizer.md) | #### Returns (`string` | [`Token`](../type-aliases/Token.md))\[] *** ### toJSON() ```ts toJSON(): LlamaTextSpecialTokensTextJSON; ``` Defined in: [utils/LlamaText.ts:475](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/LlamaText.ts#L475) #### Returns [`LlamaTextSpecialTokensTextJSON`](../type-aliases/LlamaTextSpecialTokensTextJSON.md) *** ### fromJSON() ```ts static fromJSON(json: LlamaTextSpecialTokensTextJSON): SpecialTokensText; ``` Defined in: [utils/LlamaText.ts:499](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/LlamaText.ts#L499) #### Parameters | Parameter | Type | | ------ | ------ | | `json` | [`LlamaTextSpecialTokensTextJSON`](../type-aliases/LlamaTextSpecialTokensTextJSON.md) | #### Returns `SpecialTokensText` *** ### isSpecialTokensTextJSON() ```ts static isSpecialTokensTextJSON(value: LlamaTextJSONValue): value is LlamaTextSpecialTokensTextJSON; ``` Defined in: [utils/LlamaText.ts:506](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/LlamaText.ts#L506) #### Parameters | Parameter | Type | | ------ | ------ | | `value` | [`LlamaTextJSONValue`](../type-aliases/LlamaTextJSONValue.md) | #### Returns `value is LlamaTextSpecialTokensTextJSON` *** ### wrapIf() ```ts static wrapIf(shouldWrap: boolean, value: string): string | SpecialTokensText; ``` Defined in: [utils/LlamaText.ts:513](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/LlamaText.ts#L513) Wraps the value with a `SpecialTokensText` only if `shouldWrap` is true #### Parameters | Parameter | Type | | ------ | ------ | | `shouldWrap` | `boolean` | | `value` | `string` | #### Returns `string` | `SpecialTokensText` --- --- url: /api/classes/TemplateChatWrapper.md --- # Class: TemplateChatWrapper Defined in: [chatWrappers/generic/TemplateChatWrapper.ts:76](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/generic/TemplateChatWrapper.ts#L76) A chat wrapper based on a simple template. ## Example ```ts import {TemplateChatWrapper} from "node-llama-cpp"; const chatWrapper = new TemplateChatWrapper({ template: "{{systemPrompt}}\n{{history}}model: {{completion}}\nuser: ", historyTemplate: { system: "system: {{message}}\n", user: "user: {{message}}\n", model: "model: {{message}}\n" }, // functionCallMessageTemplate: { // optional // call: "[[call: {{functionName}}({{functionParams}})]]", // result: " [[result: {{functionCallResult}}]]" // }, // segments: { // thoughtTemplate: "{{content}}", // reopenThoughtAfterFunctionCalls: true // } }); ``` **`{{systemPrompt}}`** is optional and is replaced with the first system message (when is does, that system message is not included in the history). **`{{history}}`** is replaced with the chat history. Each message in the chat history is converted using the template passed to `historyTemplate` for the message role, and all messages are joined together. **`{{completion}}`** is where the model's response is generated. The text that comes after `{{completion}}` is used to determine when the model has finished generating the response, and thus is mandatory. **`functionCallMessageTemplate`** is used to specify the format in which functions can be called by the model and how their results are fed to the model after the function call. **`segments`** is used to specify the format of the segments generated by the model (like thought segments). ## Extends * [`ChatWrapper`](ChatWrapper.md) ## Constructors ### Constructor ```ts new TemplateChatWrapper(__namedParameters: TemplateChatWrapperOptions): TemplateChatWrapper; ``` Defined in: [chatWrappers/generic/TemplateChatWrapper.ts:91](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/generic/TemplateChatWrapper.ts#L91) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | [`TemplateChatWrapperOptions`](../type-aliases/TemplateChatWrapperOptions.md) | #### Returns `TemplateChatWrapper` #### Overrides [`ChatWrapper`](ChatWrapper.md).[`constructor`](ChatWrapper.md#constructor) ## Properties ### defaultSettings ```ts static defaultSettings: ChatWrapperSettings; ``` Defined in: [ChatWrapper.ts:15](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L15) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`defaultSettings`](ChatWrapper.md#defaultsettings) *** ### wrapperName ```ts readonly wrapperName: "Template" = "Template"; ``` Defined in: [chatWrappers/generic/TemplateChatWrapper.ts:77](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/generic/TemplateChatWrapper.ts#L77) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`wrapperName`](ChatWrapper.md#wrappername) *** ### settings ```ts readonly settings: ChatWrapperSettings; ``` Defined in: [chatWrappers/generic/TemplateChatWrapper.ts:78](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/generic/TemplateChatWrapper.ts#L78) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`settings`](ChatWrapper.md#settings) *** ### template ```ts readonly template: | `${string}{{history}}${string}{{completion}}${string}` | `${string}{{systemPrompt}}${string}{{history}}${string}{{completion}}${string}`; ``` Defined in: [chatWrappers/generic/TemplateChatWrapper.ts:80](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/generic/TemplateChatWrapper.ts#L80) *** ### historyTemplate ```ts readonly historyTemplate: Readonly; ``` Defined in: [chatWrappers/generic/TemplateChatWrapper.ts:81](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/generic/TemplateChatWrapper.ts#L81) *** ### joinAdjacentMessagesOfTheSameType ```ts readonly joinAdjacentMessagesOfTheSameType: boolean; ``` Defined in: [chatWrappers/generic/TemplateChatWrapper.ts:82](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/generic/TemplateChatWrapper.ts#L82) ## Methods ### generateFunctionCallsAndResults() ```ts generateFunctionCallsAndResults(functionCalls: ChatModelFunctionCall[], useRawCall?: boolean): LlamaText; ``` Defined in: [ChatWrapper.ts:63](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L63) #### Parameters | Parameter | Type | Default value | | ------ | ------ | ------ | | `functionCalls` | [`ChatModelFunctionCall`](../type-aliases/ChatModelFunctionCall.md)\[] | `undefined` | | `useRawCall` | `boolean` | `true` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCallsAndResults`](ChatWrapper.md#generatefunctioncallsandresults) *** ### generateFunctionCall() ```ts generateFunctionCall(name: string, params: any): LlamaText; ``` Defined in: [ChatWrapper.ts:110](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L110) #### Parameters | Parameter | Type | | ------ | ------ | | `name` | `string` | | `params` | `any` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCall`](ChatWrapper.md#generatefunctioncall) *** ### generateFunctionCallResult() ```ts generateFunctionCallResult( functionName: string, functionParams: any, result: any): LlamaText; ``` Defined in: [ChatWrapper.ts:127](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L127) #### Parameters | Parameter | Type | | ------ | ------ | | `functionName` | `string` | | `functionParams` | `any` | | `result` | `any` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateFunctionCallResult`](ChatWrapper.md#generatefunctioncallresult) *** ### generateModelResponseText() ```ts generateModelResponseText(modelResponse: ( | string | ChatModelFunctionCall | ChatModelSegment)[], useRawValues?: boolean): LlamaText; ``` Defined in: [ChatWrapper.ts:158](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L158) #### Parameters | Parameter | Type | Default value | | ------ | ------ | ------ | | `modelResponse` | ( | `string` | [`ChatModelFunctionCall`](../type-aliases/ChatModelFunctionCall.md) | [`ChatModelSegment`](../type-aliases/ChatModelSegment.md))\[] | `undefined` | | `useRawValues` | `boolean` | `true` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateModelResponseText`](ChatWrapper.md#generatemodelresponsetext) *** ### generateAvailableFunctionsSystemText() ```ts generateAvailableFunctionsSystemText(availableFunctions: ChatModelFunctions, __namedParameters: { documentParams?: boolean; }): LlamaText; ``` Defined in: [ChatWrapper.ts:243](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L243) #### Parameters | Parameter | Type | | ------ | ------ | | `availableFunctions` | [`ChatModelFunctions`](../type-aliases/ChatModelFunctions.md) | | `__namedParameters` | { `documentParams?`: `boolean`; } | | `__namedParameters.documentParams?` | `boolean` | #### Returns [`LlamaText`](LlamaText.md) #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateAvailableFunctionsSystemText`](ChatWrapper.md#generateavailablefunctionssystemtext) *** ### addAvailableFunctionsSystemMessageToHistory() ```ts addAvailableFunctionsSystemMessageToHistory( history: readonly ChatHistoryItem[], availableFunctions?: ChatModelFunctions, __namedParameters?: { documentParams?: boolean; }): readonly ChatHistoryItem[]; ``` Defined in: [ChatWrapper.ts:269](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L269) #### Parameters | Parameter | Type | | ------ | ------ | | `history` | readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] | | `availableFunctions?` | [`ChatModelFunctions`](../type-aliases/ChatModelFunctions.md) | | `__namedParameters?` | { `documentParams?`: `boolean`; } | | `__namedParameters.documentParams?` | `boolean` | #### Returns readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`addAvailableFunctionsSystemMessageToHistory`](ChatWrapper.md#addavailablefunctionssystemmessagetohistory) *** ### generateInitialChatHistory() ```ts generateInitialChatHistory(__namedParameters?: ChatWrapperGenerateInitialHistoryOptions): ChatHistoryItem[]; ``` Defined in: [ChatWrapper.ts:290](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/ChatWrapper.ts#L290) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | [`ChatWrapperGenerateInitialHistoryOptions`](../type-aliases/ChatWrapperGenerateInitialHistoryOptions.md) | #### Returns [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] #### Inherited from [`ChatWrapper`](ChatWrapper.md).[`generateInitialChatHistory`](ChatWrapper.md#generateinitialchathistory) *** ### generateContextState() ```ts generateContextState(__namedParameters: ChatWrapperGenerateContextStateOptions): ChatWrapperGeneratedContextState; ``` Defined in: [chatWrappers/generic/TemplateChatWrapper.ts:124](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/generic/TemplateChatWrapper.ts#L124) #### Parameters | Parameter | Type | | ------ | ------ | | `__namedParameters` | [`ChatWrapperGenerateContextStateOptions`](../type-aliases/ChatWrapperGenerateContextStateOptions.md) | #### Returns [`ChatWrapperGeneratedContextState`](../type-aliases/ChatWrapperGeneratedContextState.md) #### Overrides [`ChatWrapper`](ChatWrapper.md).[`generateContextState`](ChatWrapper.md#generatecontextstate) --- --- url: /api/classes/TokenAttributes.md --- # Class: TokenAttributes Defined in: [evaluator/LlamaModel/utils/TokenAttributes.ts:18](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/utils/TokenAttributes.ts#L18) ## Properties ### token ```ts readonly token: Token; ``` Defined in: [evaluator/LlamaModel/utils/TokenAttributes.ts:19](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/utils/TokenAttributes.ts#L19) ## Accessors ### undefined #### Get Signature ```ts get undefined(): boolean; ``` Defined in: [evaluator/LlamaModel/utils/TokenAttributes.ts:27](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/utils/TokenAttributes.ts#L27) ##### Returns `boolean` *** ### unknown #### Get Signature ```ts get unknown(): boolean; ``` Defined in: [evaluator/LlamaModel/utils/TokenAttributes.ts:31](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/utils/TokenAttributes.ts#L31) ##### Returns `boolean` *** ### unused #### Get Signature ```ts get unused(): boolean; ``` Defined in: [evaluator/LlamaModel/utils/TokenAttributes.ts:35](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/utils/TokenAttributes.ts#L35) ##### Returns `boolean` *** ### normal #### Get Signature ```ts get normal(): boolean; ``` Defined in: [evaluator/LlamaModel/utils/TokenAttributes.ts:39](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/utils/TokenAttributes.ts#L39) ##### Returns `boolean` *** ### control #### Get Signature ```ts get control(): boolean; ``` Defined in: [evaluator/LlamaModel/utils/TokenAttributes.ts:43](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/utils/TokenAttributes.ts#L43) ##### Returns `boolean` *** ### userDefined #### Get Signature ```ts get userDefined(): boolean; ``` Defined in: [evaluator/LlamaModel/utils/TokenAttributes.ts:47](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/utils/TokenAttributes.ts#L47) ##### Returns `boolean` *** ### byte #### Get Signature ```ts get byte(): boolean; ``` Defined in: [evaluator/LlamaModel/utils/TokenAttributes.ts:51](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/utils/TokenAttributes.ts#L51) ##### Returns `boolean` *** ### normalized #### Get Signature ```ts get normalized(): boolean; ``` Defined in: [evaluator/LlamaModel/utils/TokenAttributes.ts:55](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/utils/TokenAttributes.ts#L55) ##### Returns `boolean` *** ### lstrip #### Get Signature ```ts get lstrip(): boolean; ``` Defined in: [evaluator/LlamaModel/utils/TokenAttributes.ts:59](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/utils/TokenAttributes.ts#L59) ##### Returns `boolean` *** ### rstrip #### Get Signature ```ts get rstrip(): boolean; ``` Defined in: [evaluator/LlamaModel/utils/TokenAttributes.ts:63](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/utils/TokenAttributes.ts#L63) ##### Returns `boolean` *** ### singleWord #### Get Signature ```ts get singleWord(): boolean; ``` Defined in: [evaluator/LlamaModel/utils/TokenAttributes.ts:67](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaModel/utils/TokenAttributes.ts#L67) ##### Returns `boolean` --- --- url: /api/classes/TokenBias.md --- # Class: TokenBias Defined in: [evaluator/TokenBias.ts:9](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/TokenBias.ts#L9) ## See [Using Token Bias](https://node-llama-cpp.withcat.ai/guide/token-bias) tutorial ## Constructors ### Constructor ```ts new TokenBias(tokenizer: Tokenizer): TokenBias; ``` Defined in: [evaluator/TokenBias.ts:13](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/TokenBias.ts#L13) #### Parameters | Parameter | Type | | ------ | ------ | | `tokenizer` | [`Tokenizer`](../type-aliases/Tokenizer.md) | #### Returns `TokenBias` ## Methods ### set() ```ts set(input: | string | LlamaText | Token | Token[], bias: | number | "never" | { logit: number; }): TokenBias; ``` Defined in: [evaluator/TokenBias.ts:41](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/TokenBias.ts#L41) Adjust the bias of the given token(s). If a text is provided, the bias will be applied to each individual token in the text. Setting a bias to `"never"` will prevent the token from being generated, unless it is required to comply with a grammar. Setting the bias of the EOS or EOT tokens to `"never"` has no effect and will be ignored. #### Parameters | Parameter | Type | Description | | ------ | ------ | ------ | | `input` | | `string` | [`LlamaText`](LlamaText.md) | [`Token`](../type-aliases/Token.md) | [`Token`](../type-aliases/Token.md)\[] | The token(s) to apply the bias to | | `bias` | | `number` | `"never"` | { `logit`: `number`; } | The probability bias to apply to the token(s). Setting to a positive number increases the probability of the token(s) being generated. Setting to a negative number decreases the probability of the token(s) being generated. Setting to `0` has no effect. For example, setting to `0.5` will increase the probability of the token(s) being generated by 50%. Setting to `-0.5` will decrease the probability of the token(s) being generated by 50%. Setting to `"never"` will prevent the token from being generated, unless it is required to comply with a grammar. Try to play around with values between `0.9` and `-0.9` to see what works for your use case. | #### Returns `TokenBias` *** ### for() ```ts static for(modelOrTokenizer: | Tokenizer | LlamaModel): TokenBias; ``` Defined in: [evaluator/TokenBias.ts:65](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/TokenBias.ts#L65) #### Parameters | Parameter | Type | | ------ | ------ | | `modelOrTokenizer` | | [`Tokenizer`](../type-aliases/Tokenizer.md) | [`LlamaModel`](LlamaModel.md) | #### Returns `TokenBias` --- --- url: /api/classes/TokenMeter.md --- # Class: TokenMeter Defined in: [evaluator/TokenMeter.ts:4](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/TokenMeter.ts#L4) Tracks the usage of tokens. ## Constructors ### Constructor ```ts new TokenMeter(): TokenMeter; ``` #### Returns `TokenMeter` ## Accessors ### usedInputTokens #### Get Signature ```ts get usedInputTokens(): number; ``` Defined in: [evaluator/TokenMeter.ts:11](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/TokenMeter.ts#L11) The number of input tokens used ##### Returns `number` *** ### usedOutputTokens #### Get Signature ```ts get usedOutputTokens(): number; ``` Defined in: [evaluator/TokenMeter.ts:18](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/TokenMeter.ts#L18) The number of tokens generated by a model ##### Returns `number` ## Methods ### useTokens() ```ts static useTokens( meters: | TokenMeter | ReadonlySet | readonly TokenMeter[] | null | undefined, tokens: number, type: "input" | "output"): void; ``` Defined in: [evaluator/TokenMeter.ts:61](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/TokenMeter.ts#L61) Log the usage of tokens on multiple meters #### Parameters | Parameter | Type | | ------ | ------ | | `meters` | | `TokenMeter` | `ReadonlySet`<`TokenMeter`> | readonly `TokenMeter`\[] | `null` | `undefined` | | `tokens` | `number` | | `type` | `"input"` | `"output"` | #### Returns `void` *** ### diff() ```ts static diff(meter1: TokenMeter | TokenMeterState, meter2: TokenMeter | TokenMeterState): { usedInputTokens: number; usedOutputTokens: number; }; ``` Defined in: [evaluator/TokenMeter.ts:80](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/TokenMeter.ts#L80) Get the difference between two meters #### Parameters | Parameter | Type | | ------ | ------ | | `meter1` | `TokenMeter` | [`TokenMeterState`](../type-aliases/TokenMeterState.md) | | `meter2` | `TokenMeter` | [`TokenMeterState`](../type-aliases/TokenMeterState.md) | #### Returns ```ts { usedInputTokens: number; usedOutputTokens: number; } ``` ##### usedInputTokens ```ts usedInputTokens: number; ``` ##### usedOutputTokens ```ts usedOutputTokens: number; ``` *** ### getState() ```ts getState(): TokenMeterState; ``` Defined in: [evaluator/TokenMeter.ts:25](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/TokenMeter.ts#L25) Get the current state of the token meter #### Returns [`TokenMeterState`](../type-aliases/TokenMeterState.md) *** ### useTokens() ```ts useTokens(tokens: number, type: "input" | "output"): void; ``` Defined in: [evaluator/TokenMeter.ts:35](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/TokenMeter.ts#L35) Log the usage of tokens #### Parameters | Parameter | Type | | ------ | ------ | | `tokens` | `number` | | `type` | `"input"` | `"output"` | #### Returns `void` *** ### diff() ```ts diff(meter: TokenMeter | TokenMeterState): { usedInputTokens: number; usedOutputTokens: number; }; ``` Defined in: [evaluator/TokenMeter.ts:54](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/TokenMeter.ts#L54) Get the difference between the current meter and another meter #### Parameters | Parameter | Type | | ------ | ------ | | `meter` | `TokenMeter` | [`TokenMeterState`](../type-aliases/TokenMeterState.md) | #### Returns ```ts { usedInputTokens: number; usedOutputTokens: number; } ``` ##### usedInputTokens ```ts usedInputTokens: number; ``` ##### usedOutputTokens ```ts usedOutputTokens: number; ``` --- --- url: /api/classes/UnsupportedError.md --- # Class: UnsupportedError Defined in: [utils/UnsupportedError.ts:1](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/UnsupportedError.ts#L1) ## Extends * [`Error`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error) --- --- url: /cli.md description: CLI commands reference --- # CLI ## Usage --- --- url: /guide/CUDA.md description: CUDA support in node-llama-cpp --- # CUDA Support > CUDA is a parallel computing platform and API created by NVIDIA for NVIDIA GPUs `node-llama-cpp` ships with pre-built binaries with CUDA support for Windows and Linux, and these are automatically used when CUDA is detected on your machine. To use `node-llama-cpp`'s CUDA support with your NVIDIA GPU, make sure you have [CUDA Toolkit](https://developer.nvidia.com/cuda-downloads) 13.1 or higher installed on your machine. If the pre-built binaries don't work with your CUDA installation, `node-llama-cpp` will automatically download a release of `llama.cpp` and build it from source with CUDA support. Building from source with CUDA support is slow and can take up to an hour. The pre-built binaries are compiled with CUDA Toolkits 12.4 and 13.1, so any CUDA Toolkit 12 that's on version 12.4 or higher or CUDA Toolkit 13 on version 13.1 or higher should work with the pre-built binaries. If you have an older version of CUDA Toolkit installed on your machine, consider updating it to avoid having to wait the long build time. ## Testing CUDA Support To check whether the CUDA support works on your machine, run this command: ```shell npx --no node-llama-cpp inspect gpu ``` You should see an output like this: ```ansi CUDA: available CUDA device: NVIDIA RTX A6000 CUDA used VRAM: 0.54% (266.88MB/47.65GB) CUDA free VRAM: 99.45% (47.39GB/47.65GB) CPU model: Intel(R) Xeon(R) Gold 5315Y CPU @ 3.20GHz Used RAM: 2.51% (1.11GB/44.08GB) Free RAM: 97.48% (42.97GB/44.08GB) ``` If you see `CUDA used VRAM` in the output, it means that CUDA support is working on your machine. ## Prerequisites * [CUDA Toolkit](https://developer.nvidia.com/cuda-downloads) 13.1 or higher * [NVIDIA Drivers](https://www.nvidia.com/en-us/drivers/) * [`cmake-js` dependencies](https://github.com/cmake-js/cmake-js#:~:text=%5Bstring%5D-,Requirements%3A,-CMake) * [CMake](https://cmake.org/download/) 3.26 or higher (optional, recommended if you have build issues) ## Manually Building `node-llama-cpp` With CUDA Support {#building} Run this command inside of your project: ```shell npx --no node-llama-cpp source download --gpu cuda ``` > If `cmake` is not installed on your machine, `node-llama-cpp` will automatically download `cmake` to an internal directory and try to use it to build `llama.cpp` from source. > If you see the message `CUDA not found` during the build process, > it means that CUDA Toolkit is not installed on your machine or that it is not detected by the build process. ### Custom `llama.cpp` CMake Options `llama.cpp` has some options you can use to customize your CUDA build. :::details `llama.cpp` CUDA CMake build options > Source: `CMakeLists` (filtered for only CUDA-related options) > > You can see all the available `llama.cpp` CMake build options [here](../guide/building-from-source.md#customize-build) ::: To build `node-llama-cpp` with any of these options, set an environment variable of an option prefixed with `NODE_LLAMA_CPP_CMAKE_OPTION_`. ### Fix the `Failed to detect a default CUDA architecture` Build Error To fix this issue you have to set the `CUDACXX` environment variable to the path of the `nvcc` compiler, and the `CUDA_PATH` environment variable to the path of the CUDA home directory that contains the `nvcc` compiler. For example, if you have installed CUDA Toolkit 13.1, you have to run a command like this: ::: code-group ```shell [Linux] export CUDACXX=/usr/local/cuda-13.1/bin/nvcc export CUDA_PATH=/usr/local/cuda-13.1 ``` ```cmd [Windows (cmd)] set CUDACXX=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1\bin\nvcc.exe set CUDA_PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1 ``` ```cmd [Windows (PowerShell)] $env:CUDACXX="C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1\bin\nvcc.exe" $env:CUDA_PATH="C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1" ``` ::: Then run the build command again to check whether setting the `CUDACXX` and `CUDA_PATH` environment variables fixed the issue. ### Fix the `The CUDA compiler identification is unknown` Build Error The solution to this error is the same as [the solution to the `Failed to detect a default CUDA architecture` error](#fix-the-failed-to-detect-a-default-cuda-architecture-build-error). ### Fix the `A single input file is required for a non-link phase when an outputfile is specified` Build Error To fix this issue you have to set the `CMAKE_GENERATOR_TOOLSET` cmake option to the CUDA home directory, usually already set as the `CUDA_PATH` environment variable. To do this, set the `NODE_LLAMA_CPP_CMAKE_OPTION_CMAKE_GENERATOR_TOOLSET` environment variable to the path of your CUDA home directory: ::: code-group ```shell [Linux] export NODE_LLAMA_CPP_CMAKE_OPTION_CMAKE_GENERATOR_TOOLSET=$CUDA_PATH ``` ```cmd [Windows (cmd)] set NODE_LLAMA_CPP_CMAKE_OPTION_CMAKE_GENERATOR_TOOLSET=%CUDA_PATH% ``` ```cmd [Windows (PowerShell)] $env:NODE_LLAMA_CPP_CMAKE_OPTION_CMAKE_GENERATOR_TOOLSET=$env:CUDA_PATH ``` ::: Then run the build command again to check whether setting the `CMAKE_GENERATOR_TOOLSET` cmake option fixed the issue. ### Fix the `forward compatibility was attempted on non supported HW` Error {#fix-cuda-forward-compatibility} This error usually happens when the CUDA version you have installed on your machine is older than the CUDA version used in the prebuilt binaries supplied by `node-llama-cpp`. To resolve this issue, you can either [update your CUDA installation](https://developer.nvidia.com/cuda-downloads) to the latest version (recommended) or [build `node-llama-cpp` on your machine](#building) against the CUDA version you have installed. ### Fix the `Binary GPU type mismatch. Expected: cuda, got: false` Error {#fix-cuda-gpu-type-mismatch} This error usually happens when you have multiple conflicting CUDA versions installed on your machine. To fix it, uninstall older CUDA versions and restart your machine (important). :::: details Check which CUDA libraries are picked up by `node-llama-cpp`'s prebuilt binaries on your machine Run this command inside of your project: ::: code-group ```shell [Linux] ldd ./node_modules/@node-llama-cpp/linux-x64-cuda/bins/linux-x64-cuda/libggml-cuda.so ``` ```cmd [Windows (cmd)] "C:\Program Files\Git\usr\bin\ldd.exe" node_modules\@node-llama-cpp\win-x64-cuda\bins\win-x64-cuda\ggml-cuda.dll ``` ```cmd [Windows (PowerShell)] & "C:\Program Files\Git\usr\bin\ldd.exe" node_modules\@node-llama-cpp\win-x64-cuda\bins\win-x64-cuda\ggml-cuda.dll ``` ::: :::: ### Fix the `ggml_cuda_init: failed to initialize CUDA: (null)` Error {#fix-failed-to-initialize-cuda-null} This error usually happens when the NVIDIA drivers installed on your machine are incompatible with the version of CUDA you have installed. To fix it, update your NVIDIA drivers to the latest version from the [NVIDIA Driver Downloads](https://www.nvidia.com/en-us/drivers/) page. ## Using `node-llama-cpp` With CUDA It's recommended to use [`getLlama`](../api/functions/getLlama) without specifying a GPU type, so it'll detect the available GPU types and use the best one automatically. To do this, just use [`getLlama`](../api/functions/getLlama) without any parameters: ```typescript import {getLlama} from "node-llama-cpp"; // ---cut--- const llama = await getLlama(); console.log("GPU type:", llama.gpu); ``` To force it to use CUDA, you can use the [`gpu`](../api/type-aliases/LlamaOptions#gpu) option: ```typescript import {getLlama} from "node-llama-cpp"; // ---cut--- const llama = await getLlama({ gpu: "cuda" }); console.log("GPU type:", llama.gpu); ``` By default, `node-llama-cpp` will offload as many layers of the model to the GPU as it can fit in the VRAM. To force it to offload a specific number of layers, you can use the [`gpuLayers`](../api/type-aliases/LlamaModelOptions.md#gpulayers) option: ```typescript import {fileURLToPath} from "url"; import path from "path"; import {getLlama} from "node-llama-cpp"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const modelPath = path.join(__dirname, "my-model.gguf") const llama = await getLlama({ gpu: "cuda" }); // ---cut--- const model = await llama.loadModel({ modelPath, gpuLayers: 33 // or any other number of layers you want }); ``` ::: warning Attempting to offload more layers to the GPU than the available VRAM can fit will result in an [`InsufficientMemoryError`](../api/classes/InsufficientMemoryError.md) error. ::: On Linux, you can monitor GPU usage with this command: ```shell watch -d nvidia-smi ``` --- --- url: /blog/v3.6-deepseek-r1.md description: >- node-llama-cpp v3.6 is here, with full support for DeepSeek R1, including function calling! --- # DeepSeek R1 with function calling [`node-llama-cpp`](https://node-llama-cpp.withcat.ai) v3.6 is here, with full support for [DeepSeek R1](https://github.com/deepseek-ai/DeepSeek-R1), including function calling! *** ## Function Calling `node-llama-cpp` includes [many tricks](../guide/function-calling) used to make function calling work with most models. This release includes special adaptations for DeepSeek R1 to improve function calling performance and stability. Here's a basic example of function calling with DeepSeek R1: ```typescript import {fileURLToPath} from "url"; import path from "path"; import { getLlama, LlamaChatSession, defineChatSessionFunction, resolveModelFile } from "node-llama-cpp"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const modelsDir = path.join(__dirname, "..", "models"); const modelUri = "hf:mradermacher/DeepSeek-R1-Distill-Qwen-7B-GGUF:Q4_K_M"; const llama = await getLlama(); const model = await llama.loadModel({ modelPath: await resolveModelFile(modelUri, modelsDir) }); const context = await model.createContext(); const session = new LlamaChatSession({ contextSequence: context.getSequence() }); const fruitPrices: Record = { "apple": "$6", "banana": "$4" }; const functions = { getFruitPrice: defineChatSessionFunction({ description: "Get the price of a fruit", params: { type: "object", properties: { name: { type: "string" } } }, async handler(params) { const name = params.name.toLowerCase(); if (Object.keys(fruitPrices).includes(name)) return { name: name, price: fruitPrices[name] }; return `Unrecognized fruit "${params.name}"`; } }) }; const q1 = "Is an apple more expensive than a banana?"; console.log("User: " + q1); const a1 = await session.prompt(q1, {functions}); console.log("AI: " + a1.trim()); ``` ## Recommended Models Here are some recommended model URIs you can use to try out DeepSeek R1 with function calling. | Model | Size | URI | |---------------------------------------------------------------------------------------------------------|--------|-------------------------------------------------------------| | [DeepSeek R1 Distill Qwen 7B](https://huggingface.co/mradermacher/DeepSeek-R1-Distill-Qwen-7B-GGUF) | 4.68GB | `hf:mradermacher/DeepSeek-R1-Distill-Qwen-7B-GGUF:Q4_K_M` | | [DeepSeek R1 Distill Qwen 14B](https://huggingface.co/mradermacher/DeepSeek-R1-Distill-Qwen-14B-GGUF) | 8.99GB | `hf:mradermacher/DeepSeek-R1-Distill-Qwen-14B-GGUF:Q4_K_M` | | [DeepSeek R1 Distill Qwen 32B](https://huggingface.co/mradermacher/DeepSeek-R1-Distill-Qwen-32B-GGUF) | 19.9GB | `hf:mradermacher/DeepSeek-R1-Distill-Qwen-32B-GGUF:Q4_K_M` | > The 7B model works well with function calling in the first prompt, but tends to deteriorate in subsequent queries. > > Use a larger model for better performance with multiple prompts. ::: info TIP Estimate the compatibility of a model with your machine before downloading it using the [`inspect estimate`](../cli/inspect/estimate.md) command: ```shell npx -y node-llama-cpp inspect estimate ``` ::: ### Try It Using the CLI To try out function calling with a given model using the CLI, you can use the [`chat` command](../cli/chat.md) with the `--ef` flag to provide the model with date and time functions: ```shell npx -y node-llama-cpp chat --ef --prompt "What is the time?" ``` ## Chain of Thought Segmentation The thoughts generated by a reasoning model are now [separated into `thought` segments](../guide/chat-session.md#stream-response-segments) in the response, so you can choose whether to use them or not. By default, the [`.prompt(...)`](../api/classes/LlamaChatSession#prompt) method returns only the main response, without any `thought` segments. Use the [`.promptWithMeta(...)`](../api/classes/LlamaChatSession#promptwithmeta) method to get the full response. You can use the new [`onResponseChunk`](../api/type-aliases/LLamaChatPromptOptions.md#onresponsechunk) option to [stream `thought` segments as they are being generated](../guide/chat-session.md#stream-response-segments). ## Electron App Template The [Electron app template](../guide/electron.md) has been updated to properly segment the thoughts in the response. Try it out by downloading the latest build [from GitHub](https://github.com/withcatai/node-llama-cpp/releases/latest), or by [scaffolding a new project](../guide/index.md#scaffold-new-project) based on the Electron template: ```shell npm create node-llama-cpp@latest ``` --- --- url: /guide/development.md description: Developing node-llama-cpp --- # Developing `node-llama-cpp` This document describes how to set up your development environment to contribute to `node-llama-cpp`. ## Prerequisites * [Git](https://git-scm.com/). [GitHub's Guide to Installing Git](https://help.github.com/articles/set-up-git) is a good source of information. * [Node.js](https://nodejs.org/en/) (v20 or higher) * [cmake dependencies](https://github.com/cmake-js/cmake-js#:~:text=%5Bstring%5D-,Requirements%3A,-CMake) - make sure the required dependencies of `cmake` are installed on your machine. More info is available [here](https://github.com/cmake-js/cmake-js#installation:~:text=projectRoot/build%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5Bstring%5D-,Requirements%3A,-CMake) (you don't necessarily have to install `cmake`, just the dependencies) ## Setup 1. [Fork `node-llama-cpp` repo](https://github.com/withcatai/node-llama-cpp/fork) 2. Clone your forked repo to your local machine 3. Install dependencies: ```shell npm install ``` 4. Build the CLI, use the CLI to clone the latest release of `llama.cpp` and build it from source, and download all the models needed by the tests: ```shell npm run dev:setup ``` ::: info What to do if the build fails If the build fails on C++ errors, this may be due to breaking interface changes on the `llama.cpp` side. You're encouraged to make changes to the usage of `llama.cpp` functions in the `llama/addon` directory to resolve these errors and then open a pull request for these changes separately from your main changes PR. We continually maintain the `llama/addon` directory to keep it up to date with the latest changes of `llama.cpp`, so any help with this is greatly appreciated. ::: ## Development Whenever you add a new functionality to `node-llama-cpp`, consider improving the CLI to reflect this change. After you're done making changes to the code, please add some tests if possible, and update the documentation. To test whether your local setup works, download a model and try using it with the `chat` command. ### Get a Model File We recommend you to get a GGUF model from either [Michael Radermacher on Hugging Face](https://huggingface.co/mradermacher) or [search HuggingFace directly](https://huggingface.co/models?library=gguf) for a GGUF model. We recommend you to start by getting a small model that doesn't have a lot of parameters just to ensure everything works, so try downloading a `7B`/`8B` parameters model first (search for models with both `7B`/`8B` and `GGUF` in their name). For improved download speeds, you can use the [`pull`](../cli/pull.md) command to download a model: ```shell npm run build; node ./dist/cli/cli.js pull --dir ./test/.models ``` ### Validate Your Setup by Chatting With a Model To validate that your setup works, run the following command to chat with the model you downloaded: ```shell npm run dev:build; node ./dist/cli/cli.js chat ``` Try telling the model `Hi there` and see how it reacts. Any response from the model means that your setup works. If the response looks weird or doesn't make sense, try using a different model. If the model doesn't stop generating output, try using a different [chat wrapper](./chat-wrapper). For example: ```shell npm run dev:build; node ./dist/cli/cli.js chat --wrapper general ``` ::: tip Important Make sure you always run `npm run dev:build` before running the CLI to make sure that your code changes are reflected in the CLI. ::: ### Debugging To run a chat session with a debugger, configure your IDE to run the following command with a debugger: ```shell npx vite-node ./src/cli/cli.ts chat ``` #### Finding Process Crash Stack Trace for Native Code (macOS) {#native-crash-stack-trace-macos} To get the stack trace of a crash stemming in `llama.cpp` or the bindings, run `node` with `lldb`: ```shell lldb node -- ./node_modules/.bin/vite-node ./src/cli/cli.ts chat ``` After it finishes loading, type `run` (or `process launch` if `run` fails) and press Enter for the execution of `node` to start. When the process crashes, you'll get a stack trace in the terminal. #### Finding Process Crash Stack Trace for Native Code (Linux) {#native-crash-stack-trace-linux} To get the stack trace of a crash stemming in `llama.cpp` or the bindings, run `node` with `gdb`: ```shell gdb --args node ./node_modules/.bin/vite-node ./src/cli/cli.ts chat ``` After it finishes loading, type `run` and press Enter for the execution of `node` to start. When the process crashes, type `bt full` and press Enter to see the stack trace. ### Updating the Documentation All the documentation is written in Markdown files in the `docs` directory. To see the changes you made to the documentation, run the following command: ```shell npm run docs:dev ``` Before sending a PR, ensure that the documentation can compile correctly by running this command: ```shell npm run docs:build ``` ## Opening a Pull Request Before starting to work on a new feature, search for a related issue on the [issues page](https://github.com/withcatai/node-llama-cpp/issues). If there's already an issue for the feature you want to work on, comment on that issue to let us know that you're working on it, to avoid duplicate work. To open a pull request, read the [pull request guidelines](./contributing.md). --- --- url: /guide/downloading-models.md description: Downloading models with node-llama-cpp --- # Downloading Models `node-llama-cpp` is equipped with solutions to download models to use them in your project. The most common use case is to [download models using the CLI](#cli). For a tutorial on how to choose models and where to get them from, read the [choosing a model tutorial](./choosing-a-model) ## Using the CLI {#cli} `node-llama-cpp` is equipped with a [model downloader](../cli/pull) you can use to download models and [their related files](../api/functions/createModelDownloader.md) easily and at high speed (using [`ipull`](https://www.npmjs.com/package/ipull)). It's recommended to add a `models:pull` script to your `package.json` to download all the models used by your project to a local `models` folder. It's also recommended to ensure all the models are automatically downloaded after running `npm install` by setting up a `postinstall` script Here's an example of how you can set this up in your `package.json`: ::: code-group ```json [package.json] { "scripts": { "postinstall": "npm run models:pull", "models:pull": "node-llama-cpp pull --dir ./models " } } ``` ::: Don't forget to add the `models` folder to your `.gitignore` file to avoid committing the models to your repository: ::: code-group ```[.gitignore] /models ``` ::: If the model consists of multiple files, only use the URL of the first one, and the rest will be downloaded automatically. For more information, see [`createModelDownloader`](../api/functions/createModelDownloader). Calling `models:pull` multiple times will only download the models that haven't been downloaded yet. If a model file was updated, calling `models:pull` will download the updated file and override the old one. You can pass a list of model URLs to download multiple models at once: ::: code-group ```json [package.json] { "scripts": { "postinstall": "npm run models:pull", "models:pull": "node-llama-cpp pull --dir ./models " } } ``` ::: ::: tip When [scaffolding a new project](./index.md#scaffold-new-project), the new project already includes this pattern. ::: ## Programmatically Downloading Models {#programmatic} You can also download models programmatically using the [`createModelDownloader`](../api/functions/createModelDownloader.md) method, and [`combineModelDownloaders`](../api/functions/combineModelDownloaders.md) to combine multiple model downloaders. This option is recommended for more advanced use cases, such as downloading models based on user input. If you know the exact model URLs you're going to need every time in your project, it's better to download the models automatically after running `npm install` as described in the [Using the CLI](#cli) section. ## Model URIs {#model-uris} You can reference models using a URI instead of their full download URL when using the CLI and relevant methods. When downloading a model from a URI, the model files will be prefixed with a corresponding adaptation of the URI. To reference a model from Hugging Face, you can use one of these schemes: * `hf:/:` (`:` is optional, [but recommended](#hf-scheme-specify-quant)) * `hf://#` (`#` is optional) Here are example usages of the Hugging Face URI scheme: ::: code-group ```[With quant] hf:mradermacher/Meta-Llama-3.1-8B-Instruct-GGUF:Q4_K_M ``` ```[Specific file] hf:mradermacher/Meta-Llama-3.1-8B-Instruct-GGUF/Meta-Llama-3.1-8B-Instruct.Q4_K_M.gguf ``` ::: When using a URI to reference a model, it's recommended [to add it to your `package.json` file](#cli) to ensure it's downloaded when running `npm install`, and also resolve it using the [`resolveModelFile`](../api/functions/resolveModelFile.md) method to get the full path of the resolved model file. Here's an example usage of the [`resolveModelFile`](../api/functions/resolveModelFile.md) method: ```typescript import {fileURLToPath} from "url"; import path from "path"; import {getLlama, resolveModelFile} from "node-llama-cpp"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const modelsDirectory = path.join(__dirname, "models"); const modelPath = await resolveModelFile( "hf:user/model:quant", modelsDirectory ); const llama = await getLlama(); const model = await llama.loadModel({modelPath}); ``` ::: tip NOTE If a corresponding model file is not found in the given directory, the model will automatically be downloaded. When a file is being downloaded, the download progress is shown in the console by default. Set the [`cli`](../api/type-aliases/ResolveModelFileOptions#cli) option to `false` to disable this behavior. ::: ::: tip TIP {#hf-scheme-specify-quant} When using the `hf:/:` scheme, always specify the quantization level in the URI (`:`). Doing this allows the resolver to resolve to a local model file without checking the model metadata on Hugging Face first, so it will be resolved offline and faster. ::: ::: tip Shortcuts for quick experimentation {#uri-shortcuts} You can copy the page URLs of models and files on Hugging Face and use them with any of the [CLI commands](../cli/index.md). **Important:** do not use these page URL shortcuts in production code, and do not commit them to your codebase. The resolving of such page URL shortcuts are inefficient and unreliable for production use. ::: ## Downloading Gated Models From Hugging Face {#hf-token} Some models on Hugging Face are "gated", meaning they require a manual consent from you before you can download them. To download such models, after completing the consent form on the model card, you need to create a [Hugging Face token](https://huggingface.co/docs/hub/en/security-tokens) and set it in one of the following locations: * Set an environment variable called `HF_TOKEN` the token * Set the `~/.cache/huggingface/token` file content to the token Now, using the CLI, the [`createModelDownloader`](../api/functions/createModelDownloader.md) method, or the [`resolveModelFile`](../api/functions/resolveModelFile.md) method will automatically use the token to download gated models. Alternatively, you can use the token in the [`tokens`](../api/type-aliases/ModelDownloaderOptions.md#tokens) option when using [`createModelDownloader`](../api/functions/createModelDownloader.md) or [`resolveModelFile`](../api/functions/resolveModelFile.md). ## Inspecting Remote Models You can inspect the metadata of a remote model without downloading it by either using the [`inspect gguf`](../cli/inspect/gguf.md) command with a URL, or using the [`readGgufFileInfo`](../api/functions/readGgufFileInfo.md) method with a URL: ```typescript import {readGgufFileInfo} from "node-llama-cpp"; const modelMetadata = await readGgufFileInfo(""); ``` > If the URL is of a model with multiple parts (either separate files or binary-split files), > pass the URL of the first file and it'll automatically inspect the rest of the files and combine the metadata. ### Detecting the Compatibility of Remote Models It's handy to check the compatibility of a remote model with your current machine hardware before downloading it, so you won't waste time downloading a model that won't work on your machine. You can do so using the [`inspect estimate`](../cli/inspect/estimate.md) command with a URL: ```shell npx --no node-llama-cpp inspect estimate ``` Running this command will attempt to find the best balance of parameters for the model to run on your machine, and it'll output the estimated compatibility of the model with your machine with [flash attention](./tips-and-tricks.md#flash-attention) either turned off (the default) or on. > **Note:** don't specify any of these configurations when loading the model. > > [`node-llama-cpp` will balance the parameters automatically](./index.md#gpu-support) also when loading the model, > context, etc. You can also estimate the compatibility of a model programmatically using the [`GgufInsights` class](../api/classes/GgufInsights.md): ```typescript import {getLlama, readGgufFileInfo, GgufInsights} from "node-llama-cpp"; const llama = await getLlama(); const modelMetadata = await readGgufFileInfo(""); const insights = await GgufInsights.from(modelMetadata, llama); const resolvedConfig = await insights.configurationResolver.resolveAndScoreConfig(); const flashAttentionconfig = await insights.configurationResolver.resolveAndScoreConfig({ flashAttention: true }); console.log(`Compatibility: ${resolvedConfig.compatibilityScore * 100}%`); console.log( `With flash attention: ${flashAttentionconfig.compatibilityScore * 100}%` ); ``` --- --- url: /api/enumerations/GgmlType.md --- # Enumeration: GgmlType Defined in: [gguf/types/GgufTensorInfoTypes.ts:25](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufTensorInfoTypes.ts#L25) ## Enumeration Members | Enumeration Member | Value | Defined in | | ------ | ------ | ------ | | `F32` | `0` | [gguf/types/GgufTensorInfoTypes.ts:26](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufTensorInfoTypes.ts#L26) | | `F16` | `1` | [gguf/types/GgufTensorInfoTypes.ts:27](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufTensorInfoTypes.ts#L27) | | `Q4_0` | `2` | [gguf/types/GgufTensorInfoTypes.ts:28](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufTensorInfoTypes.ts#L28) | | `Q4_1` | `3` | [gguf/types/GgufTensorInfoTypes.ts:29](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufTensorInfoTypes.ts#L29) | | `Q4_2` | `4` | [gguf/types/GgufTensorInfoTypes.ts:30](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufTensorInfoTypes.ts#L30) | | `Q4_3` | `5` | [gguf/types/GgufTensorInfoTypes.ts:31](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufTensorInfoTypes.ts#L31) | | `Q5_0` | `6` | [gguf/types/GgufTensorInfoTypes.ts:32](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufTensorInfoTypes.ts#L32) | | `Q5_1` | `7` | [gguf/types/GgufTensorInfoTypes.ts:33](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufTensorInfoTypes.ts#L33) | | `Q8_0` | `8` | [gguf/types/GgufTensorInfoTypes.ts:34](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufTensorInfoTypes.ts#L34) | | `Q8_1` | `9` | [gguf/types/GgufTensorInfoTypes.ts:35](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufTensorInfoTypes.ts#L35) | | `Q2_K` | `10` | [gguf/types/GgufTensorInfoTypes.ts:36](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufTensorInfoTypes.ts#L36) | | `Q3_K` | `11` | [gguf/types/GgufTensorInfoTypes.ts:37](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufTensorInfoTypes.ts#L37) | | `Q4_K` | `12` | [gguf/types/GgufTensorInfoTypes.ts:38](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufTensorInfoTypes.ts#L38) | | `Q5_K` | `13` | [gguf/types/GgufTensorInfoTypes.ts:39](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufTensorInfoTypes.ts#L39) | | `Q6_K` | `14` | [gguf/types/GgufTensorInfoTypes.ts:40](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufTensorInfoTypes.ts#L40) | | `Q8_K` | `15` | [gguf/types/GgufTensorInfoTypes.ts:41](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufTensorInfoTypes.ts#L41) | | `IQ2_XXS` | `16` | [gguf/types/GgufTensorInfoTypes.ts:42](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufTensorInfoTypes.ts#L42) | | `IQ2_XS` | `17` | [gguf/types/GgufTensorInfoTypes.ts:43](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufTensorInfoTypes.ts#L43) | | `IQ3_XXS` | `18` | [gguf/types/GgufTensorInfoTypes.ts:44](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufTensorInfoTypes.ts#L44) | | `IQ1_S` | `19` | [gguf/types/GgufTensorInfoTypes.ts:45](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufTensorInfoTypes.ts#L45) | | `IQ4_NL` | `20` | [gguf/types/GgufTensorInfoTypes.ts:46](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufTensorInfoTypes.ts#L46) | | `IQ3_S` | `21` | [gguf/types/GgufTensorInfoTypes.ts:47](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufTensorInfoTypes.ts#L47) | | `IQ2_S` | `22` | [gguf/types/GgufTensorInfoTypes.ts:48](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufTensorInfoTypes.ts#L48) | | `IQ4_XS` | `23` | [gguf/types/GgufTensorInfoTypes.ts:49](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufTensorInfoTypes.ts#L49) | | `I8` | `24` | [gguf/types/GgufTensorInfoTypes.ts:50](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufTensorInfoTypes.ts#L50) | | `I16` | `25` | [gguf/types/GgufTensorInfoTypes.ts:51](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufTensorInfoTypes.ts#L51) | | `I32` | `26` | [gguf/types/GgufTensorInfoTypes.ts:52](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufTensorInfoTypes.ts#L52) | | `I64` | `27` | [gguf/types/GgufTensorInfoTypes.ts:53](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufTensorInfoTypes.ts#L53) | | `F64` | `28` | [gguf/types/GgufTensorInfoTypes.ts:54](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufTensorInfoTypes.ts#L54) | | `IQ1_M` | `29` | [gguf/types/GgufTensorInfoTypes.ts:55](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufTensorInfoTypes.ts#L55) | | `BF16` | `30` | [gguf/types/GgufTensorInfoTypes.ts:56](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufTensorInfoTypes.ts#L56) | | `Q4_0_4_4` | `31` | [gguf/types/GgufTensorInfoTypes.ts:57](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufTensorInfoTypes.ts#L57) | | `Q4_0_4_8` | `32` | [gguf/types/GgufTensorInfoTypes.ts:58](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufTensorInfoTypes.ts#L58) | | `Q4_0_8_8` | `33` | [gguf/types/GgufTensorInfoTypes.ts:59](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufTensorInfoTypes.ts#L59) | | `TQ1_0` | `34` | [gguf/types/GgufTensorInfoTypes.ts:60](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufTensorInfoTypes.ts#L60) | | `TQ2_0` | `35` | [gguf/types/GgufTensorInfoTypes.ts:61](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufTensorInfoTypes.ts#L61) | | `IQ4_NL_4_4` | `36` | [gguf/types/GgufTensorInfoTypes.ts:62](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufTensorInfoTypes.ts#L62) | | `IQ4_NL_4_8` | `37` | [gguf/types/GgufTensorInfoTypes.ts:63](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufTensorInfoTypes.ts#L63) | | `IQ4_NL_8_8` | `38` | [gguf/types/GgufTensorInfoTypes.ts:64](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufTensorInfoTypes.ts#L64) | | `MXFP4` | `39` | [gguf/types/GgufTensorInfoTypes.ts:65](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufTensorInfoTypes.ts#L65) | | `NVFP4` | `40` | [gguf/types/GgufTensorInfoTypes.ts:66](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufTensorInfoTypes.ts#L66) | | `Q1_0` | `41` | [gguf/types/GgufTensorInfoTypes.ts:67](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufTensorInfoTypes.ts#L67) | | `Q2_0` | `42` | [gguf/types/GgufTensorInfoTypes.ts:68](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufTensorInfoTypes.ts#L68) | --- --- url: /api/enumerations/GgufArchitectureType.md --- # Enumeration: GgufArchitectureType Defined in: [gguf/types/GgufMetadataTypes.ts:1](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L1) ## Enumeration Members | Enumeration Member | Value | Defined in | | ------ | ------ | ------ | | `llama` | `"llama"` | [gguf/types/GgufMetadataTypes.ts:2](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L2) | | `llama4` | `"llama4"` | [gguf/types/GgufMetadataTypes.ts:3](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L3) | | `deci` | `"deci"` | [gguf/types/GgufMetadataTypes.ts:4](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L4) | | `falcon` | `"falcon"` | [gguf/types/GgufMetadataTypes.ts:5](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L5) | | `grok` | `"grok"` | [gguf/types/GgufMetadataTypes.ts:6](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L6) | | `gpt2` | `"gpt2"` | [gguf/types/GgufMetadataTypes.ts:7](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L7) | | `gptj` | `"gptj"` | [gguf/types/GgufMetadataTypes.ts:8](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L8) | | `gptneox` | `"gptneox"` | [gguf/types/GgufMetadataTypes.ts:9](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L9) | | `mpt` | `"mpt"` | [gguf/types/GgufMetadataTypes.ts:10](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L10) | | `baichuan` | `"baichuan"` | [gguf/types/GgufMetadataTypes.ts:11](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L11) | | `starcoder` | `"starcoder"` | [gguf/types/GgufMetadataTypes.ts:12](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L12) | | `refact` | `"refact"` | [gguf/types/GgufMetadataTypes.ts:13](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L13) | | `bert` | `"bert"` | [gguf/types/GgufMetadataTypes.ts:14](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L14) | | `modernBert` | `"modern-bert"` | [gguf/types/GgufMetadataTypes.ts:15](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L15) | | `nomicBert` | `"nomic-bert"` | [gguf/types/GgufMetadataTypes.ts:16](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L16) | | `nomicBertMoe` | `"nomic-bert-moe"` | [gguf/types/GgufMetadataTypes.ts:17](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L17) | | `neoBert` | `"neo-bert"` | [gguf/types/GgufMetadataTypes.ts:18](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L18) | | `jinaBertV2` | `"jina-bert-v2"` | [gguf/types/GgufMetadataTypes.ts:19](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L19) | | `jinaBertV3` | `"jina-bert-v3"` | [gguf/types/GgufMetadataTypes.ts:20](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L20) | | `eurobert` | `"eurobert"` | [gguf/types/GgufMetadataTypes.ts:21](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L21) | | `bloom` | `"bloom"` | [gguf/types/GgufMetadataTypes.ts:22](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L22) | | `stablelm` | `"stablelm"` | [gguf/types/GgufMetadataTypes.ts:23](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L23) | | `qwen` | `"qwen"` | [gguf/types/GgufMetadataTypes.ts:24](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L24) | | `qwen2` | `"qwen2"` | [gguf/types/GgufMetadataTypes.ts:25](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L25) | | `qwen2moe` | `"qwen2moe"` | [gguf/types/GgufMetadataTypes.ts:26](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L26) | | `qwen2vl` | `"qwen2vl"` | [gguf/types/GgufMetadataTypes.ts:27](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L27) | | `qwen3` | `"qwen3"` | [gguf/types/GgufMetadataTypes.ts:28](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L28) | | `qwen3moe` | `"qwen3moe"` | [gguf/types/GgufMetadataTypes.ts:29](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L29) | | `qwen3next` | `"qwen3next"` | [gguf/types/GgufMetadataTypes.ts:30](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L30) | | `qwen3vl` | `"qwen3vl"` | [gguf/types/GgufMetadataTypes.ts:31](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L31) | | `qwen3vlmoe` | `"qwen3vlmoe"` | [gguf/types/GgufMetadataTypes.ts:32](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L32) | | `qwen35` | `"qwen35"` | [gguf/types/GgufMetadataTypes.ts:33](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L33) | | `qwen35moe` | `"qwen35moe"` | [gguf/types/GgufMetadataTypes.ts:34](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L34) | | `phi2` | `"phi2"` | [gguf/types/GgufMetadataTypes.ts:35](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L35) | | `phi3` | `"phi3"` | [gguf/types/GgufMetadataTypes.ts:36](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L36) | | `phimoe` | `"phimoe"` | [gguf/types/GgufMetadataTypes.ts:37](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L37) | | `plamo` | `"plamo"` | [gguf/types/GgufMetadataTypes.ts:38](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L38) | | `plamo2` | `"plamo2"` | [gguf/types/GgufMetadataTypes.ts:39](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L39) | | `plamo3` | `"plamo3"` | [gguf/types/GgufMetadataTypes.ts:40](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L40) | | `codeshell` | `"codeshell"` | [gguf/types/GgufMetadataTypes.ts:41](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L41) | | `orion` | `"orion"` | [gguf/types/GgufMetadataTypes.ts:42](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L42) | | `internlm2` | `"internlm2"` | [gguf/types/GgufMetadataTypes.ts:43](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L43) | | `minicpm` | `"minicpm"` | [gguf/types/GgufMetadataTypes.ts:44](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L44) | | `minicpm3` | `"minicpm3"` | [gguf/types/GgufMetadataTypes.ts:45](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L45) | | `gemma` | `"gemma"` | [gguf/types/GgufMetadataTypes.ts:46](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L46) | | `gemma2` | `"gemma2"` | [gguf/types/GgufMetadataTypes.ts:47](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L47) | | `gemma3` | `"gemma3"` | [gguf/types/GgufMetadataTypes.ts:48](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L48) | | `gemma3n` | `"gemma3n"` | [gguf/types/GgufMetadataTypes.ts:49](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L49) | | `gemma4` | `"gemma4"` | [gguf/types/GgufMetadataTypes.ts:50](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L50) | | `gemma4assistant` | `"gemma4-assistant"` | [gguf/types/GgufMetadataTypes.ts:51](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L51) | | `gemmaEmbedding` | `"gemma-embedding"` | [gguf/types/GgufMetadataTypes.ts:52](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L52) | | `starcoder2` | `"starcoder2"` | [gguf/types/GgufMetadataTypes.ts:53](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L53) | | `mamba` | `"mamba"` | [gguf/types/GgufMetadataTypes.ts:54](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L54) | | `mamba2` | `"mamba2"` | [gguf/types/GgufMetadataTypes.ts:55](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L55) | | `jamba` | `"jamba"` | [gguf/types/GgufMetadataTypes.ts:56](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L56) | | `falconH1` | `"falcon-h1"` | [gguf/types/GgufMetadataTypes.ts:57](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L57) | | `xverse` | `"xverse"` | [gguf/types/GgufMetadataTypes.ts:58](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L58) | | `commandR` | `"command-r"` | [gguf/types/GgufMetadataTypes.ts:59](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L59) | | `cohere2` | `"cohere2"` | [gguf/types/GgufMetadataTypes.ts:60](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L60) | | `cohere2moe` | `"cohere2moe"` | [gguf/types/GgufMetadataTypes.ts:61](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L61) | | `dbrx` | `"dbrx"` | [gguf/types/GgufMetadataTypes.ts:62](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L62) | | `olmo` | `"olmo"` | [gguf/types/GgufMetadataTypes.ts:63](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L63) | | `olmo2` | `"olmo2"` | [gguf/types/GgufMetadataTypes.ts:64](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L64) | | `olmoe` | `"olmoe"` | [gguf/types/GgufMetadataTypes.ts:65](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L65) | | `museGlimmer` | `"muse-glimmer"` | [gguf/types/GgufMetadataTypes.ts:66](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L66) | | `openelm` | `"openelm"` | [gguf/types/GgufMetadataTypes.ts:67](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L67) | | `arctic` | `"arctic"` | [gguf/types/GgufMetadataTypes.ts:68](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L68) | | `deepseek` | `"deepseek"` | [gguf/types/GgufMetadataTypes.ts:69](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L69) | | `deepseek2` | `"deepseek2"` | [gguf/types/GgufMetadataTypes.ts:70](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L70) | | `deepseek2ocr` | `"deepseek2-ocr"` | [gguf/types/GgufMetadataTypes.ts:71](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L71) | | `deepseek32` | `"deepseek32"` | [gguf/types/GgufMetadataTypes.ts:72](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L72) | | `deepseek4` | `"deepseek4"` | [gguf/types/GgufMetadataTypes.ts:73](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L73) | | `chatglm` | `"chatglm"` | [gguf/types/GgufMetadataTypes.ts:74](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L74) | | `glm4` | `"glm4"` | [gguf/types/GgufMetadataTypes.ts:75](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L75) | | `glm4moe` | `"glm4moe"` | [gguf/types/GgufMetadataTypes.ts:76](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L76) | | `glmDsa` | `"glm-dsa"` | [gguf/types/GgufMetadataTypes.ts:77](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L77) | | `bitnet` | `"bitnet"` | [gguf/types/GgufMetadataTypes.ts:78](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L78) | | `t5` | `"t5"` | [gguf/types/GgufMetadataTypes.ts:79](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L79) | | `t5encoder` | `"t5encoder"` | [gguf/types/GgufMetadataTypes.ts:80](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L80) | | `jais` | `"jais"` | [gguf/types/GgufMetadataTypes.ts:81](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L81) | | `jais2` | `"jais2"` | [gguf/types/GgufMetadataTypes.ts:82](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L82) | | `nemotron` | `"nemotron"` | [gguf/types/GgufMetadataTypes.ts:83](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L83) | | `nemotronH` | `"nemotron_h"` | [gguf/types/GgufMetadataTypes.ts:84](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L84) | | `nemotronHMoe` | `"nemotron_h_moe"` | [gguf/types/GgufMetadataTypes.ts:85](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L85) | | `exaone` | `"exaone"` | [gguf/types/GgufMetadataTypes.ts:86](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L86) | | `exaone4` | `"exaone4"` | [gguf/types/GgufMetadataTypes.ts:87](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L87) | | `exaoneMoe` | `"exaone-moe"` | [gguf/types/GgufMetadataTypes.ts:88](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L88) | | `rwkv6` | `"rwkv6"` | [gguf/types/GgufMetadataTypes.ts:89](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L89) | | `rwkv6qwen2` | `"rwkv6qwen2"` | [gguf/types/GgufMetadataTypes.ts:90](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L90) | | `rwkv7` | `"rwkv7"` | [gguf/types/GgufMetadataTypes.ts:91](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L91) | | `arwkv7` | `"arwkv7"` | [gguf/types/GgufMetadataTypes.ts:92](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L92) | | `granite` | `"granite"` | [gguf/types/GgufMetadataTypes.ts:93](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L93) | | `granitemoe` | `"granitemoe"` | [gguf/types/GgufMetadataTypes.ts:94](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L94) | | `granitehybrid` | `"granitehybrid"` | [gguf/types/GgufMetadataTypes.ts:95](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L95) | | `graniteswitch` | `"graniteswitch"` | [gguf/types/GgufMetadataTypes.ts:96](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L96) | | `chameleon` | `"chameleon"` | [gguf/types/GgufMetadataTypes.ts:97](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L97) | | `wavtokenizerDec` | `"wavtokenizer-dec"` | [gguf/types/GgufMetadataTypes.ts:98](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L98) | | `plm` | `"plm"` | [gguf/types/GgufMetadataTypes.ts:99](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L99) | | `bailingmoe` | `"bailingmoe"` | [gguf/types/GgufMetadataTypes.ts:100](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L100) | | `bailingmoe2` | `"bailingmoe2"` | [gguf/types/GgufMetadataTypes.ts:101](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L101) | | `dots1` | `"dots1"` | [gguf/types/GgufMetadataTypes.ts:102](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L102) | | `arcee` | `"arcee"` | [gguf/types/GgufMetadataTypes.ts:103](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L103) | | `afmoe` | `"afmoe"` | [gguf/types/GgufMetadataTypes.ts:104](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L104) | | `laguna` | `"laguna"` | [gguf/types/GgufMetadataTypes.ts:105](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L105) | | `ernie4_5` | `"ernie4_5"` | [gguf/types/GgufMetadataTypes.ts:106](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L106) | | `ernie4_5Moe` | `"ernie4_5-moe"` | [gguf/types/GgufMetadataTypes.ts:107](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L107) | | `hunyuanMoe` | `"hunyuan-moe"` | [gguf/types/GgufMetadataTypes.ts:108](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L108) | | `hunyuanDense` | `"hunyuan-dense"` | [gguf/types/GgufMetadataTypes.ts:109](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L109) | | `hunyuanVl` | `"hunyuan_vl"` | [gguf/types/GgufMetadataTypes.ts:110](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L110) | | `hyV3` | `"hy_v3"` | [gguf/types/GgufMetadataTypes.ts:111](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L111) | | `smollm3` | `"smollm3"` | [gguf/types/GgufMetadataTypes.ts:112](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L112) | | `gptOss` | `"gpt-oss"` | [gguf/types/GgufMetadataTypes.ts:113](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L113) | | `lfm2` | `"lfm2"` | [gguf/types/GgufMetadataTypes.ts:114](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L114) | | `lfm2moe` | `"lfm2moe"` | [gguf/types/GgufMetadataTypes.ts:115](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L115) | | `dream` | `"dream"` | [gguf/types/GgufMetadataTypes.ts:116](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L116) | | `smallthinker` | `"smallthinker"` | [gguf/types/GgufMetadataTypes.ts:117](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L117) | | `llada` | `"llada"` | [gguf/types/GgufMetadataTypes.ts:118](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L118) | | `lladaMoe` | `"llada-moe"` | [gguf/types/GgufMetadataTypes.ts:119](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L119) | | `seedOss` | `"seed_oss"` | [gguf/types/GgufMetadataTypes.ts:120](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L120) | | `grovemoe` | `"grovemoe"` | [gguf/types/GgufMetadataTypes.ts:121](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L121) | | `apertus` | `"apertus"` | [gguf/types/GgufMetadataTypes.ts:122](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L122) | | `minimaxM2` | `"minimax-m2"` | [gguf/types/GgufMetadataTypes.ts:123](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L123) | | `minimaxM3` | `"minimax-m3"` | [gguf/types/GgufMetadataTypes.ts:124](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L124) | | `cogvlm` | `"cogvlm"` | [gguf/types/GgufMetadataTypes.ts:125](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L125) | | `rnd1` | `"rnd1"` | [gguf/types/GgufMetadataTypes.ts:126](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L126) | | `panguEmbedded` | `"pangu-embedded"` | [gguf/types/GgufMetadataTypes.ts:127](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L127) | | `mistral3` | `"mistral3"` | [gguf/types/GgufMetadataTypes.ts:128](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L128) | | `eagle3` | `"eagle3"` | [gguf/types/GgufMetadataTypes.ts:129](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L129) | | `dflash` | `"dflash"` | [gguf/types/GgufMetadataTypes.ts:130](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L130) | | `mistral4` | `"mistral4"` | [gguf/types/GgufMetadataTypes.ts:131](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L131) | | `paddleocr` | `"paddleocr"` | [gguf/types/GgufMetadataTypes.ts:132](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L132) | | `mimo2` | `"mimo2"` | [gguf/types/GgufMetadataTypes.ts:133](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L133) | | `step35` | `"step35"` | [gguf/types/GgufMetadataTypes.ts:134](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L134) | | `llamaEmbed` | `"llama-embed"` | [gguf/types/GgufMetadataTypes.ts:135](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L135) | | `maincoder` | `"maincoder"` | [gguf/types/GgufMetadataTypes.ts:136](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L136) | | `kimiLinear` | `"kimi-linear"` | [gguf/types/GgufMetadataTypes.ts:137](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L137) | | `talkie` | `"talkie"` | [gguf/types/GgufMetadataTypes.ts:138](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L138) | | `mellum` | `"mellum"` | [gguf/types/GgufMetadataTypes.ts:139](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L139) | | `nanbeige` | `"nanbeige"` | [gguf/types/GgufMetadataTypes.ts:140](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L140) | | `qwen3tts` | `"qwen3tts"` | [gguf/types/GgufMetadataTypes.ts:141](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L141) | | `clip` | `"clip"` | [gguf/types/GgufMetadataTypes.ts:142](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L142) | | `unknown` | `"(unknown)"` | [gguf/types/GgufMetadataTypes.ts:143](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L143) | --- --- url: /api/enumerations/GgufFileType.md --- # Enumeration: GgufFileType Defined in: [gguf/types/GgufMetadataTypes.ts:176](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L176) ## Enumeration Members | Enumeration Member | Value | Defined in | | ------ | ------ | ------ | | `ALL_F32` | `0` | [gguf/types/GgufMetadataTypes.ts:177](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L177) | | `MOSTLY_F16` | `1` | [gguf/types/GgufMetadataTypes.ts:178](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L178) | | `MOSTLY_Q4_0` | `2` | [gguf/types/GgufMetadataTypes.ts:179](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L179) | | `MOSTLY_Q4_1` | `3` | [gguf/types/GgufMetadataTypes.ts:180](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L180) | | `MOSTLY_Q4_1_SOME_F16` | `4` | [gguf/types/GgufMetadataTypes.ts:181](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L181) | | `MOSTLY_Q4_2` | `5` | [gguf/types/GgufMetadataTypes.ts:182](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L182) | | `MOSTLY_Q4_3` | `6` | [gguf/types/GgufMetadataTypes.ts:183](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L183) | | `MOSTLY_Q8_0` | `7` | [gguf/types/GgufMetadataTypes.ts:184](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L184) | | `MOSTLY_Q5_0` | `8` | [gguf/types/GgufMetadataTypes.ts:185](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L185) | | `MOSTLY_Q5_1` | `9` | [gguf/types/GgufMetadataTypes.ts:186](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L186) | | `MOSTLY_Q2_K` | `10` | [gguf/types/GgufMetadataTypes.ts:187](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L187) | | `MOSTLY_Q3_K_S` | `11` | [gguf/types/GgufMetadataTypes.ts:188](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L188) | | `MOSTLY_Q3_K_M` | `12` | [gguf/types/GgufMetadataTypes.ts:189](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L189) | | `MOSTLY_Q3_K_L` | `13` | [gguf/types/GgufMetadataTypes.ts:190](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L190) | | `MOSTLY_Q4_K_S` | `14` | [gguf/types/GgufMetadataTypes.ts:191](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L191) | | `MOSTLY_Q4_K_M` | `15` | [gguf/types/GgufMetadataTypes.ts:192](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L192) | | `MOSTLY_Q5_K_S` | `16` | [gguf/types/GgufMetadataTypes.ts:193](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L193) | | `MOSTLY_Q5_K_M` | `17` | [gguf/types/GgufMetadataTypes.ts:194](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L194) | | `MOSTLY_Q6_K` | `18` | [gguf/types/GgufMetadataTypes.ts:195](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L195) | | `MOSTLY_IQ2_XXS` | `19` | [gguf/types/GgufMetadataTypes.ts:196](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L196) | | `MOSTLY_IQ2_XS` | `20` | [gguf/types/GgufMetadataTypes.ts:197](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L197) | | `MOSTLY_Q2_K_S` | `21` | [gguf/types/GgufMetadataTypes.ts:198](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L198) | | `MOSTLY_IQ3_XS` | `22` | [gguf/types/GgufMetadataTypes.ts:199](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L199) | | `MOSTLY_IQ3_XXS` | `23` | [gguf/types/GgufMetadataTypes.ts:200](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L200) | | `MOSTLY_IQ1_S` | `24` | [gguf/types/GgufMetadataTypes.ts:201](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L201) | | `MOSTLY_IQ4_NL` | `25` | [gguf/types/GgufMetadataTypes.ts:202](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L202) | | `MOSTLY_IQ3_S` | `26` | [gguf/types/GgufMetadataTypes.ts:203](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L203) | | `MOSTLY_IQ3_M` | `27` | [gguf/types/GgufMetadataTypes.ts:204](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L204) | | `MOSTLY_IQ2_S` | `28` | [gguf/types/GgufMetadataTypes.ts:205](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L205) | | `MOSTLY_IQ2_M` | `29` | [gguf/types/GgufMetadataTypes.ts:206](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L206) | | `MOSTLY_IQ4_XS` | `30` | [gguf/types/GgufMetadataTypes.ts:207](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L207) | | `MOSTLY_IQ1_M` | `31` | [gguf/types/GgufMetadataTypes.ts:208](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L208) | | `MOSTLY_BF16` | `32` | [gguf/types/GgufMetadataTypes.ts:209](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L209) | | `MOSTLY_Q4_0_4_4` | `33` | [gguf/types/GgufMetadataTypes.ts:210](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L210) | | `MOSTLY_Q4_0_4_8` | `34` | [gguf/types/GgufMetadataTypes.ts:211](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L211) | | `MOSTLY_Q4_0_8_8` | `35` | [gguf/types/GgufMetadataTypes.ts:212](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L212) | | `MOSTLY_TQ1_0` | `36` | [gguf/types/GgufMetadataTypes.ts:213](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L213) | | `MOSTLY_TQ2_0` | `37` | [gguf/types/GgufMetadataTypes.ts:214](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L214) | | `MOSTLY_MXFP4_MOE` | `38` | [gguf/types/GgufMetadataTypes.ts:215](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L215) | | `MOSTLY_NVFP4` | `39` | [gguf/types/GgufMetadataTypes.ts:216](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L216) | | `MOSTLY_Q1_0` | `40` | [gguf/types/GgufMetadataTypes.ts:217](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L217) | | `MOSTLY_Q2_0` | `41` | [gguf/types/GgufMetadataTypes.ts:218](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L218) | --- --- url: /api/enumerations/GgufMetadataArchitecturePoolingType.md --- # Enumeration: GgufMetadataArchitecturePoolingType Defined in: [gguf/types/GgufMetadataTypes.ts:379](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L379) ## Enumeration Members | Enumeration Member | Value | Defined in | | ------ | ------ | ------ | | `unspecified` | `-1` | [gguf/types/GgufMetadataTypes.ts:380](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L380) | | `none` | `0` | [gguf/types/GgufMetadataTypes.ts:381](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L381) | | `mean` | `1` | [gguf/types/GgufMetadataTypes.ts:382](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L382) | | `cls` | `2` | [gguf/types/GgufMetadataTypes.ts:383](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L383) | | `last` | `3` | [gguf/types/GgufMetadataTypes.ts:384](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L384) | | `rank` | `4` | [gguf/types/GgufMetadataTypes.ts:385](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L385) | --- --- url: /api/enumerations/GgufMetadataTokenizerTokenType.md --- # Enumeration: GgufMetadataTokenizerTokenType Defined in: [gguf/types/GgufMetadataTypes.ts:321](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L321) ## Enumeration Members | Enumeration Member | Value | Defined in | | ------ | ------ | ------ | | `undefined` | `0` | [gguf/types/GgufMetadataTypes.ts:322](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L322) | | `normal` | `1` | [gguf/types/GgufMetadataTypes.ts:323](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L323) | | `unknown` | `2` | [gguf/types/GgufMetadataTypes.ts:324](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L324) | | `control` | `3` | [gguf/types/GgufMetadataTypes.ts:325](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L325) | | `userDefined` | `4` | [gguf/types/GgufMetadataTypes.ts:326](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L326) | | `unused` | `5` | [gguf/types/GgufMetadataTypes.ts:327](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L327) | | `byte` | `6` | [gguf/types/GgufMetadataTypes.ts:328](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L328) | --- --- url: /api/enumerations/LlamaLogLevel.md --- # Enumeration: LlamaLogLevel Defined in: [bindings/types.ts:99](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/types.ts#L99) ## Enumeration Members | Enumeration Member | Value | Defined in | | ------ | ------ | ------ | | `disabled` | `"disabled"` | [bindings/types.ts:100](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/types.ts#L100) | | `fatal` | `"fatal"` | [bindings/types.ts:101](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/types.ts#L101) | | `error` | `"error"` | [bindings/types.ts:102](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/types.ts#L102) | | `warn` | `"warn"` | [bindings/types.ts:103](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/types.ts#L103) | | `info` | `"info"` | [bindings/types.ts:104](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/types.ts#L104) | | `log` | `"log"` | [bindings/types.ts:105](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/types.ts#L105) | | `debug` | `"debug"` | [bindings/types.ts:106](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/types.ts#L106) | --- --- url: /api/enumerations/LlamaVocabularyType.md --- # Enumeration: LlamaVocabularyType Defined in: [bindings/types.ts:118](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/types.ts#L118) ## Enumeration Members | Enumeration Member | Value | Defined in | | ------ | ------ | ------ | | `none` | `"none"` | [bindings/types.ts:119](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/types.ts#L119) | | `spm` | `"spm"` | [bindings/types.ts:120](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/types.ts#L120) | | `bpe` | `"bpe"` | [bindings/types.ts:121](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/types.ts#L121) | | `wpm` | `"wpm"` | [bindings/types.ts:122](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/types.ts#L122) | | `ugm` | `"ugm"` | [bindings/types.ts:123](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/types.ts#L123) | | `rwkv` | `"rwkv"` | [bindings/types.ts:124](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/types.ts#L124) | | `plamo2` | `"plamo2"` | [bindings/types.ts:125](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/types.ts#L125) | --- --- url: /guide/external-chat-state.md description: Chat with a model and manage the chat state externally --- # External Chat State ::: warning If you're not building a library around `node-llama-cpp`, you'd probably want to use the simpler [`LlamaChatSession`](../api/classes/LlamaChatSession.md); read more on the [chat session documentation](./chat-session.md). You can [save and restore a chat history](./chat-session.md#save-and-restore) on [`LlamaChatSession`](../api/classes/LlamaChatSession.md) instead of managing the chat state externally. ::: To interact with a model in a chat form, you can use [`LlamaChatSession`](../api/classes/LlamaChatSession.md), which is a stateful chat session that manages the chat state on its own. When building a library around `node-llama-cpp`, you may want to store that chat state externally and control the evaluations yourself. This is where [`LlamaChat`](../api/classes/LlamaChat.md) may come in handy. [`LlamaChat`](../api/classes/LlamaChat.md) Allows you to generate a completion to an existing chat session and manage the evaluation yourself, which allows you to also store the chat state externally. [`LlamaChat`](../api/classes/LlamaChat.md) is stateless and has no state of its own. In fact, [`LlamaChatSession`](../api/classes/LlamaChatSession.md) is just a wrapper around [`LlamaChat`](../api/classes/LlamaChat.md) to make it more convenient to use. Let's see how you can use [`LlamaChat`](../api/classes/LlamaChat.md) to prompt a model: ```typescript import {fileURLToPath} from "url"; import path from "path"; import {getLlama, LlamaChat} 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 llamaChat = new LlamaChat({ contextSequence: context.getSequence() }); let chatHistory = llamaChat.chatWrapper.generateInitialChatHistory({ // systemPrompt: "You're a helpful assistant" }); const prompt = "Hi there, how are you?"; // add the user prompt to the chat history chatHistory.push({ type: "user", text: prompt }); // add a slot for the model response, for the model to complete. // if we want the model response to start with a specific text, // we can do so by adding it to the response array chatHistory.push({ type: "model", response: [] }); console.log("User: " + prompt); const res = await llamaChat.generateResponse(chatHistory, { onTextChunk(text) { // stream the text to the console process.stdout.write(text); } }); const fullResponse = res.fullResponse .map((item) => { if (typeof item === "string") return item; else if (item.type === "segment") { let res = ""; if (item.startTime != null) res += ` [segment start: ${item.segmentType}] `; res += item.text; if (item.endTime != null) res += ` [segment end: ${item.segmentType}] `; return res; } return ""; }) .join(""); console.log("AI: " + res.response); console.log("Full response:", fullResponse); ``` Now, let's say we want to ask the model a follow-up question based on the previous response. Since we already have a context sequence loaded with the previous chat history, we'd want to reuse it as much a possible. To do so, we pass the context window of the previous evaluation output to the new evaluation. This is important, since if a context shift has happened, we want to use the existing post-context-shift context sequence state as much as possible instead of starting from scratch. ::: info NOTE Keeping and passing the context window and context shift metadata is only necessary if you use the same context sequence in the next evaluation, and the state from the previous evaluation is still present in the context sequence. ::: ```typescript import {fileURLToPath} from "url"; import path from "path"; import {getLlama, LlamaChat} 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 llamaChat = new LlamaChat({ contextSequence: context.getSequence() }); let chatHistory = llamaChat.chatWrapper.generateInitialChatHistory(); const prompt = "Hi there, how are you?"; // add the user prompt to the chat history chatHistory.push({ type: "user", text: prompt }); // add a slot for the model response, for the model to complete. // if we want the model response to start with a specific text, // we can do so by adding it to the response array chatHistory.push({ type: "model", response: [] }); console.log("User: " + prompt); const res = await llamaChat.generateResponse(chatHistory, { onTextChunk(text) { // stream the text to the console process.stdout.write(text); } }); console.log("AI: " + res.response); // ---cut--- chatHistory = res.lastEvaluation.cleanHistory; let chatHistoryContextWindow = res.lastEvaluation.contextWindow; let lastContextShiftMetadata = res.lastEvaluation.contextShiftMetadata; const prompt2 = "Summarize what you said"; // add the user prompt to the chat history chatHistory.push({ type: "user", text: prompt2 }); // add the user prompt to the chat history context window chatHistoryContextWindow.push({ type: "user", text: prompt2 }); // add a slot for the model response, for the model to complete chatHistory.push({ type: "model", response: [] }); // add a slot for the model response in the context window chatHistoryContextWindow.push({ type: "model", response: [] }); console.log("User: " + prompt2); const res2 = await llamaChat.generateResponse(chatHistory, { onTextChunk(text) { // stream the text to the console process.stdout.write(text); }, contextShift: { // pass the context shift metadata from the previous evaluation lastEvaluationMetadata: lastContextShiftMetadata }, lastEvaluationContextWindow: { history: chatHistoryContextWindow }, }); console.log("AI: " + res2.response); console.log("Full response:", res2.fullResponse); ``` ## Handling Function Calling {#function-calling} When passing information about functions the model can call, the response of the [`.generateResponse()`](../api/classes/LlamaChat.md#generateresponse) can contain function calls. Then, it's our implementation's responsibility to: * Print the textual response the model generated * Perform the appropriate function calls * Add the function calls and their results to the chat history Here's an example of how we can prompt a model and support function calling: ```typescript import {fileURLToPath} from "url"; import path from "path"; import { getLlama, LlamaChat, ChatModelFunctions, ChatHistoryItem, ChatModelResponse, ChatModelFunctionCall } 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 llamaChat = new LlamaChat({ contextSequence: context.getSequence() }); let chatHistory = llamaChat.chatWrapper.generateInitialChatHistory(); const prompt = "Give me the result of 2 dice rolls"; const functionDefinitions = { getRandomNumber: { description: "Get a random number", params: { type: "object", properties: { min: { type: "number" }, max: { type: "number" } } } } } satisfies ChatModelFunctions; function getRandomNumber(params: {min: number, max: number}) { return Math.floor( (Math.random() * (params.max - params.min + 1)) + params.min ); } // add the user prompt to the chat history chatHistory.push({ type: "user", text: prompt }); // add a slot for the model response, for the model to complete. // if we want the model response to start with a specific text, // we can do so by adding it to the response array chatHistory.push({ type: "model", response: [] }); console.log("User: " + prompt); let chatHistoryContextWindow: ChatHistoryItem[] | undefined; let lastContextShiftMetadata: any; while (true) { const res = await llamaChat.generateResponse(chatHistory, { functions: functionDefinitions, onFunctionCall(functionCall) { // we can use this callback to start performing // the function as soon as the model calls it console.log( "model called function", functionCall.functionName, "with params", functionCall.params ); }, contextShift: { lastEvaluationMetadata: lastContextShiftMetadata }, lastEvaluationContextWindow: { history: chatHistoryContextWindow }, }); chatHistory = res.lastEvaluation.cleanHistory; chatHistoryContextWindow = res.lastEvaluation.contextWindow; lastContextShiftMetadata = res.lastEvaluation.contextShiftMetadata; // print the text the model generated before calling functions if (res.response !== "") { const fullResponse = res.fullResponse .map((item) => { if (typeof item === "string") return item; else if (item.type === "segment") { let res = ""; if (item.startTime != null) res += ` [segment start: ${item.segmentType}] `; res += item.text; if (item.endTime != null) res += ` [segment end: ${item.segmentType}] `; return res; } return ""; }) .join(""); console.log("AI: " + res.response); console.log("Full response:", fullResponse); } // when there are no function calls, // it means the model has finished generating the response if (res.functionCalls == null) break; // perform the function calls const callItems: ChatModelFunctionCall[] = res.functionCalls .map((functionCall) => { if (functionCall.functionName !== "getRandomNumber") throw new Error("only function getRandomNumber is supported"); const res = getRandomNumber(functionCall.params); console.log( "Responding to function", functionCall.functionName, "with params", functionCall.params, "with result", res ); const functionDefinition = functionDefinitions[functionCall.functionName]; return { type: "functionCall", name: functionCall.functionName, params: functionCall.params, rawCall: functionCall.raw, description: functionDefinition?.description, result: res } satisfies ChatModelFunctionCall; }); // needed for maintaining the existing context sequence state // with parallel function calling, // and avoiding redundant context shifts callItems[0]!.startsNewChunk = true; if (chatHistory.at(-1)?.type !== "model") chatHistory.push({ type: "model", response: [] }); if (chatHistoryContextWindow.at(-1)?.type !== "model") chatHistoryContextWindow.push({ type: "model", response: [] }); const modelResponse = chatHistory.at(-1)! as ChatModelResponse; const contextWindowModelResponse = chatHistoryContextWindow.at(-1)! as ChatModelResponse; // add the function calls and their results // both to the chat history and the context window chat history for (const callItem of callItems) { modelResponse.response.push(callItem); contextWindowModelResponse.response.push(callItem); } } ``` --- --- url: /api/functions/appendUserMessageToChatHistory.md --- # Function: appendUserMessageToChatHistory() ```ts function appendUserMessageToChatHistory(chatHistory: readonly ChatHistoryItem[], message: string): ChatHistoryItem[]; ``` Defined in: [utils/appendUserMessageToChatHistory.ts:7](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/appendUserMessageToChatHistory.ts#L7) Appends a user message to the chat history. If the last message in the chat history is also a user message, the new message will be appended to it. ## Parameters | Parameter | Type | | ------ | ------ | | `chatHistory` | readonly [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] | | `message` | `string` | ## Returns [`ChatHistoryItem`](../type-aliases/ChatHistoryItem.md)\[] --- --- url: /api/functions/combineModelDownloaders.md --- # Function: combineModelDownloaders() ```ts function combineModelDownloaders(downloaders: ( | ModelDownloader | Promise)[], options?: CombinedModelDownloaderOptions): Promise; ``` Defined in: [utils/createModelDownloader.ts:202](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/createModelDownloader.ts#L202) Combine multiple models downloaders to a single downloader to download everything using as much parallelism as possible. You can check each individual model downloader for its download progress, but only the `onProgress` passed to the combined downloader will be called during the download. When combining `ModelDownloader` instances, the following options on each individual `ModelDownloader` are ignored: * `showCliProgress` * `onProgress` * `parallelDownloads` To set any of those options for the combined downloader, you have to pass them to the combined downloader instance. ## Parameters | Parameter | Type | | ------ | ------ | | `downloaders` | ( | [`ModelDownloader`](../classes/ModelDownloader.md) | [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[`ModelDownloader`](../classes/ModelDownloader.md)>)\[] | | `options?` | [`CombinedModelDownloaderOptions`](../type-aliases/CombinedModelDownloaderOptions.md) | ## Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[`CombinedModelDownloader`](../classes/CombinedModelDownloader.md)> ## Example ```typescript import {fileURLToPath} from "url"; import path from "path"; import {createModelDownloader, combineModelDownloaders, getLlama} from "node-llama-cpp"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const downloaders = [ createModelDownloader({ modelUri: "https://example.com/model1.gguf", dirPath: path.join(__dirname, "models") }), createModelDownloader({ modelUri: "hf:user/model2:quant", dirPath: path.join(__dirname, "models") }), createModelDownloader({ modelUri: "hf:user/model/model3.gguf", dirPath: path.join(__dirname, "models") }) ]; const combinedDownloader = await combineModelDownloaders(downloaders, { showCliProgress: true // show download progress in the CLI }); const [ model1Path, model2Path, model3Path ] = await combinedDownloader.download(); const llama = await getLlama(); const model1 = await llama.loadModel({ modelPath: model1Path! }); const model2 = await llama.loadModel({ modelPath: model2Path! }); const model3 = await llama.loadModel({ modelPath: model3Path! }); ``` --- --- url: /api/functions/createModelDownloader.md --- # Function: createModelDownloader() ```ts function createModelDownloader(options: ModelDownloaderOptions): Promise; ``` Defined in: [utils/createModelDownloader.ts:143](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/createModelDownloader.ts#L143) Create a model downloader to download a model from a URI. Uses [`ipull`](https://github.com/ido-pluto/ipull) to download a model file as fast as possible with parallel connections and other optimizations. If the uri points to a `.gguf` file that is split into multiple parts (for example, `model-00001-of-00009.gguf`), all the parts will be downloaded to the specified directory. If the uri points to a `.gguf` file that is binary split into multiple parts (for example, `model.gguf.part1of9`), all the parts will be spliced into a single file and be downloaded to the specified directory. If the uri points to a `.gguf` file that is not split or binary spliced (for example, `model.gguf`), the file will be downloaded to the specified directory. The supported URI schemes are: * **HTTP:** `https://`, `http://` * **Hugging Face:** `hf:/:` (`:` is optional, but recommended) * **Hugging Face:** `hf://#` (`#` is optional) ## Parameters | Parameter | Type | | ------ | ------ | | `options` | [`ModelDownloaderOptions`](../type-aliases/ModelDownloaderOptions.md) | ## Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[`ModelDownloader`](../classes/ModelDownloader.md)> ## Examples ```typescript import {fileURLToPath} from "url"; import path from "path"; import {createModelDownloader, getLlama} from "node-llama-cpp"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const downloader = await createModelDownloader({ modelUri: "https://example.com/model.gguf", dirPath: path.join(__dirname, "models") }); const modelPath = await downloader.download(); const llama = await getLlama(); const model = await llama.loadModel({ modelPath }); ``` ```typescript import {fileURLToPath} from "url"; import path from "path"; import {createModelDownloader, getLlama} from "node-llama-cpp"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const downloader = await createModelDownloader({ modelUri: "hf:user/model:quant", dirPath: path.join(__dirname, "models") }); const modelPath = await downloader.download(); const llama = await getLlama(); const model = await llama.loadModel({ modelPath }); ``` --- --- url: /api/functions/defineChatSessionFunction.md --- # Function: defineChatSessionFunction() ```ts function defineChatSessionFunction(functionDefinition: { description?: string; params?: Readonly & GbnfJsonSchema; handler: (params: GbnfJsonSchemaToType>) => any; }): ChatSessionModelFunction>; ``` Defined in: [evaluator/LlamaChatSession/utils/defineChatSessionFunction.ts:12](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/evaluator/LlamaChatSession/utils/defineChatSessionFunction.ts#L12) Define a function that can be used by the model in a chat session, and return it. This is a helper function to facilitate defining functions with full TypeScript type information. The handler function can return a Promise, and the return value will be awaited before being returned to the model. ## Type Parameters | Type Parameter | | ------ | | `Params` *extends* | [`GbnfJsonBasicSchema`](../type-aliases/GbnfJsonBasicSchema.md) | [`GbnfJsonConstSchema`](../type-aliases/GbnfJsonConstSchema.md) | [`GbnfJsonEnumSchema`](../type-aliases/GbnfJsonEnumSchema.md) | [`GbnfJsonBasicStringSchema`](../type-aliases/GbnfJsonBasicStringSchema.md) | [`GbnfJsonFormatStringSchema`](../type-aliases/GbnfJsonFormatStringSchema.md) | [`GbnfJsonOneOfSchema`](../type-aliases/GbnfJsonOneOfSchema.md)<`Defs`> | [`GbnfJsonObjectSchema`](../type-aliases/GbnfJsonObjectSchema.md)<`string`, `Defs`> | [`GbnfJsonArraySchema`](../type-aliases/GbnfJsonArraySchema.md)<`Defs`> | [`GbnfJsonRefSchema`](../type-aliases/GbnfJsonRefSchema.md)<`Defs`> | | `Defs` *extends* [`GbnfJsonDefList`](../type-aliases/GbnfJsonDefList.md)<`Defs`> | ## Parameters | Parameter | Type | Description | | ------ | ------ | ------ | | `functionDefinition` | { `description?`: `string`; `params?`: Readonly\ & GbnfJsonSchema\; `handler`: (`params`: [`GbnfJsonSchemaToType`](../type-aliases/GbnfJsonSchemaToType.md)<[`NoInfer`](https://www.typescriptlang.org/docs/handbook/utility-types.html#noinfertype)<`Params`>>) => `any`; } | - | | `functionDefinition.description?` | `string` | - | | `functionDefinition.params?` | Readonly\ & GbnfJsonSchema\ | - | | `functionDefinition.handler` | (`params`: [`GbnfJsonSchemaToType`](../type-aliases/GbnfJsonSchemaToType.md)<[`NoInfer`](https://www.typescriptlang.org/docs/handbook/utility-types.html#noinfertype)<`Params`>>) => `any` | - | ## Returns [`ChatSessionModelFunction`](../type-aliases/ChatSessionModelFunction.md)<[`NoInfer`](https://www.typescriptlang.org/docs/handbook/utility-types.html#noinfertype)<`Params`>> --- --- url: /api/functions/getLlama.md --- # Function: getLlama() ## Call Signature ```ts function getLlama(options?: LlamaOptions): Promise; ``` Defined in: [bindings/getLlama.ts:437](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/getLlama.ts#L437) Get a `llama.cpp` binding. Defaults to use a local binary built using the `source download` or `source build` CLI commands if one exists, otherwise, uses a prebuilt binary, and fallbacks to building from source if a prebuilt binary is not found. Pass `"lastBuild"` to default to use the last successful build created using the `source download` or `source build` CLI commands if one exists. The difference between using `"lastBuild"` and not using it is that `"lastBuild"` will use the binary built using a CLI command with the configuration used to build that binary (like using its GPU type), while not using `"lastBuild"` will only attempt to only use a binary that complies with the given options. For example, if your machine supports both CUDA and Vulkan, and you run the `source download --gpu vulkan` command, calling `getLlama("lastBuild")` will return the binary you built with Vulkan, while calling `getLlama()` will return a binding from a pre-built binary with CUDA, since CUDA is preferable on systems that support it. For example, if your machine supports CUDA, and you run the `source download --gpu cuda` command, calling `getLlama("lastBuild")` will return the binary you built with CUDA, and calling `getLlama()` will also return that same binary you built with CUDA. You should prefer to use `getLlama()` without `"lastBuild"` unless you have a specific reason to use the last build. ### Parameters | Parameter | Type | | ------ | ------ | | `options?` | [`LlamaOptions`](../type-aliases/LlamaOptions.md) | ### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[`Llama`](../classes/Llama.md)> ## Call Signature ```ts function getLlama(type: "lastBuild", lastBuildOptions?: LastBuildOptions): Promise; ``` Defined in: [bindings/getLlama.ts:438](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/getLlama.ts#L438) Get a `llama.cpp` binding. Defaults to use a local binary built using the `source download` or `source build` CLI commands if one exists, otherwise, uses a prebuilt binary, and fallbacks to building from source if a prebuilt binary is not found. Pass `"lastBuild"` to default to use the last successful build created using the `source download` or `source build` CLI commands if one exists. The difference between using `"lastBuild"` and not using it is that `"lastBuild"` will use the binary built using a CLI command with the configuration used to build that binary (like using its GPU type), while not using `"lastBuild"` will only attempt to only use a binary that complies with the given options. For example, if your machine supports both CUDA and Vulkan, and you run the `source download --gpu vulkan` command, calling `getLlama("lastBuild")` will return the binary you built with Vulkan, while calling `getLlama()` will return a binding from a pre-built binary with CUDA, since CUDA is preferable on systems that support it. For example, if your machine supports CUDA, and you run the `source download --gpu cuda` command, calling `getLlama("lastBuild")` will return the binary you built with CUDA, and calling `getLlama()` will also return that same binary you built with CUDA. You should prefer to use `getLlama()` without `"lastBuild"` unless you have a specific reason to use the last build. ### Parameters | Parameter | Type | | ------ | ------ | | `type` | `"lastBuild"` | | `lastBuildOptions?` | [`LastBuildOptions`](../type-aliases/LastBuildOptions.md) | ### Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[`Llama`](../classes/Llama.md)> --- --- url: /api/functions/getLlamaGpuTypes.md --- # Function: getLlamaGpuTypes() ```ts function getLlamaGpuTypes(include: "supported" | "allValid"): Promise; ``` Defined in: [bindings/utils/getLlamaGpuTypes.ts:17](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/utils/getLlamaGpuTypes.ts#L17) Get the list of GPU types that can be used with `getLlama` on the current machine. When passing `"supported"`, only the GPU types that have the necessary libraries and drivers installed on the current machine will be returned. All of these GPU types have prebuilt binaries for the current platform and architecture. When passing `"allValid"`, all GPU types that are compatible with the current OS and architecture will be returned. Some of these GPU types may not have prebuilt binaries for the current platform and architecture, as some of them are inadvisable for the current machine (like CUDA on an x64 Mac machine). ## Parameters | Parameter | Type | | ------ | ------ | | `include` | `"supported"` | `"allValid"` | ## Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[`LlamaGpuType`](../type-aliases/LlamaGpuType.md)\[]> --- --- url: /api/functions/getModuleVersion.md --- # Function: getModuleVersion() ```ts function getModuleVersion(): Promise; ``` Defined in: [utils/getModuleVersion.ts:8](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/getModuleVersion.ts#L8) ## Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`string`> --- --- url: /api/functions/isChatModelResponseFunctionCall.md --- # Function: isChatModelResponseFunctionCall() ```ts function isChatModelResponseFunctionCall(item: | string | ChatModelFunctionCall | ChatModelSegment | undefined): item is ChatModelFunctionCall; ``` Defined in: [types.ts:422](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/types.ts#L422) ## Parameters | Parameter | Type | | ------ | ------ | | `item` | | `string` | [`ChatModelFunctionCall`](../type-aliases/ChatModelFunctionCall.md) | [`ChatModelSegment`](../type-aliases/ChatModelSegment.md) | `undefined` | ## Returns `item is ChatModelFunctionCall` --- --- url: /api/functions/isChatModelResponseSegment.md --- # Function: isChatModelResponseSegment() ```ts function isChatModelResponseSegment(item: | string | ChatModelFunctionCall | ChatModelSegment | undefined): item is ChatModelSegment; ``` Defined in: [types.ts:429](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/types.ts#L429) ## Parameters | Parameter | Type | | ------ | ------ | | `item` | | `string` | [`ChatModelFunctionCall`](../type-aliases/ChatModelFunctionCall.md) | [`ChatModelSegment`](../type-aliases/ChatModelSegment.md) | `undefined` | ## Returns `item is ChatModelSegment` --- --- url: /api/functions/isGgufMetadataOfArchitectureType.md --- # Function: isGgufMetadataOfArchitectureType() ```ts function isGgufMetadataOfArchitectureType(metadata: GgufMetadata, type: A): metadata is GgufMetadata; ``` Defined in: [gguf/types/GgufMetadataTypes.ts:613](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/types/GgufMetadataTypes.ts#L613) ## Type Parameters | Type Parameter | | ------ | | `A` *extends* [`GgufArchitectureType`](../enumerations/GgufArchitectureType.md) | ## Parameters | Parameter | Type | | ------ | ------ | | `metadata` | [`GgufMetadata`](../type-aliases/GgufMetadata.md) | | `type` | `A` | ## Returns `metadata is GgufMetadata` --- --- url: /api/functions/isLlamaText.md --- # Function: isLlamaText() ```ts function isLlamaText(value: unknown): value is LlamaText; ``` Defined in: [utils/LlamaText.ts:590](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/LlamaText.ts#L590) ## Parameters | Parameter | Type | | ------ | ------ | | `value` | `unknown` | ## Returns `value is LlamaText` --- --- url: /api/functions/jsonDumps.md --- # Function: jsonDumps() ```ts function jsonDumps(value: any): string; ``` Defined in: [chatWrappers/utils/jsonDumps.ts:7](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/utils/jsonDumps.ts#L7) Like `JSON.stringify` but results in a value formatted in the format that Python produces when using `json.dumps(value)`. We need to format results this way since this is what many models use in their training data, so this is what many models expect to have in their context state. ## Parameters | Parameter | Type | | ------ | ------ | | `value` | `any` | ## Returns `string` --- --- url: /api/functions/LlamaLogLevelGreaterThan.md --- # Function: LlamaLogLevelGreaterThan() ```ts function LlamaLogLevelGreaterThan(a: LlamaLogLevel, b: LlamaLogLevel): boolean; ``` Defined in: [bindings/types.ts:144](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/types.ts#L144) Check if a log level is higher than another log level ## Parameters | Parameter | Type | | ------ | ------ | | `a` | [`LlamaLogLevel`](../enumerations/LlamaLogLevel.md) | | `b` | [`LlamaLogLevel`](../enumerations/LlamaLogLevel.md) | ## Returns `boolean` ## Example ```ts LlamaLogLevelGreaterThan(LlamaLogLevel.error, LlamaLogLevel.info); // true ``` --- --- url: /api/functions/LlamaLogLevelGreaterThanOrEqual.md --- # Function: LlamaLogLevelGreaterThanOrEqual() ```ts function LlamaLogLevelGreaterThanOrEqual(a: LlamaLogLevel, b: LlamaLogLevel): boolean; ``` Defined in: [bindings/types.ts:156](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/bindings/types.ts#L156) Check if a log level is higher than or equal to another log level ## Parameters | Parameter | Type | | ------ | ------ | | `a` | [`LlamaLogLevel`](../enumerations/LlamaLogLevel.md) | | `b` | [`LlamaLogLevel`](../enumerations/LlamaLogLevel.md) | ## Returns `boolean` ## Example ```ts LlamaLogLevelGreaterThanOrEqual(LlamaLogLevel.error, LlamaLogLevel.info); // true LlamaLogLevelGreaterThanOrEqual(LlamaLogLevel.error, LlamaLogLevel.error); // true ``` --- --- url: /api/functions/readGgufFileInfo.md --- # Function: readGgufFileInfo() ```ts function readGgufFileInfo(pathOrUri: string, options?: { readTensorInfo?: boolean; sourceType?: "network" | "filesystem"; ignoreKeys?: string[]; logWarnings?: boolean; fetchRetryOptions?: Options; fetchHeaders?: Record; spliceSplitFiles?: boolean; signal?: AbortSignal; tokens?: ModelFileAccessTokens; endpoints?: ModelDownloadEndpoints; }): Promise; ``` Defined in: [gguf/readGgufFileInfo.ts:23](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/gguf/readGgufFileInfo.ts#L23) Read a GGUF file and return its metadata and tensor info (unless `readTensorInfo` is set to `false`). Only the parts of the file required for the metadata and tensor info are read. ## Parameters | Parameter | Type | Description | | ------ | ------ | ------ | | `pathOrUri` | `string` | - | | `options` | { `readTensorInfo?`: `boolean`; `sourceType?`: `"network"` | `"filesystem"`; `ignoreKeys?`: `string`\[]; `logWarnings?`: `boolean`; `fetchRetryOptions?`: `Options`<`unknown`>; `fetchHeaders?`: [`Record`](https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkeys-type)<`string`, `string`>; `spliceSplitFiles?`: `boolean`; `signal?`: `AbortSignal`; `tokens?`: [`ModelFileAccessTokens`](../type-aliases/ModelFileAccessTokens.md); `endpoints?`: [`ModelDownloadEndpoints`](../type-aliases/ModelDownloadEndpoints.md); } | - | | `options.readTensorInfo?` | `boolean` | Whether to read the tensor info from the file's header. Defaults to `true`. | | `options.sourceType?` | `"network"` | `"filesystem"` | Set to a specific value to force it to only use that source type. By default, it detects whether the path is a network URL or a filesystem path and uses the appropriate reader accordingly. | | `options.ignoreKeys?` | `string`\[] | Metadata keys to ignore when parsing the metadata. For example, `["tokenizer.ggml.tokens"]` | | `options.logWarnings?` | `boolean` | Whether to log warnings Defaults to `true`. | | `options.fetchRetryOptions?` | `Options`<`unknown`> | Relevant only when fetching from a network | | `options.fetchHeaders?` | [`Record`](https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkeys-type)<`string`, `string`> | Relevant only when fetching from a network | | `options.spliceSplitFiles?` | `boolean` | When split files are detected, read the metadata of the first file and splice the tensor info from all the parts. Defaults to `true`. | | `options.signal?` | `AbortSignal` | - | | `options.tokens?` | [`ModelFileAccessTokens`](../type-aliases/ModelFileAccessTokens.md) | Tokens to use to access the remote model file. | | `options.endpoints?` | [`ModelDownloadEndpoints`](../type-aliases/ModelDownloadEndpoints.md) | Configure the URLs used for resolving model URIs. **See** [Model URIs](https://node-llama-cpp.withcat.ai/guide/downloading-models#model-uris) | ## Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[`GgufFileInfo`](../type-aliases/GgufFileInfo.md)> --- --- url: /api/functions/resolveChatWrapper.md --- # Function: resolveChatWrapper() ## Call Signature ```ts function resolveChatWrapper(model: LlamaModel, options?: ResolveChatWrapperWithModelOptions): BuiltInChatWrapperType; ``` Defined in: [chatWrappers/utils/resolveChatWrapper.ts:197](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/utils/resolveChatWrapper.ts#L197) Resolve to a chat wrapper instance based on the provided information. The more information provided, the better the resolution will be (except for `type`). It's recommended to not set `type` to a specific chat wrapper in order for the resolution to be more flexible, but it is useful for when you need to provide the ability to force a specific chat wrapper type. Note that when setting `type` to a generic chat wrapper type (such as `"template"` or `"jinjaTemplate"`), the `customWrapperSettings` must contain the necessary settings for that chat wrapper to be created. When loading a Jinja chat template from either `fileInfo` or `customWrapperSettings.jinjaTemplate.template`, if the chat template format is invalid, it fallbacks to resolve other chat wrappers, unless `fallbackToOtherWrappersOnJinjaError` is set to `false` (in which case, it will throw an error). ### Parameters | Parameter | Type | | ------ | ------ | | `model` | [`LlamaModel`](../classes/LlamaModel.md) | | `options?` | [`ResolveChatWrapperWithModelOptions`](../type-aliases/ResolveChatWrapperWithModelOptions.md) | ### Returns [`BuiltInChatWrapperType`](../type-aliases/BuiltInChatWrapperType.md) ### Examples ```typescript import {getLlama, resolveChatWrapper, GeneralChatWrapper} from "node-llama-cpp"; const llama = await getLlama(); const model = await llama.loadModel({modelPath: "path/to/model.gguf"}); const chatWrapper = resolveChatWrapper(model, { customWrapperSettings: { "llama3.1": { cuttingKnowledgeDate: new Date("2025-01-01T00:00:00Z") } } }) ?? new GeneralChatWrapper() ``` ```typescript import {getLlama, resolveChatWrapper, GeneralChatWrapper} from "node-llama-cpp"; const llama = await getLlama(); const model = await llama.loadModel({modelPath: "path/to/model.gguf"}); const chatWrapper = resolveChatWrapper({ bosString: model.tokens.bosString, architecture: model.architecture, filename: model.filename, fileInfo: model.fileInfo, tokenizer: model.tokenizer }) ?? new GeneralChatWrapper() ``` ## Call Signature ```ts function resolveChatWrapper(options: ResolveChatWrapperOptions): | BuiltInChatWrapperType | null; ``` Defined in: [chatWrappers/utils/resolveChatWrapper.ts:198](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/chatWrappers/utils/resolveChatWrapper.ts#L198) Resolve to a chat wrapper instance based on the provided information. The more information provided, the better the resolution will be (except for `type`). It's recommended to not set `type` to a specific chat wrapper in order for the resolution to be more flexible, but it is useful for when you need to provide the ability to force a specific chat wrapper type. Note that when setting `type` to a generic chat wrapper type (such as `"template"` or `"jinjaTemplate"`), the `customWrapperSettings` must contain the necessary settings for that chat wrapper to be created. When loading a Jinja chat template from either `fileInfo` or `customWrapperSettings.jinjaTemplate.template`, if the chat template format is invalid, it fallbacks to resolve other chat wrappers, unless `fallbackToOtherWrappersOnJinjaError` is set to `false` (in which case, it will throw an error). ### Parameters | Parameter | Type | | ------ | ------ | | `options` | [`ResolveChatWrapperOptions`](../type-aliases/ResolveChatWrapperOptions.md) | ### Returns | [`BuiltInChatWrapperType`](../type-aliases/BuiltInChatWrapperType.md) | `null` ### Examples ```typescript import {getLlama, resolveChatWrapper, GeneralChatWrapper} from "node-llama-cpp"; const llama = await getLlama(); const model = await llama.loadModel({modelPath: "path/to/model.gguf"}); const chatWrapper = resolveChatWrapper(model, { customWrapperSettings: { "llama3.1": { cuttingKnowledgeDate: new Date("2025-01-01T00:00:00Z") } } }) ?? new GeneralChatWrapper() ``` ```typescript import {getLlama, resolveChatWrapper, GeneralChatWrapper} from "node-llama-cpp"; const llama = await getLlama(); const model = await llama.loadModel({modelPath: "path/to/model.gguf"}); const chatWrapper = resolveChatWrapper({ bosString: model.tokens.bosString, architecture: model.architecture, filename: model.filename, fileInfo: model.fileInfo, tokenizer: model.tokenizer }) ?? new GeneralChatWrapper() ``` --- --- url: /api/functions/resolveModelFile.md --- # Function: resolveModelFile() ```ts function resolveModelFile(uriOrPath: string, optionsOrDirectory?: | string | ResolveModelFileOptions): Promise; ``` Defined in: [utils/resolveModelFile.ts:164](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/resolveModelFile.ts#L164) Resolves a local model file path from a URI or file path, and downloads the necessary files first if needed. If a URL or a URI is given, it'll be resolved to the corresponding file path. If the file path exists, it will be returned, otherwise it will be downloaded and then be returned. If a file path is given, and the path exists, it will be returned, otherwise an error will be thrown. Files are resolved from and downloaded to the `directory` option, which defaults to `node-llama-cpp`'s default global models directory (`~/.node-llama-cpp/models`). Set the `cli` option to `false` to hide the download progress from the console. ## Parameters | Parameter | Type | | ------ | ------ | | `uriOrPath` | `string` | | `optionsOrDirectory?` | | `string` | [`ResolveModelFileOptions`](../type-aliases/ResolveModelFileOptions.md) | ## Returns [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`string`> The resolved model file path ## Examples ```typescript import {fileURLToPath} from "url"; import path from "path"; import {getLlama, resolveModelFile} from "node-llama-cpp"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); // resolve a model from Hugging Face to the models directory const modelPath = await resolveModelFile( "hf:user/model:quant", path.join(__dirname, "models") ); const llama = await getLlama(); const model = await llama.loadModel({modelPath}); ``` ```typescript import {fileURLToPath} from "url"; import path from "path"; import {getLlama, resolveModelFile} from "node-llama-cpp"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); // resolve a model from a URL to the models directory const modelPath = await resolveModelFile( "https://example.com/model.gguf", path.join(__dirname, "models") ); const llama = await getLlama(); const model = await llama.loadModel({modelPath}); ``` ```typescript import {fileURLToPath} from "url"; import path from "path"; import {getLlama, resolveModelFile} from "node-llama-cpp"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); // resolve a local model that is in the models directory const modelPath = await resolveModelFile( "model.gguf", path.join(__dirname, "models") ); const llama = await getLlama(); const model = await llama.loadModel({modelPath}); ``` --- --- url: /api/functions/tokenizeText.md --- # Function: tokenizeText() ```ts function tokenizeText(text: string | LlamaText, tokenizer: Tokenizer): Token[]; ``` Defined in: [utils/LlamaText.ts:597](https://github.com/withcatai/node-llama-cpp/blob/adb92f28a5b57688361aad6c5e226f695f85d130/src/utils/LlamaText.ts#L597) Tokenize the given input using the given tokenizer, whether it's a `string` or a `LlamaText` ## Parameters | Parameter | Type | | ------ | ------ | | `text` | `string` | [`LlamaText`](../classes/LlamaText.md) | | `tokenizer` | [`Tokenizer`](../type-aliases/Tokenizer.md) | ## Returns [`Token`](../type-aliases/Token.md)\[] --- --- url: /blog/v3.19-gemma-4.md description: >- node-llama-cpp v3.19 is here, with full support for Gemma 4 models and improved performance! --- # Gemma 4 is here! [`node-llama-cpp`](https://node-llama-cpp.withcat.ai) v3.19 is here, with full support for [Gemma 4](https://huggingface.co/google/gemma-4-E2B-it) models and improved performance! *** ## Gemma 4 [Gemma 4](https://huggingface.co/google/gemma-4-E2B-it) comes in five flavors: * [`gemma-4-E2B-it`](https://huggingface.co/google/gemma-4-E2B-it) - 5.1B parameters with 2.3B active parameters, 128K context window * [`gemma-4-E4B-it`](https://huggingface.co/google/gemma-4-E4B-it) - 8B parameters with 4.5B active parameters, 128K context window * [`gemma-4-12B-it`](https://huggingface.co/google/gemma-4-12B-it) - 11.95B parameters dense model, 256K context window * [`gemma-4-26B-A4B-it`](https://huggingface.co/google/gemma-4-26B-A4B-it) - 25.2B parameters with 3.8B active parameters, 256K context window * [`gemma-4-31B-it`](https://huggingface.co/google/gemma-4-31B-it) - 30.7B parameters dense model, 256K context window Here are a few highlights of these models: * The non-dense models are pretty fast due to the low number of effective parameters * These are reasoning models, and you can disable reasoning when you don't need it * They are very good at function calling and coding, and are built with agentic capabilities in mind * The models family uses Sliding Window Attention (`SWA`), making 128K and 256K context windows much more efficient and thus practical * They are provided with an Apache 2.0 license, so you can use them in your commercial applications ## Recommended Models Here are some recommended model URIs you can use to try out Gemma 4 right away: | Model | Size | Recommended URIs | |-------------------------------------------------------------------------------|--------|---------------------------------------------| | [Gemma 4 5B E2B](https://huggingface.co/giladgd/gemma-4-E2B-it-GGUF) | 5.0GB | `hf:giladgd/gemma-4-E2B-it-GGUF:Q8_0` | | [Gemma 4 5B E2B](https://huggingface.co/giladgd/gemma-4-E2B-it-GGUF) | 3.9GB | `hf:giladgd/gemma-4-E2B-it-GGUF:Q6_K` | | | | | | [Gemma 4 8B E4B](https://huggingface.co/giladgd/gemma-4-E4B-it-GGUF) | 8.1GB | `hf:giladgd/gemma-4-E4B-it-GGUF:Q8_0` | | [Gemma 4 8B E4B](https://huggingface.co/giladgd/gemma-4-E4B-it-GGUF) | 6.3GB | `hf:giladgd/gemma-4-E4B-it-GGUF:Q6_K` | | [Gemma 4 8B E4B](https://huggingface.co/giladgd/gemma-4-E4B-it-GGUF) | 5.4GB | `hf:giladgd/gemma-4-E4B-it-GGUF:Q4_K_M` | | | | | | [Gemma 4 12B](https://huggingface.co/giladgd/gemma-4-12B-it-GGUF) | 12.7GB | `hf:giladgd/gemma-4-12B-it-GGUF:Q8_0` | | [Gemma 4 12B](https://huggingface.co/giladgd/gemma-4-12B-it-GGUF) | 9.8GB | `hf:giladgd/gemma-4-12B-it-GGUF:Q6_K` | | [Gemma 4 12B](https://huggingface.co/giladgd/gemma-4-12B-it-GGUF) | 8.5GB | `hf:giladgd/gemma-4-12B-it-GGUF:Q5_K_M` | | [Gemma 4 12B](https://huggingface.co/giladgd/gemma-4-12B-it-GGUF) | 7.4GB | `hf:giladgd/gemma-4-12B-it-GGUF:Q4_K_M` | | | | | | [Gemma 4 26B A4B MoE](https://huggingface.co/giladgd/gemma-4-26B-A4B-it-GGUF) | 26.9GB | `hf:giladgd/gemma-4-26B-A4B-it-GGUF:Q8_0` | | [Gemma 4 26B A4B MoE](https://huggingface.co/giladgd/gemma-4-26B-A4B-it-GGUF) | 22.6GB | `hf:giladgd/gemma-4-26B-A4B-it-GGUF:Q6_K` | | [Gemma 4 26B A4B MoE](https://huggingface.co/giladgd/gemma-4-26B-A4B-it-GGUF) | 19.1GB | `hf:giladgd/gemma-4-26B-A4B-it-GGUF:Q5_K_M` | | [Gemma 4 26B A4B MoE](https://huggingface.co/giladgd/gemma-4-26B-A4B-it-GGUF) | 16.8GB | `hf:giladgd/gemma-4-26B-A4B-it-GGUF:Q4_K_M` | | | | | | [Gemma 4 31B](https://huggingface.co/giladgd/gemma-4-31B-it-GGUF) | 32.6GB | `hf:giladgd/gemma-4-31B-it-GGUF:Q8_0` | | [Gemma 4 31B](https://huggingface.co/giladgd/gemma-4-31B-it-GGUF) | 25.2GB | `hf:giladgd/gemma-4-31B-it-GGUF:Q6_K` | | [Gemma 4 31B](https://huggingface.co/giladgd/gemma-4-31B-it-GGUF) | 21.8GB | `hf:giladgd/gemma-4-31B-it-GGUF:Q5_K_M` | | [Gemma 4 31B](https://huggingface.co/giladgd/gemma-4-31B-it-GGUF) | 18.7GB | `hf:giladgd/gemma-4-31B-it-GGUF:Q4_K_M` | ::: info TIP [Estimate the compatibility](../cli/inspect/estimate.md) of a model with your machine before downloading it: ```shell npx -y node-llama-cpp inspect estimate ``` ::: ### Try It Using the CLI To quickly try out [Gemma 4 5B E2B](https://huggingface.co/giladgd/gemma-4-E2B-it-GGUF), you can use the [CLI `chat` command](../cli/chat.md): ```shell npx -y node-llama-cpp chat --prompt "Hi there" hf:giladgd/gemma-4-E2B-it-GGUF:Q8_0 ``` ## Long Context One of the nicest things about Gemma 4 is how practical its long context is. These models use hybrid attention: a mix of regular full-context attention and Sliding Window Attention (SWA). This allows the model to still make use of the broader context, while SWA keeps long contexts much cheaper to work with by focusing part of the attention to the [recent window of tokens](../api/classes/GgufInsights.md#swasize). This makes long context much more practical, but reverting to a point in the context sequence before the SWA window can require reevaluating the tokens up to that point (unless you enable [`swaFullCache`](../api/type-aliases/LlamaContextOptions.md#swafullcache)). `node-llama-cpp` [automatically takes lightweight checkpoints](../api/classes/LlamaContext.md#getsequence) at strategic points in the sequence, so you don't have to worry about this. You can also manually [take a checkpoint](../api/classes/LlamaContextSequence.md#takecheckpoint) at strategic points in your workflow if you have a special case where you need more control. ## Configuring Reasoning Reasoning is enabled by default, but you can disable it or limit its budget if you want faster answers or to keep the token usage under control. You can do so by either configuring [`Gemma4ChatWrapper`](../api/classes/Gemma4ChatWrapper.md), or by setting a reasoning budget for individual prompts. ```typescript import { getLlama, resolveModelFile, LlamaChatSession, Gemma4ChatWrapper } from "node-llama-cpp"; const modelUri = "hf:giladgd/gemma-4-E2B-it-GGUF:Q8_0"; const llama = await getLlama(); const model = await llama.loadModel({ modelPath: await resolveModelFile(modelUri) }); const context = await model.createContext(); const session = new LlamaChatSession({ contextSequence: context.getSequence(), chatWrapper: new Gemma4ChatWrapper({ // Tell the model to not think: // reasoning: false }) }); const q1 = "Where do llamas come from?"; console.log("User: " + q1); process.stdout.write("AI: "); const a1 = await session.prompt(q1, { budgets: { // Force stop the model's reasoning when // it reaches 4096 tokens spent on thought segments: // thoughtTokens: 4096 }, onResponseChunk(chunk) { const isThoughtSegment = chunk.type === "segment" && chunk.segmentType === "thought"; const isCommentSegment = chunk.type === "segment" && chunk.segmentType === "comment"; if (chunk.type === "segment" && chunk.segmentStartTime != null) process.stdout.write(` [segment start: ${chunk.segmentType}] `); process.stdout.write(chunk.text); if (chunk.type === "segment" && chunk.segmentEndTime != null) process.stdout.write(` [segment end: ${chunk.segmentType}] `); } }); process.stdout.write("\n\n"); console.log("AI: " + a1); ``` ## Stability and Performance Improvements This release includes a myriad of stability and performance improvements across the board, but here are a few highlights: * Flash attention is now enabled by default when supported * [mmap](../api/type-aliases/LlamaModelOptions.md#usemmap) is automatically disabled when it could lead to better performance * Grammar and function calling inference performance is now much faster * Resource usage estimations are now much more accurate, so `"auto"` (the default) model and context configurations adapt to your machine much better * Prebuilt binaries for arm architectures are now more optimized and should perform better * Loading huge models won't crash the process anymore * If in the past your machine felt laggy when loading a model to memory, it now should be a rare occurrence * If in the past some models failed to load due to insufficient memory errors even though the machine had enough memory, then this issue should now be generally resolved ## Resource Capping In this release, you can set resource usage caps for a [`Llama`](../api/classes/Llama.md) instance to ensure that the total memory of all objects created from it won't exceed a certain amount of [RAM](../api/classes/Llama.md#setramcap) or [VRAM](../api/classes/Llama.md#setvramcap). This should help you ensure that `node-llama-cpp` plays nicely with other GPU workloads that you might run from the same process. ::: warning NOTE Setting the caps too low may prevent you from loading models at all, so use with caution. When using caps, make sure to provide users with the ability to configure the caps themselves to avoid bad defaults, since there's no one-size-fits-all configuration for all machines. ::: ```typescript import { getLlama, resolveModelFile } from "node-llama-cpp"; const modelUri = "hf:giladgd/gemma-4-E2B-it-GGUF:Q8_0"; const llama = await getLlama(); llama.setVramCap(4 * Math.pow(1024, 3)); // 4GB VRAM cap const model = await llama.loadModel({ modelPath: await resolveModelFile(modelUri) }); const context = await model.createContext(); // the total of the model and context VRAM won't exceed 6GB ``` ## Behind the Scenes The making of this release took longer than usual, as it includes many infrastructural improvements that required a more thorough testing to ensure everything works as expected across a wide range of machines and configurations. While working on this release, I've got a new machine to test on, and received help from community members who tested the PR and spotted issues on their machines. These improvements mean that in the future it'll take much less effort to support new models as they come out, and that `node-llama-cpp` will perform even better across a wider range of machines and configurations. If your project or company relies on `node-llama-cpp`, [consider becoming a sponsor](https://github.com/sponsors/giladgd) to accelerate the development of new features, improve hardware coverage, and expand testing. Until the next release, ♥️ `node-llama-cpp` maintainers. --- --- url: /guide.md description: Get started with node-llama-cpp --- # Getting Started ## Installation {#installation} ### Scaffold a New Project {#scaffold-new-project} To create a new `node-llama-cpp` project with everything set up, run this command: ```shell npm create node-llama-cpp@latest ``` > It may take a minute to download all the prebuilt binaries You will be asked to enter a project name, select a template, and choose a model from a list of recommended models. If this is your first time running models on your machine, we recommend starting with the `Node + TypeScript` template. ### Existing Project {#add-to-existing-project} Inside of your node.js project directory, run this command: ```shell npm install node-llama-cpp ``` > `node-llama-cpp` 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`. > > To ensure resolving the binaries happens during `npm install` (instead of on the first time of calling [`getLlama`](../api/functions/getLlama.md)), allow scripts from `node-llama-cpp` in your `package.json`: > > ```shell > npm pkg set --json "allowScripts[node-llama-cpp]=true" > ``` ## ESM Usage {#esm-usage} `node-llama-cpp` is an [ES module](https://nodejs.org/api/esm.html#modules-ecmascript-modules), so can only use `import` to load it and cannot use `require`. To make sure you can use it in your project, make sure your `package.json` file has `"type": "module"` in it. For workarounds for existing projects, see the [ESM troubleshooting guide](./troubleshooting.md#esm-usage). ## GPU Support {#gpu-support} `node-llama-cpp` automatically detects the available compute layers on your machine and uses the best one by default, as well as balances the default settings to get the best performance from your hardware. No need to manually configure anything. **Metal:** Enabled by default on Macs with Apple Silicon. If you're using a Mac with an Intel chip, [you can manually enable it](./Metal.md). [Accelerate framework](https://developer.apple.com/accelerate/) is always enabled. **CUDA:** Used by default when support is detected. For more details, see the [CUDA guide](./CUDA.md). **Vulkan:** Used by default when support is detected. For more details, see the [Vulkan guide](./Vulkan.md). To inspect your hardware, run this command: ```shell npx --no node-llama-cpp inspect gpu ``` ## Getting a Model File We recommend getting a GGUF model from either [Michael Radermacher on Hugging Face](https://huggingface.co/mradermacher) or by [searching HuggingFace directly](https://huggingface.co/models?library=gguf) for a GGUF model. We recommend starting by getting a small model that doesn't have a lot of parameters just to ensure everything works, so try downloading a `7B`/`8B` parameters model first (search for models with both `7B`/`8B` and `GGUF` in their name). To ensure you can chat with the model, make sure you [choose an Instruct model](./choosing-a-model.md#model-purpose) by looking for `Instruct` or `it` in the model name. For improved download speeds, you can use the [`pull`](../cli/pull.md) command to download a model: ```shell npx --no node-llama-cpp pull --dir ./models ``` ::: tip Not sure what model to get started with? Run the [`chat`](../cli/chat.md) command with no parameters to see a list of recommended models: ```shell npx --no node-llama-cpp chat ``` ::: For more tips on choosing a model, see the [choosing a model guide](./choosing-a-model.md). ## Validating the Model To validate that the model you downloaded is working properly, use the [`chat`](../cli/chat.md) command to chat with it: ```shell npx --no node-llama-cpp chat ``` Try telling the model `Hi there` and see how it reacts. If the response looks weird or doesn't make sense, try using a different model. If the model doesn't stop generating output, try using a different [chat wrapper](./chat-wrapper). For example: ```shell npx --no node-llama-cpp chat --wrapper general ``` > \[!TIP] > To download a model and prompt it right away with a single command, > use the [`chat`](../cli/chat.md) command and pass a model URL together with a `--prompt` flag: > > ```shell > npx --no node-llama-cpp chat --prompt 'Hi there' > ``` ## Usage {#usage} ### Chatbot {#chatbot} ```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-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); ``` > To use a custom chat wrapper, see the [chat wrapper guide](./chat-wrapper). ### Chatbot With JSON Schema {#chatbot-with-json-schema} To enforce a model to generate output according to a JSON schema, use [`llama.createGrammarForJsonSchema()`](../api/classes/Llama.md#creategrammarforjsonschema). It'll force the model to generate output according to the JSON schema you provide, and it'll do it on the text generation level. It only supports [a small subset of the JSON schema spec](../api/type-aliases/GbnfJsonSchema.md), but it's enough to generate useful JSON objects using a text generation model. ::: tip NOTE To learn more about using grammars correctly, read the [grammar guide](./grammar.md). ::: ```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-8B-Instruct.Q4_K_M.gguf") }); const context = await model.createContext(); const session = new LlamaChatSession({ contextSequence: context.getSequence() }); const grammar = await llama.createGrammarForJsonSchema({ type: "object", properties: { positiveWordsInUserMessage: { type: "array", items: { type: "string" } }, userMessagePositivityScoreFromOneToTen: { enum: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] }, nameOfUser: { oneOf: [{ type: "null" }, { type: "string" }] } } }); const prompt = "Hi there! I'm John. Nice to meet you!"; const res = await session.prompt(prompt, {grammar}); const parsedRes = grammar.parse(res); console.log("User name:", parsedRes.nameOfUser); console.log( "Positive words in user message:", parsedRes.positiveWordsInUserMessage ); console.log( "User message positivity score:", parsedRes.userMessagePositivityScoreFromOneToTen ); ``` ### Chatbot With Function Calling {#chatbot-with-function-calling} You can provide functions that the model can call during generation to retrieve information or perform actions. Some models have official support for function calling in `node-llama-cpp` (such as [Functionary](https://huggingface.co/meetkai/functionary-small-v2.5-GGUF/blob/main/functionary-small-v2.5.Q4_0.gguf) and [Llama 3 Instruct](https://huggingface.co/mradermacher/Meta-Llama-3-8B-Instruct-GGUF/blob/main/Meta-Llama-3-8B-Instruct.Q4_K_M.gguf)), while other models fallback to a generic function calling mechanism that works with many models, but not all of them. ::: tip NOTE To learn more about using function calling correctly, read the [function calling guide](./function-calling.md). ::: ```typescript import {fileURLToPath} from "url"; import path from "path"; import {getLlama, LlamaChatSession, defineChatSessionFunction} 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-8B-Instruct.Q4_K_M.gguf") }); const context = await model.createContext(); const session = new LlamaChatSession({ contextSequence: context.getSequence() }); const fruitPrices: Record = { "apple": "$6", "banana": "$4" }; const functions = { getFruitPrice: defineChatSessionFunction({ description: "Get the price of a fruit", params: { type: "object", properties: { name: { type: "string" } } }, async handler(params) { const name = params.name.toLowerCase(); if (Object.keys(fruitPrices).includes(name)) return { name: name, price: fruitPrices[name] }; return `Unrecognized fruit "${params.name}"`; } }) }; const q1 = "Is an apple more expensive than a banana?"; console.log("User: " + q1); const a1 = await session.prompt(q1, {functions}); console.log("AI: " + a1); ``` ### Raw ::: tip NOTE To learn more about using low level APIs, read the [low level API guide](./low-level-api.md). ::: ```typescript import {fileURLToPath} from "url"; import path from "path"; import {getLlama, Token} 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-8B-Instruct.Q4_K_M.gguf") }); const context = await model.createContext(); const sequence = context.getSequence(); const q1 = "Hi there, how are you?"; console.log("User: " + q1); const tokens = model.tokenize("USER: " + q1 + "\nASSISTANT: "); const res: Token[] = []; for await (const generatedToken of sequence.evaluate(tokens)) { res.push(generatedToken); // It's important to not concatenate the results as strings, // as doing so breaks some characters (like some emojis) // that consist of multiple tokens. // By using an array of tokens, we can decode them correctly together. const resString = model.detokenize(res); const lastPart = resString.split("ASSISTANT:").pop(); if (lastPart?.includes("USER:")) break; } const a1 = model.detokenize(res).split("USER:")[0]!; console.log("AI: " + a1.trim()); ``` ## Next Steps {#next-steps} Now that you've learned the basics of `node-llama-cpp`, you can explore more advanced topics by reading the guides in the *Guide* section of the sidebar. Use [GitHub Discussions](https://github.com/withcatai/node-llama-cpp/discussions) to ask questions if you get stuck, and [give `node-llama-cpp` a star on GitHub](https://github.com/withcatai/node-llama-cpp) if you found it useful. Explore the [API reference](../api/functions/getLlama.md) to learn more about the available functions and classes, and use the search bar (press /) to find documentation for a specific topic or API. Check out the [roadmap](https://github.com/orgs/withcatai/projects/1) to see what's coming next, visit the [awesome list](./awesome.md) to find great projects that use `node-llama-cpp`, and consider [sponsoring `node-llama-cpp`](https://github.com/sponsors/giladgd) to accelerate the development of new features. --- --- url: /blog/v3.12-gpt-oss.md description: Learn how to use gpt-oss to its full potential with node-llama-cpp --- # gpt-oss is here! [`node-llama-cpp`](https://node-llama-cpp.withcat.ai) v3.12 is here, with full support for [`gpt-oss`](https://huggingface.co/openai/gpt-oss-20b) models! *** ## gpt-oss [`gpt-oss`](https://huggingface.co/openai/gpt-oss-20b) comes in two flavors: * [`gpt-oss-20b`](https://huggingface.co/openai/gpt-oss-20b) - 21B parameters with 3.6B active parameters * [`gpt-oss-120b`](https://huggingface.co/openai/gpt-oss-120b) - 117B parameters with 5.1B active parameters Here are a few highlights of these models: * Due to the low number of active parameters, these models are very fast * These are reasoning models, and you can adjust their reasoning effort * They are very good at function calling, and are built with agentic capabilities in mind * These models were trained with native MXFP4 precision, so no need to quantize them further. They're small compared to their capabilities already * They are provided with an Apache 2.0 license, so you can use them in your commercial applications ## Recommended Models Here are some recommended model URIs you can use to try out `gpt-oss` right away: | Model | Size | URI | |--------------------------------------------------------------------|--------|-----------------------------------------------------------------------| | [`gpt-oss-20b`](https://huggingface.co/giladgd/gpt-oss-20b-GGUF) | 12.1GB | `hf:giladgd/gpt-oss-20b-GGUF/gpt-oss-20b.MXFP4.gguf` | | [`gpt-oss-120b`](https://huggingface.co/giladgd/gpt-oss-120b-GGUF) | 63.4GB | `hf:giladgd/gpt-oss-120b-GGUF/gpt-oss-120b.MXFP4-00001-of-00002.gguf` | ::: info TIP [Estimate the compatibility](../cli/inspect/estimate.md) of a model with your machine before downloading it: ```shell npx -y node-llama-cpp inspect estimate ``` ::: ## `MXFP4` Quantization You might be used to looking for a `Q4_K_M` quantization because of its good balance between quality and size, and be looking for a `Q4_K_M` quantization of `gpt-oss` models. You don't have to, because these models are already natively provided in a similar quantization format called `MXFP4`. Let's break down what `MXFP4` is: * `MXFP4` stands for Microscaling FP4 (Floating Point, 4-bit). `Q4_K_M` is also a 4-bit quantization. * It's a format what was created and standardized by the Open Compute Project (OCP) in early 2024. OCP is backed by big players like OpenAI, NVIDIA, AMD, Microsoft, and Meta, with the goal of lowering the hardware and compute barriers to running AI models. * Designed to dramatically reduce the memory and compute requirements for training and running AI models, while preserving as much precision as possible. This format was used to train the `gpt-oss` models, so the most precise format of these models is `MXFP4`. Since this is a 4-bit precision format, its size footprint is similar to `Q4_K_M` quantization, but it provides better precision and thus better quality. First class support for `MXFP4` in `llama.cpp` was introduced as part of the `gpt-oss` release. The bottom line is that you don't have to find a `Q4_K_M` quantization of `gpt-oss` models, because the `MXFP4` format is as small, efficient, and fast as `Q4_K_M`, but offers better precision and thus better quality. ### Try It Using the CLI To quickly try out [`gpt-oss-20b`](https://huggingface.co/giladgd/gpt-oss-20b-GGUF), you can use the [CLI `chat` command](../cli/chat.md): ```shell npx -y node-llama-cpp chat --prompt "Hi there" hf:giladgd/gpt-oss-20b-GGUF/gpt-oss-20b.MXFP4.gguf ``` ## `thought` Segments Since `gpt-oss` models are reasoning models, they generate thoughts as part of their response. These thoughts are useful for debugging and understanding the model's reasoning process, and can be used to iterate on the system prompt and inputs you provide to the model to improve its responses. However, OpenAI [emphasizes](https://openai.com/index/chain-of-thought-monitoring/#:~:text=leaving%20CoTs%20unrestricted%20may%20make%20them%20unfit%20to%20be%20shown%20to%20end%2Dusers%2C%20as%20they%20might%20violate%20some%20misuse%20policies) that the thoughts generated by these models may not be safe to show to end users as they are unrestricted and might include sensitive information, uncontained language, hallucinations, or other issues. Thus, OpenAI recommends not showing these to users without further filtering, moderation or summarization. Check out the [segment streaming example](../guide/chat-session.md#stream-response-segments) to learn how to use segments. ## `comment` Segments `gpt-oss` models output "preamble" messages in their response; these are segmented as a new `comment` segment in the model's response. The model might choose to generate those segments to inform the user about the functions it's about to call. For example, when it plans to use multiple functions, it may generate a plan in advance. These are intended for the user to see, but not as part of the main response. Check out the [segment streaming example](../guide/chat-session.md#stream-response-segments) to learn how to use segments. ::: info Experiment with `comment` segments The [Electron app template](../guide/electron.md) has been updated to properly segment comments in the response. Try it out by downloading the latest build [from GitHub](https://github.com/withcatai/node-llama-cpp/releases/latest), or by [scaffolding a new project](../guide/index.md#scaffold-new-project) based on the Electron template: ```shell npm create node-llama-cpp@latest ``` ::: ## Customizing gpt-oss You can adjust `gpt-oss`'s responses by configuring the options of [`HarmonyChatWrapper`](../api/classes/HarmonyChatWrapper.md): ```typescript import { getLlama, resolveModelFile, LlamaChatSession, HarmonyChatWrapper } from "node-llama-cpp"; const modelUri = "hf:giladgd/gpt-oss-20b-GGUF/gpt-oss-20b.MXFP4.gguf"; const llama = await getLlama(); const model = await llama.loadModel({ modelPath: await resolveModelFile(modelUri) }); const context = await model.createContext(); const session = new LlamaChatSession({ contextSequence: context.getSequence(), chatWrapper: new HarmonyChatWrapper({ modelIdentity: "You are ChatGPT, a large language model trained by OpenAI.", reasoningEffort: "high" }) }); const q1 = "What is the weather like in SF?"; console.log("User: " + q1); const a1 = await session.prompt(q1); console.log("AI: " + a1); ``` ### Using Function Calling `gpt-oss` models have great support for function calling. However, these models don't support parallel function calling, so only one function will be called at a time. ```typescript import { getLlama, resolveModelFile, LlamaChatSession, defineChatSessionFunction } from "node-llama-cpp"; const modelUri = "hf:giladgd/gpt-oss-20b-GGUF/gpt-oss-20b.MXFP4.gguf"; const llama = await getLlama(); const model = await llama.loadModel({ modelPath: await resolveModelFile(modelUri) }); const context = await model.createContext(); const session = new LlamaChatSession({ contextSequence: context.getSequence() }); const functions = { getCurrentWeather: defineChatSessionFunction({ description: "Gets the current weather in the provided location.", params: { type: "object", properties: { location: { type: "string", description: "The city and state, e.g. San Francisco, CA" }, format: { enum: ["celsius", "fahrenheit"] } } }, handler({location, format}) { console.log(`Getting current weather for "${location}" in ${format}`); return { // simulate a weather API response temperature: format === "celsius" ? 20 : 68, format }; } }) }; const q1 = "What is the weather like in SF?"; console.log("User: " + q1); const a1 = await session.prompt(q1, {functions}); console.log("AI: " + a1); ``` --- --- url: /guide/low-level-api.md description: Learn how to use the low-level API of node-llama-cpp --- # Low Level API `node-llama-cpp` provides high-level APIs for the most common use cases to make it easy to use. However, it also provides low-level APIs for more advanced use cases. There are various low-level APIs that you can use - the more high level you can go, the more optimizations and features you can leverage. ## Background {#background} Before you can use the low-level API, here are a few concepts you should be familiar with: ### Context Sequence {#context-sequence} A [`LlamaContextSequence`](../api/classes/LlamaContextSequence.md) is an isolated component that holds an inference state. The state is constructed from tokens you evaluate to "append" to the state, and you can access the current state tokens using [`.contextTokens`](../api/classes/LlamaContextSequence.md#contexttokens). When evaluating input (tokens) onto a context sequence, you can choose to generate a "next token" for each of the input tokens you evaluate. When choosing to generate a "next token" for a given token, the model will "see" all the tokens up to it (input tokens and the current context sequence state tokens), and the generated token will be in the generation result you get from the API and won't be appended to the context sequence state. ### Probabilities List {#probabilities-list} When generating a token, the model actually generates a list of probabilities for each token in the vocabulary to be the next token. It then uses the probabilities to choose the next token based on the heuristics you provide (like [`temperature`](../api/type-aliases/SequenceEvaluateOptions#temperature), for example). The operation of applying such heuristics to choose the next token is also called *sampling*. When you pass sampling options (like [`temperature`](../api/type-aliases/SequenceEvaluateOptions#temperature), for example) for the generation of a token, it may make adjustments to the probabilities list so it can choose the next token based on the heuristics you provide. The sampling is done on the native side of `node-llama-cpp` for performance reasons. However, you can still opt to get the full probabilities list after the sampling is done, and you can pass no sampling options to avoid making any adjustments to the probabilities list. It's best to avoid getting the full probabilities list unless you really need it, as passing it to the JavaScript side can be slow. ### Context Shift {#context-shift} When the context sequence is full and you want to evaluate more tokens onto it, some tokens will have to be removed to make room for new ones to be added. Ideally, you'd want to do that on your logic level, so you can control which content to keep and which to remove. > All the high-level APIs of `node-llama-cpp` [automatically do that](./chat-context-shift.md). If you don't do that, `node-llama-cpp` will automatically remove the oldest tokens from the context sequence state to make room for new ones. You can customize the context shift strategy `node-llama-cpp` uses for the context sequence by configuring the [`contextShift`](../api/classes/LlamaContext.md#parameters) option when calling [`.getSequence(...)`](../api/classes/LlamaContext.md#getsequence), or by passing a customized the [`contextShift`](../api/type-aliases/SequenceEvaluateOptions#contextshift) option to the evaluation method you use. ## Simple Evaluation {#simple-evaluation} You can evaluate the given input tokens onto a context sequence using [`.evaluate(...)`](../api/classes/LlamaContextSequence.md#evaluate) and generate the next token for the last input token. On each iteration of the returned iterator, the generated token is then added to the context sequence state and the next token is generated for it, and so on. When using [`.evaluate(...)`](../api/classes/LlamaContextSequence.md#evaluate), the configured [token predictor](./token-prediction.md) is used to speed up the generation process. ```typescript import {fileURLToPath} from "url"; import path from "path"; import {getLlama, Token, SequenceEvaluateOptions} 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-8B-Instruct.Q4_K_M.gguf") }); const context = await model.createContext(); const sequence = context.getSequence(); const input = "The best way to"; const tokens = model.tokenize(input); const maxTokens = 10; const res: Token[] = []; const options: SequenceEvaluateOptions = { temperature: 0.8 }; for await (const generatedToken of sequence.evaluate(tokens, options)) { res.push(generatedToken); if (res.length >= maxTokens) break; } const resText = model.detokenize(res); console.log("Result: " + resText); ``` > For generating text completion, it's better to use [`LlamaCompletion`](./text-completion.md) instead of manually evaluating input, > since it supports all models, and provides many more features and optimizations ### Replacement Token(s) {#replacement-tokens} You can manually iterate over the evaluation iterator and provide a replacement to the generated token. You you provide a replacement token(s), it'll be appended to the context sequence state instead of the generated token. ```typescript import {fileURLToPath} from "url"; import path from "path"; import {getLlama, Token, SequenceEvaluateOptions} 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-8B-Instruct.Q4_K_M.gguf") }); const context = await model.createContext(); const sequence = context.getSequence(); const input = "The best way to"; const tokens = model.tokenize(input); const options: SequenceEvaluateOptions = { temperature: 0.8 }; const maxTokens = 10; const res: Token[] = []; // fill this with tokens to replace const replacementMap = new Map(); const iterator = sequence.evaluate(tokens, options); let replacementToken: Token | undefined; while (true) { const {value: token, done} = await iterator.next(replacementToken); replacementToken = undefined; if (done || token == null) break; replacementToken = replacementMap.get(token); res.push(replacementToken ?? token); if (res.length >= maxTokens) break; } const resText = model.detokenize(res); console.log("Result: " + resText); ``` > If you want to adjust the token probabilities when generating output, consider using [token bias](./token-bias.md) instead ### With Metadata {#evaluation-with-metadata} You can use [`.evaluateWithMetadata(...)`](../api/classes/LlamaContextSequence.md#evaluatewithmetadata) to evaluate tokens onto the context sequence state like [`.evaluate(...)`](#simple-evaluation), but with metadata emitted for each token. ```typescript import {fileURLToPath} from "url"; import path from "path"; import {getLlama, Token, SequenceEvaluateOptions} 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-8B-Instruct.Q4_K_M.gguf") }); const context = await model.createContext(); const sequence = context.getSequence(); const input = "The best way to"; const tokens = model.tokenize(input); const maxTokens = 10; const res: Array<{ token: Token, confidence: number, probabilities: Map }> = []; const metadataOptions = { // configure which metadata should be returned confidence: true, probabilities: true } as const; const options: SequenceEvaluateOptions = { temperature: 0.8 }; const iterator = sequence.evaluateWithMetadata( tokens, metadataOptions, options ); for await (const item of iterator) { res.push({ token: item.token, confidence: item.confidence, probabilities: new Map( // only keep the top 5 probabilities [...item.probabilities.entries()].slice(0, 5) ) }); if (res.length >= maxTokens) break; } const resText = model.detokenize(res.map(({token}) => token)); console.log("Result: " + resText); console.log("With metadata:", res); ``` ### No Generation {#evaluation-without-generation} To evaluate the input tokens onto a context sequence without generating new tokens, you can use [`.evaluateWithoutGeneratingNewTokens(...)`](../api/classes/LlamaContextSequence.md#evaluatewithoutgeneratingnewtokens). ```typescript import {fileURLToPath} from "url"; import path from "path"; import {getLlama} 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-8B-Instruct.Q4_K_M.gguf") }); const context = await model.createContext(); const sequence = context.getSequence(); const input = "The best way to"; const tokens = model.tokenize(input); await sequence.evaluateWithoutGeneratingNewTokens(tokens); ``` ## Controlled Evaluation {#controlled-evaluation} To manually control for which of the input tokens to generate output, you can use [`.controlledEvaluate(...)`](../api/classes/LlamaContextSequence.md#controlledevaluate). ```typescript import {fileURLToPath} from "url"; import path from "path"; import {getLlama, Token, ControlledEvaluateInputItem} 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-8B-Instruct.Q4_K_M.gguf") }); const context = await model.createContext(); const sequence = context.getSequence(); const input = "The best way to"; const tokens = model.tokenize(input); const evaluateInput: ControlledEvaluateInputItem[] = tokens.slice(); // generate output for the last token only const lastToken = evaluateInput.pop() as Token; if (lastToken != null) evaluateInput.push([lastToken, { generateNext: { token: true, probabilities: true, options: { temperature: 0.8 } } }]) const res = await sequence.controlledEvaluate(evaluateInput); const lastTokenResult = res[evaluateInput.length - 1]; if (lastTokenResult != null) { const {next} = lastTokenResult; if (next.token != null) console.log( "next token", next.token, model.detokenize([next.token], true) ); if (next.probabilities != null) console.log( "next probabilities", [...next.probabilities.entries()] .slice(0, 5) // top 5 probabilities .map(([token, probability]) => ( [model.detokenize([token], true), probability] )) ); // next: evalute `next.token` onto the context sequence // and generate the next token for it } ``` ## State Manipulation {#state-manipulation} You can manipulate the context sequence state by erasing tokens from it or shifting tokens in it. Make sure that you don't attempt to manipulate the state while waiting for a generation result from an evaluation operation, as it may lead to unexpected results. ### Erase State Ranges {#erase-state-ranges} To erase a range of tokens from the context sequence state, you can use [`.eraseContextTokenRanges(...)`](../api/classes/LlamaContextSequence.md#erasecontexttokenranges). ```typescript import {fileURLToPath} from "url"; import path from "path"; import {getLlama} 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-8B-Instruct.Q4_K_M.gguf") }); const context = await model.createContext(); const sequence = context.getSequence(); const input = "The best way to"; const tokens = model.tokenize(input); await sequence.evaluateWithoutGeneratingNewTokens(tokens); console.log( "Current state:", model.detokenize(sequence.contextTokens, true), sequence.contextTokens ); // erase the last token from the state if (sequence.nextTokenIndex > 0) await sequence.eraseContextTokenRanges([{ start: sequence.nextTokenIndex - 1, end: sequence.nextTokenIndex }]); console.log( "Current state:", model.detokenize(sequence.contextTokens, true), sequence.contextTokens ); ``` ### Adapt State to Tokens {#adapt-state-to-tokens} You can adapt the existing context state to a new input to avoid re-evaluating some of the tokens you've already evaluated. ::: tip NOTE All the high-level APIs provided by `node-llama-cpp` automatically do this to improve efficiency and performance. ::: ```typescript import {fileURLToPath} from "url"; import path from "path"; import {getLlama} 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-8B-Instruct.Q4_K_M.gguf") }); const context = await model.createContext(); const sequence = context.getSequence(); const input = "The best way to"; const tokens = model.tokenize(input); await sequence.evaluateWithoutGeneratingNewTokens(tokens); console.log( "Current state:", model.detokenize(sequence.contextTokens, true), sequence.contextTokens ); const newInput = "The best method to"; const newTokens = model.tokenize(newInput); // only align the current state if the length // of the new tokens won't incur a context shift if (newTokens.length < sequence.contextSize && newTokens.length > 0) { // ensure we have at least one token to evalute const lastToken = newTokens.pop()!; await sequence.adaptStateToTokens(newTokens); newTokens.push(lastToken); // remove the tokens that already exist in the state newTokens.splice(0, sequence.nextTokenIndex) } console.log( "Current state:", model.detokenize(sequence.contextTokens, true), sequence.contextTokens ); console.log( "New tokens:", model.detokenize(newTokens, true), newTokens ); ``` ### Save and Restore State {#save-and-restore-state} You can save the evaluation state of a context sequence to then later load it back. This is useful for avoiding the evaluation of tokens that you've already evaluated in the past. ::: warning When loading a context sequence state from a file, always ensure that the model used to create the context sequence is exactly the same as the one used to save the state file. Loading a state file created from a different model can crash the process, thus you have to pass `{acceptRisk: true}` to the [`loadStateFromFile`](../api/classes/LlamaContextSequence.md#loadstatefromfile) method to use it. Use with caution. ::: ::: code-group ```typescript [Save state] import {fileURLToPath} from "url"; import path from "path"; import {getLlama} 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-8B-Instruct.Q4_K_M.gguf") }); const context = await model.createContext(); const sequence = context.getSequence(); const input = "The best way to"; const tokens = model.tokenize(input); await sequence.evaluateWithoutGeneratingNewTokens(tokens); console.log( "Current state:", model.detokenize(sequence.contextTokens, true), sequence.contextTokens ); await sequence.saveStateToFile("state.bin");// [!code highlight] ``` ::: ::: code-group ```typescript [Load state] import {fileURLToPath} from "url"; import path from "path"; import {getLlama, Token} from "node-llama-cpp"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); // ---cut--- const llama = await getLlama(); const model = await llama.loadModel({ modelPath: path.join(__dirname, "models", "Meta-Llama-3-8B-Instruct.Q4_K_M.gguf") }); const context = await model.createContext(); const sequence = context.getSequence(); await sequence.loadStateFromFile("state.bin", {acceptRisk: true});// [!code highlight] console.log( "Loaded state:", model.detokenize(sequence.contextTokens, true), sequence.contextTokens ); const input = " find"; const inputTokens = model.tokenize(input); const maxTokens = 10; const res: Token[] = []; for await (const token of sequence.evaluate(inputTokens)) { res.push(token); if (res.length >= maxTokens) break; } console.log("Result:", model.detokenize(res)); ``` ::: --- --- url: /guide/Metal.md description: Metal support in node-llama-cpp --- # Metal Support > Metal is a low-level 3D graphics and compute API created by Apple for Apple platforms Metal support is enabled by default on macOS on Apple Silicon Macs, and is disabled by default on Intel Macs. The pre-built binaries of `node-llama-cpp` for macOS are built with Metal support enabled for Apple Silicon Macs, and when building from source on macOS on Apple Silicon Macs, Metal support is enabled by default. `llama.cpp` doesn't support Metal well on Intel Macs, so it is disabled by default on those machines. [Accelerate framework](https://developer.apple.com/accelerate/) is always enabled on Mac. ## Toggling Metal Support {#building} ### Prerequisites * [`cmake-js` dependencies](https://github.com/cmake-js/cmake-js#:~:text=%5Bstring%5D-,Requirements%3A,-CMake) * [CMake](https://cmake.org/download/) 3.26 or higher (optional, recommended if you have build issues) ### Building `node-llama-cpp` With Metal Support Disabled Run this command inside of your project: ```shell npx --no node-llama-cpp source download --gpu false ``` > If `cmake` is not installed on your machine, `node-llama-cpp` will automatically download `cmake` to an internal directory and try to use it to build `llama.cpp` from source. ### Building `node-llama-cpp` With Metal Support Enabled Run this command inside of your project: ```shell npx --no node-llama-cpp source download --gpu metal ``` > If `cmake` is not installed on your machine, `node-llama-cpp` will automatically download `cmake` to an internal directory and try to use it to build `llama.cpp` from source. --- --- url: /blog/v3.md description: Learn more about the new features in node-llama-cpp v3.0! --- # node-llama-cpp v3.0 [`node-llama-cpp`](https://node-llama-cpp.withcat.ai) 3.0 is finally here. With [`node-llama-cpp`](https://node-llama-cpp.withcat.ai), you can run large language models locally on your machine using the power of [`llama.cpp`](https://github.com/ggml-org/llama.cpp) with a simple and easy-to-use API. It includes everything you need, from downloading models, to running them in the most optimized way for your hardware, and integrating them in your projects. *** ## Why `node-llama-cpp`? You might be wondering, why choose `node-llama-cpp` over using an OpenAI API of a service running on your machine? The answer is simple: simplicity, performance, and flexibility. Let's break it down: ### Simplicity To use `node-llama-cpp`, you install it like any other npm package, and you're good to go. To run your project, all you have to do is `npm install` and `npm start`. That's it. No installing additional software on your machine, no setting up API keys or environment variables, no setup process at all. Everything is self-contained in your project, giving you complete control over it. With `node-llama-cpp`, you can run large language models on your machine using Node.js and TypeScript, *without* any Python at all. Say goodbye to setup headaches, "it works on my machine" issues, and all other Python-related problems. While `llama.cpp` is an amazing project, it's also highly technical and can be challenging for beginners. `node-llama-cpp` bridge that gap, making `llama.cpp` accessible to everyone, regardless of their experience level. ### Performance [`node-llama-cpp`](https://node-llama-cpp.withcat.ai) is built on top of [`llama.cpp`](https://github.com/ggml-org/llama.cpp), a highly optimized C++ library for running large language models. `llama.cpp` supports many compute backends, including Metal, CUDA, and Vulkan. It also uses [Accelerate](https://developer.apple.com/accelerate/) on Mac. `node-llama-cpp` automatically adapts to your hardware and adjusts the default settings to give you the best performance, so you don't *have* to configure anything to use it. By using `node-llama-cpp` you are essentially running models *inside* your project. With no overhead of network calls or data serializations, you can more effectively take advantage of the stateful nature of inference operations. For example, you can prompt a model on top of an existing conversation inference state, without re-evaluating the entire history just to process the new prompt. This reduces the time it takes to start generating a response, and makes more efficient use of your resources. If you were using an API, you would have to re-evaluate the entire history every time you prompt the model, or have the API store the state for you, which can use huge amounts of disk space. ### Flexibility Since `node-llama-cpp` runs inside your project, you can also deploy it together with your project. You can run models in your [Electron](../guide/electron.md) app without requiring any additional setup on the user's machine. You can build libraries that use large language models and distribute them as npm packages, or deploy self-contained Docker images and run them on any hardware you want. You can use [any model you want](../guide/choosing-a-model.md), or even create your own and use it with `node-llama-cpp`. Download models [as part of `npm install`](../guide/downloading-models.md) or [on-demand from your code](../guide/downloading-models.md#programmatic). [Tweak inference settings](../guide/chat-session.md#repeat-penalty) to get better results for your particular use case. `node-llama-cpp` is regularly updated with the latest `llama.cpp` release, but you can also [download and build the latest release](../guide/building-from-source.md#download-new-release) at any time with a single command. The possibilities are endless. You have full control over the models you use, how you use them, and where you use them. You can tailor `node-llama-cpp` to your needs in ways that aren't possible with an OpenAI API (at least not efficiently or easily). ## Powerful Features `node-llama-cpp` includes a complete suite of everything you need to use large language models in your projects, with convenient wrappers for popular tasks, such as: * [Enforcing a JSON schema](../guide/chat-session.md#response-json-schema) on the output the model generates * Providing the model with [functions it can call on demand](../guide/chat-session.md#function-calling) to retrieve information or perform actions, even with some models that don't officially support it * [Generating completion](../guide/text-completion.md) for a given text * [Embedding text](../guide/embedding.md) for similarity searches or other tasks * Much more ## Why Node.js? JavaScript is the most popular programming language in the world, and Node.js is the most popular runtime for JavaScript server-side applications. Developers choose Node.js for its versatility, reliability, ease of use, forward compatibility, and the vast ecosystem of npm packages. While Python is currently the go-to language for data science and machine learning, the needs of data scientists differ from those of developers building services and applications. `node-llama-cpp` bridges this gap, making it easier to integrate large language models into Node.js and Electron projects, while focusing on the needs of developers building services and applications. ## Try It Out `node-llama-cpp` comes with comprehensive documentation, covering everything from installation to advanced usage. It's beginner-friendly, with explanations for every step of the way for those who are new to the world of large language models, while still being flexible enough to allow advanced usage for those who are more experienced and knowledgeable. Experience the ease of running models on your machine with this single command: ```shell npx -y node-llama-cpp chat ``` Check out the [getting started guide](../guide/index.md) to learn how to use `node-llama-cpp`. ## Thank You `node-llama-cpp` is only possible thanks to the amazing work done on [`llama.cpp`](https://github.com/ggml-org/llama.cpp) by [Georgi Gerganov](https://github.com/ggerganov), [Slaren](https://github.com/slaren) and all the contributors from the community. ## What's next? Version 3.0 is a major milestone, but there's plenty more planned for the future. Check out the [roadmap](https://github.com/orgs/withcatai/projects/1) to see what's coming next, and [give `node-llama-cpp` a star on GitHub](https://github.com/withcatai/node-llama-cpp) to support the project. --- --- url: /guide/objects-lifecycle.md description: Objects lifecycle in node-llama-cpp --- # Objects Lifecycle Every object in `node-llama-cpp` has a ` .dispose()` function you can call to free up its resources. Calling the `.dispose()` function on an object also disposes all of its dependant objects. For example, calling [`.dispose()`](../api/classes/LlamaModel.md#dispose) on a model automatically disposes all of its contexts: ```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 modelPath = path.join(__dirname, "my-model.gguf"); // ---cut--- const llama = await getLlama(); const model = await llama.loadModel({modelPath}); const context = await model.createContext(); await model.dispose(); console.log("Context disposed:", context.disposed); // true ``` > You cannot use a disposed object after disposing it. > > Attempting to create a context from a disposed model will throw a `DisposedError`, > attempting to evaluate input on a disposed context sequence will also throw a `DisposedError`, etc. To automatically dispose an object when it goes out of scope, you can use [`await using` in TypeScript](https://devblogs.microsoft.com/typescript/announcing-typescript-5-2/#using-declarations-and-explicit-resource-management) (TypeScript 5.2 or later): ```typescript import {fileURLToPath} from "url"; import path from "path"; import {getLlama, LlamaChatSession, LlamaContext} from "node-llama-cpp"; const __dirname = path.dirname( fileURLToPath(import.meta.url) ); const modelPath = path.join(__dirname, "my-model.gguf"); // ---cut--- const llama = await getLlama(); let context: LlamaContext | undefined; async function doThings() { await using model = await llama.loadModel({modelPath}); context = await model.createContext(); } await doThings(); // the model is disposed when the `doThings` function is done, // and so are its contexts console.log("Context disposed:", context?.disposed); // true ``` ## Garbage Collection If you forget to dispose an object, it will automatically be disposed when the garbage collector runs. It's best to dispose objects yourself to free up resources as soon as you're done with them, so you can allocate new resources sooner when needed. Disposing objects yourself can make a big difference in what you can do with the resources you have available, especially since models and contexts use a lot of VRAM. ## Llama Instances Every call to [`getLlama`](../api/functions/getLlama.md) creates a new instance of [`Llama`](../api/classes/Llama.md) that allocates its own resources, so it's best to create a single instance and reuse it throughout your entire application. You can do so by creating a `llama.ts` file and exporting the instance from there: ::: code-group ```typescript [llama.ts] import {getLlama} from "node-llama-cpp"; export const llama = await getLlama();// [!code highlight] ``` ```typescript [index.ts] // @filename: llama.ts import {getLlama} from "node-llama-cpp"; export const llama = await getLlama(); // @filename: index.ts // ---cut--- import {fileURLToPath} from "url"; import path from "path"; import {llama} from "./llama.js";// [!code highlight] const __dirname = path.dirname(fileURLToPath(import.meta.url)); const modelPath = path.join(__dirname, "my-model.gguf"); const model = await llama.loadModel({modelPath}); ``` ```typescript [vram.ts] // @filename: llama.ts import {getLlama} from "node-llama-cpp"; export const llama = await getLlama(); // @filename: memory.ts // ---cut--- import {llama} from "./llama.js";// [!code highlight] export async function logVramState() { const vramState = await llama.getVramState(); console.log("Used VRAM:", vramState.used); console.log("Free VRAM:", vramState.free); } ``` ::: ## Reusing Existing Context Sequence State When prompting a model using [`LlamaChatSession`](../api/classes/LlamaChatSession.md) or [`LlamaChat`](../api/classes/LlamaChat.md), it attempts to use the existing context sequence state as much as possible to avoid redundant evaluations, but when needed, it'll flush irrelevant parts of the state (or all of it) to perform the requested evaluation. You can reuse a context sequence for a new [`LlamaChatSession`](../api/classes/LlamaChatSession.md) or [`LlamaChat`](../api/classes/LlamaChat.md) without worrying about data leakage between different chat sessions. You'll probably want to do so to utilize the existing state for faster evaluation using the new chat, since the preamble system prompt and other chat history items may have already been evaluated in the existing context sequence, so reusing the context sequence for a new chat will allow it to automatically continue evaluation from the first difference in the existing state, thus reducing the time needed to start generating output. ::: warning It's important to make sure you don't use the same context sequence for multiple chats *at the same time*, as it'll cause the chats to compete for the same resources and may lead to unexpected results. Always make sure you're done with the existing chat before reusing the context sequence for a new chat. ::: ## Objects Relationship ### [`Llama`](../api/classes/Llama.md) The main class returned by the [`getLlama()`](../api/functions/getLlama.md) method that provides access to `llama.cpp` APIs as well as additional native APIs. ### [`LlamaModel`](../api/classes/LlamaModel.md) A model loaded using the [`.loadModel()`](../api/classes/Llama.md#loadmodel) method of a [`Llama`](../api/classes/Llama.md) instance. ### [`LlamaContext`](../api/classes/LlamaContext.md) A context created using the [`.createContext()`](../api/classes/LlamaModel.md#createcontext) method of a [`LlamaModel`](../api/classes/LlamaModel.md) instance. A context can hold [multiple context sequences](./batching.md). Having multiple context sequences is more efficient and performant than creating multiple contexts, and allows using [batching](./batching.md). ### [`LlamaContextSequence`](../api/classes/LlamaContextSequence.md) A context sequence created using the [`.createContextSequence()`](../api/classes/LlamaContext.md#createcontextsequence) method of a [`LlamaContext`](../api/classes/LlamaContext.md) instance. A context sequence holds a state ([usually tokens](../api/classes/LlamaContextSequence.md#contexttokens)) of the conversation and is used to generate completions and evaluate inputs. All context sequences are independent of each other and do not share data between them. ### [`LlamaChatSession`](../api/classes/LlamaChatSession.md) A chat session created with a [`LlamaContextSequence`](../api/classes/LlamaContextSequence.md) instance. A chat session is used to prompt a model with a conversation history and generate responses. The existing state of the context sequence will be overridden if it cannot be reused for the chat session. You don't need to provide a clean context sequence for a [`LlamaChatSession`](../api/classes/LlamaChatSession.md) to work as expected. --- --- url: /guide/contributing.md description: Contributing to node-llama-cpp --- # Opening a PR on `node-llama-cpp` This document describes the guidelines of how to open a PR on the `node-llama-cpp` project. ## Development To set up your development environment, read the [development guide](./development.md). ## Commit Message Guidelines {#commit} This repository has very precise rules over how git commit messages can be formatted. This leads to **more readable messages** that are easy to follow when looking through the **project history**. But also, git commit messages as used to **generate changelog**. ### Commit Message Format Each commit message consists of a **header**, a **body** and a **footer**. The header has a special format that includes a **type** and a **subject**: ``` :