add config file validation

This commit is contained in:
Vivian Fang
2023-10-25 14:43:06 -07:00
parent 246e1e955a
commit c47f7b426c

View File

@@ -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: