mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-17 05:54:26 +01:00
refactor(agent): Remove redundant parsing functions in config classes
Pydantic has built-in typecasting logic, so converting to Python builtin types and enums is done automatically.
This commit is contained in:
@@ -63,10 +63,7 @@ class Config(SystemSettings, arbitrary_types_allowed=True):
|
|||||||
|
|
||||||
# File storage
|
# File storage
|
||||||
file_storage_backend: FileStorageBackendName = UserConfigurable(
|
file_storage_backend: FileStorageBackendName = UserConfigurable(
|
||||||
default=FileStorageBackendName.LOCAL,
|
default=FileStorageBackendName.LOCAL, from_env="FILE_STORAGE_BACKEND"
|
||||||
from_env=lambda: FileStorageBackendName(v)
|
|
||||||
if (v := os.getenv("FILE_STORAGE_BACKEND"))
|
|
||||||
else None,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
##########################
|
##########################
|
||||||
@@ -74,27 +71,23 @@ class Config(SystemSettings, arbitrary_types_allowed=True):
|
|||||||
##########################
|
##########################
|
||||||
# Paths
|
# Paths
|
||||||
ai_settings_file: Path = UserConfigurable(
|
ai_settings_file: Path = UserConfigurable(
|
||||||
default=AI_SETTINGS_FILE,
|
default=AI_SETTINGS_FILE, from_env="AI_SETTINGS_FILE"
|
||||||
from_env=lambda: Path(f) if (f := os.getenv("AI_SETTINGS_FILE")) else None,
|
|
||||||
)
|
)
|
||||||
prompt_settings_file: Path = UserConfigurable(
|
prompt_settings_file: Path = UserConfigurable(
|
||||||
default=PROMPT_SETTINGS_FILE,
|
default=PROMPT_SETTINGS_FILE,
|
||||||
from_env=lambda: Path(f) if (f := os.getenv("PROMPT_SETTINGS_FILE")) else None,
|
from_env="PROMPT_SETTINGS_FILE",
|
||||||
)
|
)
|
||||||
|
|
||||||
# Model configuration
|
# Model configuration
|
||||||
fast_llm: str = UserConfigurable(
|
fast_llm: str = UserConfigurable(
|
||||||
default="gpt-3.5-turbo-0125",
|
default="gpt-3.5-turbo-0125",
|
||||||
from_env=lambda: os.getenv("FAST_LLM"),
|
from_env="FAST_LLM",
|
||||||
)
|
)
|
||||||
smart_llm: str = UserConfigurable(
|
smart_llm: str = UserConfigurable(
|
||||||
default="gpt-4-turbo-preview",
|
default="gpt-4-turbo-preview",
|
||||||
from_env=lambda: os.getenv("SMART_LLM"),
|
from_env="SMART_LLM",
|
||||||
)
|
|
||||||
temperature: float = UserConfigurable(
|
|
||||||
default=0,
|
|
||||||
from_env=lambda: float(v) if (v := os.getenv("TEMPERATURE")) else None,
|
|
||||||
)
|
)
|
||||||
|
temperature: float = UserConfigurable(default=0, from_env="TEMPERATURE")
|
||||||
openai_functions: bool = UserConfigurable(
|
openai_functions: bool = UserConfigurable(
|
||||||
default=False, from_env=lambda: os.getenv("OPENAI_FUNCTIONS", "False") == "True"
|
default=False, from_env=lambda: os.getenv("OPENAI_FUNCTIONS", "False") == "True"
|
||||||
)
|
)
|
||||||
@@ -115,10 +108,7 @@ class Config(SystemSettings, arbitrary_types_allowed=True):
|
|||||||
memory_backend: str = UserConfigurable("json_file", from_env="MEMORY_BACKEND")
|
memory_backend: str = UserConfigurable("json_file", from_env="MEMORY_BACKEND")
|
||||||
memory_index: str = UserConfigurable("auto-gpt-memory", from_env="MEMORY_INDEX")
|
memory_index: str = UserConfigurable("auto-gpt-memory", from_env="MEMORY_INDEX")
|
||||||
redis_host: str = UserConfigurable("localhost", from_env="REDIS_HOST")
|
redis_host: str = UserConfigurable("localhost", from_env="REDIS_HOST")
|
||||||
redis_port: int = UserConfigurable(
|
redis_port: int = UserConfigurable(default=6379, from_env="REDIS_PORT")
|
||||||
default=6379,
|
|
||||||
from_env=lambda: int(v) if (v := os.getenv("REDIS_PORT")) else None,
|
|
||||||
)
|
|
||||||
redis_password: str = UserConfigurable("", from_env="REDIS_PASSWORD")
|
redis_password: str = UserConfigurable("", from_env="REDIS_PASSWORD")
|
||||||
wipe_redis_on_start: bool = UserConfigurable(
|
wipe_redis_on_start: bool = UserConfigurable(
|
||||||
default=True,
|
default=True,
|
||||||
@@ -170,10 +160,7 @@ class Config(SystemSettings, arbitrary_types_allowed=True):
|
|||||||
sd_webui_url: Optional[str] = UserConfigurable(
|
sd_webui_url: Optional[str] = UserConfigurable(
|
||||||
default="http://localhost:7860", from_env="SD_WEBUI_URL"
|
default="http://localhost:7860", from_env="SD_WEBUI_URL"
|
||||||
)
|
)
|
||||||
image_size: int = UserConfigurable(
|
image_size: int = UserConfigurable(default=256, from_env="IMAGE_SIZE")
|
||||||
default=256,
|
|
||||||
from_env=lambda: int(v) if (v := os.getenv("IMAGE_SIZE")) else None,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Audio to text
|
# Audio to text
|
||||||
audio_to_text_provider: str = UserConfigurable(
|
audio_to_text_provider: str = UserConfigurable(
|
||||||
@@ -198,8 +185,7 @@ class Config(SystemSettings, arbitrary_types_allowed=True):
|
|||||||
###################
|
###################
|
||||||
plugins_dir: str = UserConfigurable("plugins", from_env="PLUGINS_DIR")
|
plugins_dir: str = UserConfigurable("plugins", from_env="PLUGINS_DIR")
|
||||||
plugins_config_file: Path = UserConfigurable(
|
plugins_config_file: Path = UserConfigurable(
|
||||||
default=PLUGINS_CONFIG_FILE,
|
default=PLUGINS_CONFIG_FILE, from_env="PLUGINS_CONFIG_FILE"
|
||||||
from_env=lambda: Path(f) if (f := os.getenv("PLUGINS_CONFIG_FILE")) else None,
|
|
||||||
)
|
)
|
||||||
plugins_config: PluginsConfig = Field(
|
plugins_config: PluginsConfig = Field(
|
||||||
default_factory=lambda: PluginsConfig(plugins={})
|
default_factory=lambda: PluginsConfig(plugins={})
|
||||||
@@ -223,8 +209,7 @@ class Config(SystemSettings, arbitrary_types_allowed=True):
|
|||||||
# OpenAI
|
# OpenAI
|
||||||
openai_credentials: Optional[OpenAICredentials] = None
|
openai_credentials: Optional[OpenAICredentials] = None
|
||||||
azure_config_file: Optional[Path] = UserConfigurable(
|
azure_config_file: Optional[Path] = UserConfigurable(
|
||||||
default=AZURE_CONFIG_FILE,
|
default=AZURE_CONFIG_FILE, from_env="AZURE_CONFIG_FILE"
|
||||||
from_env=lambda: Path(f) if (f := os.getenv("AZURE_CONFIG_FILE")) else None,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Github
|
# Github
|
||||||
@@ -234,7 +219,7 @@ class Config(SystemSettings, arbitrary_types_allowed=True):
|
|||||||
# Google
|
# Google
|
||||||
google_api_key: Optional[str] = UserConfigurable(from_env="GOOGLE_API_KEY")
|
google_api_key: Optional[str] = UserConfigurable(from_env="GOOGLE_API_KEY")
|
||||||
google_custom_search_engine_id: Optional[str] = UserConfigurable(
|
google_custom_search_engine_id: Optional[str] = UserConfigurable(
|
||||||
from_env=lambda: os.getenv("GOOGLE_CUSTOM_SEARCH_ENGINE_ID"),
|
from_env="GOOGLE_CUSTOM_SEARCH_ENGINE_ID",
|
||||||
)
|
)
|
||||||
|
|
||||||
# Huggingface
|
# Huggingface
|
||||||
|
|||||||
@@ -29,9 +29,7 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
class S3FileStorageConfiguration(FileStorageConfiguration):
|
class S3FileStorageConfiguration(FileStorageConfiguration):
|
||||||
bucket: str = UserConfigurable("autogpt", from_env="STORAGE_BUCKET")
|
bucket: str = UserConfigurable("autogpt", from_env="STORAGE_BUCKET")
|
||||||
s3_endpoint_url: Optional[SecretStr] = UserConfigurable(
|
s3_endpoint_url: Optional[SecretStr] = UserConfigurable(from_env="S3_ENDPOINT_URL")
|
||||||
from_env=lambda: SecretStr(v) if (v := os.getenv("S3_ENDPOINT_URL")) else None
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class S3FileStorage(FileStorage):
|
class S3FileStorage(FileStorage):
|
||||||
|
|||||||
@@ -57,8 +57,7 @@ class LoggingConfig(SystemConfiguration):
|
|||||||
|
|
||||||
# Console output
|
# Console output
|
||||||
log_format: LogFormatName = UserConfigurable(
|
log_format: LogFormatName = UserConfigurable(
|
||||||
default=LogFormatName.SIMPLE,
|
default=LogFormatName.SIMPLE, from_env="LOG_FORMAT"
|
||||||
from_env=lambda: LogFormatName(os.getenv("LOG_FORMAT", "simple")),
|
|
||||||
)
|
)
|
||||||
plain_console_output: bool = UserConfigurable(
|
plain_console_output: bool = UserConfigurable(
|
||||||
default=False,
|
default=False,
|
||||||
@@ -69,8 +68,8 @@ class LoggingConfig(SystemConfiguration):
|
|||||||
log_dir: Path = LOG_DIR
|
log_dir: Path = LOG_DIR
|
||||||
log_file_format: Optional[LogFormatName] = UserConfigurable(
|
log_file_format: Optional[LogFormatName] = UserConfigurable(
|
||||||
default=LogFormatName.SIMPLE,
|
default=LogFormatName.SIMPLE,
|
||||||
from_env=lambda: LogFormatName(
|
from_env=lambda: os.getenv(
|
||||||
os.getenv("LOG_FILE_FORMAT", os.getenv("LOG_FORMAT", "simple"))
|
"LOG_FILE_FORMAT", os.getenv("LOG_FORMAT", "simple")
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user