Skip to content

Class: TemplateChatWrapper

Defined in: chatWrappers/generic/TemplateChatWrapper.ts:56

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}}]]"
    // }
});

{{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.

Extends

Constructors

new TemplateChatWrapper()

ts
new TemplateChatWrapper(__namedParameters: TemplateChatWrapperOptions): TemplateChatWrapper

Defined in: chatWrappers/generic/TemplateChatWrapper.ts:71

Parameters

ParameterType
__namedParametersTemplateChatWrapperOptions

Returns

TemplateChatWrapper

Overrides

ChatWrapper.constructor

Properties

defaultSettings

ts
static defaultSettings: ChatWrapperSettings;

Defined in: ChatWrapper.ts:11

Inherited from

ChatWrapper.defaultSettings


wrapperName

ts
readonly wrapperName: "Template" = "Template";

Defined in: chatWrappers/generic/TemplateChatWrapper.ts:57

Overrides

ChatWrapper.wrapperName


settings

ts
readonly settings: ChatWrapperSettings;

Defined in: chatWrappers/generic/TemplateChatWrapper.ts:58

Overrides

ChatWrapper.settings


template

ts
readonly template: 
  | `${string}${string}${string}`
  | `${string}${string}${string}${string}`;

Defined in: chatWrappers/generic/TemplateChatWrapper.ts:60


historyTemplate

ts
readonly historyTemplate: Readonly<{
  system: `${string}${string}`;
  user: `${string}${string}`;
  model: `${string}${string}`;
 }>;

Defined in: chatWrappers/generic/TemplateChatWrapper.ts:61


joinAdjacentMessagesOfTheSameType

ts
readonly joinAdjacentMessagesOfTheSameType: boolean;

Defined in: chatWrappers/generic/TemplateChatWrapper.ts:62

Methods

generateFunctionCallsAndResults()

ts
generateFunctionCallsAndResults(functionCalls: ChatModelFunctionCall[], useRawCall: boolean): LlamaText

Defined in: ChatWrapper.ts:55

Parameters

ParameterTypeDefault value
functionCallsChatModelFunctionCall[]undefined
useRawCallbooleantrue

Returns

LlamaText

Inherited from

ChatWrapper.generateFunctionCallsAndResults


generateFunctionCall()

ts
generateFunctionCall(name: string, params: any): LlamaText

Defined in: ChatWrapper.ts:102

Parameters

ParameterType
namestring
paramsany

Returns

LlamaText

Inherited from

ChatWrapper.generateFunctionCall


generateFunctionCallResult()

ts
generateFunctionCallResult(
   functionName: string, 
   functionParams: any, 
   result: any): LlamaText

Defined in: ChatWrapper.ts:116

Parameters

ParameterType
functionNamestring
functionParamsany
resultany

Returns

LlamaText

Inherited from

ChatWrapper.generateFunctionCallResult


generateModelResponseText()

ts
generateModelResponseText(modelResponse: (
  | string
  | ChatModelFunctionCall)[], useRawCall: boolean): LlamaText

Defined in: ChatWrapper.ts:140

Parameters

ParameterTypeDefault value
modelResponse( | string | ChatModelFunctionCall)[]undefined
useRawCallbooleantrue

Returns

LlamaText

Inherited from

ChatWrapper.generateModelResponseText


generateAvailableFunctionsSystemText()

ts
generateAvailableFunctionsSystemText(availableFunctions: ChatModelFunctions, __namedParameters: {
  documentParams: boolean;
 }): LlamaText

Defined in: ChatWrapper.ts:170

Parameters

ParameterType
availableFunctionsChatModelFunctions
__namedParameters{ documentParams: boolean; }
__namedParameters.documentParams?boolean

Returns

LlamaText

Inherited from

ChatWrapper.generateAvailableFunctionsSystemText


addAvailableFunctionsSystemMessageToHistory()

ts
addAvailableFunctionsSystemMessageToHistory(
   history: readonly ChatHistoryItem[], 
   availableFunctions?: ChatModelFunctions, 
   __namedParameters?: {
  documentParams: boolean;
 }): readonly ChatHistoryItem[]

Defined in: ChatWrapper.ts:196

Parameters

ParameterType
historyreadonly ChatHistoryItem[]
availableFunctions?ChatModelFunctions
__namedParameters?{ documentParams: boolean; }
__namedParameters.documentParams?boolean

Returns

readonly ChatHistoryItem[]

Inherited from

ChatWrapper.addAvailableFunctionsSystemMessageToHistory


generateInitialChatHistory()

ts
generateInitialChatHistory(__namedParameters: ChatWrapperGenerateInitialHistoryOptions): ChatHistoryItem[]

Defined in: ChatWrapper.ts:217

Parameters

ParameterType
__namedParametersChatWrapperGenerateInitialHistoryOptions

Returns

ChatHistoryItem[]

Inherited from

ChatWrapper.generateInitialChatHistory


generateContextState()

ts
generateContextState(__namedParameters: ChatWrapperGenerateContextStateOptions): ChatWrapperGeneratedContextState

Defined in: chatWrappers/generic/TemplateChatWrapper.ts:102

Parameters

ParameterType
__namedParametersChatWrapperGenerateContextStateOptions

Returns

ChatWrapperGeneratedContextState

Overrides

ChatWrapper.generateContextState