KoboldAI / KoboldAI-Client

https://koboldai.com
GNU Affero General Public License v3.0
3.45k stars 743 forks source link

Fix def get_folder_path_info(base) for MacOS - any input? #438

Open djbritt opened 4 months ago

djbritt commented 4 months ago

This seemed to fix issues with loading a model from the models folder for MacOS, compared to what is live in the repo now. Does anyone have any input? I just used Claude to help recode this, and it seemed to help. If you guys can confirm it helps, I'll do a pull request.

File: aiserver.py

def get_folder_path_info(base):
    if base == 'This PC':
        breadcrumbs = [['This PC', 'This PC']]
        if os.name == 'nt':  # Windows
            paths = [["{}:\\".format(chr(i)), "{}:\\".format(chr(i))] for i in range(65, 91) if os.path.exists("{}:".format(chr(i)))]
        else:  # macOS/Linux
            paths = []
    else:
        path = os.path.abspath(base)
        breadcrumbs = []
        for i in range(len(path.split(os.path.sep))):
            breadcrumbs.append([os.path.sep.join(path.split(os.path.sep)[:i+1]),
                                path.split(os.path.sep)[i]])

        if len(breadcrumbs) == 1:
            if os.name == 'nt':  # Windows
                breadcrumbs = [["{}:\\".format(chr(i)), "{}:\\".format(chr(i))] for i in range(65, 91) if os.path.exists("{}:".format(chr(i)))]
            else:  # macOS/Linux
                breadcrumbs = [['/','/']]

        else:
            if os.name == 'nt':  # Windows
                if len([["{}:\\".format(chr(i)), "{}:\\".format(chr(i))] for i in range(65, 91) if os.path.exists("{}:".format(chr(i)))]) > 0:
                    breadcrumbs.insert(0, ['This PC', 'This PC'])

        paths = []
        base_path = os.path.abspath(base)
        for item in os.listdir(base_path):
            if os.path.isdir(os.path.join(base_path, item)):
                paths.append([os.path.join(base_path, item), item])

    return (paths, breadcrumbs)

Before, I was getting this error

FileNotFoundError: [Errno 2] No such file or directory: '/Users/user/github/KoboldAI-Client/\Users\user\github\KoboldAI-Client\models'