diff --git a/memgpt/config.py b/memgpt/config.py index 0e495dca..a75020c0 100644 --- a/memgpt/config.py +++ b/memgpt/config.py @@ -225,6 +225,17 @@ class Config: f"{Style.BRIGHT}{Fore.MAGENTA}⚙️ Saved config file to {self.config_file}.{Style.RESET_ALL}" ) + @staticmethod + def is_valid_config_file(file: str): + cfg = Config() + try: + cfg.load_config(file) + except Exception: + return False + return ( + cfg.memgpt_persona is not None and cfg.human_persona is not None + ) # TODO: more validation for configs + @staticmethod def get_memgpt_personas(): dir_path = Config.personas_dir @@ -319,6 +330,7 @@ class Config: os.path.join(configs_dir, f) for f in os.listdir(configs_dir) if os.path.isfile(os.path.join(configs_dir, f)) + and Config.is_valid_config_file(os.path.join(configs_dir, f)) ] # Return the file with the most recent modification time if len(files) == 0: