From cb2776a5497f2e4f14aeb18fc372ea4d237530bd Mon Sep 17 00:00:00 2001 From: Zed <33319711+Zedai00@users.noreply.github.com> Date: Thu, 30 May 2024 19:29:16 +0530 Subject: Update models.py to create models directory when its not present It will create a models directory in current folder if it can't find the directory due to previous way where it tries to return models directory where its not present which in turns returns None causing os.path to fail Fix #2030 --- g4f/locals/models.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'g4f') diff --git a/g4f/locals/models.py b/g4f/locals/models.py index f82f5448..8e1c06bf 100644 --- a/g4f/locals/models.py +++ b/g4f/locals/models.py @@ -37,8 +37,10 @@ def get_model_dir() -> str: local_dir = os.path.dirname(os.path.abspath(__file__)) project_dir = os.path.dirname(os.path.dirname(local_dir)) model_dir = os.path.join(project_dir, "models") - if os.path.exists(model_dir): - return model_dir + if not os.path.exists(model_dir): + os.mkdir(model_dir) + return model_dir + def get_models() -> dict[str, dict]: model_dir = get_model_dir() @@ -48,4 +50,4 @@ def get_models() -> dict[str, dict]: else: models = load_models() save_models(file_path, models) - return models \ No newline at end of file + return models -- cgit v1.2.3