Skip to content

Class: JinjaTemplateChatWrapper

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: "<Jinja template here>",
    // functionCallMessageTemplate: { // optional
    //     call: "[[call: {{functionName}}({{functionParams}})]]",
    //     result: " [[result: {{functionCallResult}}]]"
    // }
});

Extends

Constructors

new JinjaTemplateChatWrapper()

ts
new JinjaTemplateChatWrapper(options: JinjaTemplateChatWrapperOptions): JinjaTemplateChatWrapper

Parameters

ParameterTypeDescription
optionsJinjaTemplateChatWrapperOptions

Returns

JinjaTemplateChatWrapper

Overrides

ChatWrapper.constructor

Defined in

chatWrappers/generic/JinjaTemplateChatWrapper.ts:119

Properties

defaultSettings

ts
static defaultSettings: ChatWrapperSettings;

Inherited from

ChatWrapper.defaultSettings

Defined in

ChatWrapper.ts:11


wrapperName

ts
readonly wrapperName: "JinjaTemplate" = "JinjaTemplate";

Overrides

ChatWrapper.wrapperName

Defined in

chatWrappers/generic/JinjaTemplateChatWrapper.ts:102


settings

ts
readonly settings: ChatWrapperSettings;

Overrides

ChatWrapper.settings

Defined in

chatWrappers/generic/JinjaTemplateChatWrapper.ts:103


template

ts
readonly template: string;

Defined in

chatWrappers/generic/JinjaTemplateChatWrapper.ts:105


modelRoleName

ts
readonly modelRoleName: string;

Defined in

chatWrappers/generic/JinjaTemplateChatWrapper.ts:106


userRoleName

ts
readonly userRoleName: string;

Defined in

chatWrappers/generic/JinjaTemplateChatWrapper.ts:107


systemRoleName

ts
readonly systemRoleName: string;

Defined in

chatWrappers/generic/JinjaTemplateChatWrapper.ts:108


convertUnsupportedSystemMessagesToUserMessages?

ts
readonly optional convertUnsupportedSystemMessagesToUserMessages: JinjaTemplateChatWrapperOptionsConvertMessageFormat;

Defined in

chatWrappers/generic/JinjaTemplateChatWrapper.ts:109


joinAdjacentMessagesOfTheSameType

ts
readonly joinAdjacentMessagesOfTheSameType: boolean;

Defined in

chatWrappers/generic/JinjaTemplateChatWrapper.ts:110


trimLeadingWhitespaceInResponses

ts
readonly trimLeadingWhitespaceInResponses: boolean;

Defined in

chatWrappers/generic/JinjaTemplateChatWrapper.ts:111


additionalRenderParameters?

ts
readonly optional additionalRenderParameters: Record<string, any>;

Defined in

chatWrappers/generic/JinjaTemplateChatWrapper.ts:112

Methods

generateFunctionCallsAndResults()

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

Parameters

ParameterTypeDefault value
functionCallsChatModelFunctionCall[]undefined
useRawCallbooleantrue

Returns

LlamaText

Inherited from

ChatWrapper.generateFunctionCallsAndResults

Defined in

ChatWrapper.ts:55


generateFunctionCall()

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

Parameters

ParameterType
namestring
paramsany

Returns

LlamaText

Inherited from

ChatWrapper.generateFunctionCall

Defined in

ChatWrapper.ts:102


generateFunctionCallResult()

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

Parameters

ParameterType
functionNamestring
functionParamsany
resultany

Returns

LlamaText

Inherited from

ChatWrapper.generateFunctionCallResult

Defined in

ChatWrapper.ts:116


generateModelResponseText()

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

Parameters

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

Returns

LlamaText

Inherited from

ChatWrapper.generateModelResponseText

Defined in

ChatWrapper.ts:140


generateAvailableFunctionsSystemText()

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

Parameters

ParameterType
availableFunctionsChatModelFunctions
__namedParametersobject
__namedParameters.documentParams?boolean

Returns

LlamaText

Inherited from

ChatWrapper.generateAvailableFunctionsSystemText

Defined in

ChatWrapper.ts:170


addAvailableFunctionsSystemMessageToHistory()

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

Parameters

ParameterType
historyreadonly ChatHistoryItem[]
availableFunctions?ChatModelFunctions
__namedParameters?object
__namedParameters.documentParams?boolean

Returns

readonly ChatHistoryItem[]

Inherited from

ChatWrapper.addAvailableFunctionsSystemMessageToHistory

Defined in

ChatWrapper.ts:196


generateInitialChatHistory()

ts
generateInitialChatHistory(__namedParameters: ChatWrapperGenerateInitialHistoryOptions): ChatHistoryItem[]

Parameters

ParameterType
__namedParametersChatWrapperGenerateInitialHistoryOptions

Returns

ChatHistoryItem[]

Inherited from

ChatWrapper.generateInitialChatHistory

Defined in

ChatWrapper.ts:217


generateContextState()

ts
generateContextState(__namedParameters: ChatWrapperGenerateContextStateOptions): ChatWrapperGeneratedContextState & {
  transformedSystemMessagesToUserMessages: boolean;
}

Parameters

ParameterType
__namedParametersChatWrapperGenerateContextStateOptions

Returns

ChatWrapperGeneratedContextState & { transformedSystemMessagesToUserMessages: boolean; }

Overrides

ChatWrapper.generateContextState

Defined in

chatWrappers/generic/JinjaTemplateChatWrapper.ts:162