Function or LLM for counting tokens in an array of BaseMessage
s.
If a BaseLanguageModel
is passed in then BaseLanguageModel.getNumTokens()
will be used.
Optional
allowWhether 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.
false
Optional
endThe 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.
Optional
includeWhether to keep the SystemMessage
if there is one at index 0.
Should only be specified if strategy: "last"
.
false
Optional
startThe 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.
Optional
strategyStrategy for trimming.
"last"
Optional
textFunction 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
Param: maxTokens
Max token count of trimmed messages.