The Chat class in MiniAutoGen is a crucial component designed to manage and store the state of group chats. It provides functionalities for handling messages, maintaining chat context, and managing agents within a chat session.
The Chat class is responsible for managing chat sessions, including message storage, chat context, and agent interactions.
- Purpose: Initializes a Chat object with a specified storage path and an optional custom DataFrame.
- Parameters:
storage_path(str): Path to the storage directory. Defaults to'groupchat_data'.custom_df(pandas.DataFrame): A DataFrame for creating a custom table in storage. Defaults toNone.
- Purpose: Ensures the existence of the storage directory, creating it if necessary.
- Purpose: Loads the chat context from a file.
- Returns: A dictionary representing the loaded chat context.
- Purpose: Persists the current chat context to a file.
- Purpose: Adds a message to the chat storage.
- Parameters:
sender_id(str): ID of the message sender.message(str): Content of the message.additional_info(dict, optional): Additional message information. Defaults toNone.
- Purpose: Adds multiple messages to the chat storage.
- Parameters:
messages(pandas.DataFrameorlist): Messages to be added.
- Purpose: Removes a message from the chat storage.
- Parameters:
message_id(int): ID of the message to be removed.
- Purpose: Retrieves messages from the chat storage.
- Parameters:
type(str): Type of the returned messages ('dataframe'or'json'). Defaults to'dataframe'.
- Returns:
pandas.DataFrameorlistof messages.
- Purpose: Retrieves the current chat context.
- Returns: A dictionary representing the current chat context.
- Purpose: Updates the chat context with new values.
- Parameters:
new_context(dict): New chat context values.
- Purpose: Adds an agent to the chat.
- Parameters:
agent(Agent): The agent to be added.
- Purpose: Removes an agent from the chat.
- Parameters:
agent_id(str): ID of the agent to be removed.
- Purpose: Converts messages to a pandas DataFrame.
- Parameters:
messages(list): Messages to be converted.
- Returns:
pandas.DataFrameof messages.
- Purpose: Converts messages to JSON format.
- Parameters:
messages(list): Messages to be converted.
- Returns:
listof messages in JSON format.
chat_session = Chat(storage_path='my_chat_data')chat_session.add_message(sender_id='user123', message='Hello, world!')messages_df = chat_session.get_messages(type='dataframe')new_context = {'topic': 'AI'}
chat_session.update_context(new_context)Assuming agent is an instance of the Agent class:
chat_session.add_agent(agent)- Ensure that the storage path provided during initialization is accessible and writable.
- The
Chatclass is designed to interact seamlessly with other components of the MiniAutoGen framework, such asAgentandChatStorage.