Sequence of BaseMessage objects to filter.
Optional filtering options.
Optional
excludeMessage IDs to exclude.
Optional
excludeMessages names to exclude.
Optional
excludeMessage types to exclude. Can be specified as string names (e.g. "system", "human", "ai", ...) or as BaseMessage classes (e.g. SystemMessage, HumanMessage, AIMessage, ...).
Optional
includeMessage IDs to include.
Optional
includeMessage names to include.
Optional
includeMessage types to include. Can be specified as string names (e.g. "system", "human", "ai", ...) or as BaseMessage classes (e.g. SystemMessage, HumanMessage, AIMessage, ...).
A list of Messages that meets at least one of the include conditions and none of the exclude conditions. If no include conditions are specified then anything that is not explicitly excluded will be included.
If two incompatible arguments are provided.
import { filterMessages, AIMessage, HumanMessage, SystemMessage } from "@langchain/core/messages";
const messages = [
new SystemMessage("you're a good assistant."),
new HumanMessage({ content: "what's your name", id: "foo", name: "example_user" }),
new AIMessage({ content: "steve-o", id: "bar", name: "example_assistant" }),
new HumanMessage({ content: "what's your favorite color", id: "baz" }),
new AIMessage({ content: "silicon blue" , id: "blah" }),
];
filterMessages(messages, {
includeNames: ["example_user", "example_assistant"],
includeTypes: ["system"],
excludeIds: ["bar"],
});
The above example would return:
[
new SystemMessage("you're a good assistant."),
new HumanMessage({ content: "what's your name", id: "foo", name: "example_user" }),
]
Generated using TypeDoc
Filter messages based on name, type or id.