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. | |
Content block for inline data from a base64 string. | |
Base class for data content blocks. | |
Content block for data specified by an identifier. | |
Content block for plain text data (e.g., from a document). | |
Content block for data from a URL. | |
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. | |
Mixin for objects that tools can return directly. |
Functions
| Add multiple AIMessageChunks together. |
| Recursively add two UsageMetadata objects. |
| Recursively subtract two UsageMetadata objects. |
| Get a title representation for a message. |
| Merge multiple message contents. |
| Convert a Message to a dictionary. |
| Convert a sequence of Messages to a list of dictionaries. |
Format standard data content block to format expected by OpenAI. | |
Convert image content block to format expected by OpenAI Chat Completions API. | |
Check if the content block is a standard data content block. | |
Best-effort parsing of tool chunks. | |
| Best-effort parsing of tools. |
| Create an invalid tool call. |
| Create a tool call. |
| Create a tool call chunk. |
| Convert a sequence of messages to a list of messages. |
Convert LangChain messages into OpenAI message dicts. | |
Approximate the total number of tokens in messages. | |
| 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. |