Messages
1. Concept
The BaseMessage
class is the base class for message objects used in the CAMEL chat system. It is designed to provide a consistent structure for the messages in the system and allow for easy conversion between different message types.
All the codes are also available on colab notebook here.
2. Get Started
2.1 Creating a BaseMessage
Instance
To create a BaseMessage
instance, you need to provide the following arguments:
role_name
: The name of the user or assistant role.role_type
: The type of role, eitherRoleType.ASSISTANT
orRoleType.USER
.meta_dict
: An optional metadata dictionary for the message.content
: The content of the message.
Below are optional arguments you can pass:
video_bytes
: Optional bytes of a video associated with the message.image_list
: Optional list of PIL Image objects associated with the message.image_detail
: Detail level of the images associated with the message. Default is “auto”.video_detail
: Detail level of the videos associated with the message. Default is “low”.
Here’s an example of creating a BaseMessage
instance:
Additionally, the BaseMessage class provides class methods to easily create user and assistant agent messages:
-
Creating a user agent message:
-
Creating an assistant agent message:
2.2 Using the Methods of the BaseMessage
Class
The BaseMessage
class offers several methods:
-
Creating a new instance with updated content:
-
Converting to an
OpenAIMessage
object: -
Converting to an
OpenAISystemMessage
object: -
Converting to an
OpenAIUserMessage
object: -
Converting to an
OpenAIAssistantMessage
object: -
Converting to a dictionary:
These methods allow you to convert a BaseMessage
instance into different message types depending on your needs.
3. Give BaseMessage
to ChatAgent
4. Conclusion
In this session, we introduced the BaseMessage
class and its conversion to different types of messages. These components play essential roles in the CAMEL chat system, facilitating the creation, management, and interpretation of messages with clarity.