CoolFace
Apppublic

coding-alt/AutoGPT

sourceHugging Facemitupdated 3y agoView on Hugging Face
0likes
configurator.py135 linesDownload Raw Back to autogpt
1"""Configurator module."""2import click3from colorama import Back, Fore, Style4 5from autogpt import utils6from autogpt.config import Config7from autogpt.logs import logger8from autogpt.memory import get_supported_memory_backends9 10CFG = Config()11 12 13def create_config(14    continuous: bool,15    continuous_limit: int,16    ai_settings_file: str,17    skip_reprompt: bool,18    speak: bool,19    debug: bool,20    gpt3only: bool,21    gpt4only: bool,22    memory_type: str,23    browser_name: str,24    allow_downloads: bool,25    skip_news: bool,26) -> None:27    """Updates the config object with the given arguments.28 29    Args:30        continuous (bool): Whether to run in continuous mode31        continuous_limit (int): The number of times to run in continuous mode32        ai_settings_file (str): The path to the ai_settings.yaml file33        skip_reprompt (bool): Whether to skip the re-prompting messages at the beginning of the script34        speak (bool): Whether to enable speak mode35        debug (bool): Whether to enable debug mode36        gpt3only (bool): Whether to enable GPT3.5 only mode37        gpt4only (bool): Whether to enable GPT4 only mode38        memory_type (str): The type of memory backend to use39        browser_name (str): The name of the browser to use when using selenium to scrape the web40        allow_downloads (bool): Whether to allow Auto-GPT to download files natively41        skips_news (bool): Whether to suppress the output of latest news on startup42    """43    CFG.set_debug_mode(False)44    CFG.set_continuous_mode(False)45    CFG.set_speak_mode(False)46 47    if debug:48        logger.typewriter_log("Debug Mode: ", Fore.GREEN, "ENABLED")49        CFG.set_debug_mode(True)50 51    if continuous:52        logger.typewriter_log("Continuous Mode: ", Fore.RED, "ENABLED")53        logger.typewriter_log(54            "WARNING: ",55            Fore.RED,56            "Continuous mode is not recommended. It is potentially dangerous and may"57            " cause your AI to run forever or carry out actions you would not usually"58            " authorise. Use at your own risk.",59        )60        CFG.set_continuous_mode(True)61 62        if continuous_limit:63            logger.typewriter_log(64                "Continuous Limit: ", Fore.GREEN, f"{continuous_limit}"65            )66            CFG.set_continuous_limit(continuous_limit)67 68    # Check if continuous limit is used without continuous mode69    if continuous_limit and not continuous:70        raise click.UsageError("--continuous-limit can only be used with --continuous")71 72    if speak:73        logger.typewriter_log("Speak Mode: ", Fore.GREEN, "ENABLED")74        CFG.set_speak_mode(True)75 76    if gpt3only:77        logger.typewriter_log("GPT3.5 Only Mode: ", Fore.GREEN, "ENABLED")78        CFG.set_smart_llm_model(CFG.fast_llm_model)79 80    if gpt4only:81        logger.typewriter_log("GPT4 Only Mode: ", Fore.GREEN, "ENABLED")82        CFG.set_fast_llm_model(CFG.smart_llm_model)83 84    if memory_type:85        supported_memory = get_supported_memory_backends()86        chosen = memory_type87        if chosen not in supported_memory:88            logger.typewriter_log(89                "ONLY THE FOLLOWING MEMORY BACKENDS ARE SUPPORTED: ",90                Fore.RED,91                f"{supported_memory}",92            )93            logger.typewriter_log("Defaulting to: ", Fore.YELLOW, CFG.memory_backend)94        else:95            CFG.memory_backend = chosen96 97    if skip_reprompt:98        logger.typewriter_log("Skip Re-prompt: ", Fore.GREEN, "ENABLED")99        CFG.skip_reprompt = True100 101    if ai_settings_file:102        file = ai_settings_file103 104        # Validate file105        (validated, message) = utils.validate_yaml_file(file)106        if not validated:107            logger.typewriter_log("FAILED FILE VALIDATION", Fore.RED, message)108            logger.double_check()109            exit(1)110 111        logger.typewriter_log("Using AI Settings File:", Fore.GREEN, file)112        CFG.ai_settings_file = file113        CFG.skip_reprompt = True114 115    if allow_downloads:116        logger.typewriter_log("Native Downloading:", Fore.GREEN, "ENABLED")117        logger.typewriter_log(118            "WARNING: ",119            Fore.YELLOW,120            f"{Back.LIGHTYELLOW_EX}Auto-GPT will now be able to download and save files to your machine.{Back.RESET} "121            + "It is recommended that you monitor any files it downloads carefully.",122        )123        logger.typewriter_log(124            "WARNING: ",125            Fore.YELLOW,126            f"{Back.RED + Style.BRIGHT}ALWAYS REMEMBER TO NEVER OPEN FILES YOU AREN'T SURE OF!{Style.RESET_ALL}",127        )128        CFG.allow_downloads = True129 130    if skip_news:131        CFG.skip_news = True132 133    if browser_name:134        CFG.selenium_web_browser = browser_name135