Skip to content

Chat History

Basic Chat History and Message store

llama_cpp_agent.chat_history.basic_chat_history

Chat History and Message store

llama_cpp_agent.chat_history.chat_history_base

ChatMessageStore

Bases: ABC

An abstract base class for storing and managing chat messages.

Source code in llama_cpp_agent/chat_history/chat_history_base.py
class ChatMessageStore(ABC):
    """
    An abstract base class for storing and managing chat messages.
    """

    @abstractmethod
    def get_messages_count(self):
        """
        Get the total count of messages in the store.
        """
        pass

    @abstractmethod
    def add_message(self, message: ChatMessage):
        """
        Add a new message to the store.

        :param message: The ChatMessage object to add.
        """
        pass

    @abstractmethod
    def edit_message(self, index: int, edited_message: ChatMessage):
        """
        Edit a message at a specific index in the store.

        :param index: The index of the message to edit.
        :param edited_message: The edited ChatMessage object.
        """
        pass

    @abstractmethod
    def add_user_message(self, message: str):
        """
        Add a user message to the store.

        :param message: The content of the user message.
        """
        pass

    @abstractmethod
    def add_assistant_message(self, message: str):
        """
        Add an assistant message to the store.

        :param message: The content of the assistant message.
        """
        pass

    @abstractmethod
    def add_system_message(self, message: str):
        """
        Add a system message to the store.

        :param message: The content of the system message.
        """
        pass

    @abstractmethod
    def remove_last_message(self):
        """
        Remove the last message from the store.
        """
        pass

    @abstractmethod
    def remove_last_k_messages(self, k: int):
        """
        Remove the last k messages from the store.

        :param k: The number of messages to remove.
        """
        pass

    @abstractmethod
    def get_message(self, index: int) -> ChatMessage:
        """
        Get a message at a specific index from the store.

        :param index: The index of the message to retrieve.
        :return: The ChatMessage object at the specified index.
        """
        pass

    @abstractmethod
    def get_last_message(self) -> ChatMessage:
        """
        Get the last message from the store.

        :return: The last ChatMessage object in the store.
        """
        pass

    @abstractmethod
    def get_last_k_messages(self, k: int) -> List[ChatMessage]:
        """
        Get the last k messages from the store.

        :param k: The number of messages to retrieve.
        :return: A list of the last k ChatMessage objects.
        """
        pass

    @abstractmethod
    def get_messages(self, k: int) -> List[ChatMessage]:
        """
        Get the messages starting from index k.

        :param k: The starting index.
        :return: A list of ChatMessage objects starting from index k.
        """
        pass

    @abstractmethod
    def get_all_messages(self) -> List[ChatMessage]:
        """
        Get all messages from the store.

        :return: A list of all ChatMessage objects in the store.
        """
        pass

    @abstractmethod
    def save_to_json(self, file_path: str):
        """
        Save the messages to a JSON file.

        :param file_path: The path to the JSON file.
        """
        pass

    @abstractmethod
    def load_from_json(self, file_path: str):
        """
        Load messages from a JSON file.

        :param file_path: The path to the JSON file.
        """
        pass
get_messages_count() abstractmethod

Get the total count of messages in the store.

Source code in llama_cpp_agent/chat_history/chat_history_base.py
@abstractmethod
def get_messages_count(self):
    """
    Get the total count of messages in the store.
    """
    pass
add_message(message) abstractmethod

Add a new message to the store.

:param message: The ChatMessage object to add.

Source code in llama_cpp_agent/chat_history/chat_history_base.py
@abstractmethod
def add_message(self, message: ChatMessage):
    """
    Add a new message to the store.

    :param message: The ChatMessage object to add.
    """
    pass
edit_message(index, edited_message) abstractmethod

Edit a message at a specific index in the store.

:param index: The index of the message to edit. :param edited_message: The edited ChatMessage object.

Source code in llama_cpp_agent/chat_history/chat_history_base.py
@abstractmethod
def edit_message(self, index: int, edited_message: ChatMessage):
    """
    Edit a message at a specific index in the store.

    :param index: The index of the message to edit.
    :param edited_message: The edited ChatMessage object.
    """
    pass
