From 59f353ae0612ebb2ee7ce69955ec2c96a195a03f Mon Sep 17 00:00:00 2001 From: James Collins Date: Sat, 8 Jul 2023 08:56:45 -0700 Subject: [PATCH] Organize the configuration args (#4913) * Organize the configuration args * Remove duplication in setting config defaults --------- Co-authored-by: Reinier van der Leer --- autogpt/config/config.py | 233 +++++++++++++++++++-------------------- 1 file changed, 112 insertions(+), 121 deletions(-) diff --git a/autogpt/config/config.py b/autogpt/config/config.py index 05590eb6..7cb578ed 100644 --- a/autogpt/config/config.py +++ b/autogpt/config/config.py @@ -8,83 +8,130 @@ from typing import Dict, Optional, Union import yaml from colorama import Fore +from pydantic import Field from autogpt.core.configuration.schema import Configurable, SystemSettings from autogpt.plugins.plugins_config import PluginsConfig AZURE_CONFIG_FILE = os.path.join(os.path.dirname(__file__), "../..", "azure.yaml") +PLUGINS_CONFIG_FILE = os.path.join( + os.path.dirname(__file__), "../..", "plugins_config.yaml" +) GPT_4_MODEL = "gpt-4" GPT_3_MODEL = "gpt-3.5-turbo" class Config(SystemSettings): - fast_llm: str - smart_llm: str - continuous_mode: bool - skip_news: bool + name: str = "Auto-GPT configuration" + description: str = "Default configuration for the Auto-GPT application." + ######################## + # Application Settings # + ######################## + skip_news: bool = False + skip_reprompt: bool = False + authorise_key: str = "y" + exit_key: str = "n" + debug_mode: bool = False + plain_output: bool = False + chat_messages_enabled: bool = True + # TTS configuration + speak_mode: bool = False + text_to_speech_provider: str = "gtts" + streamelements_voice: str = "Brian" + elevenlabs_voice_id: Optional[str] = None + + ########################## + # Agent Control Settings # + ########################## + # Paths + ai_settings_file: str = "ai_settings.yaml" + prompt_settings_file: str = "prompt_settings.yaml" workspace_path: Optional[str] = None file_logger_path: Optional[str] = None - debug_mode: bool - plugins_dir: str - plugins_config: PluginsConfig - continuous_limit: int - speak_mode: bool - skip_reprompt: bool - allow_downloads: bool - exit_key: str - plain_output: bool - disabled_command_categories: list[str] - shell_command_control: str - shell_denylist: list[str] - shell_allowlist: list[str] - ai_settings_file: str - prompt_settings_file: str - embedding_model: str - browse_spacy_language_model: str + # Model configuration + fast_llm: str = "gpt-3.5-turbo" + smart_llm: str = "gpt-4" + temperature: float = 0 + openai_functions: bool = False + embedding_model: str = "text-embedding-ada-002" + browse_spacy_language_model: str = "en_core_web_sm" + # Run loop configuration + continuous_mode: bool = False + continuous_limit: int = 0 + + ########## + # Memory # + ########## + memory_backend: str = "json_file" + memory_index: str = "auto-gpt-memory" + redis_host: str = "localhost" + redis_port: int = 6379 + redis_password: str = "" + wipe_redis_on_start: bool = True + + ############ + # Commands # + ############ + # General + disabled_command_categories: list[str] = Field(default_factory=list) + # File ops + restrict_to_workspace: bool = True + allow_downloads: bool = False + # Shell commands + shell_command_control: str = "denylist" + execute_local_commands: bool = False + shell_denylist: list[str] = Field(default_factory=lambda: ["sudo", "su"]) + shell_allowlist: list[str] = Field(default_factory=list) + # Text to image + image_provider: Optional[str] = None + huggingface_image_model: str = "CompVis/stable-diffusion-v1-4" + sd_webui_url: Optional[str] = "http://localhost:7860" + image_size: int = 256 + # Audio to text + audio_to_text_provider: str = "huggingface" + huggingface_audio_to_text_model: Optional[str] = None + # Web browsing + selenium_web_browser: str = "chrome" + selenium_headless: bool = True + user_agent: str = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36" + + ################### + # Plugin Settings # + ################### + plugins_dir: str = "plugins" + plugins_config_file: str = PLUGINS_CONFIG_FILE + plugins_config: PluginsConfig = Field( + default_factory=lambda: PluginsConfig(plugins={}) + ) + plugins: list[str] = Field(default_factory=list) + plugins_allowlist: list[str] = Field(default_factory=list) + plugins_denylist: list[str] = Field(default_factory=list) + plugins_openai: list[str] = Field(default_factory=list) + + ############### + # Credentials # + ############### + # OpenAI openai_api_key: Optional[str] = None - openai_organization: Optional[str] = None - temperature: float - use_azure: bool - azure_config_file: Optional[str] = None - azure_model_to_deployment_id_map: Optional[Dict[str, str]] = None - execute_local_commands: bool - restrict_to_workspace: bool openai_api_type: Optional[str] = None openai_api_base: Optional[str] = None openai_api_version: Optional[str] = None - openai_functions: bool + openai_organization: Optional[str] = None + use_azure: bool = False + azure_config_file: Optional[str] = AZURE_CONFIG_FILE + azure_model_to_deployment_id_map: Optional[Dict[str, str]] = None + # Elevenlabs elevenlabs_api_key: Optional[str] = None - streamelements_voice: str - text_to_speech_provider: str + # Github github_api_key: Optional[str] = None github_username: Optional[str] = None + # Google google_api_key: Optional[str] = None google_custom_search_engine_id: Optional[str] = None - image_provider: Optional[str] = None - image_size: int + # Huggingface huggingface_api_token: Optional[str] = None - huggingface_image_model: str - audio_to_text_provider: str - huggingface_audio_to_text_model: Optional[str] = None - sd_webui_url: Optional[str] = None + # Stable Diffusion sd_webui_auth: Optional[str] = None - selenium_web_browser: str - selenium_headless: bool - user_agent: str - memory_backend: str - memory_index: str - redis_host: str - redis_port: int - redis_password: str - wipe_redis_on_start: bool - plugins_allowlist: list[str] - plugins_denylist: list[str] - plugins_openai: list[str] - plugins_config_file: str - chat_messages_enabled: bool - elevenlabs_voice_id: Optional[str] = None - plugins: list[str] - authorise_key: str def get_azure_kwargs(self, model: str) -> dict[str, str]: """Get the kwargs for the Azure API.""" @@ -138,73 +185,7 @@ class Config(SystemSettings): class ConfigBuilder(Configurable[Config]): - default_plugins_config_file = os.path.join( - os.path.dirname(os.path.abspath(__file__)), "..", "..", "plugins_config.yaml" - ) - - elevenlabs_api_key = os.getenv("ELEVENLABS_API_KEY") - if os.getenv("USE_MAC_OS_TTS"): - default_tts_provider = "macos" - elif elevenlabs_api_key: - default_tts_provider = "elevenlabs" - elif os.getenv("USE_BRIAN_TTS"): - default_tts_provider = "streamelements" - else: - default_tts_provider = "gtts" - - default_settings = Config( - name="Default Server Config", - description="This is a default server configuration", - smart_llm="gpt-4", - fast_llm="gpt-3.5-turbo", - continuous_mode=False, - continuous_limit=0, - skip_news=False, - debug_mode=False, - plugins_dir="plugins", - plugins_config=PluginsConfig(plugins={}), - speak_mode=False, - skip_reprompt=False, - allow_downloads=False, - exit_key="n", - plain_output=False, - disabled_command_categories=[], - shell_command_control="denylist", - shell_denylist=["sudo", "su"], - shell_allowlist=[], - ai_settings_file="ai_settings.yaml", - prompt_settings_file="prompt_settings.yaml", - embedding_model="text-embedding-ada-002", - browse_spacy_language_model="en_core_web_sm", - temperature=0, - use_azure=False, - azure_config_file=AZURE_CONFIG_FILE, - execute_local_commands=False, - restrict_to_workspace=True, - openai_functions=False, - streamelements_voice="Brian", - text_to_speech_provider=default_tts_provider, - image_size=256, - huggingface_image_model="CompVis/stable-diffusion-v1-4", - audio_to_text_provider="huggingface", - sd_webui_url="http://localhost:7860", - selenium_web_browser="chrome", - selenium_headless=True, - user_agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36", - memory_backend="json_file", - memory_index="auto-gpt-memory", - redis_host="localhost", - redis_port=6379, - wipe_redis_on_start=True, - plugins_allowlist=[], - plugins_denylist=[], - plugins_openai=[], - plugins_config_file=default_plugins_config_file, - chat_messages_enabled=True, - plugins=[], - authorise_key="y", - redis_password="", - ) + default_settings = Config() @classmethod def build_config_from_env(cls) -> Config: @@ -274,6 +255,16 @@ class ConfigBuilder(Configurable[Config]): config_dict["elevenlabs_voice_id"] = os.getenv( "ELEVENLABS_VOICE_ID", os.getenv("ELEVENLABS_VOICE_1_ID") ) + elevenlabs_api_key = os.getenv("ELEVENLABS_API_KEY") + if os.getenv("USE_MAC_OS_TTS"): + default_tts_provider = "macos" + elif elevenlabs_api_key: + default_tts_provider = "elevenlabs" + elif os.getenv("USE_BRIAN_TTS"): + default_tts_provider = "streamelements" + else: + default_tts_provider = "gtts" + config_dict["text_to_speech_provider"] = default_tts_provider config_dict["plugins_allowlist"] = _safe_split(os.getenv("ALLOWLISTED_PLUGINS")) config_dict["plugins_denylist"] = _safe_split(os.getenv("DENYLISTED_PLUGINS"))