Ana içeriğe geç

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>

Returns

SummaryChatHistory

Overrides

ChatHistory.constructor

Defined in

packages/core/src/ChatHistory.ts:79

Properties

llm

llm: LLM<Record<string, unknown>, Record<string, unknown>>

Defined in

packages/core/src/ChatHistory.ts:76


messages

messages: { content: MessageContent ; options?: Record<string, unknown> ; role: MessageType }[]

Overrides

ChatHistory.messages

Defined in

packages/core/src/ChatHistory.ts:74


messagesBefore

Private messagesBefore: number

Defined in

packages/core/src/ChatHistory.ts:77


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:75


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:71


tokensToSummarize

tokensToSummarize: number

Defined in

packages/core/src/ChatHistory.ts:73

Accessors

nonSystemMessages

get nonSystemMessages(): { content: MessageContent ; options?: Record<string, unknown> ; role: MessageType }[]

Returns

{ content: MessageContent ; options?: Record<string, unknown> ; role: MessageType }[]

Defined in

packages/core/src/ChatHistory.ts:149


systemMessages

get systemMessages(): { content: MessageContent ; options?: Record<string, unknown> ; role: MessageType }[]

Returns

{ content: MessageContent ; options?: Record<string, unknown> ; role: MessageType }[]

Defined in

packages/core/src/ChatHistory.ts:144

Methods

addMessage

addMessage(message): void

Adds a message to the chat history.

Parameters

NameType
messageObject
message.contentMessageContent
message.options?Record<string, unknown>
message.roleMessageType

Returns

void

Overrides

ChatHistory.addMessage

Defined in

packages/core/src/ChatHistory.ts:123


calcConversationMessages

calcConversationMessages(transformSummary?): { content: MessageContent ; options?: Record<string, unknown> ; role: MessageType }[]

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

{ content: MessageContent ; options?: Record<string, unknown> ; role: MessageType }[]

Defined in

packages/core/src/ChatHistory.ts:159


calcCurrentRequestMessages

calcCurrentRequestMessages(transientMessages?): { content: MessageContent ; options?: Record<string, unknown> ; role: MessageType }[]

Parameters

NameType
transientMessages?{ content: MessageContent ; options?: Record<string, unknown> ; role: MessageType }[]

Returns

{ content: MessageContent ; options?: Record<string, unknown> ; role: MessageType }[]

Defined in

packages/core/src/ChatHistory.ts:177


getLastSummary

getLastSummary(): null | { content: MessageContent ; options?: Record<string, unknown> ; role: MessageType }

Returns

null | { content: MessageContent ; options?: Record<string, unknown> ; role: MessageType }

Defined in

packages/core/src/ChatHistory.ts:139


getLastSummaryIndex

getLastSummaryIndex(): null | number

Returns

null | number

Defined in

packages/core/src/ChatHistory.ts:128


newMessages

newMessages(): { content: MessageContent ; options?: Record<string, unknown> ; role: MessageType }[]

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

Returns

{ content: MessageContent ; options?: Record<string, unknown> ; role: MessageType }[]

Overrides

ChatHistory.newMessages

Defined in

packages/core/src/ChatHistory.ts:221


requestMessages

requestMessages(transientMessages?): Promise<{ content: MessageContent ; options?: Record<string, unknown> ; role: MessageType }[]>

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

Parameters

NameType
transientMessages?{ content: MessageContent ; options?: Record<string, unknown> ; role: MessageType }[]

Returns

Promise<{ content: MessageContent ; options?: Record<string, unknown> ; role: MessageType }[]>

Overrides

ChatHistory.requestMessages

Defined in

packages/core/src/ChatHistory.ts:187


reset

reset(): void

Resets the chat history so that it's empty.

Returns

void

Overrides

ChatHistory.reset

Defined in

packages/core/src/ChatHistory.ts:217


summarize

summarize(): Promise<{ content: MessageContent ; options?: Record<string, unknown> ; role: MessageType }>

Returns

Promise<{ content: MessageContent ; options?: Record<string, unknown> ; role: MessageType }>

Defined in

packages/core/src/ChatHistory.ts:99