chat_history Module

Classes

ChatHistory

This class holds the history of chat messages from a chat conversation.

Note: the constructor takes a system_message parameter, which is not part of the class definition. This is to allow the system_message to be passed in as a keyword argument, but not be part of the class definition.

Initializes a new instance of the ChatHistory class.

Optionally incorporating a message and/or a system message at the beginning of the chat history.

This constructor allows for flexible initialization with chat messages and an optional messages or a system message. If both 'messages' (a list of ChatMessageContent instances) and 'system_message' are provided, the 'system_message' is prepended to the list of messages, ensuring it appears as the first message in the history. If only 'system_message' is provided without any 'messages', the chat history is initialized with the 'system_message' as its first item. If 'messages' are provided without a 'system_message', the chat history is initialized with the provided messages as is.

Note: The 'system_message' is not retained as part of the class's attributes; it's used during initialization and then discarded. The rest of the keyword arguments are passed to the superclass constructor and handled according to the Pydantic model's behavior.