Pular para o conteúdo principal

Class: SummaryChatHistory

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

Implements

Constructors

constructor

new SummaryChatHistory(init?)

Parameters

NameType
init?Partial<SummaryChatHistory>

Defined in

packages/core/src/ChatHistory.ts:70

Properties

llm

llm: LLM

Defined in

packages/core/src/ChatHistory.ts:67


messages

messages: ChatMessage[]

Implementation of

ChatHistory.messages

Defined in

packages/core/src/ChatHistory.ts:65


messagesBefore

Private messagesBefore: number

Defined in

packages/core/src/ChatHistory.ts:68


summaryPrompt

summaryPrompt: (__namedParameters: Object) => string

Type declaration

▸ («destructured»): string

Parameters
NameType
«destructured»Object
Returns

string

Defined in

packages/core/src/ChatHistory.ts:66


tokensToSummarize

tokensToSummarize: number

Defined in

packages/core/src/ChatHistory.ts:64

Accessors

nonSystemMessages

Private get nonSystemMessages(): ChatMessage[]

Returns

ChatMessage[]

Defined in

packages/core/src/ChatHistory.ts:127


systemMessages

Private get systemMessages(): ChatMessage[]

Returns

ChatMessage[]

Defined in

packages/core/src/ChatHistory.ts:122

Methods

addMessage

addMessage(message): void

Adds a message to the chat history.

Parameters

NameType
messageChatMessage

Returns

void

Implementation of

ChatHistory.addMessage

Defined in

packages/core/src/ChatHistory.ts:106


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

NameType
transformSummary?boolean

Returns

ChatMessage[]

Defined in

packages/core/src/ChatHistory.ts:137


calcCurrentRequestMessages

Private calcCurrentRequestMessages(transientMessages?): ChatMessage[]

Parameters

NameType
transientMessages?ChatMessage[]

Returns

ChatMessage[]

Defined in

packages/core/src/ChatHistory.ts:155


getLastSummaryIndex

Private getLastSummaryIndex(): null | number

Returns

null | number

Defined in

packages/core/src/ChatHistory.ts:111


newMessages

newMessages(): ChatMessage[]

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

Returns

ChatMessage[]

Implementation of

ChatHistory.newMessages

Defined in

packages/core/src/ChatHistory.ts:195


requestMessages

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

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

Parameters

NameType
transientMessages?ChatMessage[]

Returns

Promise<ChatMessage[]>

Implementation of

ChatHistory.requestMessages

Defined in

packages/core/src/ChatHistory.ts:165


reset

reset(): void

Resets the chat history so that it's empty.

Returns

void

Implementation of

ChatHistory.reset

Defined in

packages/core/src/ChatHistory.ts:191


summarize

Private summarize(): Promise<ChatMessage>

Returns

Promise<ChatMessage>

Defined in

packages/core/src/ChatHistory.ts:84