espnet2.sds.utils.chat.Chat
espnet2.sds.utils.chat.Chat
class espnet2.sds.utils.chat.Chat(size: int)
Bases: object
Handles the chat to avoid OOM issues.
size
The maximum size of the buffer for chat pairs.
- Type: int
init_chat_message
The initial message to prepend to the chat history, if any.
- Type: Union[Dict[str, str], None]
buffer
A list of chat messages in the form of dictionaries, maintaining the chat history.
- Type: List[Dict[str, str]]
Initializes the Chat object with a buffer size.
- Parameters:size (int) – The maximum number of chat pairs (prompt-response) to retain in the buffer.
append(item: Dict[str, str]) → None
Adds a new message to the chat buffer. Removes the oldest prompt-response pair if the buffer exceeds the maximum allowed size.
- Parameters:item (Dict *[*str , str ]) – The chat message to be added to the buffer, typically with keys like “role” (e.g., “user”, “assistant”) and “content”.
init_chat(init_chat_message: Dict[str, str]) → None
Sets the initial chat message, which will be prepended to the chat history.
- Parameters:init_chat_message (Dict *[*str , str ]) – The initial message to set, typically with keys like “role” and “content”.
to_list() → List[Dict[str, str]]
Returns the complete chat history as a list, including the initial message if set.
- Returns: The chat history as a list of dictionaries, starting with the initial message if it is set, followed by the buffer contents.
- Return type: List[Dict[str, str]]