انتقل إلى المحتوى الرئيسي

Class: SummaryChatHistory

A ChatHistory is used to keep the state of back and forth chat messages

Hierarchy

Constructors

constructor

new SummaryChatHistory(init?): SummaryChatHistory

Parameters

NameType
init?Partial<SummaryChatHistory> & Partial<SummaryChatHistoryOptions>

Returns

SummaryChatHistory

Overrides

ChatHistory.constructor

Defined in

packages/core/src/ChatHistory.ts:89

Properties

#maxTokens

Private Readonly #maxTokens: number

Defined in

packages/core/src/ChatHistory.ts:87


llm

llm: LLM<object, object>

Defined in

packages/core/src/ChatHistory.ts:85


messages

messages: ChatMessage[]

Overrides

ChatHistory.messages

Defined in

packages/core/src/ChatHistory.ts:83


messagesBefore

Private messagesBefore: number

Defined in

packages/core/src/ChatHistory.ts:86


summaryPrompt

summaryPrompt: (__namedParameters: { context: undefined | string = "" }) => string

Type declaration

▸ («destructured»): string

Parameters
NameTypeDefault value
«destructured»Objectundefined
› contextundefined | string""
Returns

string

Defined in

packages/core/src/ChatHistory.ts:84


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
NameType
textstring
Returns

Uint32Array

Defined in

packages/core/src/ChatHistory.ts:80


tokensToSummarize

tokensToSummarize: number

Defined in

packages/core/src/ChatHistory.ts:82

Accessors

nonSystemMessages

get nonSystemMessages(): ChatMessage[]

Returns

ChatMessage[]

Defined in

packages/core/src/ChatHistory.ts:164


systemMessages

get systemMessages(): ChatMessage[]

Returns

ChatMessage[]

Defined in

packages/core/src/ChatHistory.ts:159

Methods

addMessage

addMessage(message): void

Adds a message to the chat history.

Parameters

NameType
messageChatMessage

Returns

void

Overrides

ChatHistory.addMessage

Defined in

packages/core/src/ChatHistory.ts:138


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

NameType
transformSummary?boolean

Returns

ChatMessage[]

Defined in

packages/core/src/ChatHistory.ts:174


calcCurrentRequestMessages

calcCurrentRequestMessages(transientMessages?): ChatMessage[]

Parameters

NameType
transientMessages?ChatMessage[]

Returns

ChatMessage[]

Defined in

packages/core/src/ChatHistory.ts:192


getLastSummary

getLastSummary(): null | ChatMessage

Returns

null | ChatMessage

Defined in

packages/core/src/ChatHistory.ts:154


getLastSummaryIndex

getLastSummaryIndex(): null | number

Returns

null | number

Defined in

packages/core/src/ChatHistory.ts:143


newMessages

newMessages(): ChatMessage[]

Returns the new messages since the last call to this function (or since calling the constructor)

Returns

ChatMessage[]

Overrides

ChatHistory.newMessages

Defined in

packages/core/src/ChatHistory.ts:236


requestMessages

requestMessages(transientMessages?): Promise<ChatMessage[]>

Returns the messages that should be used as input to the LLM.

Parameters

NameType
transientMessages?ChatMessage[]

Returns

Promise<ChatMessage[]>

Overrides

ChatHistory.requestMessages

Defined in

packages/core/src/ChatHistory.ts:202


reset

reset(): void

Resets the chat history so that it's empty.

Returns

void

Overrides

ChatHistory.reset

Defined in

packages/core/src/ChatHistory.ts:232


summarize

summarize(): Promise<ChatMessage>

Returns

Promise<ChatMessage>

Defined in

packages/core/src/ChatHistory.ts:111