From c47f7b426caf3a02a1c9c2237c5580b971fcf155 Mon Sep 17 00:00:00 2001 From: Vivian Fang Date: Wed, 25 Oct 2023 14:43:06 -0700 Subject: [PATCH] add config file validation --- memgpt/config.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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: