Build applications that make decisions (chatbots, agents, simulations, etc...). Monitor, trace, persist, and execute on your own infrastructure.
Python aiburrchatbot-frameworkdagsgenerative-aigraphshacktoberfestllmopsllmsmlopspersistent-data-structurestate-machinestate-managementvisibility
Adds **kwargs to persister interface
Stefan Krawczykf6ce3aa6da27
diff --git a/burr/core/persistence.py b/burr/core/persistence.pyindex 66a1b85a..ef3a2ae6 100644--- a/burr/core/persistence.py+++ b/burr/core/persistence.py@@ -25,7 +25,7 @@ class BaseStateLoader(abc.ABC):@abc.abstractmethoddef load(- self, partition_key: str, app_id: Optional[str], sequence_id: Optional[int] = None+ self, partition_key: str, app_id: Optional[str], sequence_id: Optional[int] = None, **kwargs) -> Optional[PersistedStateData]:"""Loads the state for a given app_id@@ -39,7 +39,7 @@ class BaseStateLoader(abc.ABC):pass@abc.abstractmethod- def list_app_ids(self, partition_key: str) -> list[str]:+ def list_app_ids(self, partition_key: str, **kwargs) -> list[str]:"""Returns list of app IDs for a given primary key"""pass@@ -62,6 +62,7 @@ class BaseStateSaver(abc.ABC):position: str,state: State,status: Literal["completed", "failed"],+ **kwargs,):"""Saves the state for a given app_id, sequence_id, position@@ -116,11 +117,11 @@ class DevNullPersister(BaseStatePersister):"""Does nothing, do not use this. This is for testing only."""def load(- self, partition_key: str, app_id: Optional[str], sequence_id: Optional[int] = None+ self, partition_key: str, app_id: Optional[str], sequence_id: Optional[int] = None, **kwargs) -> Optional[PersistedStateData]:return None- def list_app_ids(self, partition_key: str) -> list[str]:+ def list_app_ids(self, partition_key: str, **kwargs) -> list[str]:return []def save(@@ -131,6 +132,7 @@ class DevNullPersister(BaseStatePersister):position: str,state: State,status: Literal["completed", "failed"],+ **kwargs,):return@@ -177,7 +179,7 @@ class SQLLitePersister(BaseStatePersister):# Usageself.create_table_if_not_exists(self.table_name)- def list_app_ids(self, partition_key: str) -> list[str]:+ def list_app_ids(self, partition_key: str, **kwargs) -> list[str]:cursor = self.connection.cursor()cursor.execute(f"SELECT DISTINCT app_id FROM {self.table_name} "@@ -189,7 +191,7 @@ class SQLLitePersister(BaseStatePersister):return app_idsdef load(- self, partition_key: str, app_id: str, sequence_id: int = None+ self, partition_key: str, app_id: str, sequence_id: int = None, **kwargs) -> Optional[PersistedStateData]:"""Loads state for a given partition id.@@ -246,6 +248,7 @@ class SQLLitePersister(BaseStatePersister):position: str,state: State,status: Literal["completed", "failed"],+ **kwargs,):"""Saves the state for a given app_id, sequence_id, and position.diff --git a/burr/integrations/persisters/postgresql.py b/burr/integrations/persisters/postgresql.pyindex 4efc9307..40eac979 100644--- a/burr/integrations/persisters/postgresql.py+++ b/burr/integrations/persisters/postgresql.py@@ -109,9 +109,8 @@ class PostgreSQLPersister(persistence.BaseStatePersister):"""Creates the table"""self.create_table(self.table_name)- # The rest of the methods (list_app_ids, load, save, __del__) remain the same as in the SQLLitePersister class-- def list_app_ids(self, partition_key: str) -> list[str]:+ def list_app_ids(self, partition_key: str, **kwargs) -> list[str]:+ """Lists the app_ids for a given partition_key."""cursor = self.connection.cursor()cursor.execute(f"SELECT DISTINCT app_id, created_at FROM {self.table_name} "@@ -123,7 +122,7 @@ class PostgreSQLPersister(persistence.BaseStatePersister):return app_idsdef load(- self, partition_key: str, app_id: str, sequence_id: int = None+ self, partition_key: str, app_id: str, sequence_id: int = None, **kwargs) -> Optional[persistence.PersistedStateData]:"""Loads state for a given partition id.@@ -180,6 +179,7 @@ class PostgreSQLPersister(persistence.BaseStatePersister):position: str,state: state.State,status: Literal["completed", "failed"],+ **kwargs,):"""Saves the state for a given app_id, sequence_id, and position.diff --git a/burr/tracking/client.py b/burr/tracking/client.pyindex a7040d82..ea2d7c39 100644--- a/burr/tracking/client.py+++ b/burr/tracking/client.py@@ -3,7 +3,7 @@ import jsonimport loggingimport osimport traceback-from typing import Any, Dict, Optional+from typing import Any, Dict, LiteralString, Optionalfrom burr.core import Action, ApplicationGraph, Statefrom burr.core.persistence import BaseStateLoader, PersistedStateData@@ -77,8 +77,6 @@ class LocalTrackingClient(:param project: Project name -- if this already exists it will be used, otherwise it will be created.:param storage_dir: Storage directory- :param app_id: Unique application ID. If not provided, a random one will be generated. If this already exists,- it will use that one/append to the files in that one."""self.f = None@@ -86,7 +84,7 @@ class LocalTrackingClient(self.project_id = project@classmethod- def get_storage_path(cls, project, storage_dir):+ def get_storage_path(cls, project, storage_dir) -> LiteralString:return os.path.join(os.path.expanduser(storage_dir), project)@classmethod@@ -288,12 +286,12 @@ class LocalTrackingClient(if self.f is not None:self.f.close()- def list_app_ids(self, partition_key: str) -> list[str]:+ def list_app_ids(self, partition_key: str, **kwargs) -> list[str]:# TODO:return []def load(- self, partition_key: str, app_id: Optional[str], sequence_id: Optional[int] = None+ self, partition_key: str, app_id: Optional[str], sequence_id: Optional[int] = None, **kwargs) -> Optional[PersistedStateData]:# TODO:if app_id is None: