AutoGPT: Clean up paths in config

This commit is contained in:
Reinier van der Leer
2023-10-07 16:43:28 -07:00
parent 69de6c0467
commit 34f2229479
9 changed files with 30 additions and 35 deletions

View File

@@ -11,7 +11,6 @@ from autogpt.memory.vector import get_memory
from autogpt.models.command_registry import CommandRegistry
from autogpt.workspace import Workspace
PROJECT_DIR = Path().resolve()
LOG_DIR = Path(__file__).parent / "logs"
@@ -21,7 +20,7 @@ def run_specific_agent(task: str, continuous_mode: bool = False) -> None:
def bootstrap_agent(task: str, continuous_mode: bool) -> Agent:
config = ConfigBuilder.build_config_from_env(workdir=PROJECT_DIR)
config = ConfigBuilder.build_config_from_env()
config.debug_mode = False
config.continuous_mode = continuous_mode
config.continuous_limit = 20

View File

@@ -134,9 +134,6 @@ def main(
browser_name=browser_name,
allow_downloads=allow_downloads,
skip_news=skip_news,
working_directory=Path(
__file__
).parent.parent.parent, # TODO: make this an option
workspace_directory=workspace_directory,
install_plugin_deps=install_plugin_deps,
ai_name=ai_name,

View File

@@ -131,7 +131,7 @@ def apply_overrides_to_config(
exit(1)
print_attribute("Using AI Settings File", file)
config.ai_settings_file = file
config.ai_settings_file = config.project_root / file
config.skip_reprompt = True
if prompt_settings_file:
@@ -145,7 +145,7 @@ def apply_overrides_to_config(
exit(1)
print_attribute("Using Prompt Settings File", file)
config.prompt_settings_file = file
config.prompt_settings_file = config.project_root / file
if browser_name:
config.selenium_web_browser = browser_name

View File

@@ -69,7 +69,7 @@ async def run_auto_gpt(
ai_role: Optional[str] = None,
ai_goals: tuple[str] = tuple(),
):
config = ConfigBuilder.build_config_from_env(workdir=working_directory)
config = ConfigBuilder.build_config_from_env()
# TODO: fill in llm values here
assert_config_has_openai_api_key(config)

View File

@@ -12,11 +12,13 @@ from auto_gpt_plugin_template import AutoGPTPluginTemplate
from colorama import Fore
from pydantic import Field, validator
import autogpt
from autogpt.core.configuration.schema import Configurable, SystemSettings
from autogpt.core.resource.model_providers.openai import OPEN_AI_CHAT_MODELS
from autogpt.plugins.plugins_config import PluginsConfig
from autogpt.speech import TTSConfig
PROJECT_ROOT = Path(autogpt.__file__).parent.parent
AI_SETTINGS_FILE = Path("ai_settings.yaml")
AZURE_CONFIG_FILE = Path("azure.yaml")
PLUGINS_CONFIG_FILE = Path("plugins_config.yaml")
@@ -32,7 +34,8 @@ class Config(SystemSettings, arbitrary_types_allowed=True):
########################
# Application Settings #
########################
workdir: Path = None
project_root: Path = PROJECT_ROOT
app_data_dir: Path = project_root / "data"
skip_news: bool = False
skip_reprompt: bool = False
authorise_key: str = "y"
@@ -48,8 +51,8 @@ class Config(SystemSettings, arbitrary_types_allowed=True):
# Agent Control Settings #
##########################
# Paths
ai_settings_file: Path = AI_SETTINGS_FILE
prompt_settings_file: Path = PROMPT_SETTINGS_FILE
ai_settings_file: Path = project_root / AI_SETTINGS_FILE
prompt_settings_file: Path = project_root / PROMPT_SETTINGS_FILE
workspace_path: Optional[Path] = None
file_logger_path: Optional[Path] = None
# Model configuration
@@ -103,7 +106,7 @@ class Config(SystemSettings, arbitrary_types_allowed=True):
# Plugin Settings #
###################
plugins_dir: str = "plugins"
plugins_config_file: Path = PLUGINS_CONFIG_FILE
plugins_config_file: Path = project_root / PLUGINS_CONFIG_FILE
plugins_config: PluginsConfig = Field(
default_factory=lambda: PluginsConfig(plugins={})
)
@@ -122,7 +125,7 @@ class Config(SystemSettings, arbitrary_types_allowed=True):
openai_api_version: Optional[str] = None
openai_organization: Optional[str] = None
use_azure: bool = False
azure_config_file: Optional[Path] = AZURE_CONFIG_FILE
azure_config_file: Optional[Path] = project_root / AZURE_CONFIG_FILE
azure_model_to_deployment_id_map: Optional[Dict[str, str]] = None
# Github
github_api_key: Optional[str] = None
@@ -221,27 +224,26 @@ class ConfigBuilder(Configurable[Config]):
default_settings = Config()
@classmethod
def build_config_from_env(cls, workdir: Path) -> Config:
def build_config_from_env(cls, project_root: Path = PROJECT_ROOT) -> Config:
"""Initialize the Config class"""
config_dict = {
"workdir": workdir,
"project_root": project_root,
"authorise_key": os.getenv("AUTHORISE_COMMAND_KEY"),
"exit_key": os.getenv("EXIT_KEY"),
"plain_output": os.getenv("PLAIN_OUTPUT", "False") == "True",
"shell_command_control": os.getenv("SHELL_COMMAND_CONTROL"),
"ai_settings_file": Path(os.getenv("AI_SETTINGS_FILE", AI_SETTINGS_FILE)),
"prompt_settings_file": Path(
os.getenv("PROMPT_SETTINGS_FILE", PROMPT_SETTINGS_FILE)
),
"ai_settings_file": project_root
/ Path(os.getenv("AI_SETTINGS_FILE", AI_SETTINGS_FILE)),
"prompt_settings_file": project_root
/ Path(os.getenv("PROMPT_SETTINGS_FILE", PROMPT_SETTINGS_FILE)),
"fast_llm": os.getenv("FAST_LLM", os.getenv("FAST_LLM_MODEL")),
"smart_llm": os.getenv("SMART_LLM", os.getenv("SMART_LLM_MODEL")),
"embedding_model": os.getenv("EMBEDDING_MODEL"),
"browse_spacy_language_model": os.getenv("BROWSE_SPACY_LANGUAGE_MODEL"),
"openai_api_key": os.getenv("OPENAI_API_KEY"),
"use_azure": os.getenv("USE_AZURE") == "True",
"azure_config_file": Path(
os.getenv("AZURE_CONFIG_FILE", AZURE_CONFIG_FILE)
),
"azure_config_file": project_root
/ Path(os.getenv("AZURE_CONFIG_FILE", AZURE_CONFIG_FILE)),
"execute_local_commands": os.getenv("EXECUTE_LOCAL_COMMANDS", "False")
== "True",
"restrict_to_workspace": os.getenv("RESTRICT_TO_WORKSPACE", "True")
@@ -271,9 +273,8 @@ class ConfigBuilder(Configurable[Config]):
"redis_password": os.getenv("REDIS_PASSWORD"),
"wipe_redis_on_start": os.getenv("WIPE_REDIS_ON_START", "True") == "True",
"plugins_dir": os.getenv("PLUGINS_DIR"),
"plugins_config_file": Path(
os.getenv("PLUGINS_CONFIG_FILE", PLUGINS_CONFIG_FILE)
),
"plugins_config_file": project_root
/ Path(os.getenv("PLUGINS_CONFIG_FILE", PLUGINS_CONFIG_FILE)),
"chat_messages_enabled": os.getenv("CHAT_MESSAGES_ENABLED") == "True",
}
@@ -325,7 +326,7 @@ class ConfigBuilder(Configurable[Config]):
if config_dict["use_azure"]:
azure_config = cls.load_azure_config(
workdir / config_dict["azure_config_file"]
project_root / config_dict["azure_config_file"]
)
config_dict.update(azure_config)
@@ -345,7 +346,7 @@ class ConfigBuilder(Configurable[Config]):
# Set secondary config variables (that depend on other config variables)
config.plugins_config = PluginsConfig.load_config(
config.workdir / config.plugins_config_file,
config.plugins_config_file,
config.plugins_denylist,
config.plugins_allowlist,
)

View File

@@ -13,8 +13,6 @@ from autogpt.models.command_registry import CommandRegistry
from autogpt.prompts.prompt import DEFAULT_TRIGGERING_PROMPT
from autogpt.workspace import Workspace
PROJECT_DIR = Path().resolve()
async def task_handler(task_input) -> StepHandler:
task = task_input.__root__ if task_input else {}
@@ -82,7 +80,7 @@ async def interaction_step(
def bootstrap_agent(task, continuous_mode) -> Agent:
config = ConfigBuilder.build_config_from_env(workdir=PROJECT_DIR)
config = ConfigBuilder.build_config_from_env()
config.debug_mode = True
config.continuous_mode = continuous_mode
config.temperature = 0

View File

@@ -47,7 +47,7 @@ def temp_plugins_config_file():
@pytest.fixture()
def config(temp_plugins_config_file: Path, mocker: MockerFixture, workspace: Workspace):
config = ConfigBuilder.build_config_from_env(workspace.root.parent)
config = ConfigBuilder.build_config_from_env(project_root=workspace.root.parent)
if not os.environ.get("OPENAI_API_KEY"):
os.environ["OPENAI_API_KEY"] = "sk-dummy"
@@ -63,7 +63,7 @@ def config(temp_plugins_config_file: Path, mocker: MockerFixture, workspace: Wor
from autogpt.plugins.plugins_config import PluginsConfig
config.plugins_config = PluginsConfig.load_config(
plugins_config_file=config.workdir / config.plugins_config_file,
plugins_config_file=config.plugins_config_file,
plugins_denylist=config.plugins_denylist,
plugins_allowlist=config.plugins_allowlist,
)

View File

@@ -151,7 +151,7 @@ azure_model_map:
os.environ["USE_AZURE"] = "True"
os.environ["AZURE_CONFIG_FILE"] = str(config_file)
config = ConfigBuilder.build_config_from_env(workspace.root.parent)
config = ConfigBuilder.build_config_from_env(project_root=workspace.root.parent)
assert config.openai_api_type == "azure"
assert config.openai_api_base == "https://dummy.openai.azure.com"

View File

@@ -71,7 +71,7 @@ def test_create_base_config(config: Config):
os.remove(config.plugins_config_file)
plugins_config = PluginsConfig.load_config(
plugins_config_file=config.workdir / config.plugins_config_file,
plugins_config_file=config.plugins_config_file,
plugins_denylist=config.plugins_denylist,
plugins_allowlist=config.plugins_allowlist,
)
@@ -107,7 +107,7 @@ def test_load_config(config: Config):
# Load the config from disk
plugins_config = PluginsConfig.load_config(
plugins_config_file=config.workdir / config.plugins_config_file,
plugins_config_file=config.plugins_config_file,
plugins_denylist=config.plugins_denylist,
plugins_allowlist=config.plugins_allowlist,
)