interface TrimMessagesFields {
    maxTokens: number;
    tokenCounter: BaseLanguageModel<any, BaseLanguageModelCallOptions> | ((messages) => number) | ((messages) => Promise<number>);
    allowPartial?: boolean;
    endOn?: "function" | typeof HumanMessage | typeof AIMessage | typeof SystemMessage | typeof FunctionMessage | typeof ToolMessage | typeof ChatMessage | "human" | "ai" | "generic" | "system" | "tool" | typeof ToolMessageChunk | typeof AIMessageChunk | typeof ChatMessageChunk | typeof FunctionMessageChunk | typeof HumanMessageChunk | typeof SystemMessageChunk | MessageTypeOrClass[];
    includeSystem?: boolean;
    startOn?: "function" | typeof HumanMessage | typeof AIMessage | typeof SystemMessage | typeof FunctionMessage | typeof ToolMessage | typeof ChatMessage | "human" | "ai" | "generic" | "system" | "tool" | typeof ToolMessageChunk | typeof AIMessageChunk | typeof ChatMessageChunk | typeof FunctionMessageChunk | typeof HumanMessageChunk | typeof SystemMessageChunk | MessageTypeOrClass[];
    strategy?: "first" | "last";
    textSplitter?: ((text) => string[]) | ((text) => Promise<string[]>) | _TextSplitterInterface;
}

Properties

maxTokens: number

Param: maxTokens

Max token count of trimmed messages.

tokenCounter: BaseLanguageModel<any, BaseLanguageModelCallOptions> | ((messages) => number) | ((messages) => Promise<number>)

Type declaration

    • (messages): number
    • Parameters

      Returns number

Type declaration

    • (messages): Promise<number>
    • Parameters

      Returns Promise<number>

Param: tokenCounter

Function or LLM for counting tokens in an array of BaseMessages. If a BaseLanguageModel is passed in then BaseLanguageModel.getNumTokens() will be used.

allowPartial?: boolean

Param: allowPartial

Whether to split a message if only part of the message can be included. If strategy: "last" then the last partial contents of a message are included. If strategy: "first" then the first partial contents of a message are included.

Default

false
endOn?: "function" | typeof HumanMessage | typeof AIMessage | typeof SystemMessage | typeof FunctionMessage | typeof ToolMessage | typeof ChatMessage | "human" | "ai" | "generic" | "system" | "tool" | typeof ToolMessageChunk | typeof AIMessageChunk | typeof ChatMessageChunk | typeof FunctionMessageChunk | typeof HumanMessageChunk | typeof SystemMessageChunk | MessageTypeOrClass[]

Param: endOn

The message type to end on. If specified then every message after the last occurrence of this type is ignored. If strategy === "last" then this is done before we attempt to get the last maxTokens. If strategy === "first" then this is done after we get the first maxTokens. Can be specified as string names (e.g. "system", "human", "ai", ...) or as BaseMessage classes (e.g. SystemMessage, HumanMessage, AIMessage, ...). Can be a single type or an array of types.

includeSystem?: boolean

Param: includeSystem

Whether to keep the SystemMessage if there is one at index 0. Should only be specified if strategy: "last".

Default

false
startOn?: "function" | typeof HumanMessage | typeof AIMessage | typeof SystemMessage | typeof FunctionMessage | typeof ToolMessage | typeof ChatMessage | "human" | "ai" | "generic" | "system" | "tool" | typeof ToolMessageChunk | typeof AIMessageChunk | typeof ChatMessageChunk | typeof FunctionMessageChunk | typeof HumanMessageChunk | typeof SystemMessageChunk | MessageTypeOrClass[]

Param: startOn

The message type to start on. Should only be specified if strategy: "last". If specified then every message before the first occurrence of this type is ignored. This is done after we trim the initial messages to the last maxTokens. Does not apply to a SystemMessage at index 0 if includeSystem: true. Can be specified as string names (e.g. "system", "human", "ai", ...) or as BaseMessage classes (e.g. SystemMessage, HumanMessage, AIMessage, ...). Can be a single type or an array of types.

strategy?: "first" | "last"

Param: strategy

Strategy for trimming.

  • "first": Keep the first <= n_count tokens of the messages.
  • "last": Keep the last <= n_count tokens of the messages.

Default

"last"
textSplitter?: ((text) => string[]) | ((text) => Promise<string[]>) | _TextSplitterInterface

Type declaration

    • (text): string[]
    • Parameters

      • text: string

      Returns string[]

Type declaration

    • (text): Promise<string[]>
    • Parameters

      • text: string

      Returns Promise<string[]>

Param: textSplitter

Function or BaseDocumentTransformer for splitting the string contents of a message. Only used if allowPartial: true. If strategy: "last" then the last split tokens from a partial message will be included. If strategy: "first" then the first split tokens from a partial message will be included. Token splitter assumes that separators are kept, so that split contents can be directly concatenated to recreate the original text. Defaults to splitting on newlines.

Generated using TypeDoc