Class: SummaryChatHistory
A ChatHistory is used to keep the state of back and forth chat messages
Extends
Constructors
new SummaryChatHistory()
new SummaryChatHistory(
init
?):SummaryChatHistory
Parameters
• init?: Partial
<SummaryChatHistory
>
Returns
Overrides
Source
packages/core/src/ChatHistory.ts:81
Properties
llm
llm:
LLM
<object
,object
>
Source
packages/core/src/ChatHistory.ts:78
messages
messages:
ChatMessage
[]
Overrides
Source
packages/core/src/ChatHistory.ts:76
messagesBefore
private
messagesBefore:number
Source
packages/core/src/ChatHistory.ts:79
summaryPrompt()
summaryPrompt: (
__namedParameters
) =>string
Parameters
• __namedParameters
• __namedParameters.context: undefined
| string
= ""
Returns
string
Source
packages/core/src/ChatHistory.ts:77
tokenizer()
tokenizer: (
text
) =>Uint32Array
=globalsHelper.defaultTokenizer.encode
Tokenizer function that converts text to tokens, this is used to calculate the number of tokens in a message.
Parameters
• text: string
Returns
Uint32Array
Source
packages/core/src/ChatHistory.ts:73
tokensToSummarize
tokensToSummarize:
number
Source
packages/core/src/ChatHistory.ts:75
Accessors
nonSystemMessages
get
private
nonSystemMessages():ChatMessage
[]
Returns
Source
packages/core/src/ChatHistory.ts:154
systemMessages
get
private
systemMessages():ChatMessage
[]
Returns
Source
packages/core/src/ChatHistory.ts:149
Methods
addMessage()
addMessage(
message
):void
Adds a message to the chat history.
Parameters
• message: ChatMessage
Returns
void
Overrides
Source
packages/core/src/ChatHistory.ts:128
calcConversationMessages()
private
calcConversationMessages(transformSummary
?):ChatMessage
[]
Calculates the messages that describe the conversation so far. If there's no memory, all non-system messages are used. If there's a memory, uses all messages after the last summary message.
Parameters
• transformSummary?: boolean
Returns
Source
packages/core/src/ChatHistory.ts:164
calcCurrentRequestMessages()
private
calcCurrentRequestMessages(transientMessages
?):ChatMessage
[]
Parameters
• transientMessages?: ChatMessage
[]
Returns
Source
packages/core/src/ChatHistory.ts:182
getLastSummary()
getLastSummary():
null
|ChatMessage
Returns
null
| ChatMessage
Source
packages/core/src/ChatHistory.ts:144
getLastSummaryIndex()
private
getLastSummaryIndex():null
|number
Returns
null
| number
Source
packages/core/src/ChatHistory.ts:133
newMessages()
newMessages():
ChatMessage
[]
Returns the new messages since the last call to this function (or since calling the constructor)