Class: TemplateChatWrapper
Defined in: chatWrappers/generic/TemplateChatWrapper.ts:56
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
Defined in: chatWrappers/generic/TemplateChatWrapper.ts:71
Parameters
Parameter | Type |
---|---|
__namedParameters | TemplateChatWrapperOptions |
Returns
Overrides
Properties
defaultSettings
static defaultSettings: ChatWrapperSettings;
Defined in: ChatWrapper.ts:11
Inherited from
wrapperName
readonly wrapperName: "Template" = "Template";
Defined in: chatWrappers/generic/TemplateChatWrapper.ts:57
Overrides
settings
readonly settings: ChatWrapperSettings;
Defined in: chatWrappers/generic/TemplateChatWrapper.ts:58
Overrides
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}`;
}>;
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
Defined in: ChatWrapper.ts:55
Parameters
Parameter | Type | Default value |
---|---|---|
functionCalls | ChatModelFunctionCall [] | undefined |
useRawCall | boolean | true |
Returns
Inherited from
ChatWrapper
.generateFunctionCallsAndResults
generateFunctionCall()
generateFunctionCall(name: string, params: any): LlamaText
Defined in: ChatWrapper.ts:102
Parameters
Parameter | Type |
---|---|
name | string |
params | any |
Returns
Inherited from
ChatWrapper
.generateFunctionCall
generateFunctionCallResult()
generateFunctionCallResult(
functionName: string,
functionParams: any,
result: any): LlamaText
Defined in: ChatWrapper.ts:116
Parameters
Parameter | Type |
---|---|
functionName | string |
functionParams | any |
result | any |
Returns
Inherited from
ChatWrapper
.generateFunctionCallResult
generateModelResponseText()
generateModelResponseText(modelResponse: (
| string
| ChatModelFunctionCall)[], useRawCall: boolean): LlamaText
Defined in: ChatWrapper.ts:140
Parameters
Parameter | Type | Default value |
---|---|---|
modelResponse | ( | string | ChatModelFunctionCall )[] | undefined |
useRawCall | boolean | true |
Returns
Inherited from
ChatWrapper
.generateModelResponseText
generateAvailableFunctionsSystemText()
generateAvailableFunctionsSystemText(availableFunctions: ChatModelFunctions, __namedParameters: {
documentParams: boolean;
}): LlamaText
Defined in: ChatWrapper.ts:170
Parameters
Parameter | Type |
---|---|
availableFunctions | ChatModelFunctions |
__namedParameters | { documentParams : boolean ; } |
__namedParameters.documentParams ? | boolean |
Returns
Inherited from
ChatWrapper
.generateAvailableFunctionsSystemText
addAvailableFunctionsSystemMessageToHistory()
addAvailableFunctionsSystemMessageToHistory(
history: readonly ChatHistoryItem[],
availableFunctions?: ChatModelFunctions,
__namedParameters?: {
documentParams: boolean;
}): readonly ChatHistoryItem[]
Defined in: ChatWrapper.ts:196
Parameters
Parameter | Type |
---|---|
history | readonly ChatHistoryItem [] |
availableFunctions ? | ChatModelFunctions |
__namedParameters ? | { documentParams : boolean ; } |
__namedParameters.documentParams ? | boolean |
Returns
readonly ChatHistoryItem
[]
Inherited from
ChatWrapper
.addAvailableFunctionsSystemMessageToHistory
generateInitialChatHistory()
generateInitialChatHistory(__namedParameters: ChatWrapperGenerateInitialHistoryOptions): ChatHistoryItem[]
Defined in: ChatWrapper.ts:217
Parameters
Parameter | Type |
---|---|
__namedParameters | ChatWrapperGenerateInitialHistoryOptions |
Returns
Inherited from
ChatWrapper
.generateInitialChatHistory
generateContextState()
generateContextState(__namedParameters: ChatWrapperGenerateContextStateOptions): ChatWrapperGeneratedContextState
Defined in: chatWrappers/generic/TemplateChatWrapper.ts:102
Parameters
Parameter | Type |
---|---|
__namedParameters | ChatWrapperGenerateContextStateOptions |
Returns
ChatWrapperGeneratedContextState