Class: TemplateChatWrapper
A chat wrapper based on a simple template.
Example
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()
new TemplateChatWrapper(__namedParameters: TemplateChatWrapperOptions): TemplateChatWrapper
Parameters
Parameter | Type |
---|---|
__namedParameters | TemplateChatWrapperOptions |
Returns
Overrides
Defined in
chatWrappers/generic/TemplateChatWrapper.ts:71
Properties
defaultSettings
static defaultSettings: ChatWrapperSettings;
Inherited from
Defined in
wrapperName
readonly wrapperName: "Template" = "Template";
Overrides
Defined in
chatWrappers/generic/TemplateChatWrapper.ts:57
settings
readonly settings: ChatWrapperSettings;
Overrides
Defined in
chatWrappers/generic/TemplateChatWrapper.ts:58
template
readonly template: `${string}${string}${string}` | `${string}${string}${string}${string}`;
Defined in
chatWrappers/generic/TemplateChatWrapper.ts:60
historyTemplate
readonly historyTemplate: Readonly<{
system: `${string}${string}`;
user: `${string}${string}`;
model: `${string}${string}`;
}>;
Type declaration
system
system: `${string}${string}`;
user
user: `${string}${string}`;
model
model: `${string}${string}`;
Defined in
chatWrappers/generic/TemplateChatWrapper.ts:61
joinAdjacentMessagesOfTheSameType
readonly joinAdjacentMessagesOfTheSameType: boolean;
Defined in
chatWrappers/generic/TemplateChatWrapper.ts:62
Methods
generateFunctionCallsAndResults()
generateFunctionCallsAndResults(functionCalls: ChatModelFunctionCall[], useRawCall: boolean): LlamaText
Parameters
Parameter | Type | Default value |
---|---|---|
functionCalls | ChatModelFunctionCall [] | undefined |
useRawCall | boolean | true |
Returns
Inherited from
ChatWrapper
.generateFunctionCallsAndResults
Defined in
generateFunctionCall()
generateFunctionCall(name: string, params: any): LlamaText
Parameters
Parameter | Type |
---|---|
name | string |
params | any |
Returns
Inherited from
ChatWrapper
.generateFunctionCall
Defined in
generateFunctionCallResult()
generateFunctionCallResult(
functionName: string,
functionParams: any,
result: any): LlamaText
Parameters
Parameter | Type |
---|---|
functionName | string |
functionParams | any |
result | any |
Returns
Inherited from
ChatWrapper
.generateFunctionCallResult
Defined in
generateModelResponseText()
generateModelResponseText(modelResponse: (string | ChatModelFunctionCall)[], useRawCall: boolean): LlamaText
Parameters
Parameter | Type | Default value |
---|---|---|
modelResponse | (string | ChatModelFunctionCall )[] | undefined |
useRawCall | boolean | true |
Returns
Inherited from
ChatWrapper
.generateModelResponseText
Defined in
generateAvailableFunctionsSystemText()
generateAvailableFunctionsSystemText(availableFunctions: ChatModelFunctions, __namedParameters: {
documentParams: true;
}): LlamaText
Parameters
Parameter | Type |
---|---|
availableFunctions | ChatModelFunctions |
__namedParameters | object |
__namedParameters.documentParams ? | boolean |
Returns
Inherited from
ChatWrapper
.generateAvailableFunctionsSystemText
Defined in
addAvailableFunctionsSystemMessageToHistory()
addAvailableFunctionsSystemMessageToHistory(
history: readonly ChatHistoryItem[],
availableFunctions?: ChatModelFunctions,
__namedParameters?: {
documentParams: true;
}): readonly ChatHistoryItem[]
Parameters
Parameter | Type |
---|---|
history | readonly ChatHistoryItem [] |
availableFunctions ? | ChatModelFunctions |
__namedParameters ? | object |
__namedParameters.documentParams ? | boolean |
Returns
readonly ChatHistoryItem
[]
Inherited from
ChatWrapper
.addAvailableFunctionsSystemMessageToHistory
Defined in
generateInitialChatHistory()
generateInitialChatHistory(__namedParameters: ChatWrapperGenerateInitialHistoryOptions): ChatHistoryItem[]
Parameters
Parameter | Type |
---|---|
__namedParameters | ChatWrapperGenerateInitialHistoryOptions |
Returns
Inherited from
ChatWrapper
.generateInitialChatHistory
Defined in
generateContextState()
generateContextState(__namedParameters: ChatWrapperGenerateContextStateOptions): ChatWrapperGeneratedContextState
Parameters
Parameter | Type |
---|---|
__namedParameters | ChatWrapperGenerateContextStateOptions |
Returns
ChatWrapperGeneratedContextState
Overrides
ChatWrapper
.generateContextState