Local

Plugin for handling local history managemnet.

class LocalHistory(config)[source]

Class meant to manage the conversation history locally.

Default constructor for class

Parameters:

config (Config) – Configuration class

_abc_impl = <_abc._abc_data object>
_initialize_database()[source]

Initialize the database connection and create tables if needed.

Return type:

DatabaseManager

Returns:

A new instance of the database.

Return type:

Database

Raises:

MissingHistoryFileError – If the database cannot be initialized properly.

clear(user_id)[source]

Clear the database by dropping and recreating tables.

Return type:

None

Parameters:

user_id (str) – The user’s identifier

Raises:

MissingHistoryFileError – Raised when the database file is missing.

clear_from_chat(user_id, from_chat)[source]

Clear the database by dropping and recreating tables.

Return type:

None

Parameters:
  • user_id (str) – The user’s identifier

  • from_chat (str) – Chat name identifier

Raises:

MissingHistoryFileError – Raised when the database file is missing.

read(user_id)[source]

Reads the history from the database.

Return type:

list[HistoryModel]

Parameters:

user_id (str) – The user’s identifier

Returns:

The history entries

Return type:

list[HistoryModel]

Raises:
  • CorruptedHistoryError – Raised when there’s an error reading from the database.

  • MissingHistoryFileError – Raised when the database file is missing.

read_from_chat(user_id, from_chat)[source]

Reads the history from the database.

Return type:

Optional[HistoryModel]

Parameters:
  • user_id (str) – The user’s identifier

  • from_chat (str) – Chat name identifier

Returns:

An optional single history entry

Return type:

Optional[HistoryModel]

Raises:
  • CorruptedHistoryError – Raised when there’s an error reading from the database.

  • MissingHistoryFileError – Raised when the database file is missing.

write(chat_id, user_id, query, response)[source]

Write history to the database.

Return type:

None

Parameters:
  • chat_id (str) – The chat id

  • user_id (str) – The user id

  • query (str) – The user question

  • response (str) – The LLM response

Raises:
  • CorruptedHistoryError – Raised when there’s an error writing to the database.

  • MissingHistoryFileError – Raised when the database file is missing.