nemoguardrails.integrations.langchain.message_utils
nemoguardrails.integrations.langchain.message_utils
Utilities for converting between LangChain messages and dictionary format.
Module Contents
Functions
Data
API
Check if all items in a list are BaseMessage instances.
Create an AIMessage with optional fields.
Create an AIMessageChunk with optional metadata.
Create a HumanMessage with optional fields.
Create a SystemMessage with optional fields.
Create a ToolMessage with optional fields.
Convert a dictionary to the appropriate BaseMessage type.
Parameters:
Dictionary with role/type, content, and optional fields
Returns: BaseMessage
The appropriate BaseMessage instance
Convert a list of dictionaries to BaseMessage objects.
Parameters:
List of message dictionaries
Returns: List[BaseMessage]
List of appropriate BaseMessage instances
Get the appropriate message class for a given type/role.
Get the role string for a BaseMessage.
Check if an object is an AIMessage.
Check if an object is any type of BaseMessage.
Check if an object is a HumanMessage.
Check if an object is an instance of a specific message type.
Check if an object is a SystemMessage.
Check if an object is a ToolMessage.
Convert a BaseMessage to dictionary format, preserving all model fields.
Parameters:
The BaseMessage to convert
Returns: Dict[str, Any]
Dictionary representation with role, content, and all other fields
Convert a list of BaseMessage objects to dictionary format.
Parameters:
List of BaseMessage objects
Returns: List[Dict[str, Any]]
List of dictionary representations