messages
#
Messages are objects used in prompts and chat conversations.
Class hierarchy:
BaseMessage --> SystemMessage, AIMessage, HumanMessage, ChatMessage, FunctionMessage, ToolMessage
--> BaseMessageChunk --> SystemMessageChunk, AIMessageChunk, HumanMessageChunk, ChatMessageChunk, FunctionMessageChunk, ToolMessageChunk
Main helpers:
ChatPromptTemplate
Classes
Message from an AI. |
|
Message chunk from an AI. |
|
Breakdown of input token counts. |
|
Breakdown of output token counts. |
|
Usage metadata for a message, such as token counts. |
|
Base abstract message class. |
|
Message chunk, which can be concatenated with other Message chunks. |
|
Message that can be assigned an arbitrary speaker (i.e. role). |
|
Chat Message chunk. |
|
Message for passing the result of executing a tool back to a model. |
|
Function Message chunk. |
|
Message from a human. |
|
Human Message chunk. |
|
Message responsible for deleting other messages. |
|
Message for priming AI behavior. |
|
System Message chunk. |
|
Allowance for errors made by LLM. |
|
Represents a request to call a tool. |
|
A chunk of a tool call (e.g., as part of a stream). |
|
Message for passing the result of executing a tool back to a model. |
|
Tool Message chunk. |
Functions
|
Add multiple AIMessageChunks together. |
|
Recursively add two UsageMetadata objects. |
|
Recursively subtract two UsageMetadata objects. |
|
Get a title representation for a message. |
|
Merge two message contents. |
|
Convert a Message to a dictionary. |
|
Convert a sequence of Messages to a list of dictionaries. |
Best-effort parsing of tool chunks. |
|
|
Best-effort parsing of tools. |
|
|
|
|
|
|
|
Convert a sequence of messages to a list of messages. |
Convert LangChain messages into OpenAI message dicts. |
|
|
Filter messages based on name, type or id. |
|
Convert a sequence of Messages to strings and concatenate them into one string. |
|
Merge consecutive Messages of the same type. |
Convert a message chunk to a message. |
|
|
Convert a sequence of messages from dicts to Message objects. |
|
Trim messages to be below a token count. |