Class: SummaryChatHistory
A ChatHistory is used to keep the state of back and forth chat messages
Hierarchy
-
↳
SummaryChatHistory
Constructors
constructor
• new SummaryChatHistory(init?
): SummaryChatHistory
Parameters
Name | Type |
---|---|
init? | Partial <SummaryChatHistory > |
Returns
Overrides
Defined in
packages/core/src/ChatHistory.ts:81
Properties
llm
• llm: LLM
<object
, object
>
Defined in
packages/core/src/ChatHistory.ts:78
messages
• messages: ChatMessage
[]
Overrides
Defined in
packages/core/src/ChatHistory.ts:76
messagesBefore
• Private
messagesBefore: number
Defined in
packages/core/src/ChatHistory.ts:79
summaryPrompt
• summaryPrompt: (__namedParameters
: { context
: undefined
| string
= "" }) => string
Type declaration
▸ («destructured»
): string
Parameters
Name | Type | Default value |
---|---|---|
«destructured» | Object | undefined |
› context | undefined | string | "" |
Returns
string
Defined in
packages/core/src/ChatHistory.ts:77
tokenizer
• tokenizer: (text
: string
) => Uint32Array
= globalsHelper.defaultTokenizer.encode
Tokenizer function that converts text to tokens, this is used to calculate the number of tokens in a message.
Type declaration
▸ (text
): Uint32Array
Parameters
Name | Type |
---|---|
text | string |
Returns
Uint32Array
Defined in
packages/core/src/ChatHistory.ts:73
tokensToSummarize
• tokensToSummarize: number
Defined in
packages/core/src/ChatHistory.ts:75
Accessors
nonSystemMessages
• get
nonSystemMessages(): ChatMessage
[]
Returns
Defined in
packages/core/src/ChatHistory.ts:154
systemMessages
• get
systemMessages(): ChatMessage
[]
Returns
Defined in
packages/core/src/ChatHistory.ts:149
Methods
addMessage
▸ addMessage(message
): void
Adds a message to the chat history.
Parameters
Name | Type |
---|---|
message | ChatMessage |
Returns
void
Overrides
Defined in
packages/core/src/ChatHistory.ts:128
calcConversationMessages
▸ 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
Name | Type |
---|---|
transformSummary? | boolean |
Returns
Defined in
packages/core/src/ChatHistory.ts:164
calcCurrentRequestMessages
▸ calcCurrentRequestMessages(transientMessages?
): ChatMessage
[]
Parameters
Name | Type |
---|---|
transientMessages? | ChatMessage [] |
Returns
Defined in
packages/core/src/ChatHistory.ts:182
getLastSummary
▸ getLastSummary(): null
| ChatMessage
Returns
null
| ChatMessage
Defined in
packages/core/src/ChatHistory.ts:144
getLastSummaryIndex
▸ getLastSummaryIndex(): null
| number
Returns
null
| number
Defined in
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)
Returns
Overrides
Defined in
packages/core/src/ChatHistory.ts:226
requestMessages
▸ requestMessages(transientMessages?
): Promise
<ChatMessage
[]>
Returns the messages that should be used as input to the LLM.
Parameters
Name | Type |
---|---|
transientMessages? | ChatMessage [] |
Returns
Promise
<ChatMessage
[]>
Overrides
Defined in
packages/core/src/ChatHistory.ts:192
reset
▸ reset(): void
Resets the chat history so that it's empty.
Returns
void