add_user_message(message) abstractmethod

Add a user message to the store.

:param message: The content of the user message.

Source code in llama_cpp_agent/chat_history/chat_history_base.py
@abstractmethod
def add_user_message(self, message: str):
    """
    Add a user message to the store.

    :param message: The content of the user message.
    """
    pass
add_assistant_message(message) abstractmethod

Add an assistant message to the store.

:param message: The content of the assistant message.

Source code in llama_cpp_agent/chat_history/chat_history_base.py
@abstractmethod
def add_assistant_message(self, message: str):
    """
    Add an assistant message to the store.

    :param message: The content of the assistant message.
    """
    pass
add_system_message(message) abstractmethod

Add a system message to the store.

:param message: The content of the system message.

Source code in llama_cpp_agent/chat_history/chat_history_base.py
@abstractmethod
def add_system_message(self, message: str):
    """
    Add a system message to the store.

    :param message: The content of the system message.
    """
    pass
remove_last_message() abstractmethod

Remove the last message from the store.

Source code in llama_cpp_agent/chat_history/chat_history_base.py
@abstractmethod
def remove_last_message(self):
    """
    Remove the last message from the store.
    """
    pass
remove_last_k_messages(k) abstractmethod

Remove the last k messages from the store.

:param k: The number of messages to remove.

Source code in llama_cpp_agent/chat_history/chat_history_base.py
@abstractmethod
def remove_last_k_messages(self, k: int):
    """
    Remove the last k messages from the store.

    :param k: The number of messages to remove.
    """
    pass
get_message(index) abstractmethod

Get a message at a specific index from the store.

:param index: The index of the message to retrieve. :return: The ChatMessage object at the specified index.

Source code in llama_cpp_agent/chat_history/chat_history_base.py
@abstractmethod
def get_message(self, index: int) -> ChatMessage:
    """
    Get a message at a specific index from the store.

    :param index: The index of the message to retrieve.
    :return: The ChatMessage object at the specified index.
    """
    pass
get_last_message() abstractmethod

Get the last message from the store.

:return: The last ChatMessage object in the store.

Source code in llama_cpp_agent/chat_history/chat_history_base.py
@abstractmethod
def get_last_message(self) -> ChatMessage:
    """
    Get the last message from the store.

    :return: The last ChatMessage object in the store.
    """
    pass
get_last_k_messages(k) abstractmethod

Get the last k messages from the store.

:param k: The number of messages to retrieve. :return: A list of the last k ChatMessage objects.

Source code in llama_cpp_agent/chat_history/chat_history_base.py
@abstractmethod
def get_last_k_messages(self, k: int) -> List[ChatMessage]:
    """
    Get the last k messages from the store.

    :param k: The number of messages to retrieve.
    :return: A list of the last k ChatMessage objects.
    """
    pass
get_messages(k) abstractmethod

Get the messages starting from index k.

:param k: The starting index. :return: A list of ChatMessage objects starting from index k.

Source code in llama_cpp_agent/chat_history/chat_history_base.py
@abstractmethod
def get_messages(self, k: int) -> List[ChatMessage]:
    """
    Get the messages starting from index k.

    :param k: The starting index.
    :return: A list of ChatMessage objects starting from index k.
    """
    pass
get_all_messages() abstractmethod

Get all messages from the store.

:return: A list of all ChatMessage objects in the store.

Source code in llama_cpp_agent/chat_history/chat_history_base.py
@abstractmethod
def get_all_messages(self) -> List[ChatMessage]:
    """
    Get all messages from the store.

    :return: A list of all ChatMessage objects in the store.
    """
    pass
save_to_json(file_path) abstractmethod

Save the messages to a JSON file.

:param file_path: The path to the JSON file.

Source code in llama_cpp_agent/chat_history/chat_history_base.py
@abstractmethod
def save_to_json(self, file_path: str):
    """
    Save the messages to a JSON file.

    :param file_path: The path to the JSON file.
    """
    pass
load_from_json(file_path) abstractmethod

Load messages from a JSON file.

