aboutsummaryrefslogtreecommitdiff
path: root/autogpts/autogpt/autogpt/utils/utils.py
blob: 725ffc688d091b4cfe3e6a88f593742a846d929a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from pathlib import Path

import yaml
from colorama import Fore

DEFAULT_FINISH_COMMAND = "finish"
DEFAULT_ASK_COMMAND = "ask_user"


def validate_yaml_file(file: str | Path):
    try:
        with open(file, encoding="utf-8") as fp:
            yaml.load(fp.read(), Loader=yaml.SafeLoader)
    except FileNotFoundError:
        return (False, f"The file {Fore.CYAN}`{file}`{Fore.RESET} wasn't found")
    except yaml.YAMLError as e:
        return (
            False,
            f"There was an issue while trying to read with your AI Settings file: {e}",
        )

    return (True, f"Successfully validated {Fore.CYAN}`{file}`{Fore.RESET}!")