:param file_path: The path to the JSON file.

Source code in llama_cpp_agent/chat_history/chat_history_base.py
@abstractmethod
def load_from_json(self, file_path: str):
    """
    Load messages from a JSON file.

    :param file_path: The path to the JSON file.
    """
    pass

ChatHistory

Bases: ABC

An abstract base class for managing chat history.

Source code in llama_cpp_agent/chat_history/chat_history_base.py
class ChatHistory(ABC):
    """
    An abstract base class for managing chat history.
    """

    @abstractmethod
    def get_message_store(self) -> ChatMessageStore:
        """
        Get the message store associated with the chat history.

        :return: The ChatMessageStore object.
        """
        pass

    @abstractmethod
    def get_chat_messages(self) -> List[Dict[str, str]]:
        """
        Get the chat messages as a list of dictionaries.

        :return: A list of dictionaries representing the chat messages.
        """
        pass

    @abstractmethod
    def add_message(self, message: Dict[str, str]):
        """
        Add a message to the chat history.

        :param message: A dictionary representing the message to add.
        """
        pass

    @abstractmethod
    def get_messages_count(self):
        """
        Get the total count of messages in the chat history.

        :return: The count of messages.
        """
        pass

    @abstractmethod
    def edit_message(self, index: int, edited_message: Dict[str, str]):
        """
        Edit a message at a specific index in the chat history.

        :param index: The index of the message to edit.
        :param edited_message: A dictionary representing the edited message.
        """
        pass

    @abstractmethod
    def get_message(self, index) -> Dict[str, str]:
        """
        Get a message at a specific index from the chat history.

        :param index: The index of the message to retrieve.
        :return: A dictionary representing the message at the specified index.
        """
        pass
get_message_store() abstractmethod

Get the message store associated with the chat history.

:return: The ChatMessageStore object.

Source code in llama_cpp_agent/chat_history/chat_history_base.py
@abstractmethod
def get_message_store(self) -> ChatMessageStore:
    """
    Get the message store associated with the chat history.

    :return: The ChatMessageStore object.
    """
    pass
get_chat_messages() abstractmethod

Get the chat messages as a list of dictionaries.

:return: A list of dictionaries representing the chat messages.

Source code in llama_cpp_agent/chat_history/chat_history_base.py
@abstractmethod
def get_chat_messages(self) -> List[Dict[str, str]]:
    """
    Get the chat messages as a list of dictionaries.

    :return: A list of dictionaries representing the chat messages.
    """
    pass
add_message(message) abstractmethod

Add a message to the chat history.

:param message: A dictionary representing the message to add.

Source code in llama_cpp_agent/chat_history/chat_history_base.py
@abstractmethod
def add_message(self, message: Dict[str, str]):
    """
    Add a message to the chat history.

    :param message: A dictionary representing the message to add.
    """
    pass
get_messages_count() abstractmethod

Get the total count of messages in the chat history.

:return: The count of messages.

Source code in llama_cpp_agent/chat_history/chat_history_base.py
@abstractmethod
def get_messages_count(self):
    """
    Get the total count of messages in the chat history.

    :return: The count of messages.
    """
    pass
edit_message(index, edited_message) abstractmethod

Edit a message at a specific index in the chat history.

:param index: The index of the message to edit. :param edited_message: A dictionary representing the edited message.

Source code in llama_cpp_agent/chat_history/chat_history_base.py
@abstractmethod
def edit_message(self, index: int, edited_message: Dict[str, str]):
    """
    Edit a message at a specific index in the chat history.

    :param index: The index of the message to edit.
    :param edited_message: A dictionary representing the edited message.
    """
    pass
get_message(index) abstractmethod

Get a message at a specific index from the chat history.

:param index: The index of the message to retrieve. :return: A dictionary representing the message at the specified index.

Source code in llama_cpp_agent/chat_history/chat_history_base.py
@abstractmethod
def get_message(self, index) -> Dict[str, str]:
    """
    Get a message at a specific index from the chat history.

    :param index: The index of the message to retrieve.
    :return: A dictionary representing the message at the specified index.
    """
    pass